xref: /illumos-gate/usr/src/cmd/refer/deliv2.c (revision 2a8bcb4e)
1*11a8fa6cSceastha /*
2*11a8fa6cSceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*11a8fa6cSceastha  * Use is subject to license terms.
4*11a8fa6cSceastha  */
5*11a8fa6cSceastha 
67c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
77c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate  */
147c478bd9Sstevel@tonic-gate 
157c478bd9Sstevel@tonic-gate #include <stdio.h>
167c478bd9Sstevel@tonic-gate #include <locale.h>
177c478bd9Sstevel@tonic-gate 
18*11a8fa6cSceastha int
hash(char * s)19*11a8fa6cSceastha hash(char *s)
207c478bd9Sstevel@tonic-gate {
217c478bd9Sstevel@tonic-gate 	int c, n;
22*11a8fa6cSceastha 	for (n = 0; c = *s; s++)
237c478bd9Sstevel@tonic-gate 		n += (c*n+ c << (n%4));
24*11a8fa6cSceastha 	return (n > 0 ? n : -n);
257c478bd9Sstevel@tonic-gate }
267c478bd9Sstevel@tonic-gate 
27*11a8fa6cSceastha void
err(char * s,int a)28*11a8fa6cSceastha err(char *s, int a)
297c478bd9Sstevel@tonic-gate {
307c478bd9Sstevel@tonic-gate 	fprintf(stderr, gettext("Error: "));
317c478bd9Sstevel@tonic-gate 	fprintf(stderr, s, a);
327c478bd9Sstevel@tonic-gate 	putc('\n', stderr);
337c478bd9Sstevel@tonic-gate 	exit(1);
347c478bd9Sstevel@tonic-gate }
357c478bd9Sstevel@tonic-gate 
36*11a8fa6cSceastha int
prefix(char * t,char * s)37*11a8fa6cSceastha prefix(char *t, char *s)
387c478bd9Sstevel@tonic-gate {
397c478bd9Sstevel@tonic-gate 	int c;
407c478bd9Sstevel@tonic-gate 
41*11a8fa6cSceastha 	while ((c = *t++) == *s++)
42*11a8fa6cSceastha 		if (c == 0)
43*11a8fa6cSceastha 			return (1);
44*11a8fa6cSceastha 	return (c == 0 ? 1 : 0);
457c478bd9Sstevel@tonic-gate }
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate char *
mindex(char * s,char c)48*11a8fa6cSceastha mindex(char *s, char c)
497c478bd9Sstevel@tonic-gate {
50*11a8fa6cSceastha 	char *p;
51*11a8fa6cSceastha 	for (p = s; *p; p++)
52*11a8fa6cSceastha 		if (*p == c)
53*11a8fa6cSceastha 			return (p);
54*11a8fa6cSceastha 	return (0);
557c478bd9Sstevel@tonic-gate }
567c478bd9Sstevel@tonic-gate 
57*11a8fa6cSceastha void *
zalloc(size_t m,size_t n)58*11a8fa6cSceastha zalloc(size_t m, size_t n)
597c478bd9Sstevel@tonic-gate {
607c478bd9Sstevel@tonic-gate 	char *calloc();
61*11a8fa6cSceastha 	void *t;
62*11a8fa6cSceastha #if D1
63*11a8fa6cSceastha 	fprintf(stderr, "calling calloc for %d*%d bytes\n", m, n);
64*11a8fa6cSceastha #endif
65*11a8fa6cSceastha 	t = calloc(m, n);
66*11a8fa6cSceastha #if D1
677c478bd9Sstevel@tonic-gate 	fprintf(stderr, "calloc returned %o\n", t);
68*11a8fa6cSceastha #endif
69*11a8fa6cSceastha 	return (t);
707c478bd9Sstevel@tonic-gate }
71