xref: /csrg-svn/usr.sbin/sendmail/src/util.c (revision 1598)
1298Seric # include <sysexits.h>
2298Seric # include "useful.h"
3298Seric 
4*1598Seric static char	SccsId[] = "@(#)util.c	1.4	10/21/80";
5409Seric 
6298Seric /*
7298Seric **  STRIPQUOTES -- Strip quotes & quote bits from a string.
8298Seric **
9298Seric **	Runs through a string and strips off unquoted quote
10298Seric **	characters and quote bits.  This is done in place.
11298Seric **
12298Seric **	Parameters:
13298Seric **		s -- the string to strip.
14298Seric **
15298Seric **	Returns:
16298Seric **		none.
17298Seric **
18298Seric **	Side Effects:
19298Seric **		none.
20298Seric **
21298Seric **	Called By:
22298Seric **		deliver
23298Seric */
24298Seric 
25298Seric stripquotes(s)
26298Seric 	char *s;
27298Seric {
28298Seric 	register char *p;
29298Seric 	register char *q;
30298Seric 	register char c;
31298Seric 
32298Seric 	for (p = q = s; (c = *p++) != '\0'; )
33298Seric 	{
34298Seric 		if (c != '"')
35298Seric 			*q++ = c & 0177;
36298Seric 	}
37298Seric 	*q = '\0';
38298Seric }
39298Seric /*
40298Seric **  XALLOC -- Allocate memory and bitch wildly on failure.
41298Seric **
42298Seric **	THIS IS A CLUDGE.  This should be made to give a proper
43298Seric **	error -- but after all, what can we do?
44298Seric **
45298Seric **	Parameters:
46298Seric **		sz -- size of area to allocate.
47298Seric **
48298Seric **	Returns:
49298Seric **		pointer to data region.
50298Seric **
51298Seric **	Side Effects:
52298Seric **		Memory is allocated.
53298Seric **
54298Seric **	Called By:
55298Seric **		lots of people.
56298Seric */
57298Seric 
58298Seric char *
59298Seric xalloc(sz)
60298Seric 	register unsigned int sz;
61298Seric {
62298Seric 	register char *p;
63298Seric 	extern char *malloc();
64298Seric 
65298Seric 	p = malloc(sz);
66298Seric 	if (p == NULL)
67298Seric 	{
68298Seric 		syserr("Out of memory!!");
69*1598Seric 		exit(EX_UNAVAILABLE);
70298Seric 	}
71298Seric 	return (p);
72298Seric }
73298Seric /*
74298Seric **  ANY -- Return TRUE if the character exists in the string.
75298Seric **
76298Seric **	Parameters:
77298Seric **		c -- the character.
78298Seric **		s -- the string
79298Seric **			(sounds like an avant garde script)
80298Seric **
81298Seric **	Returns:
82298Seric **		TRUE -- if c could be found in s.
83298Seric **		FALSE -- otherwise.
84298Seric **
85298Seric **	Side Effects:
86298Seric **		none.
87298Seric **
88298Seric **	Called By:
89298Seric **		prescan
90298Seric */
91298Seric 
92298Seric any(c, s)
93298Seric 	register char c;
94298Seric 	register char *s;
95298Seric {
96298Seric 	register char c2;
97298Seric 
98298Seric 	while ((c2 = *s++) != '\0')
99298Seric 		if (c2 == c)
100298Seric 			return (TRUE);
101298Seric 	return (FALSE);
102298Seric }
103