From 9c60701e4f39d7039da73e7dd5a36f5edade308a Mon Sep 17 00:00:00 2001 From: ocean Date: Sat, 22 Oct 2005 01:28:00 +0000 Subject: [PATCH] * missing.h, missing/*.c: SUSv3 compatible strcasecmp and strncasecmp, ANSI compatible strtol and strtoul, and ANSI styled other functions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9438 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ missing.h | 14 +++++--------- missing/acosh.c | 9 +++------ missing/dup2.c | 3 +-- missing/erf.c | 12 ++++-------- missing/finite.c | 3 +-- missing/hypot.c | 3 +-- missing/isnan.c | 8 +++----- missing/strcasecmp.c | 3 +-- missing/strerror.c | 3 +-- missing/strncasecmp.c | 6 ++---- missing/strtol.c | 9 +++------ missing/strtoul.c | 14 +++++++------- 13 files changed, 37 insertions(+), 55 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0b34aa069f..9aac6984e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Oct 22 10:08:28 2005 Hirokazu Yamamoto + + * missing.h, missing/*.c: SUSv3 compatible strcasecmp and strncasecmp, + ANSI compatible strtol and strtoul, and ANSI styled other functions. + Fri Oct 21 19:16:08 2005 Hirokazu Yamamoto * rubysig.h (CHECK_INTS): fixed typo. (I believe bit-or is improper) diff --git a/missing.h b/missing.h index 3703c00309..675d0d5e17 100644 --- a/missing.h +++ b/missing.h @@ -91,11 +91,11 @@ extern double modf(double, double *); */ #ifndef HAVE_STRCASECMP -extern int strcasecmp(char *, char *); +extern int strcasecmp(const char *, const char *); #endif #ifndef HAVE_STRNCASECMP -extern int strncasecmp(char *, char *, int); +extern int strncasecmp(const char *, const char *, size_t); #endif #ifndef HAVE_STRCHR @@ -117,20 +117,16 @@ extern char *strstr(const char *, const char *); /* #ifndef HAVE_STRTOL -extern long strtol(char *, char **, int); +extern long strtol(const char *, char **, int); #endif */ #ifndef HAVE_STRTOUL -extern unsigned long strtoul(char *, char **, int); +extern unsigned long strtoul(const char *, char **, int); #endif #ifndef HAVE_VSNPRINTF -# ifdef HAVE_STDARG_PROTOTYPES -# include -# else -# include -# endif +# include extern int snprintf(char *, size_t n, char const *, ...); extern int vsnprintf(char *, size_t n, char const *, va_list); #endif diff --git a/missing/acosh.c b/missing/acosh.c index a4443e191f..59f4af9248 100644 --- a/missing/acosh.c +++ b/missing/acosh.c @@ -33,8 +33,7 @@ #ifndef HAVE_ACOSH double -acosh(x) - double x; +acosh(double x) { if (x < 1) x = -1; /* NaN */ @@ -50,8 +49,7 @@ acosh(x) #ifndef HAVE_ASINH double -asinh(x) - double x; +asinh(double x) { int neg = x < 0; double z = fabs(x); @@ -74,8 +72,7 @@ asinh(x) #ifndef HAVE_ATANH double -atanh(x) - double x; +atanh(double x) { int neg = x < 0; double z = fabs(x); diff --git a/missing/dup2.c b/missing/dup2.c index e7cc46f4c1..00d8145976 100644 --- a/missing/dup2.c +++ b/missing/dup2.c @@ -24,8 +24,7 @@ #define BADEXIT -1 int -dup2(fd1, fd2) -int fd1, fd2; +dup2(int fd1, int fd2) { #if defined(HAVE_FCNTL) && defined(F_DUPFD) if (fd1 != fd2) { diff --git a/missing/erf.c b/missing/erf.c index d9e7469024..fe65b9a479 100644 --- a/missing/erf.c +++ b/missing/erf.c @@ -25,8 +25,7 @@ static double q_gamma(double, double, double); /* Incomplete gamma function 1 / Gamma(a) * Int_0^x exp(-t) t^(a-1) dt */ -static double p_gamma(a, x, loggamma_a) - double a, x, loggamma_a; +static double p_gamma(double a, double x, double loggamma_a) { int k; double result, term, previous; @@ -45,8 +44,7 @@ static double p_gamma(a, x, loggamma_a) /* Incomplete gamma function 1 / Gamma(a) * Int_x^inf exp(-t) t^(a-1) dt */ -static double q_gamma(a, x, loggamma_a) - double a, x, loggamma_a; +static double q_gamma(double a, double x, double loggamma_a) { int k; double result, w, temp, previous; @@ -69,8 +67,7 @@ static double q_gamma(a, x, loggamma_a) #define LOG_PI_OVER_2 0.572364942924700087071713675675 /* log_e(PI)/2 */ -double erf(x) - double x; +double erf(double x) { if (!finite(x)) { if (isnan(x)) return x; /* erf(NaN) = NaN */ @@ -80,8 +77,7 @@ double erf(x) else return - p_gamma(0.5, x * x, LOG_PI_OVER_2); } -double erfc(x) - double x; +double erfc(double x) { if (!finite(x)) { if (isnan(x)) return x; /* erfc(NaN) = NaN */ diff --git a/missing/finite.c b/missing/finite.c index f91035a8cd..8d0b7af262 100644 --- a/missing/finite.c +++ b/missing/finite.c @@ -1,8 +1,7 @@ /* public domain rewrite of finite(3) */ int -finite(n) - double n; +finite(double n) { return !isnan(n) && !isinf(n); } diff --git a/missing/hypot.c b/missing/hypot.c index aad5259e92..5a663553cf 100644 --- a/missing/hypot.c +++ b/missing/hypot.c @@ -2,8 +2,7 @@ #include -double hypot(x,y) - double x, y; +double hypot(double x, double y) { if (x < 0) x = -x; if (y < 0) y = -y; diff --git a/missing/isnan.c b/missing/isnan.c index 459048e936..a8733978ad 100644 --- a/missing/isnan.c +++ b/missing/isnan.c @@ -1,17 +1,15 @@ /* public domain rewrite of isnan(3) */ -static int double_ne(); +static int double_ne(double n1, double n2); int -isnan(n) - double n; +isnan(double n) { return double_ne(n, n); } static int -double_ne(n1, n2) - double n1, n2; +double_ne(double n1, double n2) { return n1 != n2; } diff --git a/missing/strcasecmp.c b/missing/strcasecmp.c index fddb8385be..1ce20704c1 100644 --- a/missing/strcasecmp.c +++ b/missing/strcasecmp.c @@ -3,8 +3,7 @@ #include int -strcasecmp(p1, p2) - char *p1, *p2; +strcasecmp(const char *p1, const char *p2) { while (*p1 && *p2) { if (toupper(*p1) != toupper(*p2)) diff --git a/missing/strerror.c b/missing/strerror.c index c1bf6feff8..023935a1ff 100644 --- a/missing/strerror.c +++ b/missing/strerror.c @@ -6,8 +6,7 @@ extern char *sys_errlist[]; static char msg[50]; char * -strerror(error) - int error; +strerror(int error) { if (error <= sys_nerr && error > 0) { return sys_errlist[error]; diff --git a/missing/strncasecmp.c b/missing/strncasecmp.c index a4cc5828b8..59d4477a40 100644 --- a/missing/strncasecmp.c +++ b/missing/strncasecmp.c @@ -1,12 +1,10 @@ /* public domain rewrite of strncasecmp(3) */ #include +#include int -strncasecmp(p1, p2, len) - char *p1; - char *p2; - int len; +strncasecmp(const char *p1, const char *p2, size_t len) { while (len != 0) { if (toupper(*p1) != toupper(*p2)) { diff --git a/missing/strtol.c b/missing/strtol.c index e94aa54ca0..da6636f316 100644 --- a/missing/strtol.c +++ b/missing/strtol.c @@ -3,13 +3,10 @@ #include long -strtol(nptr, endptr, base) - char *nptr; - char **endptr; - int base; +strtol(const char *nptr, char **endptr, int base) { long result; - char *p = nptr; + const char *p = nptr; while (isspace(*p)) { p++; @@ -23,7 +20,7 @@ strtol(nptr, endptr, base) result = strtoul(p, endptr, base); } if (endptr != 0 && *endptr == p) { - *endptr = nptr; + *endptr = (char *)nptr; } return result; } diff --git a/missing/strtoul.c b/missing/strtoul.c index f16f2ad9cf..4f09f899a1 100644 --- a/missing/strtoul.c +++ b/missing/strtoul.c @@ -21,7 +21,7 @@ * (100 for non-digit characters). */ -static char cvtIn[] = { +static const char cvtIn[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* '0' - '9' */ 100, 100, 100, 100, 100, 100, 100, /* punctuation */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, /* 'A' - 'Z' */ @@ -53,22 +53,22 @@ static char cvtIn[] = { */ unsigned long int -strtoul(string, endPtr, base) - char *string; /* String of ASCII digits, possibly +strtoul( + const char *string, /* String of ASCII digits, possibly * preceded by white space. For bases * greater than 10, either lower- or * upper-case digits may be used. */ - char **endPtr; /* Where to store address of terminating + char **endPtr, /* Where to store address of terminating * character, or NULL. */ - int base; /* Base for conversion. Must be less + int base) /* Base for conversion. Must be less * than 37. If 0, then the base is chosen * from the leading characters of string: * "0x" means hex, "0" means octal, anything * else means decimal. */ { - register char *p; + register const char *p; register unsigned long int result = 0; register unsigned digit; int anyDigits = 0; @@ -177,7 +177,7 @@ strtoul(string, endPtr, base) } if (endPtr != 0) { - *endPtr = p; + *endPtr = (char *)p; } return result;