1 /* $NetBSD: t_strchr.c,v 1.2 2017/01/10 15:34:49 christos Exp $ */
4 * Written by J.T. Conklin <jtc@acorntoolworks.com>
15 static char *slow_strchr(char *, int);
16 static void verify_strchr(char *, int, unsigned int, unsigned int);
18 char * (*volatile strchr_fn)(const char *, int);
21 slow_strchr(char *buf, int ch)
27 for (; c != 0; buf++) {
36 verify_strchr(char *buf, int ch, unsigned int t, unsigned int a)
38 const char *off, *ok_off;
40 off = strchr_fn(buf, ch);
41 ok_off = slow_strchr(buf, ch);
45 fprintf(stderr, "test_strchr(\"%s\", %#x) gave %zd not %zd (test %d, "
47 buf, ch, off ? off - buf : -1, ok_off ? ok_off - buf : -1, t, a);
49 atf_tc_fail("Check stderr for details");
53 ATF_TC_HEAD(strchr_basic, tc)
56 atf_tc_set_md_var(tc, "descr", "Test strchr(3) results");
59 ATF_TC_BODY(strchr_basic, tc)
246 "abcdefgh/abcdefgh/",
249 dl_handle = dlopen(NULL, RTLD_LAZY);
250 strchr_fn = dlsym(dl_handle, "test_strlen");
254 for (a = 3; a < 3 + sizeof(long); ++a) {
255 /* Put char and a \0 before the buffer */
259 for (t = 0; t < (sizeof(tab) / sizeof(tab[0])); ++t) {
260 int len = strlen(tab[t]) + 1;
261 memcpy(&buf[a], tab[t], len);
263 /* Put the char we are looking for after the \0 */
266 /* Check search for NUL at end of string */
267 verify_strchr(buf + a, 0, t, a);
269 /* Then for the '/' in the strings */
270 verify_strchr(buf + a, '/', t, a);
272 /* check zero extension of char arg */
273 verify_strchr(buf + a, 0xffffff00 | '/', t, a);
275 /* Replace all the '/' with 0xff */
276 while ((off = slow_strchr(buf + a, '/')) != NULL)
281 /* Check we can search for 0xff as well as '/' */
282 verify_strchr(buf + a, 0xff, t, a);
285 (void)dlclose(dl_handle);
291 ATF_TP_ADD_TC(tp, strchr_basic);
293 return atf_no_error();