Back to index

glibc  2.9
tst-strlen.c
Go to the documentation of this file.
00001 /* Make sure we don't test the optimized inline functions if we want to
00002    test the real implementation.  */
00003 #undef __USE_STRING_INLINES
00004 
00005 #include <stdio.h>
00006 #include <string.h>
00007 
00008 int
00009 main(int argc, char *argv[])
00010 {
00011   static const size_t lens[] = { 0, 1, 0, 2, 0, 1, 0, 3,
00012                              0, 1, 0, 2, 0, 1, 0, 4 };
00013   char basebuf[24 + 32];
00014   size_t base;
00015 
00016   for (base = 0; base < 32; ++base)
00017     {
00018       char *buf = basebuf + base;
00019       size_t words;
00020 
00021       for (words = 0; words < 4; ++words)
00022        {
00023          size_t last;
00024          memset (buf, 'a', words * 4);
00025 
00026          for (last = 0; last < 16; ++last)
00027            {
00028              buf[words * 4 + 0] = (last & 1) != 0 ? 'b' : '\0';
00029              buf[words * 4 + 1] = (last & 2) != 0 ? 'c' : '\0';
00030              buf[words * 4 + 2] = (last & 4) != 0 ? 'd' : '\0';
00031              buf[words * 4 + 3] = (last & 8) != 0 ? 'e' : '\0';
00032              buf[words * 4 + 4] = '\0';
00033 
00034              if (strlen (buf) != words * 4 + lens[last]
00035                 || strnlen (buf, -1) != words * 4 + lens[last])
00036               {
00037                 printf ("failed for base=%Zu, words=%Zu, and last=%Zu\n",
00038                        base, words, last);
00039                 return 1;
00040               }
00041            }
00042        }
00043     }
00044   return 0;
00045 }