1d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote/* Tester for string functions. 2d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote Copyright (C) 1995-2000, 2001, 2003 Free Software Foundation, Inc. 3d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote This file is part of the GNU C Library. 4d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 5d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote The GNU C Library is free software; you can redistribute it and/or 6d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote modify it under the terms of the GNU Lesser General Public 7d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote License as published by the Free Software Foundation; either 8d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote version 2.1 of the License, or (at your option) any later version. 9d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 10d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote The GNU C Library is distributed in the hope that it will be useful, 11d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote but WITHOUT ANY WARRANTY; without even the implied warranty of 12d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote Lesser General Public License for more details. 14d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 15d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote You should have received a copy of the GNU Lesser General Public 16d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote License along with the GNU C Library; if not, write to the Free 17d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 18d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 02111-1307 USA. */ 19d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 20d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#ifndef _GNU_SOURCE 21d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#define _GNU_SOURCE 22d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#endif 23d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 24d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote/* Make sure we don't test the optimized inline functions if we want to 25d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test the real implementation. */ 26d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#if !defined DO_STRING_INLINES 27d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#undef __USE_STRING_INLINES 28d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#endif 29d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 30d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#include <errno.h> 31d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#include <stdio.h> 32d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#include <stdlib.h> 33d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#include <string.h> 34d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#include <strings.h> 35d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#include <fcntl.h> 36d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 37d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#ifndef HAVE_GNU_LD 38d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#define _sys_nerr sys_nerr 39d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#define _sys_errlist sys_errlist 40d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#endif 41d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 42d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#define STREQ(a, b) (strcmp((a), (b)) == 0) 43d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 44d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercoteconst char *it = "<UNSET>"; /* Routine name for message routines. */ 45d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotesize_t errors = 0; 46d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 47d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote/* Complain if condition is not true. */ 48d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 49d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotecheck (int thing, int number) 50d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 51d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote if (!thing) 52d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 53d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote printf("%s flunked test %d\n", it, number); 54d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote ++errors; 55d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 56d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 57d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 58d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote/* Complain if first two args don't strcmp as equal. */ 59d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 60d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercoteequal (const char *a, const char *b, int number) 61d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 62d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(a != NULL && b != NULL && STREQ (a, b), number); 63d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 64d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 65d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotechar one[50]; 66d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotechar two[50]; 67d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotechar *cp; 68d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 69d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 70d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strcmp (void) 71d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 72d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strcmp"; 73d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strcmp ("", "") == 0, 1); /* Trivial case. */ 74d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strcmp ("a", "a") == 0, 2); /* Identity. */ 75d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strcmp ("abc", "abc") == 0, 3); /* Multicharacter. */ 76d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strcmp ("abc", "abcd") < 0, 4); /* Length mismatches. */ 77d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strcmp ("abcd", "abc") > 0, 5); 78d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strcmp ("abcd", "abce") < 0, 6); /* Honest miscompares. */ 79d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strcmp ("abce", "abcd") > 0, 7); 80d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strcmp ("a\203", "a") > 0, 8); /* Tricky if char signed. */ 81d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strcmp ("a\203", "a\003") > 0, 9); 82d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 83d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 84d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote char buf1[0x40], buf2[0x40]; 85d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote int i, j; 86d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (i=0; i < 0x10; i++) 87d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (j = 0; j < 0x10; j++) 88d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 89d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote int k; 90d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (k = 0; k < 0x3f; k++) 91d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 92d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote buf1[k] = '0' ^ (k & 4); 93d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote buf2[k] = '4' ^ (k & 4); 94d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 95d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote buf1[i] = buf1[0x3f] = 0; 96d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote buf2[j] = buf2[0x3f] = 0; 97d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (k = 0; k < 0xf; k++) 98d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 99d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote int cnum = 0x10+0x10*k+0x100*j+0x1000*i; 100d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strcmp (buf1+i,buf2+j) == 0, cnum); 101d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote buf1[i+k] = 'A' + i + k; 102d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote buf1[i+k+1] = 0; 103d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strcmp (buf1+i,buf2+j) > 0, cnum+1); 104d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strcmp (buf2+j,buf1+i) < 0, cnum+2); 105d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote buf2[j+k] = 'B' + i + k; 106d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote buf2[j+k+1] = 0; 107d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strcmp (buf1+i,buf2+j) < 0, cnum+3); 108d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strcmp (buf2+j,buf1+i) > 0, cnum+4); 109d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote buf2[j+k] = 'A' + i + k; 110d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote buf1[i] = 'A' + i + 0x80; 111d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strcmp (buf1+i,buf2+j) > 0, cnum+5); 112d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strcmp (buf2+j,buf1+i) < 0, cnum+6); 113d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote buf1[i] = 'A' + i; 114d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 115d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 116d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 117d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 118d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 119d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#define SIMPLE_COPY(fn, n, str, ntest) \ 120d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote do { \ 121d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote int __n; \ 122d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote char *cp; \ 123d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (__n = 0; __n < (int) sizeof (one); ++__n) \ 124d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote one[__n] = 'Z'; \ 125d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote fn (one, str); \ 126d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (cp = one, __n = 0; __n < n; ++__n, ++cp) \ 127d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (*cp == '0' + (n % 10), ntest); \ 128d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (*cp == '\0', ntest); \ 129d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } while (0) 130d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 131d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 132d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strcpy (void) 133d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 134d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote int i; 135d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strcpy"; 136d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strcpy (one, "abcd") == one, 1); /* Returned value. */ 137d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "abcd", 2); /* Basic test. */ 138d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 139d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "x"); 140d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "x", 3); /* Writeover. */ 141d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one+2, "cd", 4); /* Wrote too much? */ 142d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 143d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (two, "hi there"); 144d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, two); 145d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "hi there", 5); /* Basic test encore. */ 146d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (two, "hi there", 6); /* Stomped on source? */ 147d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 148d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, ""); 149d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "", 7); /* Boundary condition. */ 150d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 151d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (i = 0; i < 16; i++) 152d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 153d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one + i, "hi there"); /* Unaligned destination. */ 154d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one + i, "hi there", 8 + (i * 2)); 155d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (two, one + i); /* Unaligned source. */ 156d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (two, "hi there", 9 + (i * 2)); 157d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 158d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 159d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(strcpy, 0, "", 41); 160d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(strcpy, 1, "1", 42); 161d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(strcpy, 2, "22", 43); 162d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(strcpy, 3, "333", 44); 163d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(strcpy, 4, "4444", 45); 164d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(strcpy, 5, "55555", 46); 165d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(strcpy, 6, "666666", 47); 166d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(strcpy, 7, "7777777", 48); 167d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(strcpy, 8, "88888888", 49); 168d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(strcpy, 9, "999999999", 50); 169d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(strcpy, 10, "0000000000", 51); 170d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(strcpy, 11, "11111111111", 52); 171d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(strcpy, 12, "222222222222", 53); 172d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(strcpy, 13, "3333333333333", 54); 173d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(strcpy, 14, "44444444444444", 55); 174d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(strcpy, 15, "555555555555555", 56); 175d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(strcpy, 16, "6666666666666666", 57); 176d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 177d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* Simple test using implicitly coerced `void *' arguments. */ 178211dc4584d2994b1865623e101c3bfb70ea052dbsewardj { const void *src = "frobozz"; 179211dc4584d2994b1865623e101c3bfb70ea052dbsewardj void *dst = one; 180211dc4584d2994b1865623e101c3bfb70ea052dbsewardj check (strcpy (dst, src) == dst, 1); 181211dc4584d2994b1865623e101c3bfb70ea052dbsewardj equal (dst, "frobozz", 2); 182211dc4584d2994b1865623e101c3bfb70ea052dbsewardj } 183d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 184d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 185d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 186d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_stpcpy (void) 187d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 188d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "stpcpy"; 189d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check ((stpcpy (one, "a") - one) == 1, 1); 190d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "a", 2); 191d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 192d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check ((stpcpy (one, "ab") - one) == 2, 3); 193d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "ab", 4); 194d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 195d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check ((stpcpy (one, "abc") - one) == 3, 5); 196d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "abc", 6); 197d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 198d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check ((stpcpy (one, "abcd") - one) == 4, 7); 199d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "abcd", 8); 200d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 201d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check ((stpcpy (one, "abcde") - one) == 5, 9); 202d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "abcde", 10); 203d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 204d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check ((stpcpy (one, "abcdef") - one) == 6, 11); 205d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "abcdef", 12); 206d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 207d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check ((stpcpy (one, "abcdefg") - one) == 7, 13); 208d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "abcdefg", 14); 209d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 210d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check ((stpcpy (one, "abcdefgh") - one) == 8, 15); 211d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "abcdefgh", 16); 212d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 213d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check ((stpcpy (one, "abcdefghi") - one) == 9, 17); 214d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "abcdefghi", 18); 215d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 216d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check ((stpcpy (one, "x") - one) == 1, 19); 217d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "x", 20); /* Writeover. */ 218d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one+2, "cdefghi", 21); /* Wrote too much? */ 219d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 220d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check ((stpcpy (one, "xx") - one) == 2, 22); 221d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "xx", 23); /* Writeover. */ 222d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one+3, "defghi", 24); /* Wrote too much? */ 223d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 224d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check ((stpcpy (one, "xxx") - one) == 3, 25); 225d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "xxx", 26); /* Writeover. */ 226d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one+4, "efghi", 27); /* Wrote too much? */ 227d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 228d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check ((stpcpy (one, "xxxx") - one) == 4, 28); 229d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "xxxx", 29); /* Writeover. */ 230d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one+5, "fghi", 30); /* Wrote too much? */ 231d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 232d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check ((stpcpy (one, "xxxxx") - one) == 5, 31); 233d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "xxxxx", 32); /* Writeover. */ 234d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one+6, "ghi", 33); /* Wrote too much? */ 235d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 236d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check ((stpcpy (one, "xxxxxx") - one) == 6, 34); 237d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "xxxxxx", 35); /* Writeover. */ 238d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one+7, "hi", 36); /* Wrote too much? */ 239d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 240d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check ((stpcpy (one, "xxxxxxx") - one) == 7, 37); 241d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "xxxxxxx", 38); /* Writeover. */ 242d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one+8, "i", 39); /* Wrote too much? */ 243d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 244d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check ((stpcpy (stpcpy (stpcpy (one, "a"), "b"), "c") - one) == 3, 40); 245d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "abc", 41); 246d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one + 4, "xxx", 42); 247d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 248d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(stpcpy, 0, "", 43); 249d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(stpcpy, 1, "1", 44); 250d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(stpcpy, 2, "22", 45); 251d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(stpcpy, 3, "333", 46); 252d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(stpcpy, 4, "4444", 47); 253d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(stpcpy, 5, "55555", 48); 254d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(stpcpy, 6, "666666", 49); 255d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(stpcpy, 7, "7777777", 50); 256d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(stpcpy, 8, "88888888", 51); 257d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(stpcpy, 9, "999999999", 52); 258d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(stpcpy, 10, "0000000000", 53); 259d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(stpcpy, 11, "11111111111", 54); 260d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(stpcpy, 12, "222222222222", 55); 261d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(stpcpy, 13, "3333333333333", 56); 262d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(stpcpy, 14, "44444444444444", 57); 263d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(stpcpy, 15, "555555555555555", 58); 264d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote SIMPLE_COPY(stpcpy, 16, "6666666666666666", 59); 265d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 266d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 267f76d27a697a7b0bf3b84490baf60623fc96a23afnjn// DDD: better done by testing for the function. 268f76d27a697a7b0bf3b84490baf60623fc96a23afnjn#if !defined(__APPLE__) 269d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 270d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_stpncpy (void) 271d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 272d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "stpncpy"; 273d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote memset (one, 'x', sizeof (one)); 274d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (stpncpy (one, "abc", 2) == one + 2, 1); 275d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (stpncpy (one, "abc", 3) == one + 3, 2); 276d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (stpncpy (one, "abc", 4) == one + 3, 3); 277d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (one[3] == '\0' && one[4] == 'x', 4); 278d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (stpncpy (one, "abcd", 5) == one + 4, 5); 279d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (one[4] == '\0' && one[5] == 'x', 6); 280d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (stpncpy (one, "abcd", 6) == one + 4, 7); 281d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (one[4] == '\0' && one[5] == '\0' && one[6] == 'x', 8); 282d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 283f76d27a697a7b0bf3b84490baf60623fc96a23afnjn#endif 284d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 285d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 286d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strcat (void) 287d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 288d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strcat"; 289d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "ijk"); 290d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strcat (one, "lmn") == one, 1); /* Returned value. */ 291d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "ijklmn", 2); /* Basic test. */ 292d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 293d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "x"); 294d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcat (one, "yz"); 295d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "xyz", 3); /* Writeover. */ 296d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one+4, "mn", 4); /* Wrote too much? */ 297d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 298d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "gh"); 299d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (two, "ef"); 300d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcat (one, two); 301d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "ghef", 5); /* Basic test encore. */ 302d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (two, "ef", 6); /* Stomped on source? */ 303d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 304d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, ""); 305d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcat (one, ""); 306d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "", 7); /* Boundary conditions. */ 307d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "ab"); 308d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcat (one, ""); 309d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "ab", 8); 310d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, ""); 311d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcat (one, "cd"); 312d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "cd", 9); 313d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 314d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 315d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 316d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strncat (void) 317d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 318d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* First test it as strcat, with big counts, then test the count 319d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote mechanism. */ 320d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strncat"; 321d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "ijk"); 322d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strncat (one, "lmn", 99) == one, 1); /* Returned value. */ 323d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "ijklmn", 2); /* Basic test. */ 324d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 325d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "x"); 326d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strncat (one, "yz", 99); 327d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "xyz", 3); /* Writeover. */ 328d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one+4, "mn", 4); /* Wrote too much? */ 329d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 330d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "gh"); 331d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (two, "ef"); 332d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strncat (one, two, 99); 333d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "ghef", 5); /* Basic test encore. */ 334d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (two, "ef", 6); /* Stomped on source? */ 335d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 336d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, ""); 337d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strncat (one, "", 99); 338d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "", 7); /* Boundary conditions. */ 339d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "ab"); 340d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strncat (one, "", 99); 341d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "ab", 8); 342d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, ""); 343d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strncat (one, "cd", 99); 344d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "cd", 9); 345d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 346d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "ab"); 347d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strncat (one, "cdef", 2); 348d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "abcd", 10); /* Count-limited. */ 349d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 350d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strncat (one, "gh", 0); 351d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "abcd", 11); /* Zero count. */ 352d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 353d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strncat (one, "gh", 2); 354d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "abcdgh", 12); /* Count and length equal. */ 355d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 356d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 357d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 358d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strncmp (void) 359d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 360d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* First test as strcmp with big counts, then test count code. */ 361d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strncmp"; 362d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strncmp ("", "", 99) == 0, 1); /* Trivial case. */ 363d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strncmp ("a", "a", 99) == 0, 2); /* Identity. */ 364d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strncmp ("abc", "abc", 99) == 0, 3); /* Multicharacter. */ 365d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strncmp ("abc", "abcd", 99) < 0, 4); /* Length unequal. */ 366d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strncmp ("abcd", "abc", 99) > 0, 5); 367d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strncmp ("abcd", "abce", 99) < 0, 6); /* Honestly unequal. */ 368d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strncmp ("abce", "abcd", 99) > 0, 7); 369d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strncmp ("a\203", "a", 2) > 0, 8); /* Tricky if '\203' < 0 */ 370d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strncmp ("a\203", "a\003", 2) > 0, 9); 371d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strncmp ("abce", "abcd", 3) == 0, 10); /* Count limited. */ 372d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strncmp ("abce", "abc", 3) == 0, 11); /* Count == length. */ 373d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strncmp ("abcd", "abce", 4) < 0, 12); /* Nudging limit. */ 374d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strncmp ("abc", "def", 0) == 0, 13); /* Zero count. */ 375d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 376d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 377d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 378d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strncpy (void) 379d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 380d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* Testing is a bit different because of odd semantics. */ 381d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strncpy"; 382d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strncpy (one, "abc", 4) == one, 1); /* Returned value. */ 383d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "abc", 2); /* Did the copy go right? */ 384d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 385d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "abcdefgh"); 386d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strncpy (one, "xyz", 2); 387d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "xycdefgh", 3); /* Copy cut by count. */ 388d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 389d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "abcdefgh"); 390d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strncpy (one, "xyz", 3); /* Copy cut just before NUL. */ 391d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "xyzdefgh", 4); 392d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 393d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "abcdefgh"); 394d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strncpy (one, "xyz", 4); /* Copy just includes NUL. */ 395d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "xyz", 5); 396d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one+4, "efgh", 6); /* Wrote too much? */ 397d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 398d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "abcdefgh"); 399d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strncpy (one, "xyz", 5); /* Copy includes padding. */ 400d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "xyz", 7); 401d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one+4, "", 8); 402d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one+5, "fgh", 9); 403d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 404d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "abc"); 405d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strncpy (one, "xyz", 0); /* Zero-length copy. */ 406d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "abc", 10); 407d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 408d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strncpy (one, "", 2); /* Zero-length source. */ 409d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "", 11); 410d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one+1, "", 12); 411d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one+2, "c", 13); 412d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 413d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "hi there"); 414d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strncpy (two, one, 9); 415d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (two, "hi there", 14); /* Just paranoia. */ 416d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one, "hi there", 15); /* Stomped on source? */ 417d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 418d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 419d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 420d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strlen (void) 421d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 422d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strlen"; 423d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strlen ("") == 0, 1); /* Empty. */ 424d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strlen ("a") == 1, 2); /* Single char. */ 425d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strlen ("abcd") == 4, 3); /* Multiple chars. */ 426d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 427d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote char buf[4096]; 428d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote int i; 429d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote char *p; 430d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (i=0; i < 0x100; i++) 431d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 432d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote p = (char *) ((unsigned long int)(buf + 0xff) & ~0xff) + i; 433d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote strcpy (p, "OK"); 434d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote strcpy (p+3, "BAD/WRONG"); 435d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strlen (p) == 2, 4+i); 436d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 437d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 438d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 439d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 440d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 441d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strchr (void) 442d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 443d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strchr"; 444d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strchr ("abcd", 'z') == NULL, 1); /* Not found. */ 445d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "abcd"); 446d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strchr (one, 'c') == one+2, 2); /* Basic test. */ 447d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strchr (one, 'd') == one+3, 3); /* End of string. */ 448d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strchr (one, 'a') == one, 4); /* Beginning. */ 449d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strchr (one, '\0') == one+4, 5); /* Finding NUL. */ 450d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "ababa"); 451d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strchr (one, 'b') == one+1, 6); /* Finding first. */ 452d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, ""); 453d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strchr (one, 'b') == NULL, 7); /* Empty string. */ 454d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strchr (one, '\0') == one, 8); /* NUL in empty string. */ 455d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 456d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote char buf[4096]; 457d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote int i; 458d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote char *p; 459d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (i=0; i < 0x100; i++) 460d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 461d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote p = (char *) ((unsigned long int) (buf + 0xff) & ~0xff) + i; 462d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote strcpy (p, "OK"); 463d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote strcpy (p+3, "BAD/WRONG"); 464d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strchr (p, '/') == NULL, 9+i); 465d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 466d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 467d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 468d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 46983b62cbbab29bde83eba40231f307c2a311e73c8njn// DDD: better done by testing for the function. 4706e9de463ef677f093e9f24f126e1b11c28cf59fdsewardj#if !defined(__APPLE__) 471d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 472d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strchrnul (void) 473d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 474d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote const char *os; 475d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strchrnul"; 476d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = strchrnul ((os = "abcd"), 'z'); 477d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (*cp == '\0', 1); /* Not found. */ 478d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (cp == os + 4, 2); 479d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "abcd"); 480d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strchrnul (one, 'c') == one+2, 3); /* Basic test. */ 481d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strchrnul (one, 'd') == one+3, 4); /* End of string. */ 482d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strchrnul (one, 'a') == one, 5); /* Beginning. */ 483d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strchrnul (one, '\0') == one+4, 6); /* Finding NUL. */ 484d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "ababa"); 485d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strchrnul (one, 'b') == one+1, 7); /* Finding first. */ 486d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, ""); 487d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strchrnul (one, 'b') == one, 8); /* Empty string. */ 488d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strchrnul (one, '\0') == one, 9); /* NUL in empty string. */ 489d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 490d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote char buf[4096]; 491d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote int i; 492d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote char *p; 493d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (i=0; i < 0x100; i++) 494d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 495d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote p = (char *) ((unsigned long int) (buf + 0xff) & ~0xff) + i; 496d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote strcpy (p, "OK"); 497d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote strcpy (p+3, "BAD/WRONG"); 498d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = strchrnul (p, '/'); 499d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (*cp == '\0', 9+2*i); 500d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (cp == p+2, 10+2*i); 501d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 502d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 503d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 5046e9de463ef677f093e9f24f126e1b11c28cf59fdsewardj#endif 505d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 50683b62cbbab29bde83eba40231f307c2a311e73c8njn// DDD: better done by testing for the function. 5076e9de463ef677f093e9f24f126e1b11c28cf59fdsewardj#if !defined(__APPLE__) 508d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 509d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_rawmemchr (void) 510d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 511d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "rawmemchr"; 512d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "abcd"); 513d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (rawmemchr (one, 'c') == one+2, 1); /* Basic test. */ 514d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (rawmemchr (one, 'd') == one+3, 2); /* End of string. */ 515d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (rawmemchr (one, 'a') == one, 3); /* Beginning. */ 516d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (rawmemchr (one, '\0') == one+4, 4); /* Finding NUL. */ 517d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "ababa"); 518d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (rawmemchr (one, 'b') == one+1, 5); /* Finding first. */ 519d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, ""); 520d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (rawmemchr (one, '\0') == one, 6); /* NUL in empty string. */ 521d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 522d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote char buf[4096]; 523d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote int i; 524d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote char *p; 525d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (i=0; i < 0x100; i++) 526d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 527d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote p = (char *) ((unsigned long int) (buf + 0xff) & ~0xff) + i; 528d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote strcpy (p, "OK"); 529d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote strcpy (p+3, "BAD/WRONG"); 530d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (rawmemchr (p, 'R') == p+8, 6+i); 531d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 532d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 533d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 5346e9de463ef677f093e9f24f126e1b11c28cf59fdsewardj#endif 535d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 536d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 537d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_index (void) 538d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 539d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "index"; 540d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (index ("abcd", 'z') == NULL, 1); /* Not found. */ 541d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "abcd"); 542d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (index (one, 'c') == one+2, 2); /* Basic test. */ 543d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (index (one, 'd') == one+3, 3); /* End of string. */ 544d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (index (one, 'a') == one, 4); /* Beginning. */ 545d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (index (one, '\0') == one+4, 5); /* Finding NUL. */ 546d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "ababa"); 547d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (index (one, 'b') == one+1, 6); /* Finding first. */ 548d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, ""); 549d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (index (one, 'b') == NULL, 7); /* Empty string. */ 550d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (index (one, '\0') == one, 8); /* NUL in empty string. */ 551d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 552d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 553d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 554d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strrchr (void) 555d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 556d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strrchr"; 557d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strrchr ("abcd", 'z') == NULL, 1); /* Not found. */ 558d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "abcd"); 559d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strrchr (one, 'c') == one+2, 2); /* Basic test. */ 560d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strrchr (one, 'd') == one+3, 3); /* End of string. */ 561d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strrchr (one, 'a') == one, 4); /* Beginning. */ 562d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strrchr (one, '\0') == one+4, 5); /* Finding NUL. */ 563d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "ababa"); 564d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strrchr (one, 'b') == one+3, 6); /* Finding last. */ 565d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, ""); 566d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strrchr (one, 'b') == NULL, 7); /* Empty string. */ 567d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strrchr (one, '\0') == one, 8); /* NUL in empty string. */ 568d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 569d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote char buf[4096]; 570d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote int i; 571d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote char *p; 572d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (i=0; i < 0x100; i++) 573d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 574d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote p = (char *) ((unsigned long int) (buf + 0xff) & ~0xff) + i; 575d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote strcpy (p, "OK"); 576d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote strcpy (p+3, "BAD/WRONG"); 577d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strrchr (p, '/') == NULL, 9+i); 578d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 579d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 580d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 581d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 58283b62cbbab29bde83eba40231f307c2a311e73c8njn// DDD: better done by testing for the function. 5836e9de463ef677f093e9f24f126e1b11c28cf59fdsewardj#if !defined(__APPLE__) 584d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 585d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_memrchr (void) 586d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 587d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote size_t l; 588d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "memrchr"; 589d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (memrchr ("abcd", 'z', 5) == NULL, 1); /* Not found. */ 590d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "abcd"); 591d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote l = strlen (one) + 1; 592d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (memrchr (one, 'c', l) == one+2, 2); /* Basic test. */ 593d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (memrchr (one, 'd', l) == one+3, 3); /* End of string. */ 594d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (memrchr (one, 'a', l) == one, 4); /* Beginning. */ 595d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (memrchr (one, '\0', l) == one+4, 5); /* Finding NUL. */ 596d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "ababa"); 597d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote l = strlen (one) + 1; 598d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (memrchr (one, 'b', l) == one+3, 6); /* Finding last. */ 599d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, ""); 600d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote l = strlen (one) + 1; 601d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (memrchr (one, 'b', l) == NULL, 7); /* Empty string. */ 602d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (memrchr (one, '\0', l) == one, 8); /* NUL in empty string. */ 603d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 604d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* now test all possible alignment and length combinations to catch 605d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote bugs due to unrolled loops (assuming unrolling is limited to no 606d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote more than 128 byte chunks: */ 607d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 608d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote char buf[128 + sizeof(long)]; 609d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote long align, len, i, pos; 610d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 611d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (align = 0; align < (long) sizeof(long); ++align) { 612d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (len = 0; len < (long) (sizeof(buf) - align); ++len) { 613d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (i = 0; i < len; ++i) 614d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote buf[align + i] = 'x'; /* don't depend on memset... */ 615d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 616d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (pos = len - 1; pos >= 0; --pos) { 617d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#if 0 618d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote printf("align %d, len %d, pos %d\n", align, len, pos); 619d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#endif 620d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memrchr(buf + align, 'x', len) == buf + align + pos, 9); 621d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memrchr(buf + align + pos + 1, 'x', len - (pos + 1)) == NULL, 622d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 10); 623d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote buf[align + pos] = '-'; 624d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 625d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 626d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 627d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 628d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 6296e9de463ef677f093e9f24f126e1b11c28cf59fdsewardj#endif 630d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 631d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 632d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_rindex (void) 633d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 634d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "rindex"; 635d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (rindex ("abcd", 'z') == NULL, 1); /* Not found. */ 636d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "abcd"); 637d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (rindex (one, 'c') == one+2, 2); /* Basic test. */ 638d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (rindex (one, 'd') == one+3, 3); /* End of string. */ 639d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (rindex (one, 'a') == one, 4); /* Beginning. */ 640d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (rindex (one, '\0') == one+4, 5); /* Finding NUL. */ 641d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, "ababa"); 642d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (rindex (one, 'b') == one+3, 6); /* Finding last. */ 643d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy (one, ""); 644d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (rindex (one, 'b') == NULL, 7); /* Empty string. */ 645d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (rindex (one, '\0') == one, 8); /* NUL in empty string. */ 646d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 647d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 648d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 649d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strpbrk (void) 650d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 651d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strpbrk"; 652d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strpbrk("abcd", "z") == NULL, 1); /* Not found. */ 653d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcd"); 654d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strpbrk(one, "c") == one+2, 2); /* Basic test. */ 655d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strpbrk(one, "d") == one+3, 3); /* End of string. */ 656d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strpbrk(one, "a") == one, 4); /* Beginning. */ 657d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strpbrk(one, "") == NULL, 5); /* Empty search list. */ 658d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strpbrk(one, "cb") == one+1, 6); /* Multiple search. */ 659d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcabdea"); 660d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strpbrk(one, "b") == one+1, 7); /* Finding first. */ 661d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strpbrk(one, "cb") == one+1, 8); /* With multiple search. */ 662d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strpbrk(one, "db") == one+1, 9); /* Another variant. */ 663d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, ""); 664d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strpbrk(one, "bc") == NULL, 10); /* Empty string. */ 665d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, ""); 666d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strpbrk(one, "bcd") == NULL, 11); /* Empty string. */ 667d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, ""); 668d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strpbrk(one, "bcde") == NULL, 12); /* Empty string. */ 669d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strpbrk(one, "") == NULL, 13); /* Both strings empty. */ 670d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcabdea"); 671d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strpbrk(one, "befg") == one+1, 14); /* Finding first. */ 672d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strpbrk(one, "cbr") == one+1, 15); /* With multiple search. */ 673d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strpbrk(one, "db") == one+1, 16); /* Another variant. */ 674d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strpbrk(one, "efgh") == one+6, 17); /* And yet another. */ 675d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 676d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 677d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 678d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strstr (void) 679d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 680d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strstr"; 681d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strstr("abcd", "z") == NULL, 1); /* Not found. */ 682d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strstr("abcd", "abx") == NULL, 2); /* Dead end. */ 683d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcd"); 684d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strstr(one, "c") == one+2, 3); /* Basic test. */ 685d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strstr(one, "bc") == one+1, 4); /* Multichar. */ 686d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strstr(one, "d") == one+3, 5); /* End of string. */ 687d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strstr(one, "cd") == one+2, 6); /* Tail of string. */ 688d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strstr(one, "abc") == one, 7); /* Beginning. */ 689d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strstr(one, "abcd") == one, 8); /* Exact match. */ 690d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strstr(one, "abcde") == NULL, 9); /* Too long. */ 691d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strstr(one, "de") == NULL, 10); /* Past end. */ 692d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strstr(one, "") == one, 11); /* Finding empty. */ 693d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "ababa"); 694d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strstr(one, "ba") == one+1, 12); /* Finding first. */ 695d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, ""); 696d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strstr(one, "b") == NULL, 13); /* Empty string. */ 697d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strstr(one, "") == one, 14); /* Empty in empty string. */ 698d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "bcbca"); 699d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strstr(one, "bca") == one+2, 15); /* False start. */ 700d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "bbbcabbca"); 701d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strstr(one, "bbca") == one+1, 16); /* With overlap. */ 702d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 703d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 704d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 705d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strspn (void) 706d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 707d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strspn"; 708d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strspn("abcba", "abc") == 5, 1); /* Whole string. */ 709d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strspn("abcba", "ab") == 2, 2); /* Partial. */ 710d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strspn("abc", "qx") == 0, 3); /* None. */ 711d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strspn("", "ab") == 0, 4); /* Null string. */ 712d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strspn("abc", "") == 0, 5); /* Null search list. */ 713d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 714d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 715d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 716d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strcspn (void) 717d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 718d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strcspn"; 719d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strcspn("abcba", "qx") == 5, 1); /* Whole string. */ 720d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strcspn("abcba", "cx") == 2, 2); /* Partial. */ 721d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strcspn("abc", "abc") == 0, 3); /* None. */ 722d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strcspn("", "ab") == 0, 4); /* Null string. */ 723d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strcspn("abc", "") == 3, 5); /* Null search list. */ 724d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 725d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 726d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 727d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strtok (void) 728d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 729d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strtok"; 730d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "first, second, third"); 731d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok(one, ", "), "first", 1); /* Basic test. */ 732d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "first", 2); 733d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok((char *)NULL, ", "), "second", 3); 734d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok((char *)NULL, ", "), "third", 4); 735d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok((char *)NULL, ", ") == NULL, 5); 736d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, ", first, "); 737d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok(one, ", "), "first", 6); /* Extra delims, 1 tok. */ 738d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok((char *)NULL, ", ") == NULL, 7); 739d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "1a, 1b; 2a, 2b"); 740d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok(one, ", "), "1a", 8); /* Changing delim lists. */ 741d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok((char *)NULL, "; "), "1b", 9); 742d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok((char *)NULL, ", "), "2a", 10); 743d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(two, "x-y"); 744d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok(two, "-"), "x", 11); /* New string before done. */ 745d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok((char *)NULL, "-"), "y", 12); 746d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok((char *)NULL, "-") == NULL, 13); 747d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "a,b, c,, ,d"); 748d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok(one, ", "), "a", 14); /* Different separators. */ 749d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok((char *)NULL, ", "), "b", 15); 750d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok((char *)NULL, " ,"), "c", 16); /* Permute list too. */ 751d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok((char *)NULL, " ,"), "d", 17); 752d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok((char *)NULL, ", ") == NULL, 18); 753d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok((char *)NULL, ", ") == NULL, 19); /* Persistence. */ 754d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, ", "); 755d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok(one, ", ") == NULL, 20); /* No tokens. */ 756d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, ""); 757d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok(one, ", ") == NULL, 21); /* Empty string. */ 758d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abc"); 759d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok(one, ", "), "abc", 22); /* No delimiters. */ 760d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok((char *)NULL, ", ") == NULL, 23); 761d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abc"); 762d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok(one, ""), "abc", 24); /* Empty delimiter list. */ 763d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok((char *)NULL, "") == NULL, 25); 764d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcdefgh"); 765d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "a,b,c"); 766d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok(one, ","), "a", 26); /* Basics again... */ 767d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok((char *)NULL, ","), "b", 27); 768d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok((char *)NULL, ","), "c", 28); 769d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok((char *)NULL, ",") == NULL, 29); 770d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one+6, "gh", 30); /* Stomped past end? */ 771d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "a", 31); /* Stomped old tokens? */ 772d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one+2, "b", 32); 773d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one+4, "c", 33); 774d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 775d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 776d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 777d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strtok_r (void) 778d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 779d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strtok_r"; 780d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "first, second, third"); 781d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = NULL; /* Always initialize cp to make sure it doesn't point to some old data. */ 782d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok_r(one, ", ", &cp), "first", 1); /* Basic test. */ 783d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "first", 2); 784d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok_r((char *)NULL, ", ", &cp), "second", 3); 785d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok_r((char *)NULL, ", ", &cp), "third", 4); 786d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok_r((char *)NULL, ", ", &cp) == NULL, 5); 787d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, ", first, "); 788d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = NULL; 789d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok_r(one, ", ", &cp), "first", 6); /* Extra delims, 1 tok. */ 790d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok_r((char *)NULL, ", ", &cp) == NULL, 7); 791d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "1a, 1b; 2a, 2b"); 792d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = NULL; 793d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok_r(one, ", ", &cp), "1a", 8); /* Changing delim lists. */ 794d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok_r((char *)NULL, "; ", &cp), "1b", 9); 795d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok_r((char *)NULL, ", ", &cp), "2a", 10); 796d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(two, "x-y"); 797d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = NULL; 798d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok_r(two, "-", &cp), "x", 11); /* New string before done. */ 799d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok_r((char *)NULL, "-", &cp), "y", 12); 800d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok_r((char *)NULL, "-", &cp) == NULL, 13); 801d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "a,b, c,, ,d"); 802d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = NULL; 803d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok_r(one, ", ", &cp), "a", 14); /* Different separators. */ 804d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok_r((char *)NULL, ", ", &cp), "b", 15); 805d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok_r((char *)NULL, " ,", &cp), "c", 16); /* Permute list too. */ 806d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok_r((char *)NULL, " ,", &cp), "d", 17); 807d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok_r((char *)NULL, ", ", &cp) == NULL, 18); 808d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok_r((char *)NULL, ", ", &cp) == NULL, 19); /* Persistence. */ 809d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, ", "); 810d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = NULL; 811d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok_r(one, ", ", &cp) == NULL, 20); /* No tokens. */ 812d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, ""); 813d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = NULL; 814d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok_r(one, ", ", &cp) == NULL, 21); /* Empty string. */ 815d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok_r((char *)NULL, ", ", &cp) == NULL, 22); /* Persistence. */ 816d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abc"); 817d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = NULL; 818d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok_r(one, ", ", &cp), "abc", 23); /* No delimiters. */ 819d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok_r((char *)NULL, ", ", &cp) == NULL, 24); 820d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abc"); 821d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = NULL; 822d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok_r(one, "", &cp), "abc", 25); /* Empty delimiter list. */ 823d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok_r((char *)NULL, "", &cp) == NULL, 26); 824d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcdefgh"); 825d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "a,b,c"); 826d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = NULL; 827d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok_r(one, ",", &cp), "a", 27); /* Basics again... */ 828d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok_r((char *)NULL, ",", &cp), "b", 28); 829d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strtok_r((char *)NULL, ",", &cp), "c", 29); 830d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strtok_r((char *)NULL, ",", &cp) == NULL, 30); 831d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one+6, "gh", 31); /* Stomped past end? */ 832d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "a", 32); /* Stomped old tokens? */ 833d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one+2, "b", 33); 834d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one+4, "c", 34); 835d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 836d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 837d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 838d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strsep (void) 839d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 840d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote char *ptr; 841d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strsep"; 842d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = strcpy(one, "first, second, third"); 843d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "first", 1); /* Basic test. */ 844d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "first", 2); 845d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "", 3); 846d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "second", 4); 847d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "", 5); 848d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "third", 6); 849d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strsep(&cp, ", ") == NULL, 7); 850d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = strcpy(one, ", first, "); 851d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "", 8); 852d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "", 9); 853d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "first", 10); /* Extra delims, 1 tok. */ 854d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "", 11); 855d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "", 12); 856d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strsep(&cp, ", ") == NULL, 13); 857d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = strcpy(one, "1a, 1b; 2a, 2b"); 858d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "1a", 14); /* Changing delim lists. */ 859d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "", 15); 860d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, "; "), "1b", 16); 861d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "", 17); 862d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "2a", 18); 863d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = strcpy(two, "x-y"); 864d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, "-"), "x", 19); /* New string before done. */ 865d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, "-"), "y", 20); 866d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strsep(&cp, "-") == NULL, 21); 867d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = strcpy(one, "a,b, c,, ,d "); 868d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "a", 22); /* Different separators. */ 869d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "b", 23); 870d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, " ,"), "", 24); 871d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, " ,"), "c", 25); /* Permute list too. */ 872d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, " ,"), "", 26); 873d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, " ,"), "", 27); 874d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, " ,"), "", 28); 875d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, " ,"), "d", 29); 876d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, " ,"), "", 30); 877d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strsep(&cp, ", ") == NULL, 31); 878d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strsep(&cp, ", ") == NULL, 32); /* Persistence. */ 879d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = strcpy(one, ", "); 880d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "", 33); 881d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "", 34); 882d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "", 35); 883d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strsep(&cp, ", ") == NULL, 36); /* No tokens. */ 884d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = strcpy(one, ""); 885d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "", 37); 886d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strsep(&cp, ", ") == NULL, 38); /* Empty string. */ 887d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = strcpy(one, "abc"); 888d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ", "), "abc", 39); /* No delimiters. */ 889d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strsep(&cp, ", ") == NULL, 40); 890d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = strcpy(one, "abc"); 891d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ""), "abc", 41); /* Empty delimiter list. */ 892d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strsep(&cp, "") == NULL, 42); 893d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcdefgh"); 894d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = strcpy(one, "a,b,c"); 895d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ","), "a", 43); /* Basics again... */ 896d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ","), "b", 44); 897d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ","), "c", 45); 898d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strsep(&cp, ",") == NULL, 46); 899d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one+6, "gh", 47); /* Stomped past end? */ 900d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "a", 48); /* Stomped old tokens? */ 901d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one+2, "b", 49); 902d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one+4, "c", 50); 903d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 904d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 9056e9de463ef677f093e9f24f126e1b11c28cf59fdsewardj# if !defined(__APPLE__) 906d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote char text[] = "This,is,a,test"; 907d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote char *list = strdupa (text); 908d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (strsep (&list, ","), "This", 51); 909d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (strsep (&list, ","), "is", 52); 910d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (strsep (&list, ","), "a", 53); 911d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (strsep (&list, ","), "test", 54); 912d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (strsep (&list, ",") == NULL, 55); 913aed053675acc9fb4fcbe7bc38c1120317bad68fasewardj# endif 914d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 915d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 916d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = strcpy(one, "a,b, c,, ,d,"); 917d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ","), "a", 56); /* Different separators. */ 918d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ","), "b", 57); 919d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ","), " c", 58); /* Permute list too. */ 920d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ","), "", 59); 921d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ","), " ", 60); 922d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ","), "d", 61); 923d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ","), "", 62); 924d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strsep(&cp, ",") == NULL, 63); 925d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strsep(&cp, ",") == NULL, 64); /* Persistence. */ 926d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 927d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = strcpy(one, "a,b, c,, ,d,"); 928d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, "xy,"), "a", 65); /* Different separators. */ 929d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, "x,y"), "b", 66); 930d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ",xy"), " c", 67); /* Permute list too. */ 931d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, "xy,"), "", 68); 932d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, "x,y"), " ", 69); 933d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ",xy"), "d", 70); 934d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, "xy,"), "", 71); 935d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strsep(&cp, "x,y") == NULL, 72); 936d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strsep(&cp, ",xy") == NULL, 73); /* Persistence. */ 937d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 938d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = strcpy(one, "ABC"); 939d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote one[4] = ':'; 940d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, "C"), "AB", 74); /* Access beyond NUL. */ 941d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote ptr = strsep(&cp, ":"); 942d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(ptr, "", 75); 943d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(ptr == one + 3, 76); 944d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(cp == NULL, 77); 945d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 946d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = strcpy(one, "ABC"); 947d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote one[4] = ':'; 948d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, "CD"), "AB", 78); /* Access beyond NUL. */ 949d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote ptr = strsep(&cp, ":."); 950d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(ptr, "", 79); 951d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(ptr == one + 3, 80); 952d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 953d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = strcpy(one, "ABC"); /* No token in string. */ 954d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(strsep(&cp, ","), "ABC", 81); 955d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(cp == NULL, 82); 956d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 957d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote *one = '\0'; /* Empty string. */ 958d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = one; 959d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote ptr = strsep(&cp, ","); 960d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(ptr, "", 83); 961d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(ptr == one, 84); 962d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(cp == NULL, 85); 963d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 964d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote *one = '\0'; /* Empty string and no token. */ 965d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote cp = one; 966d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote ptr = strsep(&cp, ""); 967d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(ptr, "", 86); 968d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(ptr == one , 87); 969d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(cp == NULL, 88); 970d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 971d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 972d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 973d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_memcmp (void) 974d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 975d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "memcmp"; 976d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memcmp("a", "a", 1) == 0, 1); /* Identity. */ 977d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memcmp("abc", "abc", 3) == 0, 2); /* Multicharacter. */ 978d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memcmp("abcd", "abce", 4) < 0, 3); /* Honestly unequal. */ 979d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memcmp("abce", "abcd", 4) > 0, 4); 980d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memcmp("alph", "beta", 4) < 0, 5); 981d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memcmp("a\203", "a\003", 2) > 0, 6); 982d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memcmp("abce", "abcd", 3) == 0, 7); /* Count limited. */ 983d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memcmp("abc", "def", 0) == 0, 8); /* Zero count. */ 984d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 985d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 986d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 987d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_memchr (void) 988d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 989d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "memchr"; 990d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memchr("abcd", 'z', 4) == NULL, 1); /* Not found. */ 991d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcd"); 992d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memchr(one, 'c', 4) == one+2, 2); /* Basic test. */ 993d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memchr(one, ~0xff|'c', 4) == one+2, 2); /* ignore highorder bits. */ 994d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memchr(one, 'd', 4) == one+3, 3); /* End of string. */ 995d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memchr(one, 'a', 4) == one, 4); /* Beginning. */ 996d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memchr(one, '\0', 5) == one+4, 5); /* Finding NUL. */ 997d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "ababa"); 998d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memchr(one, 'b', 5) == one+1, 6); /* Finding first. */ 999d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memchr(one, 'b', 0) == NULL, 7); /* Zero count. */ 1000d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memchr(one, 'a', 1) == one, 8); /* Singleton case. */ 1001d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "a\203b"); 1002d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memchr(one, 0203, 3) == one+1, 9); /* Unsignedness. */ 1003d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1004d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* now test all possible alignment and length combinations to catch 1005d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote bugs due to unrolled loops (assuming unrolling is limited to no 1006d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote more than 128 byte chunks: */ 1007d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 1008d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote char buf[128 + sizeof(long)]; 1009d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote long align, len, i, pos; 1010d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1011d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (align = 0; align < (long) sizeof(long); ++align) { 1012d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (len = 0; len < (long) (sizeof(buf) - align); ++len) { 1013d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (i = 0; i < len; ++i) { 1014d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote buf[align + i] = 'x'; /* don't depend on memset... */ 1015d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 1016d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (pos = 0; pos < len; ++pos) { 1017d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#if 0 1018d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote printf("align %d, len %d, pos %d\n", align, len, pos); 1019d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote#endif 1020d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memchr(buf + align, 'x', len) == buf + align + pos, 10); 1021d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memchr(buf + align, 'x', pos) == NULL, 11); 1022d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote buf[align + pos] = '-'; 1023d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 1024d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 1025d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 1026d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 1027d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 1028d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1029d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 1030d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_memcpy (void) 1031d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 1032d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote int i; 1033d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "memcpy"; 1034d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memcpy(one, "abc", 4) == one, 1); /* Returned value. */ 1035d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "abc", 2); /* Did the copy go right? */ 1036d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1037d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcdefgh"); 1038d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) memcpy(one+1, "xyz", 2); 1039d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "axydefgh", 3); /* Basic test. */ 1040d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1041d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abc"); 1042d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) memcpy(one, "xyz", 0); 1043d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "abc", 4); /* Zero-length copy. */ 1044d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1045d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "hi there"); 1046d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(two, "foo"); 1047d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) memcpy(two, one, 9); 1048d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(two, "hi there", 5); /* Just paranoia. */ 1049d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "hi there", 6); /* Stomped on source? */ 1050d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1051d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (i = 0; i < 16; i++) 1052d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 1053d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote const char *x = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; 1054d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote strcpy (one, x); 1055d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (memcpy (one + i, "hi there", 9) == one + i, 1056d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 7 + (i * 6)); /* Unaligned destination. */ 1057d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (memcmp (one, x, i) == 0, 8 + (i * 6)); /* Wrote under? */ 1058d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one + i, "hi there", 9 + (i * 6)); 1059d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (one[i + 9] == 'x', 10 + (i * 6)); /* Wrote over? */ 1060d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (memcpy (two, one + i, 9) == two, 1061d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 11 + (i * 6)); /* Unaligned source. */ 1062d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (two, "hi there", 12 + (i * 6)); 1063d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 1064d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 1065d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 10666e9de463ef677f093e9f24f126e1b11c28cf59fdsewardj#if !defined(__APPLE__) 1067d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 1068d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_mempcpy (void) 1069d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 1070d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote int i; 1071d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "mempcpy"; 1072d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(mempcpy(one, "abc", 4) == one + 4, 1); /* Returned value. */ 1073d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "abc", 2); /* Did the copy go right? */ 1074d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1075d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcdefgh"); 1076d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) mempcpy(one+1, "xyz", 2); 1077d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "axydefgh", 3); /* Basic test. */ 1078d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1079d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abc"); 1080d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) mempcpy(one, "xyz", 0); 1081d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "abc", 4); /* Zero-length copy. */ 1082d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1083d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "hi there"); 1084d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(two, "foo"); 1085d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) mempcpy(two, one, 9); 1086d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(two, "hi there", 5); /* Just paranoia. */ 1087d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "hi there", 6); /* Stomped on source? */ 1088d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1089d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (i = 0; i < 16; i++) 1090d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 1091d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote const char *x = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; 1092d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote strcpy (one, x); 1093d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (mempcpy (one + i, "hi there", 9) == one + i + 9, 1094d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 7 + (i * 6)); /* Unaligned destination. */ 1095d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (memcmp (one, x, i) == 0, 8 + (i * 6)); /* Wrote under? */ 1096d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (one + i, "hi there", 9 + (i * 6)); 1097d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (one[i + 9] == 'x', 10 + (i * 6)); /* Wrote over? */ 1098d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (mempcpy (two, one + i, 9) == two + 9, 1099d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 11 + (i * 6)); /* Unaligned source. */ 1100d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal (two, "hi there", 12 + (i * 6)); 1101d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 1102d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 11036e9de463ef677f093e9f24f126e1b11c28cf59fdsewardj#endif 1104d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1105d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 1106d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_memmove (void) 1107d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 1108d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "memmove"; 1109d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memmove(one, "abc", 4) == one, 1); /* Returned value. */ 1110d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "abc", 2); /* Did the copy go right? */ 1111d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1112d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcdefgh"); 1113d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) memmove(one+1, "xyz", 2); 1114d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "axydefgh", 3); /* Basic test. */ 1115d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1116d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abc"); 1117d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) memmove(one, "xyz", 0); 1118d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "abc", 4); /* Zero-length copy. */ 1119d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1120d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "hi there"); 1121d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(two, "foo"); 1122d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) memmove(two, one, 9); 1123d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(two, "hi there", 5); /* Just paranoia. */ 1124d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "hi there", 6); /* Stomped on source? */ 1125d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1126d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcdefgh"); 1127d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) memmove(one+1, one, 9); 1128d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "aabcdefgh", 7); /* Overlap, right-to-left. */ 1129d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1130d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcdefgh"); 1131d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) memmove(one+1, one+2, 7); 1132d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "acdefgh", 8); /* Overlap, left-to-right. */ 1133d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1134d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcdefgh"); 1135d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) memmove(one, one, 9); 1136d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "abcdefgh", 9); /* 100% overlap. */ 1137d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 1138d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1139d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 1140d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_memccpy (void) 1141d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 1142d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* First test like memcpy, then the search part The SVID, the only 1143d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote place where memccpy is mentioned, says overlap might fail, so we 1144d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote don't try it. Besides, it's hard to see the rationale for a 1145d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote non-left-to-right memccpy. */ 1146d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "memccpy"; 1147d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memccpy(one, "abc", 'q', 4) == NULL, 1); /* Returned value. */ 1148d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "abc", 2); /* Did the copy go right? */ 1149d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1150d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcdefgh"); 1151d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) memccpy(one+1, "xyz", 'q', 2); 1152d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "axydefgh", 3); /* Basic test. */ 1153d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1154d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abc"); 1155d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) memccpy(one, "xyz", 'q', 0); 1156d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "abc", 4); /* Zero-length copy. */ 1157d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1158d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "hi there"); 1159d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(two, "foo"); 1160d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) memccpy(two, one, 'q', 9); 1161d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(two, "hi there", 5); /* Just paranoia. */ 1162d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "hi there", 6); /* Stomped on source? */ 1163d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1164d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcdefgh"); 1165d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(two, "horsefeathers"); 1166d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memccpy(two, one, 'f', 9) == two+6, 7); /* Returned value. */ 1167d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "abcdefgh", 8); /* Source intact? */ 1168d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(two, "abcdefeathers", 9); /* Copy correct? */ 1169d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1170d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcd"); 1171d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(two, "bumblebee"); 1172d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memccpy(two, one, 'a', 4) == two+1, 10); /* First char. */ 1173d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(two, "aumblebee", 11); 1174d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memccpy(two, one, 'd', 4) == two+4, 12); /* Last char. */ 1175d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(two, "abcdlebee", 13); 1176d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "xyz"); 1177d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memccpy(two, one, 'x', 1) == two+1, 14); /* Singleton. */ 1178d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(two, "xbcdlebee", 15); 1179d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 1180d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1181d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 1182d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_memset (void) 1183d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 1184d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote int i; 1185d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1186d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "memset"; 1187d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcdefgh"); 1188d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(memset(one+1, 'x', 3) == one+1, 1); /* Return value. */ 1189d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "axxxefgh", 2); /* Basic test. */ 1190d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1191d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) memset(one+2, 'y', 0); 1192d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "axxxefgh", 3); /* Zero-length set. */ 1193d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1194d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) memset(one+5, 0, 1); 1195d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "axxxe", 4); /* Zero fill. */ 1196d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one+6, "gh", 5); /* And the leftover. */ 1197d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1198d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) memset(one+2, 010045, 1); 1199d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "ax\045xe", 6); /* Unsigned char convert. */ 1200d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1201d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* Non-8bit fill character. */ 1202d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote memset (one, 0x101, sizeof (one)); 1203d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (i = 0; i < (int) sizeof (one); ++i) 1204d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (one[i] == '\01', 7); 1205d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1206d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* Test for more complex versions of memset, for all alignments and 1207d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote lengths up to 256. This test takes a little while, perhaps it should 1208d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote be made weaker? */ 1209d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 1210d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote char data[512]; 1211d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote int j; 1212d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote int k; 1213d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote int c; 1214d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1215d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (i = 0; i < 512; i++) 1216d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote data[i] = 'x'; 1217d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (c = 0; c <= 'y'; c += 'y') /* check for memset(,0,) and 1218d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote memset(,'y',) */ 1219d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (j = 0; j < 256; j++) 1220d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (i = 0; i < 256; i++) 1221d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 1222d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote memset (data + i, c, j); 1223d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (k = 0; k < i; k++) 1224d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote if (data[k] != 'x') 1225d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote goto fail; 1226d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (k = i; k < i+j; k++) 1227d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 1228d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote if (data[k] != c) 1229d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote goto fail; 1230d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote data[k] = 'x'; 1231d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 1232d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote for (k = i+j; k < 512; k++) 1233d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote if (data[k] != 'x') 1234d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote goto fail; 1235d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote continue; 1236d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1237d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote fail: 1238d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check (0, 8 + i + j * 256 + (c != 0) * 256 * 256); 1239d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 1240d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 1241d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 1242d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1243d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 1244d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_bcopy (void) 1245d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 1246d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* Much like memcpy. Berklix manual is silent about overlap, so 1247d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote don't test it. */ 1248d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "bcopy"; 1249d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) bcopy("abc", one, 4); 1250d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "abc", 1); /* Simple copy. */ 1251d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1252d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcdefgh"); 1253d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) bcopy("xyz", one+1, 2); 1254d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "axydefgh", 2); /* Basic test. */ 1255d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1256d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abc"); 1257d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) bcopy("xyz", one, 0); 1258d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "abc", 3); /* Zero-length copy. */ 1259d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1260d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "hi there"); 1261d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(two, "foo"); 1262d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) bcopy(one, two, 9); 1263d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(two, "hi there", 4); /* Just paranoia. */ 1264d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "hi there", 5); /* Stomped on source? */ 1265d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 1266d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1267d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 1268d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_bzero (void) 1269d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 1270d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "bzero"; 1271d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcdef"); 1272d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote bzero(one+2, 2); 1273d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "ab", 1); /* Basic test. */ 1274d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one+3, "", 2); 1275d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one+4, "ef", 3); 1276d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1277d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote (void) strcpy(one, "abcdef"); 1278d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote bzero(one+2, 0); 1279d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(one, "abcdef", 4); /* Zero-length copy. */ 1280d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 1281d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1282f76d27a697a7b0bf3b84490baf60623fc96a23afnjn#if !defined(__APPLE__) 1283d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 1284d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strndup (void) 1285d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 1286d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote char *p, *q; 1287d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strndup"; 1288d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote p = strndup("abcdef", 12); 1289d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(p != NULL, 1); 1290d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote if (p != NULL) 1291d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 1292d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(p, "abcdef", 2); 1293d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote q = strndup(p + 1, 2); 1294d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(q != NULL, 3); 1295d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote if (q != NULL) 1296d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(q, "bc", 4); 1297d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote free (q); 1298d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 1299d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote free (p); 1300d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote p = strndup("abc def", 3); 1301d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(p != NULL, 5); 1302d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote if (p != NULL) 1303d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote equal(p, "abc", 6); 1304d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote free (p); 1305d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 1306f76d27a697a7b0bf3b84490baf60623fc96a23afnjn#endif 1307d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1308d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 1309d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_bcmp (void) 1310d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 1311d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "bcmp"; 1312d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(bcmp("a", "a", 1) == 0, 1); /* Identity. */ 1313d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(bcmp("abc", "abc", 3) == 0, 2); /* Multicharacter. */ 1314d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(bcmp("abcd", "abce", 4) != 0, 3); /* Honestly unequal. */ 1315d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(bcmp("abce", "abcd", 4) != 0, 4); 1316d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(bcmp("alph", "beta", 4) != 0, 5); 1317d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(bcmp("abce", "abcd", 3) == 0, 6); /* Count limited. */ 1318d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(bcmp("abc", "def", 0) == 0, 8); /* Zero count. */ 1319d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 1320d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1321d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 1322d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strerror (void) 1323d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 1324d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strerror"; 1325d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strerror(EDOM) != 0, 1); 1326d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strerror(ERANGE) != 0, 2); 1327d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strerror(ENOENT) != 0, 3); 1328d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 1329d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1330d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 1331d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strcasecmp (void) 1332d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 1333d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strcasecmp"; 1334d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* Note that the locale is "C". */ 1335d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strcasecmp("a", "a") == 0, 1); 1336d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strcasecmp("a", "A") == 0, 2); 1337d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strcasecmp("A", "a") == 0, 3); 1338d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strcasecmp("a", "b") < 0, 4); 1339d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strcasecmp("c", "b") > 0, 5); 1340d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strcasecmp("abc", "AbC") == 0, 6); 1341d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strcasecmp("0123456789", "0123456789") == 0, 7); 1342d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strcasecmp("", "0123456789") < 0, 8); 1343d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strcasecmp("AbC", "") > 0, 9); 1344d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strcasecmp("AbC", "A") > 0, 10); 1345d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strcasecmp("AbC", "Ab") > 0, 11); 1346d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strcasecmp("AbC", "ab") > 0, 12); 1347d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 1348d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1349d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotestatic void 1350d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotetest_strncasecmp (void) 1351d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 1352d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote it = "strncasecmp"; 1353d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* Note that the locale is "C". */ 1354d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("a", "a", 5) == 0, 1); 1355d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("a", "A", 5) == 0, 2); 1356d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("A", "a", 5) == 0, 3); 1357d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("a", "b", 5) < 0, 4); 1358d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("c", "b", 5) > 0, 5); 1359d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("abc", "AbC", 5) == 0, 6); 1360d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("0123456789", "0123456789", 10) == 0, 7); 1361d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("", "0123456789", 10) < 0, 8); 1362d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("AbC", "", 5) > 0, 9); 1363d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("AbC", "A", 5) > 0, 10); 1364d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("AbC", "Ab", 5) > 0, 11); 1365d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("AbC", "ab", 5) > 0, 12); 1366d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("0123456789", "AbC", 0) == 0, 13); 1367d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("AbC", "abc", 1) == 0, 14); 1368d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("AbC", "abc", 2) == 0, 15); 1369d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("AbC", "abc", 3) == 0, 16); 1370d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("AbC", "abcd", 3) == 0, 17); 1371d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("AbC", "abcd", 4) < 0, 18); 1372d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("ADC", "abcd", 1) == 0, 19); 1373d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote check(strncasecmp("ADC", "abcd", 2) > 0, 20); 1374d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 1375d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1376284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardjstatic void 1377284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardjtest_strcasestr (void) 1378284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj{ 1379284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj it = "strcasestr"; 1380284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj check(strcasestr("abCd", "z") == NULL, 1); /* Not found. */ 1381284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj check(strcasestr("AbcD", "abX") == NULL, 2); /* Dead end. */ 1382284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj (void) strcpy(one, "abCd"); 1383284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj check(strcasestr(one, "c") == one+2, 3); /* Basic test. */ 1384284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj check(strcasestr(one, "Bc") == one+1, 4); /* Multichar. */ 1385284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj check(strcasestr(one, "d") == one+3, 5); /* End of string. */ 1386284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj check(strcasestr(one, "Cd") == one+2, 6); /* Tail of string. */ 1387284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj check(strcasestr(one, "aBc") == one, 7); /* Beginning. */ 1388284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj check(strcasestr(one, "aBcd") == one, 8); /* Exact match. */ 1389284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj check(strcasestr(one, "AbcDe") == NULL, 9); /* Too long. */ 1390284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj check(strcasestr(one, "dE") == NULL, 10); /* Past end. */ 1391284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj check(strcasestr(one, "") == one, 11); /* Finding empty. */ 1392284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj (void) strcpy(one, "abAba"); 1393284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj check(strcasestr(one, "Ba") == one+1, 12); /* Finding first. */ 1394284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj (void) strcpy(one, ""); 1395284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj check(strcasestr(one, "b") == NULL, 13); /* Empty string. */ 1396284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj check(strcasestr(one, "") == one, 14); /* Empty in empty string. */ 1397284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj (void) strcpy(one, "BcbCa"); 1398284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj check(strcasestr(one, "bCa") == one+2, 15); /* False start. */ 1399284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj (void) strcpy(one, "bbBcaBbcA"); 1400284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj check(strcasestr(one, "bbCa") == one+1, 16); /* With overlap. */ 1401284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj} 1402284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj 1403d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercoteint 1404d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercotemain (void) 1405d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote{ 1406d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote int status; 1407d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1408d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* Test strcmp first because we use it to test other things. */ 1409d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strcmp (); 1410d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1411d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* Test strcpy next because we need it to set up other tests. */ 1412d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strcpy (); 1413d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1414d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* A closely related function is stpcpy. */ 1415d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_stpcpy (); 1416d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1417f76d27a697a7b0bf3b84490baf60623fc96a23afnjn#if !defined(__APPLE__) 1418d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* stpncpy. */ 1419d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_stpncpy (); 1420f76d27a697a7b0bf3b84490baf60623fc96a23afnjn#endif 1421d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1422d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* strcat. */ 1423d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strcat (); 1424d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1425d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* strncat. */ 1426d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strncat (); 1427d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1428d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* strncmp. */ 1429d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strncmp (); 1430d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1431d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* strncpy. */ 1432d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strncpy (); 1433d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1434d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* strlen. */ 1435d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strlen (); 1436d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1437d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* strchr. */ 1438d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strchr (); 1439d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 14406e9de463ef677f093e9f24f126e1b11c28cf59fdsewardj# if !defined(__APPLE__) 1441d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* strchrnul. */ 1442d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strchrnul (); 1443aed053675acc9fb4fcbe7bc38c1120317bad68fasewardj# endif 1444d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 14456e9de463ef677f093e9f24f126e1b11c28cf59fdsewardj# if !defined(__APPLE__) 1446d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* rawmemchr. */ 1447d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_rawmemchr (); 1448aed053675acc9fb4fcbe7bc38c1120317bad68fasewardj# endif 1449d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1450d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* index - just like strchr. */ 1451d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_index (); 1452d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1453d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* strrchr. */ 1454d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strrchr (); 1455d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 14566e9de463ef677f093e9f24f126e1b11c28cf59fdsewardj# if !defined(__APPLE__) 1457d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* memrchr. */ 1458d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_memrchr (); 1459aed053675acc9fb4fcbe7bc38c1120317bad68fasewardj# endif 1460d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1461d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* rindex - just like strrchr. */ 1462d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_rindex (); 1463d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1464d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* strpbrk - somewhat like strchr. */ 1465d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strpbrk (); 1466d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1467d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* strstr - somewhat like strchr. */ 1468d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strstr (); 1469d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1470d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* strspn. */ 1471d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strspn (); 1472d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1473d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* strcspn. */ 1474d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strcspn (); 1475d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1476d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* strtok - the hard one. */ 1477d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strtok (); 1478d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1479d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* strtok_r. */ 1480d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strtok_r (); 1481d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1482d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* strsep. */ 1483d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strsep (); 1484d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1485d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* memcmp. */ 1486d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_memcmp (); 1487d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1488d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* memchr. */ 1489d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_memchr (); 1490d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1491d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* memcpy - need not work for overlap. */ 1492d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_memcpy (); 1493d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1494d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* memmove - must work on overlap. */ 1495d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_memmove (); 1496d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 14976e9de463ef677f093e9f24f126e1b11c28cf59fdsewardj# if !defined(__APPLE__) 1498d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* mempcpy */ 1499d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_mempcpy (); 1500aed053675acc9fb4fcbe7bc38c1120317bad68fasewardj# endif 1501d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1502d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* memccpy. */ 1503d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_memccpy (); 1504d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1505d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* memset. */ 1506d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_memset (); 1507d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1508d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* bcopy. */ 1509d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_bcopy (); 1510d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1511d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* bzero. */ 1512d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_bzero (); 1513d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1514d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* bcmp - somewhat like memcmp. */ 1515d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_bcmp (); 1516d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1517f76d27a697a7b0bf3b84490baf60623fc96a23afnjn#if !defined(__APPLE__) 1518d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* strndup. */ 1519d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strndup (); 1520f76d27a697a7b0bf3b84490baf60623fc96a23afnjn#endif 1521d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1522d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* strerror - VERY system-dependent. */ 1523d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strerror (); 1524d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1525d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* strcasecmp. Without locale dependencies. */ 1526d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strcasecmp (); 1527d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1528d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote /* strncasecmp. Without locale dependencies. */ 1529d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote test_strncasecmp (); 1530d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1531284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj test_strcasestr (); 1532284f2a39a1b20d8d158272966a33a9d0cc6b4c35sewardj 1533d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote if (errors == 0) 1534d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 1535d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote status = EXIT_SUCCESS; 1536d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote //puts("No errors."); 1537d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 1538d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote else 1539d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote { 1540d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote status = EXIT_FAILURE; 1541aed053675acc9fb4fcbe7bc38c1120317bad68fasewardj printf("%d errors.\n", (int)errors); 1542d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote } 1543d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote 1544d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote return status; 1545d91ea07acbb9da8c9f3c70d62ada540b9c0b0821nethercote} 1546