From 57be0f2e6a2fa86318aa964f5927d3602c2205e5 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 20 Oct 2018 20:10:11 +0200 Subject: [PATCH] Ich habe mich geirrt, was das Verhalten von atoi in Windows angeht. Alles zurueck. --- src/kernel/build.c | 5 +++-- src/util/strings.c | 9 --------- src/util/strings.h | 2 +- src/util/strings.test.c | 22 ---------------------- 4 files changed, 4 insertions(+), 34 deletions(-) diff --git a/src/kernel/build.c b/src/kernel/build.c index 4ad7815c8..f5e1eec91 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -180,8 +180,9 @@ int destroy_cmd(unit * u, struct order *ord) s = gettoken(token, sizeof(token)); if (s && *s) { - n = str_atoi(s); - + ERRNO_CHECK(); + n = atoi(s); + errno = 0; if (n <= 0) { n = INT_MAX; } diff --git a/src/util/strings.c b/src/util/strings.c index e85d8ca56..e9434fb25 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -24,7 +24,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* libc includes */ #include #include -#include #include #include #include @@ -35,14 +34,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #endif -int str_atoi(const char *str) -{ - int e = errno; - int i = atoi(str); - errno = e; - return i; -} - size_t str_strlcpy(char *dst, const char *src, size_t len) { #ifdef HAVE_BSDSTRING diff --git a/src/util/strings.h b/src/util/strings.h index 6524f5970..bd58c0eb2 100644 --- a/src/util/strings.h +++ b/src/util/strings.h @@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define STRINGS_H #include +#include #ifdef __cplusplus extern "C" { @@ -27,7 +28,6 @@ extern "C" { void str_replace(char *buffer, size_t size, const char *tmpl, const char *var, const char *value); int str_hash(const char *s); - int str_atoi(const char *s); size_t str_slprintf(char * dst, size_t size, const char * format, ...); size_t str_strlcpy(char *dst, const char *src, size_t len); size_t str_strlcat(char *dst, const char *src, size_t len); diff --git a/src/util/strings.test.c b/src/util/strings.test.c index 211ec65cc..2205e538b 100644 --- a/src/util/strings.test.c +++ b/src/util/strings.test.c @@ -71,27 +71,6 @@ static void test_str_hash(CuTest * tc) CuAssertIntEquals(tc, 140703196, str_hash("Hodor")); } -static void test_str_atoi(CuTest * tc) -{ - errno = 0; - CuAssertIntEquals(tc, 0, str_atoi("0")); - CuAssertIntEquals(tc, 4, str_atoi("4")); - CuAssertIntEquals(tc, 42, str_atoi("42")); - CuAssertIntEquals(tc, -4, str_atoi("-4")); - CuAssertIntEquals(tc, 0, errno); - CuAssertIntEquals(tc, 4, str_atoi("4a")); - CuAssertIntEquals(tc, 8, str_atoi("08")); - CuAssertIntEquals(tc, 0, str_atoi("0x8")); - CuAssertIntEquals(tc, 0, str_atoi("a")); - CuAssertIntEquals(tc, 0, errno); - errno = ERANGE; - CuAssertIntEquals(tc, 0, str_atoi("a")); - CuAssertIntEquals(tc, ERANGE, errno); - errno = EINVAL; - CuAssertIntEquals(tc, 0, str_atoi("a")); - CuAssertIntEquals(tc, EINVAL, errno); -} - static void test_str_slprintf(CuTest * tc) { char buffer[32]; @@ -178,7 +157,6 @@ static void test_sbstring(CuTest * tc) CuSuite *get_strings_suite(void) { CuSuite *suite = CuSuiteNew(); - SUITE_ADD_TEST(suite, test_str_atoi); SUITE_ADD_TEST(suite, test_str_hash); SUITE_ADD_TEST(suite, test_str_escape); SUITE_ADD_TEST(suite, test_str_escape_ex);