commit dafdd8c02c6362f4e9c0ed60d839d939ed4baedf
parent 7fd464216a0a7b9b257ac939e5e3368b0708f6c2
Author: Roberto E. Vargas Caballero <k0ga@shike2.net>
Date: Thu, 30 Apr 2026 21:57:28 +0200
tests/libc: Add 0081-atol
Diffstat:
3 files changed, 65 insertions(+), 0 deletions(-)
diff --git a/tests/libc/execute/.gitignore b/tests/libc/execute/.gitignore
@@ -79,3 +79,4 @@ test.log
0078-time
0079-atof
0080-atoi
+0081-atol
diff --git a/tests/libc/execute/0081-atol.c b/tests/libc/execute/0081-atol.c
@@ -0,0 +1,63 @@
+#include <assert.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+/*
+output:
+testing
+done
+end:
+*/
+
+void
+test(void)
+{
+ long n;
+ char buf[64];
+
+ n = atol("abc");
+ assert(n == 0);
+
+ n = atol(" abc");
+ assert(n == 0);
+
+ n = atol("1234 ");
+ assert(n == 1234);
+
+ n = atol(" 1234 0");
+ assert(n == 1234);
+
+ n = atol("+");
+ assert(n == 0);
+
+ n = atol(" +1");
+ assert(n == 1);
+
+ n = atol("+ 1");
+ assert(n == 0);
+
+ n = atol(" -1");
+ assert(n == -1);
+
+ n = atol("- 1");
+ assert(n == 0);
+
+ sprintf(buf, "%ld", LONG_MAX);
+ n = atol(buf);
+ assert(n == LONG_MAX);
+
+ sprintf(buf, "%ld", LONG_MIN);
+ n = atol(buf);
+ assert(n == LONG_MIN);
+}
+
+int
+main()
+{
+ puts("testing");
+ test();
+ puts("done");
+
+ return 0;
+}
diff --git a/tests/libc/execute/libc-tests.lst b/tests/libc/execute/libc-tests.lst
@@ -77,3 +77,4 @@
0078-time
0079-atof [TODO]
0080-atoi
+0081-atol