1 /* Copyright (C) 2000 Free Software Foundation.
3 Ensure all expected transformations of builtin strncpy occur and
6 Written by Kaveh R. Ghazi, 11/25/2000. */
8 extern void abort (void);
9 typedef __SIZE_TYPE__ size_t;
10 extern char *strncpy (char *, const char *, size_t);
11 extern int strcmp (const char *, const char *);
12 extern int strncmp (const char *, const char *, size_t);
13 extern void *memset (void *, int, size_t);
19 const char *const src = "hello world";
23 memset (dst, 0, sizeof (dst));
24 if (strncpy (dst, src, 4) != dst || strncmp (dst, src, 4))
27 memset (dst, 0, sizeof (dst));
28 if (strncpy (dst+16, src, 4) != dst+16 || strncmp (dst+16, src, 4))
31 memset (dst, 0, sizeof (dst));
32 if (strncpy (dst+32, src+5, 4) != dst+32 || strncmp (dst+32, src+5, 4))
35 memset (dst, 0, sizeof (dst));
37 if (strncpy (++dst2, src+5, 4) != dst+1 || strncmp (dst2, src+5, 4)
41 memset (dst, 0, sizeof (dst));
42 if (strncpy (dst, src, 0) != dst || strcmp (dst, ""))
45 memset (dst, 0, sizeof (dst));
46 dst2 = dst; src2 = src;
47 if (strncpy (++dst2, ++src2, 0) != dst+1 || strcmp (dst2, "")
48 || dst2 != dst+1 || src2 != src+1)
51 memset (dst, 0, sizeof (dst));
52 dst2 = dst; src2 = src;
53 if (strncpy (++dst2+5, ++src2+5, 0) != dst+6 || strcmp (dst2+5, "")
54 || dst2 != dst+1 || src2 != src+1)
57 memset (dst, 0, sizeof (dst));
58 if (strncpy (dst, src, 12) != dst || strcmp (dst, src))
61 /* Test at least one instance of the __builtin_ style. We do this
62 to ensure that it works and that the prototype is correct. */
63 memset (dst, 0, sizeof (dst));
64 if (__builtin_strncpy (dst, src, 4) != dst || strncmp (dst, src, 4))
67 memset (dst, 0, sizeof (dst));
68 if (strncpy (dst, i++ ? "xfoo" + 1 : "bar", 4) != dst
69 || strcmp (dst, "bar")
77 /* When optimizing, all the above cases should be transformed into
78 something else. So any remaining calls to the original function
80 __attribute__ ((noinline))
82 strncpy(char *s1, const char *s2, size_t n)