Back to index

glibc  2.9
bug-strtok1.c
Go to the documentation of this file.
00001 /* See BZ #2126.  */
00002 #include <string.h>
00003 #include <stdio.h>
00004 
00005 static int
00006 do_test (void)
00007 {
00008   const char str[] = "axaaba";
00009   char *token;
00010   char *cp;
00011   char *l;
00012   int result = 0;
00013 
00014   puts ("test strtok");
00015   cp = strdupa (str);
00016   printf ("cp = %p, len = %zu\n", cp, strlen (cp));
00017   token = strtok (cp, "ab");
00018   result |= token == NULL || strcmp (token, "x");
00019   printf ("token: %s (%d)\n", token ? token : "NULL", result);
00020   token = strtok(0, "ab");
00021   result |= token != NULL;
00022   printf ("token: %s (%d)\n", token ? token : "NULL", result);
00023   token = strtok(0, "a");
00024   result |= token != NULL;
00025   printf ("token: %s (%d)\n", token ? token : "NULL", result);
00026 
00027   puts ("test strtok_r");
00028   cp = strdupa (str);
00029   size_t len = strlen (cp);
00030   printf ("cp = %p, len = %zu\n", cp, len);
00031   token = strtok_r (cp, "ab", &l);
00032   result |= token == NULL || strcmp (token, "x");
00033   printf ("token: %s, next = %p (%d)\n", token ? token : "NULL", l, result);
00034   token = strtok_r(0, "ab", &l);
00035   result |= token != NULL || l != cp + len;
00036   printf ("token: %s, next = %p (%d)\n", token ? token : "NULL", l, result);
00037   token = strtok_r(0, "a", &l);
00038   result |= token != NULL || l != cp + len;
00039   printf ("token: %s,  next = %p (%d)\n", token ? token : "NULL", l, result);
00040 
00041   return result;
00042 }
00043 
00044 #define TEST_FUNCTION do_test ()
00045 #include "../test-skeleton.c"