tester.c 49 KB

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