aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libsimple.c302
-rw-r--r--libsimple.h33
2 files changed, 324 insertions, 11 deletions
diff --git a/libsimple.c b/libsimple.c
index 36cc690..03d7611 100644
--- a/libsimple.c
+++ b/libsimple.c
@@ -13,6 +13,8 @@ int
main(void)
{
char buf[1024];
+ int intarray[10];
+ size_t i, n;
assert(MIN(1, 3) == 1);
assert(MIN(1, 1) == 1);
@@ -213,6 +215,37 @@ main(void)
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);
@@ -229,6 +262,52 @@ main(void)
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);
@@ -240,6 +319,37 @@ main(void)
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);
@@ -256,6 +366,198 @@ main(void)
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);
+
+ for (i = 0, n = 10; i < n; i++)
+ buf[i] = i;
+ LIBSIMPLE_UNLIST(buf, 4, &n);
+ LIBSIMPLE_UNLIST(buf, 9 - 1, &n);
+ LIBSIMPLE_UNLIST(buf, 6 - 1, &n);
+ assert(n == 7);
+ assert(buf[0] == 0);
+ assert(buf[1] == 1);
+ assert(buf[2] == 2);
+ assert(buf[3] == 3);
+ assert(buf[4] == 5);
+ assert(buf[5] == 7);
+ assert(buf[6] == 8);
+
+ for (i = 0, n = 10; i < n; i++)
+ intarray[i] = i;
+ LIBSIMPLE_UNLIST(intarray, 4, &n);
+ LIBSIMPLE_UNLIST(intarray, 9 - 1, &n);
+ LIBSIMPLE_UNLIST(intarray, 6 - 1, &n);
+ assert(n == 7);
+ assert(intarray[0] == 0);
+ assert(intarray[1] == 1);
+ assert(intarray[2] == 2);
+ assert(intarray[3] == 3);
+ assert(intarray[4] == 5);
+ assert(intarray[5] == 7);
+ assert(intarray[6] == 8);
+
+ 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);
+
return 0;
}
diff --git a/libsimple.h b/libsimple.h
index 2ced0c8..c163f76 100644
--- a/libsimple.h
+++ b/libsimple.h
@@ -479,8 +479,19 @@ extern int libsimple_default_failure_exit;
#define FREE(PTR) (free(PTR), (PTR) = NULL, 0) /* TODO test */
+#define CLOSE(FD) libsimple_close(&(FD)) /* TODO test */
-#define CLOSE(FD) ((FD) >= 0 ? (close(FD), (FD) = -1, 0) : 0) /* TODO test */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__)))
+static inline int
+libsimple_close(int *__fdp)
+{
+ int __ret;
+ if (*__fdp < 0)
+ return 0;
+ __ret = close(*__fdp);
+ *__fdp = -1;
+ return __ret;
+}
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__)))
@@ -772,7 +783,7 @@ char *libsimple_strrcasestr(const char *, const char *);
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__)))
-static inline int libsimple_strcmpnul(const char *__a, const char *__b) /* TODO test */
+static inline int libsimple_strcmpnul(const char *__a, const char *__b)
{ return (!__a || !__b) ? !__b - !__a : strcmp(__a, __b); }
#ifndef strcmpnul
# define strcmpnul libsimple_strcmpnul
@@ -780,7 +791,7 @@ static inline int libsimple_strcmpnul(const char *__a, const char *__b) /* TODO
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__)))
-static inline int libsimple_strcasecmpnul(const char *__a, const char *__b) /* TODO test */
+static inline int libsimple_strcasecmpnul(const char *__a, const char *__b)
{ return (!__a || !__b) ? !__b - !__a : strcasecmp(__a, __b); }
#ifndef strcasecmpnul
# define strcasecmpnul libsimple_strcasecmpnul
@@ -788,7 +799,7 @@ static inline int libsimple_strcasecmpnul(const char *__a, const char *__b) /* T
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__)))
-static inline int libsimple_strncmpnul(const char *__a, const char *__b, size_t __n) /* TODO test */
+static inline int libsimple_strncmpnul(const char *__a, const char *__b, size_t __n)
{ return (!__a || !__b) ? !__b - !__a : strncmp(__a, __b, __n); }
#ifndef strncmpnul
# define strncmpnul libsimple_strncmpnul
@@ -796,7 +807,7 @@ static inline int libsimple_strncmpnul(const char *__a, const char *__b, size_t
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__)))
-static inline int libsimple_strncasecmpnul(const char *__a, const char *__b, size_t __n) /* TODO test */
+static inline int libsimple_strncasecmpnul(const char *__a, const char *__b, size_t __n)
{ return (!__a || !__b) ? !__b - !__a : strncasecmp(__a, __b, __n); }
#ifndef strncasecmpnul
# define strncasecmpnul libsimple_strncasecmpnul
@@ -811,7 +822,7 @@ static inline int libsimple_streq(const char *__a, const char *__b) { return !st
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__)))
-static inline int libsimple_strneq(const char *__a, const char *__b, size_t __n) { return !strncmp(__a, __b, __n); } /* TODO test */
+static inline int libsimple_strneq(const char *__a, const char *__b, size_t __n) { return !strncmp(__a, __b, __n); }
#ifndef strneq
# define strneq libsimple_strneq
#endif
@@ -825,7 +836,7 @@ static inline int libsimple_streqnul(const char *__a, const char *__b) { return
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__)))
-static inline int libsimple_strneqnul(const char *__a, const char *__b, size_t __n) /* TODO test */
+static inline int libsimple_strneqnul(const char *__a, const char *__b, size_t __n)
{ return !strncmpnul(__a, __b, __n); }
#ifndef strneqnul
# define strneqnul libsimple_strneqnul
@@ -840,7 +851,7 @@ static inline int libsimple_strcaseeq(const char *__a, const char *__b) { return
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __nonnull__, __warn_unused_result__)))
-static inline int libsimple_strncaseeq(const char *__a, const char *__b, size_t __n) { return !strncasecmp(__a, __b, __n); } /* TODO test */
+static inline int libsimple_strncaseeq(const char *__a, const char *__b, size_t __n) { return !strncasecmp(__a, __b, __n); }
#ifndef strncaseeq
# define strncaseeq libsimple_strncaseeq
#endif
@@ -854,7 +865,7 @@ static inline int libsimple_strcaseeqnul(const char *__a, const char *__b) { ret
_LIBSIMPLE_GCC_ONLY(__attribute__((__pure__, __warn_unused_result__)))
-static inline int libsimple_strncaseeqnul(const char *__a, const char *__b, size_t __n) /* TODO test */
+static inline int libsimple_strncaseeqnul(const char *__a, const char *__b, size_t __n)
{ return !strncasecmpnul(__a, __b, __n); }
#ifndef strncaseeqnul
# define strncaseeqnul libsimple_strncaseeqnul
@@ -1380,7 +1391,7 @@ void libsimple_doubletotimeval(struct timeval *, double);
#endif
-#define LIBSIMPLE_UNLIST(LIST, I, NP) libsimple_unlist((LIST), (I), (NP), sizeof(*(LIST))) /* TODO test */
+#define LIBSIMPLE_UNLIST(LIST, I, NP) libsimple_unlist((LIST), (I), (NP), sizeof(*(LIST)))
#ifndef UNLIST
# define UNLIST(LIST, I, NP) LIBSIMPLE_UNLIST((LIST), (I), (NP))
#endif
@@ -1388,7 +1399,7 @@ void libsimple_doubletotimeval(struct timeval *, double);
_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__)))
static inline void
-libsimple_unlist(void *__list, size_t __i, size_t *__np, size_t __width) /* TODO test */
+libsimple_unlist(void *__list, size_t __i, size_t *__np, size_t __width)
{
char *__lst = __list;
memmove(&__lst[__i * __width], &__lst[(__i + 1) * __width], (--*__np - __i) * __width);