|
|
1.1 root 1: /*
2: * Copyright (c) 1980 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that the above copyright notice and this paragraph are
7: * duplicated in all such forms and that any documentation,
8: * advertising materials, and other materials related to such
9: * distribution and use acknowledge that the software was developed
10: * by the University of California, Berkeley. The name of the
11: * University may not be used to endorse or promote products derived
12: * from this software without specific prior written permission.
13: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15: * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16: */
17:
18: #ifndef lint
19: static char sccsid[] = "@(#)utility.c 5.3 (Berkeley) 6/18/88";
20: #endif /* not lint */
21:
22: /*
23: ** ASSORTED UTILITY ROUTINES
24: */
25:
26: /*
27: ** BLOCK MOVE
28: **
29: ** Moves a block of storage of length `l' bytes from the data
30: ** area pointed to by `a' to the area pointed to by `b'.
31: ** Returns the address of the byte following the `b' field.
32: ** Overflow of `b' is not tested.
33: */
34:
35: char *bmove(a, b, l)
36: char *a, *b;
37: int l;
38: {
39: register int n;
40: register char *p, *q;
41:
42: p = a;
43: q = b;
44: n = l;
45: while (n--)
46: *q++ = *p++;
47: return (q);
48: }
49:
50:
51: /*
52: ** STRING EQUALITY TEST
53: ** null-terminated strings `a' and `b' are tested for
54: ** absolute equality.
55: ** returns one if equal, zero otherwise.
56: */
57:
58: sequal(a, b)
59: char *a, *b;
60: {
61: register char *p, *q;
62:
63: p = a;
64: q = b;
65: while (*p || *q)
66: if (*p++ != *q++)
67: return(0);
68: return(1);
69: }
70:
71:
72: /*
73: ** STRING CONCATENATE
74: **
75: ** The strings `s1' and `s2' are concatenated and stored into
76: ** `s3'. It is ok for `s1' to equal `s3', but terrible things
77: ** will happen if `s2' equals `s3'. The return value is is a
78: ** pointer to the end of `s3' field.
79: */
80:
81: char *concat(s1, s2, s3)
82: char *s1, *s2, *s3;
83: {
84: register char *p;
85: register char *q;
86:
87: p = s3;
88: q = s1;
89: while (*q)
90: *p++ = *q++;
91: q = s2;
92: while (*q)
93: *p++ = *q++;
94: *p = 0;
95: return (p);
96: }
97:
98:
99: /*
100: ** FIND STRING LENGTH
101: **
102: ** The length of string `s' (excluding the null byte which
103: ** terminates the string) is returned.
104: */
105:
106: length(s)
107: char *s;
108: {
109: register int l;
110: register char *p;
111:
112: l = 0;
113: p = s;
114: while (*p++)
115: l++;
116: return(l);
117: }
118:
119:
120: /*
121: ** SYSTEM ERROR
122: */
123:
124: syserr(p0, p1, p2, p3, p4, p5)
125: {
126: extern int errno;
127:
128: printf("\n\07TREK SYSERR: ");
129: printf(p0, p1, p2, p3, p4, p5);
130: printf("\n");
131: if (errno)
132: printf("\tsystem error %d\n", errno);
133: exit(-1);
134: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.