1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
ocean 2005-10-22 01:28:00 +00:00
parent 1a61008f18
commit 9c60701e4f
13 changed files with 37 additions and 55 deletions

View file

@ -1,3 +1,8 @@
Sat Oct 22 10:08:28 2005 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* 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 <ocean@m2.ccsnet.ne.jp>
* rubysig.h (CHECK_INTS): fixed typo. (I believe bit-or is improper)

View file

@ -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 <stdarg.h>
# else
# include <varargs.h>
# endif
extern int snprintf(char *, size_t n, char const *, ...);
extern int vsnprintf(char *, size_t n, char const *, va_list);
#endif

View file

@ -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);

View file

@ -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) {

View file

@ -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 */

View file

@ -1,8 +1,7 @@
/* public domain rewrite of finite(3) */
int
finite(n)
double n;
finite(double n)
{
return !isnan(n) && !isinf(n);
}

View file

@ -2,8 +2,7 @@
#include <math.h>
double hypot(x,y)
double x, y;
double hypot(double x, double y)
{
if (x < 0) x = -x;
if (y < 0) y = -y;

View file

@ -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;
}

View file

@ -3,8 +3,7 @@
#include <ctype.h>
int
strcasecmp(p1, p2)
char *p1, *p2;
strcasecmp(const char *p1, const char *p2)
{
while (*p1 && *p2) {
if (toupper(*p1) != toupper(*p2))

View file

@ -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];

View file

@ -1,12 +1,10 @@
/* public domain rewrite of strncasecmp(3) */
#include <ctype.h>
#include <stddef.h>
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)) {

View file

@ -3,13 +3,10 @@
#include <ctype.h>
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;
}

View file

@ -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;