1 /* Copyright (C) 2000 Free Software Foundation.
3 Ensure builtin strlen, strcmp, strchr, strrchr and strncpy
6 Written by Jakub Jelinek, 11/7/2000. */
8 extern void abort (void);
9 extern __SIZE_TYPE__
strlen (const char *);
10 extern int strcmp (const char *, const char *);
11 extern char *strchr (const char *, int);
12 extern char *strrchr (const char *, int);
13 extern char *strncpy (char *, const char *, __SIZE_TYPE__
);
14 extern void *memset (void *, int, __SIZE_TYPE__
);
15 extern int memcmp (const void *, const void *, __SIZE_TYPE__
);
19 char *bar
= "hi world";
24 const char *const foo
= "hello world";
27 if (strlen (bar
) != 8)
29 if (strlen (bar
+ (++x
& 2)) != 6)
33 if (strlen (foo
+ (x
++, 6)) != 5)
37 if (strlen (foo
+ (++x
& 1)) != 10)
41 if (strcmp (foo
+ (x
-= 6), "lo world"))
45 if (strcmp (foo
, bar
) >= 0)
47 if (strcmp (foo
, bar
+ (x
++ & 1)) >= 0)
51 if (strchr (foo
+ (x
++ & 7), 'l') != foo
+ 9)
55 if (strchr (bar
, 'o') != bar
+ 4)
57 if (strchr (bar
, '\0') != bar
+ 8)
59 if (strrchr (bar
, 'x'))
61 if (strrchr (bar
, 'o') != bar
+ 4)
63 if (strcmp (foo
+ (x
++ & 1), "ello world" + (--y
& 1)))
71 if (strncpy (dst
+ 1, foo
+ (x
++ & 3), 4) != dst
+ 1
73 || strcmp (dst
+ 1, "ello "))
75 memset (dst
, ' ', sizeof dst
);
76 if (strncpy (dst
+ (++x
& 1), (y
++ & 3) + "foo", 10) != dst
+ 1
79 || memcmp (dst
, " oo\0\0\0\0\0\0\0\0 ", 12))
81 memset (dst
, ' ', sizeof dst
);
82 if (strncpy (dst
, "hello", 8) != dst
|| memcmp (dst
, "hello\0\0\0 ", 9))
85 memset (buf
, ' ', sizeof buf
);
86 if (memset (buf
, x
++, ++y
) != buf
89 || memcmp (buf
, "!!!", 3))
91 if (memset (buf
+ y
++, '-', 8) != buf
+ 3
93 || memcmp (buf
, "!!!--------", 11))
96 if (memset (buf
+ ++x
, 0, y
++) != buf
+ 11
99 || memcmp (buf
+ 8, "---\0\0\0", 7))
101 if (memset (buf
+ (x
+= 4), 0, 6) != buf
+ 15
103 || memcmp (buf
+ 10, "-\0\0\0\0\0\0\0\0\0", 11))