xref: /illumos-gate/usr/src/cmd/refer/deliv2.c (revision ddb365bfc9e868ad24ccdcb0dc91af18b10df082)
1 /*
2  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
7 /*	  All Rights Reserved  	*/
8 
9 /*
10  * Copyright (c) 1980 Regents of the University of California.
11  * All rights reserved. The Berkeley software License Agreement
12  * specifies the terms and conditions for redistribution.
13  */
14 
15 #include <stdio.h>
16 #include <locale.h>
17 
18 int
19 hash(char *s)
20 {
21 	int c, n;
22 	for (n = 0; c = *s; s++)
23 		n += (c*n+ c << (n%4));
24 	return (n > 0 ? n : -n);
25 }
26 
27 void
28 err(char *s, int a)
29 {
30 	fprintf(stderr, gettext("Error: "));
31 	fprintf(stderr, s, a);
32 	putc('\n', stderr);
33 	exit(1);
34 }
35 
36 int
37 prefix(char *t, char *s)
38 {
39 	int c;
40 
41 	while ((c = *t++) == *s++)
42 		if (c == 0)
43 			return (1);
44 	return (c == 0 ? 1 : 0);
45 }
46 
47 char *
48 mindex(char *s, char c)
49 {
50 	char *p;
51 	for (p = s; *p; p++)
52 		if (*p == c)
53 			return (p);
54 	return (0);
55 }
56 
57 void *
58 zalloc(size_t m, size_t n)
59 {
60 	char *calloc();
61 	void *t;
62 #if D1
63 	fprintf(stderr, "calling calloc for %d*%d bytes\n", m, n);
64 #endif
65 	t = calloc(m, n);
66 #if D1
67 	fprintf(stderr, "calloc returned %o\n", t);
68 #endif
69 	return (t);
70 }
71