|
@@ -34,6 +34,11 @@
|
|
|
#include <strings.h>
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
+#ifdef __UCLIBC__
|
|
|
+# define __TEST_BSD_FUNCS__
|
|
|
+#else
|
|
|
+# undef __TEST_BSD_FUNCS__
|
|
|
+#endif
|
|
|
|
|
|
#define STREQ(a, b) (strcmp((a), (b)) == 0)
|
|
|
|
|
@@ -349,6 +354,53 @@ test_strncat (void)
|
|
|
equal (one, "abcdghij", 13);
|
|
|
}
|
|
|
|
|
|
+static void
|
|
|
+test_strlcat (void)
|
|
|
+{
|
|
|
+#ifdef __TEST_BSD_FUNCS__
|
|
|
+
|
|
|
+ mechanism. */
|
|
|
+ it = "strlcat";
|
|
|
+ (void) strcpy (one, "ijk");
|
|
|
+ check (strlcat (one, "lmn", 99) == 6, 1);
|
|
|
+ equal (one, "ijklmn", 2);
|
|
|
+
|
|
|
+ (void) strcpy (one, "x");
|
|
|
+ (void) strlcat (one, "yz", 99);
|
|
|
+ equal (one, "xyz", 3);
|
|
|
+ equal (one+4, "mn", 4);
|
|
|
+
|
|
|
+ (void) strcpy (one, "gh");
|
|
|
+ (void) strcpy (two, "ef");
|
|
|
+ (void) strlcat (one, two, 99);
|
|
|
+ equal (one, "ghef", 5);
|
|
|
+ equal (two, "ef", 6);
|
|
|
+
|
|
|
+ (void) strcpy (one, "");
|
|
|
+ (void) strlcat (one, "", 99);
|
|
|
+ equal (one, "", 7);
|
|
|
+ (void) strcpy (one, "ab");
|
|
|
+ (void) strlcat (one, "", 99);
|
|
|
+ equal (one, "ab", 8);
|
|
|
+ (void) strcpy (one, "");
|
|
|
+ (void) strlcat (one, "cd", 99);
|
|
|
+ equal (one, "cd", 9);
|
|
|
+
|
|
|
+ (void) strcpy (one, "ab");
|
|
|
+ (void) strlcat (one, "cdef", 2);
|
|
|
+ equal (one, "ab", 10);
|
|
|
+
|
|
|
+ (void) strlcat (one, "gh", 0);
|
|
|
+ equal (one, "ab", 11);
|
|
|
+
|
|
|
+ (void) strlcat (one, "gh", 4);
|
|
|
+ equal (one, "abg", 12);
|
|
|
+
|
|
|
+ (void) strlcat (one, "ij", (size_t)-1);
|
|
|
+ equal (one, "abgij", 13);
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
static void
|
|
|
test_strncmp (void)
|
|
|
{
|
|
@@ -413,6 +465,50 @@ test_strncpy (void)
|
|
|
equal (one, "hi there", 15);
|
|
|
}
|
|
|
|
|
|
+static void
|
|
|
+test_strlcpy (void)
|
|
|
+{
|
|
|
+#ifdef __TEST_BSD_FUNCS__
|
|
|
+
|
|
|
+ it = "strlcpy";
|
|
|
+ check (strlcpy (one, "abc", sizeof(one)) == 3, 1);
|
|
|
+ equal (one, "abc", 2);
|
|
|
+
|
|
|
+ (void) strcpy (one, "abcdefgh");
|
|
|
+ (void) strlcpy (one, "xyz", 2);
|
|
|
+ equal (one, "x\0cdefgh", 3);
|
|
|
+
|
|
|
+ (void) strcpy (one, "abcdefgh");
|
|
|
+ (void) strlcpy (one, "xyz", 3);
|
|
|
+ equal (one, "xy\0defgh", 4);
|
|
|
+
|
|
|
+ (void) strcpy (one, "abcdefgh");
|
|
|
+ (void) strlcpy (one, "xyz", 4);
|
|
|
+ equal (one, "xyz", 5);
|
|
|
+ equal (one+4, "efgh", 6);
|
|
|
+
|
|
|
+ (void) strcpy (one, "abcdefgh");
|
|
|
+ (void) strlcpy (one, "xyz", 5);
|
|
|
+ equal (one, "xyz", 7);
|
|
|
+ equal (one+3, "", 8);
|
|
|
+ equal (one+4, "efgh", 9);
|
|
|
+
|
|
|
+ (void) strcpy (one, "abc");
|
|
|
+ (void) strlcpy (one, "xyz", 0);
|
|
|
+ equal (one, "abc", 10);
|
|
|
+
|
|
|
+ (void) strlcpy (one, "", 2);
|
|
|
+ equal (one, "", 11);
|
|
|
+ equal (one+1, "bc", 12);
|
|
|
+ equal (one+2, "c", 13);
|
|
|
+
|
|
|
+ (void) strcpy (one, "hi there");
|
|
|
+ (void) strlcpy (two, one, 9);
|
|
|
+ equal (two, "hi there", 14);
|
|
|
+ equal (one, "hi there", 15);
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
static void
|
|
|
test_strlen (void)
|
|
|
{
|
|
@@ -1401,12 +1497,18 @@ main (void)
|
|
|
|
|
|
test_strncat ();
|
|
|
|
|
|
+
|
|
|
+ test_strlcat ();
|
|
|
+
|
|
|
|
|
|
test_strncmp ();
|
|
|
|
|
|
|
|
|
test_strncpy ();
|
|
|
|
|
|
+
|
|
|
+ test_strlcpy ();
|
|
|
+
|
|
|
|
|
|
test_strlen ();
|
|
|
|