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