Fix "ls: not found" problem during buildworld. mdate.sh script
[dragonfly.git] / games / trek / utility.c
blob973ebf3f15f59631569153086d45873dc4a838cf
1 /*
2 * Copyright (c) 1980, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
33 * @(#)utility.c 8.1 (Berkeley) 5/31/93
34 * $FreeBSD: src/games/trek/utility.c,v 1.5 1999/11/30 03:49:55 billf Exp $
35 * $DragonFly: src/games/trek/utility.c,v 1.3 2005/04/29 09:22:57 joerg Exp $
38 #include <errno.h>
41 ** ASSORTED UTILITY ROUTINES
45 ** BLOCK MOVE
47 ** Moves a block of storage of length `l' bytes from the data
48 ** area pointed to by `a' to the area pointed to by `b'.
49 ** Returns the address of the byte following the `b' field.
50 ** Overflow of `b' is not tested.
53 char *bmove(a, b, l)
54 char *a, *b;
55 int l;
57 int n;
58 char *p, *q;
60 p = a;
61 q = b;
62 n = l;
63 while (n--)
64 *q++ = *p++;
65 return (q);
70 ** STRING EQUALITY TEST
71 ** null-terminated strings `a' and `b' are tested for
72 ** absolute equality.
73 ** returns one if equal, zero otherwise.
76 sequal(a, b)
77 char *a, *b;
79 char *p, *q;
81 p = a;
82 q = b;
83 while (*p || *q)
84 if (*p++ != *q++)
85 return(0);
86 return(1);
91 ** STRING CONCATENATE
93 ** The strings `s1' and `s2' are concatenated and stored into
94 ** `s3'. It is ok for `s1' to equal `s3', but terrible things
95 ** will happen if `s2' equals `s3'. The return value is is a
96 ** pointer to the end of `s3' field.
99 char *concat(s1, s2, s3)
100 char *s1, *s2, *s3;
102 char *p;
103 char *q;
105 p = s3;
106 q = s1;
107 while (*q)
108 *p++ = *q++;
109 q = s2;
110 while (*q)
111 *p++ = *q++;
112 *p = 0;
113 return (p);
118 ** FIND STRING LENGTH
120 ** The length of string `s' (excluding the null byte which
121 ** terminates the string) is returned.
124 length(s)
125 char *s;
127 int l;
128 char *p;
130 l = 0;
131 p = s;
132 while (*p++)
133 l++;
134 return(l);
139 ** SYSTEM ERROR
142 syserr(p0, p1, p2, p3, p4, p5)
144 printf("\n\07TREK SYSERR: ");
145 printf(p0, p1, p2, p3, p4, p5);
146 printf("\n");
147 if (errno)
148 printf("\tsystem error %d\n", errno);
149 exit(1);