mirror of
https://github.com/json-c/json-c.git
synced 2026-03-26 00:19:07 +08:00
Merge pull request #663 from stoeckmann/strerror
Properly format errnos in _json_c_strerror
This commit is contained in:
@@ -94,7 +94,7 @@ char *_json_c_strerror(int errno_in)
|
||||
}
|
||||
|
||||
// It's not one of the known errno values, return the numeric value.
|
||||
for (ii = 0; errno_in > 10; errno_in /= 10, ii++)
|
||||
for (ii = 0; errno_in >= 10; errno_in /= 10, ii++)
|
||||
{
|
||||
digbuf[ii] = "0123456789"[(errno_in % 10)];
|
||||
}
|
||||
@@ -105,5 +105,6 @@ char *_json_c_strerror(int errno_in)
|
||||
{
|
||||
errno_buf[start_idx] = digbuf[ii];
|
||||
}
|
||||
errno_buf[start_idx] = '\0';
|
||||
return errno_buf;
|
||||
}
|
||||
|
||||
@@ -32,12 +32,13 @@ foreach(TESTNAME
|
||||
test_printbuf
|
||||
test_set_serializer
|
||||
test_set_value
|
||||
test_strerror
|
||||
test_util_file
|
||||
test_visit
|
||||
test_object_iterator)
|
||||
|
||||
add_executable(${TESTNAME} ${TESTNAME}.c)
|
||||
if(${TESTNAME} STREQUAL test_util_file)
|
||||
if(${TESTNAME} STREQUAL test_strerror OR ${TESTNAME} STREQUAL test_util_file)
|
||||
# For output consistency, we need _json_c_strerror() in some tests:
|
||||
target_sources(${TESTNAME} PRIVATE ../strerror_override.c)
|
||||
endif()
|
||||
|
||||
11
tests/test_strerror.c
Normal file
11
tests/test_strerror.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "strerror_override.h"
|
||||
#include "strerror_override_private.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
puts(strerror(10000));
|
||||
puts(strerror(999));
|
||||
return 0;
|
||||
}
|
||||
2
tests/test_strerror.expected
Normal file
2
tests/test_strerror.expected
Normal file
@@ -0,0 +1,2 @@
|
||||
ERRNO=10000
|
||||
ERRNO=999
|
||||
1
tests/test_strerror.test
Symbolic link
1
tests/test_strerror.test
Symbolic link
@@ -0,0 +1 @@
|
||||
test_basic.test
|
||||
Reference in New Issue
Block a user