xref: /titanic_51/usr/src/cmd/refer/deliv2.c (revision 1bdd6c0e3710e91cb1f31aa78de33cb638494480)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
16 
17 
18 #include <stdio.h>
19 #include <locale.h>
20 
21 int
22 hash(char *s)
23 {
24 	int c, n;
25 	for (n = 0; c = *s; s++)
26 		n += (c*n+ c << (n%4));
27 	return (n > 0 ? n : -n);
28 }
29 
30 void
31 err(char *s, int a)
32 {
33 	fprintf(stderr, gettext("Error: "));
34 	fprintf(stderr, s, a);
35 	putc('\n', stderr);
36 	exit(1);
37 }
38 
39 int
40 prefix(char *t, char *s)
41 {
42 	int c;
43 
44 	while ((c = *t++) == *s++)
45 		if (c == 0)
46 			return (1);
47 	return (c == 0 ? 1 : 0);
48 }
49 
50 char *
51 mindex(char *s, char c)
52 {
53 	char *p;
54 	for (p = s; *p; p++)
55 		if (*p == c)
56 			return (p);
57 	return (0);
58 }
59 
60 void *
61 zalloc(size_t m, size_t n)
62 {
63 	char *calloc();
64 	void *t;
65 #if D1
66 	fprintf(stderr, "calling calloc for %d*%d bytes\n", m, n);
67 #endif
68 	t = calloc(m, n);
69 #if D1
70 	fprintf(stderr, "calloc returned %o\n", t);
71 #endif
72 	return (t);
73 }
74