1 /*
2  * Copyright (c) 1994 Cygnus Support.
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  * and/or other materials related to such
9  * distribution and use acknowledge that the software was developed
10  * at Cygnus Support, Inc.  Cygnus Support, Inc. may not be used to
11  * endorse or promote products derived from this software without
12  * 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 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
16  */
17 #include "test.h"
18 #include <string.h>
19 #include <errno.h>
20 
21 
22 /* Suppresses compiler warnings
23  *    As described by items in quotes
24  */
25 
26 #pragma GCC diagnostic ignored "-Wmemset-transposed-args"
27 #ifndef __clang__
28 #pragma GCC diagnostic ignored "-Wstringop-overflow="
29 #pragma GCC diagnostic ignored "-Wstringop-truncation"
30 #endif
31 #pragma GCC diagnostic ignored "-Warray-bounds"
32 
33 
34 const char *it = "<UNSET>";	/* Routine name for message routines. */
35 int  errors = 0;
36 
37 /* Complain if condition is not true.  */
38 #define check(thing) checkit(thing, __LINE__)
39 
40 void
checkit(int ok,int l)41 checkit (int ok,
42        int l )
43 
44 {
45   newfunc(it);
46   line(l);
47 
48   if (!ok)
49   {
50     printf("string.c:%d %s\n", l, it);
51     ++errors;
52   }
53 }
54 
55 
56 
57 /* Complain if first two args don't strcmp as equal.  */
58 #define equal(a, b)  funcqual(a,b,__LINE__);
59 
60 void
funcqual(char * a,char * b,int l)61 funcqual (char *a,
62        char *b,
63        int l)
64 {
65   newfunc(it);
66 
67   line(l);
68   if (a == NULL && b == NULL) return;
69   if (strcmp(a,b)) {
70       printf("string.c:%d (%s)\n", l, it);
71     }
72 }
73 
74 
75 
76 static char one[100];
77 static char two[50];
78 
79 
test_string(void)80 void test_string(void)
81 {
82   /* Test strcmp first because we use it to test other things.  */
83   it = "strcmp";
84   check(strcmp("", "") == 0); /* Trivial case. */
85   check(strcmp("a", "a") == 0); /* Identity. */
86   check(strcmp("abc", "abc") == 0); /* Multicharacter. */
87   check(strcmp("abc", "abcd") < 0); /* Length mismatches. */
88   check(strcmp("abcd", "abc") > 0);
89   check(strcmp("abcd", "abce") < 0);	/* Honest miscompares. */
90   check(strcmp("abce", "abcd") > 0);
91   check(strcmp("a\103", "a") > 0); /* Tricky if char signed. */
92   check(strcmp("a\103", "a\003") > 0);
93 
94   /* Test strcpy next because we need it to set up other tests.  */
95   it = "strcpy";
96   check(strcpy(one, "abcd") == one);	/* Returned value. */
97   equal(one, "abcd");	/* Basic test. */
98 
99   (void) strcpy(one, "x");
100   equal(one, "x");		/* Writeover. */
101   equal(one+2, "cd");	/* Wrote too much? */
102 
103   (void) strcpy(two, "hi there");
104   (void) strcpy(one, two);
105   equal(one, "hi there");	/* Basic test encore. */
106   equal(two, "hi there");	/* Stomped on source? */
107 
108   (void) strcpy(one, "");
109   equal(one, "");		/* Boundary condition. */
110 
111   /* strcat.  */
112   it = "strcat";
113   (void) strcpy(one, "ijk");
114   check(strcat(one, "lmn") == one); /* Returned value. */
115   equal(one, "ijklmn");	/* Basic test. */
116 
117   (void) strcpy(one, "x");
118   (void) strcat(one, "yz");
119   equal(one, "xyz");		/* Writeover. */
120   equal(one+4, "mn");	/* Wrote too much? */
121 
122   (void) strcpy(one, "gh");
123   (void) strcpy(two, "ef");
124   (void) strcat(one, two);
125   equal(one, "ghef");	/* Basic test encore. */
126   equal(two, "ef");		/* Stomped on source? */
127 
128   (void) strcpy(one, "");
129   (void) strcat(one, "");
130   equal(one, "");		/* Boundary conditions. */
131   (void) strcpy(one, "ab");
132   (void) strcat(one, "");
133   equal(one, "ab");
134   (void) strcpy(one, "");
135   (void) strcat(one, "cd");
136   equal(one, "cd");
137 
138   /* strncat - first test it as strcat, with big counts,
139      then test the count mechanism.  */
140   it = "strncat";
141   (void) strcpy(one, "ijk");
142   check(strncat(one, "lmn", 99) == one); /* Returned value. */
143   equal(one, "ijklmn");	/* Basic test. */
144 
145   (void) strcpy(one, "x");
146   (void) strncat(one, "yz", 99);
147   equal(one, "xyz");		/* Writeover. */
148   equal(one+4, "mn");	/* Wrote too much? */
149 
150   (void) strcpy(one, "gh");
151   (void) strcpy(two, "ef");
152   (void) strncat(one, two, 99);
153   equal(one, "ghef");	/* Basic test encore. */
154   equal(two, "ef");		/* Stomped on source? */
155 
156   (void) strcpy(one, "");
157   (void) strncat(one, "", 99);
158   equal(one, "");		/* Boundary conditions. */
159   (void) strcpy(one, "ab");
160   (void) strncat(one, "", 99);
161   equal(one, "ab");
162   (void) strcpy(one, "");
163   (void) strncat(one, "cd", 99);
164   equal(one, "cd");
165 
166   (void) strcpy(one, "ab");
167   (void) strncat(one, "cdef", 2);
168   equal(one, "abcd");	/* Count-limited. */
169 
170   (void) strncat(one, "gh", 0);
171   equal(one, "abcd");	/* Zero count. */
172 
173   (void) strncat(one, "gh", 2);
174   equal(one, "abcdgh");	/* Count, length equal. */
175   it = "strncmp";
176   /* strncmp - first test as strcmp with big counts";*/
177   check(strncmp("", "", 99) == 0); /* Trivial case. */
178   check(strncmp("a", "a", 99) == 0);	/* Identity. */
179   check(strncmp("abc", "abc", 99) == 0); /* Multicharacter. */
180   check(strncmp("abc", "abcd", 99) < 0); /* Length unequal. */
181   check(strncmp("abcd", "abc",99) > 0);
182   check(strncmp("abcd", "abce", 99) < 0); /* Honestly unequal. */
183   check(strncmp("abce", "abcd",99)>0);
184   check(strncmp("abce", "abcd", 3) == 0); /* Count limited. */
185   check(strncmp("abce", "abc", 3) == 0); /* Count == length. */
186   check(strncmp("abcd", "abce", 4) < 0); /* Nudging limit. */
187   check(strncmp("abc", "def", 0) == 0); /* Zero count. */
188 
189   /* strncpy - testing is a bit different because of odd semantics.  */
190   it = "strncpy";
191   check(strncpy(one, "abc", 4) == one); /* Returned value. */
192   equal(one, "abc");		/* Did the copy go right? */
193 
194   (void) strcpy(one, "abcdefgh");
195   (void) strncpy(one, "xyz", 2);
196   equal(one, "xycdefgh");	/* Copy cut by count. */
197 
198   (void) strcpy(one, "abcdefgh");
199   (void) strncpy(one, "xyz", 3); /* Copy cut just before NUL. */
200   equal(one, "xyzdefgh");
201 
202   (void) strcpy(one, "abcdefgh");
203   (void) strncpy(one, "xyz", 4); /* Copy just includes NUL. */
204   equal(one, "xyz");
205   equal(one+4, "efgh");	/* Wrote too much? */
206 
207   (void) strcpy(one, "abcdefgh");
208   (void) strncpy(one, "xyz", 5); /* Copy includes padding. */
209   equal(one, "xyz");
210   equal(one+4, "");
211   equal(one+5, "fgh");
212 
213   (void) strcpy(one, "abc");
214   (void) strncpy(one, "xyz", 0); /* Zero-length copy. */
215   equal(one, "abc");
216 
217   (void) strncpy(one, "", 2);	/* Zero-length source. */
218   equal(one, "");
219   equal(one+1, "");
220   equal(one+2, "c");
221 
222   (void) strcpy(one, "hi there");
223   (void) strncpy(two, one, 9);
224   equal(two, "hi there");	/* Just paranoia. */
225   equal(one, "hi there");	/* Stomped on source? */
226 
227   /* strlen.  */
228   it = "strlen";
229   check(strlen("") == 0);	/* Empty. */
230   check(strlen("a") == 1);	/* Single char. */
231   check(strlen("abcd") == 4); /* Multiple chars. */
232 
233   /* strchr.  */
234   it = "strchr";
235   check(strchr("abcd", 'z') == NULL); /* Not found. */
236   (void) strcpy(one, "abcd");
237   check(strchr(one, 'c') == one+2); /* Basic test. */
238   check(strchr(one, 'd') == one+3); /* End of string. */
239   check(strchr(one, 'a') == one); /* Beginning. */
240   check(strchr(one, '\0') == one+4);	/* Finding NUL. */
241   (void) strcpy(one, "ababa");
242   check(strchr(one, 'b') == one+1); /* Finding first. */
243   (void) strcpy(one, "");
244   check(strchr(one, 'b') == NULL); /* Empty string. */
245   check(strchr(one, '\0') == one); /* NUL in empty string. */
246 
247   /* index - just like strchr.  */
248   it = "index";
249   check(index("abcd", 'z') == NULL);	/* Not found. */
250   (void) strcpy(one, "abcd");
251   check(index(one, 'c') == one+2); /* Basic test. */
252   check(index(one, 'd') == one+3); /* End of string. */
253   check(index(one, 'a') == one); /* Beginning. */
254   check(index(one, '\0') == one+4); /* Finding NUL. */
255   (void) strcpy(one, "ababa");
256   check(index(one, 'b') == one+1); /* Finding first. */
257   (void) strcpy(one, "");
258   check(index(one, 'b') == NULL); /* Empty string. */
259   check(index(one, '\0') == one); /* NUL in empty string. */
260 
261   /* strrchr.  */
262   it = "strrchr";
263   check(strrchr("abcd", 'z') == NULL); /* Not found. */
264   (void) strcpy(one, "abcd");
265   check(strrchr(one, 'c') == one+2);	/* Basic test. */
266   check(strrchr(one, 'd') == one+3);	/* End of string. */
267   check(strrchr(one, 'a') == one); /* Beginning. */
268   check(strrchr(one, '\0') == one+4); /* Finding NUL. */
269   (void) strcpy(one, "ababa");
270   check(strrchr(one, 'b') == one+3);	/* Finding last. */
271   (void) strcpy(one, "");
272   check(strrchr(one, 'b') == NULL); /* Empty string. */
273   check(strrchr(one, '\0') == one); /* NUL in empty string. */
274 
275   /* rindex - just like strrchr.  */
276   it = "rindex";
277   check(rindex("abcd", 'z') == NULL); /* Not found. */
278   (void) strcpy(one, "abcd");
279   check(rindex(one, 'c') == one+2); /* Basic test. */
280   check(rindex(one, 'd') == one+3); /* End of string. */
281   check(rindex(one, 'a') == one); /* Beginning. */
282   check(rindex(one, '\0') == one+4);	/* Finding NUL. */
283   (void) strcpy(one, "ababa");
284   check(rindex(one, 'b') == one+3); /* Finding last. */
285   (void) strcpy(one, "");
286   check(rindex(one, 'b') == NULL); /* Empty string. */
287   check(rindex(one, '\0') == one); /* NUL in empty string. */
288 
289   /* strpbrk - somewhat like strchr.  */
290   it = "strpbrk";
291   check(strpbrk("abcd", "z") == NULL); /* Not found. */
292   (void) strcpy(one, "abcd");
293   check(strpbrk(one, "c") == one+2);	/* Basic test. */
294   check(strpbrk(one, "d") == one+3);	/* End of string. */
295   check(strpbrk(one, "a") == one); /* Beginning. */
296   check(strpbrk(one, "") == NULL); /* Empty search list. */
297   check(strpbrk(one, "cb") == one+1); /* Multiple search. */
298   (void) strcpy(one, "abcabdea");
299   check(strpbrk(one, "b") == one+1);	/* Finding first. */
300   check(strpbrk(one, "cb") == one+1); /* With multiple search. */
301   check(strpbrk(one, "db") == one+1); /* Another variant. */
302   (void) strcpy(one, "");
303   check(strpbrk(one, "bc") == NULL); /* Empty string. */
304   check(strpbrk(one, "") == NULL); /* Both strings empty. */
305 
306   /* strstr - somewhat like strchr.  */
307   it = "strstr";
308   check(strstr("z", "abcd") == NULL); /* Not found. */
309   check(strstr("abx", "abcd") == NULL); /* Dead end. */
310   (void) strcpy(one, "abcd");
311   check(strstr(one,"c") == one+2); /* Basic test. */
312   check(strstr(one, "bc") == one+1);	/* Multichar. */
313   check(strstr(one,"d") == one+3); /* End of string. */
314   check(strstr(one,"cd") == one+2);	/* Tail of string. */
315   check(strstr(one,"abc") == one); /* Beginning. */
316   check(strstr(one,"abcd") == one);	/* Exact match. */
317   check(strstr(one,"de") == NULL);	/* Past end. */
318   check(strstr(one,"") == one); /* Finding empty. */
319   (void) strcpy(one, "ababa");
320   check(strstr(one,"ba") == one+1); /* Finding first. */
321   (void) strcpy(one, "");
322   check(strstr(one, "b") == NULL); /* Empty string. */
323   check(strstr(one,"") == one); /* Empty in empty string. */
324   (void) strcpy(one, "bcbca");
325   check(strstr(one,"bca") == one+2); /* False start. */
326   (void) strcpy(one, "bbbcabbca");
327   check(strstr(one,"bbca") == one+1); /* With overlap. */
328 
329   /* strspn.  */
330   it = "strspn";
331   check(strspn("abcba", "abc") == 5); /* Whole string. */
332   check(strspn("abcba", "ab") == 2);	/* Partial. */
333   check(strspn("abc", "qx") == 0); /* None. */
334   check(strspn("", "ab") == 0); /* Null string. */
335   check(strspn("abc", "") == 0); /* Null search list. */
336 
337   /* strcspn.  */
338   it = "strcspn";
339   check(strcspn("abcba", "qx") == 5); /* Whole string. */
340   check(strcspn("abcba", "cx") == 2); /* Partial. */
341   check(strcspn("abc", "abc") == 0);	/* None. */
342   check(strcspn("", "ab") == 0); /* Null string. */
343   check(strcspn("abc", "") == 3); /* Null search list. */
344 
345   /* strtok - the hard one.  */
346   it = "strtok";
347   (void) strcpy(one, "first, second, third");
348   equal(strtok(one, ", "), "first");	/* Basic test. */
349   equal(one, "first");
350   equal(strtok((char *)NULL, ", "), "second");
351   equal(strtok((char *)NULL, ", "), "third");
352   check(strtok((char *)NULL, ", ") == NULL);
353   (void) strcpy(one, ", first, ");
354   equal(strtok(one, ", "), "first");	/* Extra delims, 1 tok. */
355   check(strtok((char *)NULL, ", ") == NULL);
356   (void) strcpy(one, "1a, 1b; 2a, 2b");
357   equal(strtok(one, ", "), "1a"); /* Changing delim lists. */
358   equal(strtok((char *)NULL, "; "), "1b");
359   equal(strtok((char *)NULL, ", "), "2a");
360   (void) strcpy(two, "x-y");
361   equal(strtok(two, "-"), "x"); /* New string before done. */
362   equal(strtok((char *)NULL, "-"), "y");
363   check(strtok((char *)NULL, "-") == NULL);
364   (void) strcpy(one, "a,b, c,, ,d");
365   equal(strtok(one, ", "), "a"); /* Different separators. */
366   equal(strtok((char *)NULL, ", "), "b");
367   equal(strtok((char *)NULL, " ,"), "c"); /* Permute list too. */
368   equal(strtok((char *)NULL, " ,"), "d");
369   check(strtok((char *)NULL, ", ") == NULL);
370   check(strtok((char *)NULL, ", ") == NULL); /* Persistence. */
371   (void) strcpy(one, ", ");
372   check(strtok(one, ", ") == NULL);	/* No tokens. */
373   (void) strcpy(one, "");
374   check(strtok(one, ", ") == NULL);	/* Empty string. */
375   (void) strcpy(one, "abc");
376   equal(strtok(one, ", "), "abc"); /* No delimiters. */
377   check(strtok((char *)NULL, ", ") == NULL);
378   (void) strcpy(one, "abc");
379   equal(strtok(one, ""), "abc"); /* Empty delimiter list. */
380   check(strtok((char *)NULL, "") == NULL);
381   (void) strcpy(one, "abcdefgh");
382   (void) strcpy(one, "a,b,c");
383   equal(strtok(one, ","), "a"); /* Basics again... */
384   equal(strtok((char *)NULL, ","), "b");
385   equal(strtok((char *)NULL, ","), "c");
386   check(strtok((char *)NULL, ",") == NULL);
387   equal(one+6, "gh");	/* Stomped past end? */
388   equal(one, "a");		/* Stomped old tokens? */
389   equal(one+2, "b");
390   equal(one+4, "c");
391 
392   /* memcmp.  */
393   it = "memcmp";
394   check(memcmp("a", "a", 1) == 0); /* Identity. */
395   check(memcmp("abc", "abc", 3) == 0); /* Multicharacter. */
396   check(memcmp("abcd", "abce", 4) < 0); /* Honestly unequal. */
397   check(memcmp("abce", "abcd",4));
398   check(memcmp("alph", "beta", 4) < 0);
399   check(memcmp("abce", "abcd", 3) == 0); /* Count limited. */
400   check(memcmp("abc", "def", 0) == 0); /* Zero count. */
401 
402   /* memcmp should test strings as unsigned */
403   one[0] = 0xfe;
404   two[0] = 0x03;
405   check(memcmp(one, two,1) > 0);
406 
407 
408   /* memchr.  */
409   it = "memchr";
410   check(memchr("abcd", 'z', 4) == NULL); /* Not found. */
411   (void) strcpy(one, "abcd");
412   check(memchr(one, 'c', 4) == one+2); /* Basic test. */
413   check(memchr(one, 'd', 4) == one+3); /* End of string. */
414   check(memchr(one, 'a', 4) == one);	/* Beginning. */
415   check(memchr(one, '\0', 5) == one+4); /* Finding NUL. */
416   (void) strcpy(one, "ababa");
417   check(memchr(one, 'b', 5) == one+1); /* Finding first. */
418   check(memchr(one, 'b', 0) == NULL); /* Zero count. */
419   check(memchr(one, 'a', 1) == one);	/* Singleton case. */
420   (void) strcpy(one, "a\203b");
421   check(memchr(one, 0203, 3) == one+1); /* Unsignedness. */
422 
423   /* memcpy - need not work for overlap.  */
424   it = "memcpy";
425   check(memcpy(one, "abc", 4) == one); /* Returned value. */
426   equal(one, "abc");		/* Did the copy go right? */
427 
428   (void) strcpy(one, "abcdefgh");
429   (void) memcpy(one+1, "xyz", 2);
430   equal(one, "axydefgh");	/* Basic test. */
431 
432   (void) strcpy(one, "abc");
433   (void) memcpy(one, "xyz", 0);
434   equal(one, "abc");		/* Zero-length copy. */
435 
436   (void) strcpy(one, "hi there");
437   (void) strcpy(two, "foo");
438   (void) memcpy(two, one, 9);
439   equal(two, "hi there");	/* Just paranoia. */
440   equal(one, "hi there");	/* Stomped on source? */
441 #if 0
442   /* memmove - must work on overlap.  */
443   it = "memmove";
444   check(memmove(one, "abc", 4) == one); /* Returned value. */
445   equal(one, "abc");		/* Did the copy go right? */
446 
447   (void) strcpy(one, "abcdefgh");
448   (void) memmove(one+1, "xyz", 2);
449   equal(one, "axydefgh");	/* Basic test. */
450 
451   (void) strcpy(one, "abc");
452   (void) memmove(one, "xyz", 0);
453   equal(one, "abc");		/* Zero-length copy. */
454 
455   (void) strcpy(one, "hi there");
456   (void) strcpy(two, "foo");
457   (void) memmove(two, one, 9);
458   equal(two, "hi there");	/* Just paranoia. */
459   equal(one, "hi there");	/* Stomped on source? */
460 
461   (void) strcpy(one, "abcdefgh");
462   (void) memmove(one+1, one, 9);
463   equal(one, "aabcdefgh");	/* Overlap, right-to-left. */
464 
465   (void) strcpy(one, "abcdefgh");
466   (void) memmove(one+1, one+2, 7);
467   equal(one, "acdefgh");	/* Overlap, left-to-right. */
468 
469   (void) strcpy(one, "abcdefgh");
470   (void) memmove(one, one, 9);
471   equal(one, "abcdefgh");	/* 100% overlap. */
472 #endif
473 #if 0
474   /* memccpy - first test like memcpy, then the search part
475      The SVID, the only place where memccpy is mentioned, says
476      overlap might fail, so we don't try it.  Besides, it's hard
477      to see the rationale for a non-left-to-right memccpy.  */
478   it = "memccpy";
479   check(memccpy(one, "abc", 'q', 4) == NULL); /* Returned value. */
480   equal(one, "abc");		/* Did the copy go right? */
481 
482   (void) strcpy(one, "abcdefgh");
483   (void) memccpy(one+1, "xyz", 'q', 2);
484   equal(one, "axydefgh");	/* Basic test. */
485 
486   (void) strcpy(one, "abc");
487   (void) memccpy(one, "xyz", 'q', 0);
488   equal(one, "abc");		/* Zero-length copy. */
489 
490   (void) strcpy(one, "hi there");
491   (void) strcpy(two, "foo");
492   (void) memccpy(two, one, 'q', 9);
493   equal(two, "hi there");	/* Just paranoia. */
494   equal(one, "hi there");	/* Stomped on source? */
495 
496   (void) strcpy(one, "abcdefgh");
497   (void) strcpy(two, "horsefeathers");
498   check(memccpy(two, one, 'f', 9) == two+6);	/* Returned value. */
499   equal(one, "abcdefgh");	/* Source intact? */
500   equal(two, "abcdefeathers"); /* Copy correct? */
501 
502   (void) strcpy(one, "abcd");
503   (void) strcpy(two, "bumblebee");
504   check(memccpy(two, one, 'a', 4) == two+1); /* First char. */
505   equal(two, "aumblebee");
506   check(memccpy(two, one, 'd', 4) == two+4); /* Last char. */
507   equal(two, "abcdlebee");
508   (void) strcpy(one, "xyz");
509   check(memccpy(two, one, 'x', 1) == two+1); /* Singleton. */
510   equal(two, "xbcdlebee");
511 #endif
512   /* memset.  */
513   it = "memset";
514   (void) strcpy(one, "abcdefgh");
515   check(memset(one+1, 'x', 3) == one+1); /* Return value. */
516   equal(one, "axxxefgh");	/* Basic test. */
517 
518   (void) memset(one+2, 'y', 0);
519   equal(one, "axxxefgh");	/* Zero-length set. */
520 
521   (void) memset(one+5, 0, 1);
522   equal(one, "axxxe");	/* Zero fill. */
523   equal(one+6, "gh");	/*, the leftover. */
524 
525   (void) memset(one+2, 010045, 1);
526   equal(one, "ax\045xe");	/* Unsigned char convert. */
527 
528   /* bcopy - much like memcpy.
529      Berklix manual is silent about overlap, so don't test it.  */
530   it = "bcopy";
531   (void) bcopy("abc", one, 4);
532   equal(one, "abc");		/* Simple copy. */
533 
534   (void) strcpy(one, "abcdefgh");
535   (void) bcopy("xyz", one+1, 2);
536   equal(one, "axydefgh");	/* Basic test. */
537 
538   (void) strcpy(one, "abc");
539   (void) bcopy("xyz", one, 0);
540   equal(one, "abc");		/* Zero-length copy. */
541 
542   (void) strcpy(one, "hi there");
543   (void) strcpy(two, "foo");
544   (void) bcopy(one, two, 9);
545   equal(two, "hi there");	/* Just paranoia. */
546   equal(one, "hi there");	/* Stomped on source? */
547 
548   /* bzero.  */
549   it = "bzero";
550   (void) strcpy(one, "abcdef");
551   bzero(one+2, 2);
552   equal(one, "ab");		/* Basic test. */
553   equal(one+3, "");
554   equal(one+4, "ef");
555 
556   (void) strcpy(one, "abcdef");
557   bzero(one+2, (0));
558   equal(one, "abcdef");	/* Zero-length copy. */
559 
560   /* bcmp - somewhat like memcmp.  */
561   it = "bcmp";
562   check(bcmp("a", "a", 1) == 0); /* Identity. */
563   check(bcmp("abc", "abc", 3) == 0);	/* Multicharacter. */
564   check(bcmp("abcd", "abce", 4) != 0); /* Honestly unequal. */
565   check(bcmp("abce", "abcd",4));
566   check(bcmp("alph", "beta", 4) != 0);
567   check(bcmp("abce", "abcd", 3) == 0); /* Count limited. */
568   check(bcmp("abc", "def", 0) == 0);	/* Zero count. */
569 
570 #if 0  /* strerror - VERY system-dependent.  */
571 {
572   extern CONST unsigned int _sys_nerr;
573   extern CONST char *CONST _sys_errlist[];
574   int f;
575   it = "strerror";
576   f = open("/", O_WRONLY);	/* Should always fail. */
577   check(f < 0 && errno > 0 && errno < _sys_nerr);
578   equal(strerror(errno), _sys_errlist[errno]);
579 }
580 #endif
581 }
582 
583