diff options
Diffstat (limited to 'libsimple.c')
-rw-r--r-- | libsimple.c | 790 |
1 files changed, 2 insertions, 788 deletions
diff --git a/libsimple.c b/libsimple.c index 2cf7b62..2bb5139 100644 --- a/libsimple.c +++ b/libsimple.c @@ -92,9 +92,9 @@ main(void) void *ptr, *old; const char *cs; const wchar_t *cws; - char buf[1024], *s; + char *s; wchar_t *ws; - size_t i, j, n; + size_t i, n; DEFINE_PAGESIZE; DEFINE_CACHELINE; @@ -280,342 +280,6 @@ main(void) assert(TYPE_MIN(int64_t) == INT64_MIN); assert(TYPE_MIN(uint64_t) == 0); - assert(strcmpnul(libsimple_strend("abc\0xyz"), "xyz")); - - assert(libsimple_inchrset('a', "xyz") == 0); - assert(libsimple_inchrset('b', "xyz") == 0); - assert(libsimple_inchrset('c', "xyz") == 0); - assert(libsimple_inchrset('x', "xyz") == 1); - assert(libsimple_inchrset('y', "xyz") == 1); - assert(libsimple_inchrset('z', "xyz") == 1); - assert(libsimple_inchrset('\0', "xyz") == 0); - - assert(libsimple_streq("abc", "abc") == 1); - assert(libsimple_streq("abc", "ab") == 0); - assert(libsimple_streq("ab", "abc") == 0); - assert(libsimple_streq("ab", "xy") == 0); - assert(libsimple_streq("xy", "ab") == 0); - assert(libsimple_streq("", "1") == 0); - assert(libsimple_streq("1", "") == 0); - assert(libsimple_streq("", "") == 1); - assert(libsimple_streq("abc", "ABC") == 0); - assert(libsimple_streq("ABC", "abc") == 0); - - assert(libsimple_strneq("abc", "abc", 5) == 1); - assert(libsimple_strneq("abc", "ab", 5) == 0); - assert(libsimple_strneq("ab", "abc", 5) == 0); - assert(libsimple_strneq("ab", "xy", 5) == 0); - assert(libsimple_strneq("xy", "ab", 5) == 0); - assert(libsimple_strneq("", "1", 5) == 0); - assert(libsimple_strneq("1", "", 5) == 0); - assert(libsimple_strneq("", "", 5) == 1); - assert(libsimple_strneq("abc", "ABC", 5) == 0); - assert(libsimple_strneq("ABC", "abc", 5) == 0); - assert(libsimple_strneq("abc", "abc", 1) == 1); - assert(libsimple_strneq("abc", "ab", 1) == 1); - assert(libsimple_strneq("ab", "abc", 1) == 1); - assert(libsimple_strneq("ab", "xy", 1) == 0); - assert(libsimple_strneq("xy", "ab", 1) == 0); - assert(libsimple_strneq("", "1", 1) == 0); - assert(libsimple_strneq("1", "", 1) == 0); - assert(libsimple_strneq("", "", 1) == 1); - assert(libsimple_strneq("abc", "ABC", 1) == 0); - assert(libsimple_strneq("ABC", "abc", 1) == 0); - assert(libsimple_strneq("abc", "abc", 0) == 1); - assert(libsimple_strneq("abc", "ab", 0) == 1); - assert(libsimple_strneq("ab", "abc", 0) == 1); - assert(libsimple_strneq("ab", "xy", 0) == 1); - assert(libsimple_strneq("xy", "ab", 0) == 1); - assert(libsimple_strneq("", "1", 0) == 1); - assert(libsimple_strneq("1", "", 0) == 1); - assert(libsimple_strneq("", "", 0) == 1); - assert(libsimple_strneq("abc", "ABC", 0) == 1); - assert(libsimple_strneq("ABC", "abc", 0) == 1); - - assert(libsimple_streqnul("abc", "abc") == 1); - assert(libsimple_streqnul("abc", "ab") == 0); - assert(libsimple_streqnul("ab", "abc") == 0); - assert(libsimple_streqnul("ab", "xy") == 0); - assert(libsimple_streqnul("xy", "ab") == 0); - assert(libsimple_streqnul("", "1") == 0); - assert(libsimple_streqnul("1", "") == 0); - assert(libsimple_streqnul("", "") == 1); - assert(libsimple_streqnul("abc", "ABC") == 0); - assert(libsimple_streqnul("ABC", "abc") == 0); - assert(libsimple_streqnul("", NULL) == 0); - assert(libsimple_streqnul("1", NULL) == 0); - assert(libsimple_streqnul(NULL, "") == 0); - assert(libsimple_streqnul(NULL, "1") == 0); - assert(libsimple_streqnul(NULL, NULL) == 1); - - assert(libsimple_strneqnul("abc", "abc", 5) == 1); - assert(libsimple_strneqnul("abc", "ab", 5) == 0); - assert(libsimple_strneqnul("ab", "abc", 5) == 0); - assert(libsimple_strneqnul("ab", "xy", 5) == 0); - assert(libsimple_strneqnul("xy", "ab", 5) == 0); - assert(libsimple_strneqnul("", "1", 5) == 0); - assert(libsimple_strneqnul("1", "", 5) == 0); - assert(libsimple_strneqnul("", "", 5) == 1); - assert(libsimple_strneqnul("abc", "ABC", 5) == 0); - assert(libsimple_strneqnul("ABC", "abc", 5) == 0); - assert(libsimple_strneqnul("", NULL, 5) == 0); - assert(libsimple_strneqnul("1", NULL, 5) == 0); - assert(libsimple_strneqnul(NULL, "", 5) == 0); - assert(libsimple_strneqnul(NULL, "1", 5) == 0); - assert(libsimple_strneqnul(NULL, NULL, 5) == 1); - assert(libsimple_strneqnul("abc", "abc", 1) == 1); - assert(libsimple_strneqnul("abc", "ab", 1) == 1); - assert(libsimple_strneqnul("ab", "abc", 1) == 1); - assert(libsimple_strneqnul("ab", "xy", 1) == 0); - assert(libsimple_strneqnul("xy", "ab", 1) == 0); - assert(libsimple_strneqnul("", "1", 1) == 0); - assert(libsimple_strneqnul("1", "", 1) == 0); - assert(libsimple_strneqnul("", "", 1) == 1); - assert(libsimple_strneqnul("abc", "ABC", 1) == 0); - assert(libsimple_strneqnul("ABC", "abc", 1) == 0); - assert(libsimple_strneqnul("", NULL, 1) == 0); - assert(libsimple_strneqnul("1", NULL, 1) == 0); - assert(libsimple_strneqnul(NULL, "", 1) == 0); - assert(libsimple_strneqnul(NULL, "1", 1) == 0); - assert(libsimple_strneqnul(NULL, NULL, 1) == 1); - assert(libsimple_strneqnul("abc", "abc", 0) == 1); - assert(libsimple_strneqnul("abc", "ab", 0) == 1); - assert(libsimple_strneqnul("ab", "abc", 0) == 1); - assert(libsimple_strneqnul("ab", "xy", 0) == 1); - assert(libsimple_strneqnul("xy", "ab", 0) == 1); - assert(libsimple_strneqnul("", "1", 0) == 1); - assert(libsimple_strneqnul("1", "", 0) == 1); - assert(libsimple_strneqnul("", "", 0) == 1); - assert(libsimple_strneqnul("abc", "ABC", 0) == 1); - assert(libsimple_strneqnul("ABC", "abc", 0) == 1); - assert(libsimple_strneqnul("", NULL, 0) == 0); - assert(libsimple_strneqnul("1", NULL, 0) == 0); - assert(libsimple_strneqnul(NULL, "", 0) == 0); - assert(libsimple_strneqnul(NULL, "1", 0) == 0); - assert(libsimple_strneqnul(NULL, NULL, 0) == 1); - - assert(libsimple_strcaseeq("abc", "abc") == 1); - assert(libsimple_strcaseeq("abc", "ab") == 0); - assert(libsimple_strcaseeq("ab", "abc") == 0); - assert(libsimple_strcaseeq("ab", "xy") == 0); - assert(libsimple_strcaseeq("xy", "ab") == 0); - assert(libsimple_strcaseeq("", "1") == 0); - assert(libsimple_strcaseeq("1", "") == 0); - assert(libsimple_strcaseeq("", "") == 1); - assert(libsimple_strcaseeq("abc", "ABC") == 1); - assert(libsimple_strcaseeq("ABC", "abc") == 1); - - assert(libsimple_strncaseeq("abc", "abc", 5) == 1); - assert(libsimple_strncaseeq("abc", "ab", 5) == 0); - assert(libsimple_strncaseeq("ab", "abc", 5) == 0); - assert(libsimple_strncaseeq("ab", "xy", 5) == 0); - assert(libsimple_strncaseeq("xy", "ab", 5) == 0); - assert(libsimple_strncaseeq("", "1", 5) == 0); - assert(libsimple_strncaseeq("1", "", 5) == 0); - assert(libsimple_strncaseeq("", "", 5) == 1); - assert(libsimple_strncaseeq("abc", "ABC", 5) == 1); - assert(libsimple_strncaseeq("ABC", "abc", 5) == 1); - assert(libsimple_strncaseeq("abc", "abc", 1) == 1); - assert(libsimple_strncaseeq("abc", "ab", 1) == 1); - assert(libsimple_strncaseeq("ab", "abc", 1) == 1); - assert(libsimple_strncaseeq("ab", "xy", 1) == 0); - assert(libsimple_strncaseeq("xy", "ab", 1) == 0); - assert(libsimple_strncaseeq("", "1", 1) == 0); - assert(libsimple_strncaseeq("1", "", 1) == 0); - assert(libsimple_strncaseeq("", "", 1) == 1); - assert(libsimple_strncaseeq("abc", "ABC", 1) == 1); - assert(libsimple_strncaseeq("ABC", "abc", 1) == 1); - assert(libsimple_strncaseeq("abc", "abc", 0) == 1); - assert(libsimple_strncaseeq("abc", "ab", 0) == 1); - assert(libsimple_strncaseeq("ab", "abc", 0) == 1); - assert(libsimple_strncaseeq("ab", "xy", 0) == 1); - assert(libsimple_strncaseeq("xy", "ab", 0) == 1); - assert(libsimple_strncaseeq("", "1", 0) == 1); - assert(libsimple_strncaseeq("1", "", 0) == 1); - assert(libsimple_strncaseeq("", "", 0) == 1); - assert(libsimple_strncaseeq("abc", "ABC", 0) == 1); - assert(libsimple_strncaseeq("ABC", "abc", 0) == 1); - - assert(libsimple_strcaseeqnul("abc", "abc") == 1); - assert(libsimple_strcaseeqnul("abc", "ab") == 0); - assert(libsimple_strcaseeqnul("ab", "abc") == 0); - assert(libsimple_strcaseeqnul("ab", "xy") == 0); - assert(libsimple_strcaseeqnul("xy", "ab") == 0); - assert(libsimple_strcaseeqnul("", "1") == 0); - assert(libsimple_strcaseeqnul("1", "") == 0); - assert(libsimple_strcaseeqnul("", "") == 1); - assert(libsimple_strcaseeqnul("abc", "ABC") == 1); - assert(libsimple_strcaseeqnul("ABC", "abc") == 1); - assert(libsimple_strcaseeqnul("", NULL) == 0); - assert(libsimple_strcaseeqnul("1", NULL) == 0); - assert(libsimple_strcaseeqnul(NULL, "") == 0); - assert(libsimple_strcaseeqnul(NULL, "1") == 0); - assert(libsimple_strcaseeqnul(NULL, NULL) == 1); - - assert(libsimple_strncaseeqnul("abc", "abc", 5) == 1); - assert(libsimple_strncaseeqnul("abc", "ab", 5) == 0); - assert(libsimple_strncaseeqnul("ab", "abc", 5) == 0); - assert(libsimple_strncaseeqnul("ab", "xy", 5) == 0); - assert(libsimple_strncaseeqnul("xy", "ab", 5) == 0); - assert(libsimple_strncaseeqnul("", "1", 5) == 0); - assert(libsimple_strncaseeqnul("1", "", 5) == 0); - assert(libsimple_strncaseeqnul("", "", 5) == 1); - assert(libsimple_strncaseeqnul("abc", "ABC", 5) == 1); - assert(libsimple_strncaseeqnul("ABC", "abc", 5) == 1); - assert(libsimple_strncaseeqnul("", NULL, 5) == 0); - assert(libsimple_strncaseeqnul("1", NULL, 5) == 0); - assert(libsimple_strncaseeqnul(NULL, "", 5) == 0); - assert(libsimple_strncaseeqnul(NULL, "1", 5) == 0); - assert(libsimple_strncaseeqnul(NULL, NULL, 5) == 1); - assert(libsimple_strncaseeqnul("abc", "abc", 1) == 1); - assert(libsimple_strncaseeqnul("abc", "ab", 1) == 1); - assert(libsimple_strncaseeqnul("ab", "abc", 1) == 1); - assert(libsimple_strncaseeqnul("ab", "xy", 1) == 0); - assert(libsimple_strncaseeqnul("xy", "ab", 1) == 0); - assert(libsimple_strncaseeqnul("", "1", 1) == 0); - assert(libsimple_strncaseeqnul("1", "", 1) == 0); - assert(libsimple_strncaseeqnul("", "", 1) == 1); - assert(libsimple_strncaseeqnul("abc", "ABC", 1) == 1); - assert(libsimple_strncaseeqnul("ABC", "abc", 1) == 1); - assert(libsimple_strncaseeqnul("", NULL, 1) == 0); - assert(libsimple_strncaseeqnul("1", NULL, 1) == 0); - assert(libsimple_strncaseeqnul(NULL, "", 1) == 0); - assert(libsimple_strncaseeqnul(NULL, "1", 1) == 0); - assert(libsimple_strncaseeqnul(NULL, NULL, 1) == 1); - assert(libsimple_strncaseeqnul("abc", "abc", 0) == 1); - assert(libsimple_strncaseeqnul("abc", "ab", 0) == 1); - assert(libsimple_strncaseeqnul("ab", "abc", 0) == 1); - assert(libsimple_strncaseeqnul("ab", "xy", 0) == 1); - assert(libsimple_strncaseeqnul("xy", "ab", 0) == 1); - assert(libsimple_strncaseeqnul("", "1", 0) == 1); - assert(libsimple_strncaseeqnul("1", "", 0) == 1); - assert(libsimple_strncaseeqnul("", "", 0) == 1); - assert(libsimple_strncaseeqnul("abc", "ABC", 0) == 1); - assert(libsimple_strncaseeqnul("ABC", "abc", 0) == 1); - assert(libsimple_strncaseeqnul("", NULL, 0) == 0); - assert(libsimple_strncaseeqnul("1", NULL, 0) == 0); - assert(libsimple_strncaseeqnul(NULL, "", 0) == 0); - assert(libsimple_strncaseeqnul(NULL, "1", 0) == 0); - assert(libsimple_strncaseeqnul(NULL, NULL, 0) == 1); - - assert(libsimple_strcmpnul(NULL, NULL) == 0); - assert(libsimple_strcmpnul(NULL, "") < 0); - assert(libsimple_strcmpnul("", NULL) > 0); - assert(libsimple_strcmpnul("", "") == 0); - assert(libsimple_strcmpnul(NULL, "x") < 0); - assert(libsimple_strcmpnul("x", NULL) > 0); - assert(libsimple_strcmpnul("x", "x") == 0); - assert(libsimple_strcmpnul("a", "b") < 0); - assert(libsimple_strcmpnul("b", "a") > 0); - assert(libsimple_strcmpnul("aa", "ab") < 0); - assert(libsimple_strcmpnul("ab", "aa") > 0); - assert(libsimple_strcmpnul("aa", "aa") == 0); - assert(libsimple_strcmpnul("A", "a") < 0); - assert(libsimple_strcmpnul("a", "A") > 0); - assert(libsimple_strcmpnul("AA", "Aa") < 0); - assert(libsimple_strcmpnul("Aa", "AA") > 0); - assert(libsimple_strcmpnul("AA", "AA") == 0); - - assert(libsimple_strcasecmpnul(NULL, NULL) == 0); - assert(libsimple_strcasecmpnul(NULL, "") < 0); - assert(libsimple_strcasecmpnul("", NULL) > 0); - assert(libsimple_strcasecmpnul("", "") == 0); - assert(libsimple_strcasecmpnul(NULL, "x") < 0); - assert(libsimple_strcasecmpnul("x", NULL) > 0); - assert(libsimple_strcasecmpnul("x", "x") == 0); - assert(libsimple_strcasecmpnul("a", "b") < 0); - assert(libsimple_strcasecmpnul("b", "a") > 0); - assert(libsimple_strcasecmpnul("aa", "ab") < 0); - assert(libsimple_strcasecmpnul("ab", "aa") > 0); - assert(libsimple_strcasecmpnul("aa", "aa") == 0); - assert(libsimple_strcasecmpnul("A", "a") == 0); - assert(libsimple_strcasecmpnul("a", "A") == 0); - assert(libsimple_strcasecmpnul("AA", "Aa") == 0); - assert(libsimple_strcasecmpnul("Aa", "AA") == 0); - assert(libsimple_strcasecmpnul("AA", "AA") == 0); - - assert(libsimple_strncmpnul(NULL, NULL, 5) == 0); - assert(libsimple_strncmpnul(NULL, "", 5) < 0); - assert(libsimple_strncmpnul("", NULL, 5) > 0); - assert(libsimple_strncmpnul("", "", 5) == 0); - assert(libsimple_strncmpnul(NULL, "x", 5) < 0); - assert(libsimple_strncmpnul("x", NULL, 5) > 0); - assert(libsimple_strncmpnul("x", "x", 5) == 0); - assert(libsimple_strncmpnul("a", "b", 5) < 0); - assert(libsimple_strncmpnul("b", "a", 5) > 0); - assert(libsimple_strncmpnul("aa", "ab", 5) < 0); - assert(libsimple_strncmpnul("ab", "aa", 5) > 0); - assert(libsimple_strncmpnul("aa", "aa", 5) == 0); - assert(libsimple_strncmpnul("A", "a", 5) < 0); - assert(libsimple_strncmpnul("a", "A", 5) > 0); - assert(libsimple_strncmpnul("AA", "Aa", 5) < 0); - assert(libsimple_strncmpnul("Aa", "AA", 5) > 0); - assert(libsimple_strncmpnul("AA", "AA", 5) == 0); - assert(libsimple_strncmpnul("aa", "ab", 1) == 0); - assert(libsimple_strncmpnul("ab", "aa", 1) == 0); - assert(libsimple_strncmpnul("aa", "aa", 1) == 0); - assert(libsimple_strncmpnul("AA", "Aa", 1) == 0); - assert(libsimple_strncmpnul("Aa", "AA", 1) == 0); - assert(libsimple_strncmpnul("AA", "AA", 1) == 0); - assert(libsimple_strncmpnul(NULL, NULL, 0) == 0); - assert(libsimple_strncmpnul(NULL, "", 0) < 0); - assert(libsimple_strncmpnul("", NULL, 0) > 0); - assert(libsimple_strncmpnul("", "", 0) == 0); - assert(libsimple_strncmpnul(NULL, "x", 0) < 0); - assert(libsimple_strncmpnul("x", NULL, 0) > 0); - assert(libsimple_strncmpnul("x", "x", 0) == 0); - assert(libsimple_strncmpnul("a", "b", 0) == 0); - assert(libsimple_strncmpnul("b", "a", 0) == 0); - assert(libsimple_strncmpnul("aa", "ab", 0) == 0); - assert(libsimple_strncmpnul("ab", "aa", 0) == 0); - assert(libsimple_strncmpnul("aa", "aa", 0) == 0); - assert(libsimple_strncmpnul("A", "a", 0) == 0); - assert(libsimple_strncmpnul("a", "A", 0) == 0); - assert(libsimple_strncmpnul("AA", "Aa", 0) == 0); - assert(libsimple_strncmpnul("Aa", "AA", 0) == 0); - assert(libsimple_strncmpnul("AA", "AA", 0) == 0); - - assert(libsimple_strncasecmpnul(NULL, NULL, 5) == 0); - assert(libsimple_strncasecmpnul(NULL, "", 5) < 0); - assert(libsimple_strncasecmpnul("", NULL, 5) > 0); - assert(libsimple_strncasecmpnul("", "", 5) == 0); - assert(libsimple_strncasecmpnul(NULL, "x", 5) < 0); - assert(libsimple_strncasecmpnul("x", NULL, 5) > 0); - assert(libsimple_strncasecmpnul("x", "x", 5) == 0); - assert(libsimple_strncasecmpnul("a", "b", 5) < 0); - assert(libsimple_strncasecmpnul("b", "a", 5) > 0); - assert(libsimple_strncasecmpnul("aa", "ab", 5) < 0); - assert(libsimple_strncasecmpnul("ab", "aa", 5) > 0); - assert(libsimple_strncasecmpnul("aa", "aa", 5) == 0); - assert(libsimple_strncasecmpnul("A", "a", 5) == 0); - assert(libsimple_strncasecmpnul("a", "A", 5) == 0); - assert(libsimple_strncasecmpnul("AA", "Aa", 5) == 0); - assert(libsimple_strncasecmpnul("Aa", "AA", 5) == 0); - assert(libsimple_strncasecmpnul("AA", "AA", 5) == 0); - assert(libsimple_strncasecmpnul("aa", "ab", 1) == 0); - assert(libsimple_strncasecmpnul("ab", "aa", 1) == 0); - assert(libsimple_strncasecmpnul("aa", "aa", 1) == 0); - assert(libsimple_strncasecmpnul("AA", "Aa", 1) == 0); - assert(libsimple_strncasecmpnul("Aa", "AA", 1) == 0); - assert(libsimple_strncasecmpnul("AA", "AA", 1) == 0); - assert(libsimple_strncasecmpnul(NULL, NULL, 0) == 0); - assert(libsimple_strncasecmpnul(NULL, "", 0) < 0); - assert(libsimple_strncasecmpnul("", NULL, 0) > 0); - assert(libsimple_strncasecmpnul("", "", 0) == 0); - assert(libsimple_strncasecmpnul(NULL, "x", 0) < 0); - assert(libsimple_strncasecmpnul("x", NULL, 0) > 0); - assert(libsimple_strncasecmpnul("x", "x", 0) == 0); - assert(libsimple_strncasecmpnul("a", "b", 0) == 0); - assert(libsimple_strncasecmpnul("b", "a", 0) == 0); - assert(libsimple_strncasecmpnul("aa", "ab", 0) == 0); - assert(libsimple_strncasecmpnul("ab", "aa", 0) == 0); - assert(libsimple_strncasecmpnul("aa", "aa", 0) == 0); - assert(libsimple_strncasecmpnul("A", "a", 0) == 0); - assert(libsimple_strncasecmpnul("a", "A", 0) == 0); - assert(libsimple_strncasecmpnul("AA", "Aa", 0) == 0); - assert(libsimple_strncasecmpnul("Aa", "AA", 0) == 0); - assert(libsimple_strncasecmpnul("AA", "AA", 0) == 0); - #ifdef libsimple_strdupa cs = ""; s = libsimple_strdupa(cs); @@ -1524,456 +1188,6 @@ main(void) fprintf(stderr, "warning: libsimple_vasprintfa missing\n"); #endif - { - char a[] = "abcdefgh", b[] = "abcdefgh"; - assert(libsimple_strreqlen("", "") == 0); - assert(libsimple_strreqlen("x", "") == 0); - assert(libsimple_strreqlen("x", "y") == 0); - assert(libsimple_strreqlen("", "y") == 0); - for (i = 0; i <= 8; i++) { - for (j = 0; j <= 8; j++) { - assert(libsimple_strreqlen(&a[i], &b[j]) == 8 - (i > j ? i : j)); - a[i] = b[j] = '\0'; - assert(libsimple_strreqlen(a, b) == (i == j ? i : 0)); - a[i] = "abcdefgh"[i]; - b[j] = "abcdefgh"[j]; - } - } - assert(libsimple_strreqlen("abc", "ABC") == 0); - assert(libsimple_strreqlen("123", "123") == 3); - } - - { - char a[] = "abcdefgh", b[] = "ABCDEFGH"; - assert(libsimple_strrcaseeqlen("", "") == 0); - assert(libsimple_strrcaseeqlen("x", "") == 0); - assert(libsimple_strrcaseeqlen("x", "y") == 0); - assert(libsimple_strrcaseeqlen("", "y") == 0); - for (i = 0; i <= 8; i++) { - for (j = 0; j <= 8; j++) { - assert(libsimple_strrcaseeqlen(&a[i], &b[j]) == 8 - (i > j ? i : j)); - assert(libsimple_strrcaseeqlen(&b[i], &a[j]) == 8 - (i > j ? i : j)); - a[i] = b[j] = '\0'; - assert(libsimple_strrcaseeqlen(a, b) == (i == j ? i : 0)); - assert(libsimple_strrcaseeqlen(b, a) == (i == j ? i : 0)); - a[i] = "abcdefgh"[i]; - b[j] = "ABCDEFGH"[j]; - } - } - assert(libsimple_strrcaseeqlen("abc", "abc") == 3); - assert(libsimple_strrcaseeqlen("123", "123") == 3); - } - - for (n = 0; n < 10; n++) { - char a[] = "abcdefgh", b[] = "abcdefgh"; - size_t I, J; - assert(libsimple_strrneqlen("", "", n) == 0); - assert(libsimple_strrneqlen("x", "", n) == 0); - assert(libsimple_strrneqlen("x", "y", n) == 0); - assert(libsimple_strrneqlen("", "y", n) == 0); - for (i = 0; i <= 8; i++) { - for (j = 0; j <= 8; j++) { - I = 8 - i; - J = 8 - j; - assert(libsimple_strrneqlen(&a[i], &b[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J)))); - a[i] = b[j] = '\0'; - assert(libsimple_strrneqlen(a, b, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0)); - a[i] = "abcdefgh"[i]; - b[j] = "abcdefgh"[j]; - } - } - assert(libsimple_strrneqlen("abc", "ABC", n) == 0); - assert(libsimple_strrneqlen("123", "123", n) == MIN(3, n)); - } - - for (n = 0; n < 10; n++) { - char a[] = "abcdefgh", b[] = "ABCDEFGH"; - size_t I, J; - assert(libsimple_strrncaseeqlen("", "", n) == 0); - assert(libsimple_strrncaseeqlen("x", "", n) == 0); - assert(libsimple_strrncaseeqlen("x", "y", n) == 0); - assert(libsimple_strrncaseeqlen("", "y", n) == 0); - for (i = 0; i <= 8; i++) { - for (j = 0; j <= 8; j++) { - I = 8 - i; - J = 8 - j; - assert(libsimple_strrncaseeqlen(&a[i], &b[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J)))); - assert(libsimple_strrncaseeqlen(&b[i], &a[j], n) == (I == J ? MIN(I,n) : MIN(I,J) * (n >= MAX(I,J)))); - a[i] = b[j] = '\0'; - assert(libsimple_strrncaseeqlen(a, b, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0)); - assert(libsimple_strrncaseeqlen(b, a, n) == (MIN(i, n) == MIN(j, n) ? MIN(i, n) : 0)); - a[i] = "abcdefgh"[i]; - b[j] = "ABCDEFGH"[j]; - } - } - assert(libsimple_strrncaseeqlen("abc", "abc", n) == MIN(3, n)); - assert(libsimple_strrncaseeqlen("123", "123", n) == MIN(3, n)); - } - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strset(buf, 'x') == buf); - assert(!strcmp(buf, "xxxxxxxxxxx")); - assert(!strcmp(&buf[12], "goodbye world")); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strset(buf, '\0') == buf); - assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_stpset(buf, 'x') == &buf[11]); - assert(!strcmp(buf, "xxxxxxxxxxx")); - assert(!strcmp(&buf[12], "goodbye world")); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_stpset(buf, '\0') == &buf[11]); - assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnset(buf, 'x', SIZE_MAX) == buf); - assert(!strcmp(buf, "xxxxxxxxxxx")); - assert(!strcmp(&buf[12], "goodbye world")); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnset(buf, '\0', SIZE_MAX) == buf); - assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_stpnset(buf, 'x', SIZE_MAX) == &buf[11]); - assert(!strcmp(buf, "xxxxxxxxxxx")); - assert(!strcmp(&buf[12], "goodbye world")); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_stpnset(buf, '\0', SIZE_MAX) == &buf[11]); - assert(!memcmp(buf, "\0\0\0\0\0\0\0\0\0\0\0\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnset(buf, 'x', 5) == buf); - assert(!strcmp(buf, "xxxxx world")); - assert(!strcmp(&buf[12], "goodbye world")); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnset(buf, '\0', 5) == buf); - assert(!memcmp(buf, "\0\0\0\0\0 world\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_stpnset(buf, 'x', 5) == &buf[5]); - assert(!strcmp(buf, "xxxxx world")); - assert(!strcmp(&buf[12], "goodbye world")); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_stpnset(buf, '\0', 5) == &buf[5]); - assert(!memcmp(buf, "\0\0\0\0\0 world\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strreplace(buf, 'o', 'x') == &buf[11]); - assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); - - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnreplace(buf, 'o', 'x', SIZE_MAX) == &buf[11]); - assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnreplace(buf, 'o', 'x', 12) == &buf[11]); - assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnreplace(buf, 'o', 'x', 11) == &buf[11]); - assert(!memcmp(buf, "hellx wxrld\0goodbye world", 26)); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnreplace(buf, 'o', 'x', 6) == &buf[6]); - assert(!memcmp(buf, "hellx world\0goodbye world", 26)); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnreplace(buf, 'o', 'x', 5) == &buf[5]); - assert(!memcmp(buf, "hellx world\0goodbye world", 26)); - - stpcpy(mempcpy(buf, "hello world", 12), "goodbye world"); - assert(libsimple_strnreplace(buf, 'o', 'x', 4) == &buf[4]); - assert(!memcmp(buf, "hello world\0goodbye world", 26)); - - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strmove(&buf[3], buf) == &buf[3]); - assert(!strcmp(buf, "helhello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strmove(buf, &buf[3]) == buf); - assert(!strcmp(buf, "lo world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strmove(buf, buf) == buf); - assert(!strcmp(buf, "hello world")); - - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(&buf[3], buf, SIZE_MAX) == &buf[3]); - assert(!strcmp(buf, "helhello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, &buf[3], SIZE_MAX) == buf); - assert(!strcmp(buf, "lo world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, buf, SIZE_MAX) == buf); - assert(!strcmp(buf, "hello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(&buf[3], buf, 12) == &buf[3]); - assert(!strcmp(buf, "helhello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, &buf[3], 9) == buf); - assert(!strcmp(buf, "lo world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, buf, 12) == buf); - assert(!strcmp(buf, "hello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(&buf[3], buf, 11) == &buf[3]); - assert(!strncmp(buf, "helhello worldx", 15)); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, &buf[3], 8) == buf); - assert(!strcmp(buf, "lo worldrld")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, buf, 11) == buf); - assert(!strcmp(buf, "hello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(&buf[3], buf, 2) == &buf[3]); - assert(!strcmp(buf, "helhe world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, &buf[3], 2) == buf); - assert(!strcmp(buf, "lollo world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_strnmove(buf, buf, 2) == buf); - assert(!strcmp(buf, "hello world")); - - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpmove(&buf[3], buf) == &buf[11 + 3]); - assert(!strcmp(buf, "helhello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpmove(buf, &buf[3]) == &buf[11 - 3]); - assert(!strcmp(buf, "lo world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpmove(buf, buf) == &buf[11]); - assert(!strcmp(buf, "hello world")); - - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(&buf[3], buf, SIZE_MAX) == &buf[11 + 3]); - assert(!strcmp(buf, "helhello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, &buf[3], SIZE_MAX) == &buf[11 - 3]); - assert(!strcmp(buf, "lo world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, buf, SIZE_MAX) == &buf[11]); - assert(!strcmp(buf, "hello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(&buf[3], buf, 12) == &buf[11 + 3]); - assert(!strcmp(buf, "helhello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, &buf[3], 9) == &buf[11 - 3]); - assert(!strcmp(buf, "lo world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, buf, 12) == &buf[11]); - assert(!strcmp(buf, "hello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(&buf[3], buf, 11) == &buf[11 + 3]); - assert(!strncmp(buf, "helhello worldx", 15)); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, &buf[3], 8) == &buf[8]); - assert(!strcmp(buf, "lo worldrld")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, buf, 11) == &buf[11]); - assert(!strcmp(buf, "hello world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(&buf[3], buf, 2) == &buf[3 + 2]); - assert(!strcmp(buf, "helhe world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, &buf[3], 2) == &buf[2]); - assert(!strcmp(buf, "lollo world")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - strcpy(buf, "hello world"); - assert(libsimple_stpnmove(buf, buf, 2) == &buf[2]); - assert(!strcmp(buf, "hello world")); - - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strccpy(buf, "hello", '\0') == &buf[6]); - assert(!strcmp(buf, "hello")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strccpy(buf, "hello", 'o') == &buf[5]); - assert(!strcmp(buf, "hello")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strccpy(buf, "hello", 'l') == &buf[3]); - assert(!strcmp(buf, "hel")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strccpy(buf, "hello", 'x') == NULL); - assert(!strcmp(buf, "hello")); - - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", '\0', 1024) == &buf[6]); - assert(!strcmp(buf, "hello")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'o', 1024) == &buf[5]); - assert(!strcmp(buf, "hello")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'l', 1024) == &buf[3]); - assert(!strcmp(buf, "hel")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'x', 1024) == NULL); - assert(!strcmp(buf, "hello")); - - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", '\0', 6) == &buf[6]); - assert(!strcmp(buf, "hello")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'o', 6) == &buf[5]); - assert(!strcmp(buf, "hello")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'l', 6) == &buf[3]); - assert(!strcmp(buf, "hel")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'x', 6) == NULL); - assert(!strcmp(buf, "hello")); - - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", '\0', 5) == NULL); - assert(!strncmp(buf, "hellox", 6)); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'o', 5) == &buf[5]); - assert(!strncmp(buf, "hellox", 6)); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'l', 5) == &buf[3]); - assert(!strcmp(buf, "hel")); - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'x', 5) == NULL); - assert(!strncmp(buf, "hellox", 6)); - - - memset(buf, 'x', sizeof(buf)); - buf[sizeof(buf) - 1] = '\0'; - assert(libsimple_strnccpy(buf, "hello", 'o', 3) == NULL); - assert(!strncmp(buf, "helx", 4)); - if (!have_custom_malloc()) { stderr_real = 1; |