mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 00:02:28 +00:00
Set errno in strtol family of functions (#110)
This commit is contained in:
parent
b16b332539
commit
f5da4efcaf
6 changed files with 57 additions and 13 deletions
|
@ -19,6 +19,7 @@
|
|||
#include "libc/bits/bits.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
#include "libc/errno.h"
|
||||
|
||||
TEST(strtoimax, testZero) {
|
||||
EXPECT_EQ(0, strtoimax("0", NULL, 0));
|
||||
|
@ -57,6 +58,17 @@ TEST(strtoimax, testTwosBane) {
|
|||
strtoimax("0x80000000000000000000000000000000", NULL, 0));
|
||||
}
|
||||
|
||||
TEST(strtol, neghex) {
|
||||
ASSERT_EQ(-16, strtol("0xfffffffffffffff0", NULL, 0));
|
||||
TEST(strtoul, neghex) {
|
||||
errno = 0;
|
||||
ASSERT_EQ(-16, (long) strtoul("0xfffffffffffffff0", NULL, 0));
|
||||
EXPECT_EQ(0, errno);
|
||||
}
|
||||
|
||||
TEST(strtol, testOutsideLimit) {
|
||||
errno = 0;
|
||||
EXPECT_EQ(0x7fffffffffffffff, strtol("0x8000000000000000", NULL, 0));
|
||||
EXPECT_EQ(ERANGE, errno);
|
||||
errno = 0;
|
||||
EXPECT_EQ(0x8000000000000000, strtol("-0x8000000000000001", NULL, 0));
|
||||
EXPECT_EQ(ERANGE, errno);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue