commit e233f10476a51629c1a70b0a16fdc01157059214
parent 93f02dd35b1cd55e620f244bff9d0e4cb71e656c
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Thu, 30 Apr 2026 23:10:00 +0200
tests/libc: Add 0089-strtoull
Diffstat:
3 files changed, 78 insertions(+), 0 deletions(-)
diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore
@@ -87,3 +87,4 @@ test.log
0086-strtol
0087-stroll
0088-stroul
+0089-stroull
diff --git a/tests/libc/execute/0089-stroull.c b/tests/libc/execute/0089-stroull.c
@@ -0,0 +1,76 @@
+#include <assert.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+/*
+output:
+testing
+done
+end:
+*/
+
+
+int
+test(void)
+{
+ unsigned long long n;
+ char buf[64], *endp;
+
+ errno = 0;
+ n = strtoull("1024", NULL, 10);
+ assert(n == 1024 && errno == 0);
+
+ n = strtoull("1024", &endp, 10);
+ assert(n == 1024 && errno == 0 && *endp == '\0');
+
+ n = strtoull("1000", &endp, 10);
+ assert(n == 1000 && errno == 0 && *endp == '\0');
+
+ n = strtoull("1000", &endp, 8);
+ assert(n == 512 && errno == 0 && *endp == '\0');
+
+ n = strtoull("1000", &endp, 16);
+ assert(n == 4096 && errno == 0 && *endp == '\0');
+
+ n = strtoull("1000", &endp, 0);
+ assert(n == 1000 && errno == 0 && *endp == '\0');
+
+ n = strtoull("0x1000", &endp, 0);
+ assert(n == 4096 && errno == 0 && *endp == '\0');
+
+ n = strtoull("01000", &endp, 0);
+ assert(n == 512 && errno == 0 && *endp == '\0');
+
+ n = strtoull(" +1a", &endp, 0);
+ assert(n == 1 && errno == 0 && *endp == 'a');
+
+ n = strtoull(" -1a", &endp, 0);
+ assert(n == -1 && errno == 0 && *endp == 'a');
+
+ sprintf(buf, "%llu", ULLONG_MAX);
+ n = strtoull(buf, NULL, 10);
+ assert(n == ULLONG_MAX && errno == 0);
+
+ sprintf(buf, "%lld", LLONG_MIN);
+ n = strtoull(buf, NULL, 10);
+ assert(n == LLONG_MIN && errno == 0);
+
+ n = strtoull("9999999999999999999999999", NULL, 10);
+ assert(n == ULLONG_MAX && errno == ERANGE);
+
+ errno = 0;
+ n = strtoull("-999999999999999999999999", NULL, 10);
+ assert(n == ULLONG_MAX && errno == ERANGE);
+}
+
+int
+main(void)
+{
+ puts("testing");
+ test();
+ puts("done");
+
+ return 0;
+}
diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst
@@ -85,3 +85,4 @@
0086-strtol
0087-stroll
0088-stroul
+0089-stroull