From ef69de161428de457cf34b6d45e1f54a6965475e Mon Sep 17 00:00:00 2001 From: ceriel Date: Tue, 22 May 1990 10:48:12 +0000 Subject: [PATCH] atol and atoi get old-fashioned behaviour --- lang/cem/libcc.ansi/stdlib/atoi.c | 26 +++++++++++++++++++------- lang/cem/libcc.ansi/stdlib/atol.c | 27 +++++++++++++++++++-------- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/lang/cem/libcc.ansi/stdlib/atoi.c b/lang/cem/libcc.ansi/stdlib/atoi.c index e8cdfdc0f..cb8495ef7 100644 --- a/lang/cem/libcc.ansi/stdlib/atoi.c +++ b/lang/cem/libcc.ansi/stdlib/atoi.c @@ -4,15 +4,27 @@ */ /* $Header$ */ -#include -#include +#include +/* We do not use strtol here for backwards compatibility in behaviour on + overflow. +*/ int -atoi(const char *nptr) +atol(register const char *nptr) { - int i, e = errno; + int total = 0; + register unsigned int digit; + int minus = 0; - i = (int)strtol(nptr, (char **)NULL, 10); - errno = e; - return i; + while (isspace(*nptr)) nptr++; + if (*nptr == '+') nptr++; + else if (*nptr == '-') { + minus = 1; + nptr++; + } + while (isdigit(*nptr)) { + total *= 10; + total += (*nptr++ - '0'); + } + return minus ? -total : total; } diff --git a/lang/cem/libcc.ansi/stdlib/atol.c b/lang/cem/libcc.ansi/stdlib/atol.c index 41f67b5e7..fe4a21a4d 100644 --- a/lang/cem/libcc.ansi/stdlib/atol.c +++ b/lang/cem/libcc.ansi/stdlib/atol.c @@ -4,16 +4,27 @@ */ /* $Header$ */ -#include -#include +#include +/* We do not use strtol here for backwards compatibility in behaviour on + overflow. +*/ long -atol(const char *nptr) +atol(register const char *nptr) { - long l; - int e = errno; + long total = 0; + register unsigned int digit; + int minus = 0; - l = strtol(nptr, (char **)NULL, 10); - errno = e; - return l; + while (isspace(*nptr)) nptr++; + if (*nptr == '+') nptr++; + else if (*nptr == '-') { + minus = 1; + nptr++; + } + while (isdigit(*nptr)) { + total *= 10; + total += (*nptr++ - '0'); + } + return minus ? -total : total; } -- 2.34.1