1 /* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)utility.c 8.1 (Berkeley) 05/31/93"; 10 #endif /* not lint */ 11 12 /* 13 ** ASSORTED UTILITY ROUTINES 14 */ 15 16 /* 17 ** BLOCK MOVE 18 ** 19 ** Moves a block of storage of length `l' bytes from the data 20 ** area pointed to by `a' to the area pointed to by `b'. 21 ** Returns the address of the byte following the `b' field. 22 ** Overflow of `b' is not tested. 23 */ 24 25 char *bmove(a, b, l) 26 char *a, *b; 27 int l; 28 { 29 register int n; 30 register char *p, *q; 31 32 p = a; 33 q = b; 34 n = l; 35 while (n--) 36 *q++ = *p++; 37 return (q); 38 } 39 40 41 /* 42 ** STRING EQUALITY TEST 43 ** null-terminated strings `a' and `b' are tested for 44 ** absolute equality. 45 ** returns one if equal, zero otherwise. 46 */ 47 48 sequal(a, b) 49 char *a, *b; 50 { 51 register char *p, *q; 52 53 p = a; 54 q = b; 55 while (*p || *q) 56 if (*p++ != *q++) 57 return(0); 58 return(1); 59 } 60 61 62 /* 63 ** STRING CONCATENATE 64 ** 65 ** The strings `s1' and `s2' are concatenated and stored into 66 ** `s3'. It is ok for `s1' to equal `s3', but terrible things 67 ** will happen if `s2' equals `s3'. The return value is is a 68 ** pointer to the end of `s3' field. 69 */ 70 71 char *concat(s1, s2, s3) 72 char *s1, *s2, *s3; 73 { 74 register char *p; 75 register char *q; 76 77 p = s3; 78 q = s1; 79 while (*q) 80 *p++ = *q++; 81 q = s2; 82 while (*q) 83 *p++ = *q++; 84 *p = 0; 85 return (p); 86 } 87 88 89 /* 90 ** FIND STRING LENGTH 91 ** 92 ** The length of string `s' (excluding the null byte which 93 ** terminates the string) is returned. 94 */ 95 96 length(s) 97 char *s; 98 { 99 register int l; 100 register char *p; 101 102 l = 0; 103 p = s; 104 while (*p++) 105 l++; 106 return(l); 107 } 108 109 110 /* 111 ** SYSTEM ERROR 112 */ 113 114 syserr(p0, p1, p2, p3, p4, p5) 115 { 116 extern int errno; 117 118 printf("\n\07TREK SYSERR: "); 119 printf(p0, p1, p2, p3, p4, p5); 120 printf("\n"); 121 if (errno) 122 printf("\tsystem error %d\n", errno); 123 exit(-1); 124 } 125