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:
parent
1a61008f18
commit
9c60701e4f
13 changed files with 37 additions and 55 deletions
|
@ -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>
|
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)
|
* rubysig.h (CHECK_INTS): fixed typo. (I believe bit-or is improper)
|
||||||
|
|
14
missing.h
14
missing.h
|
@ -91,11 +91,11 @@ extern double modf(double, double *);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef HAVE_STRCASECMP
|
#ifndef HAVE_STRCASECMP
|
||||||
extern int strcasecmp(char *, char *);
|
extern int strcasecmp(const char *, const char *);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_STRNCASECMP
|
#ifndef HAVE_STRNCASECMP
|
||||||
extern int strncasecmp(char *, char *, int);
|
extern int strncasecmp(const char *, const char *, size_t);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_STRCHR
|
#ifndef HAVE_STRCHR
|
||||||
|
@ -117,20 +117,16 @@ extern char *strstr(const char *, const char *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
#ifndef HAVE_STRTOL
|
#ifndef HAVE_STRTOL
|
||||||
extern long strtol(char *, char **, int);
|
extern long strtol(const char *, char **, int);
|
||||||
#endif
|
#endif
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef HAVE_STRTOUL
|
#ifndef HAVE_STRTOUL
|
||||||
extern unsigned long strtoul(char *, char **, int);
|
extern unsigned long strtoul(const char *, char **, int);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_VSNPRINTF
|
#ifndef HAVE_VSNPRINTF
|
||||||
# ifdef HAVE_STDARG_PROTOTYPES
|
# include <stdarg.h>
|
||||||
# include <stdarg.h>
|
|
||||||
# else
|
|
||||||
# include <varargs.h>
|
|
||||||
# endif
|
|
||||||
extern int snprintf(char *, size_t n, char const *, ...);
|
extern int snprintf(char *, size_t n, char const *, ...);
|
||||||
extern int vsnprintf(char *, size_t n, char const *, va_list);
|
extern int vsnprintf(char *, size_t n, char const *, va_list);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -33,8 +33,7 @@
|
||||||
|
|
||||||
#ifndef HAVE_ACOSH
|
#ifndef HAVE_ACOSH
|
||||||
double
|
double
|
||||||
acosh(x)
|
acosh(double x)
|
||||||
double x;
|
|
||||||
{
|
{
|
||||||
if (x < 1)
|
if (x < 1)
|
||||||
x = -1; /* NaN */
|
x = -1; /* NaN */
|
||||||
|
@ -50,8 +49,7 @@ acosh(x)
|
||||||
|
|
||||||
#ifndef HAVE_ASINH
|
#ifndef HAVE_ASINH
|
||||||
double
|
double
|
||||||
asinh(x)
|
asinh(double x)
|
||||||
double x;
|
|
||||||
{
|
{
|
||||||
int neg = x < 0;
|
int neg = x < 0;
|
||||||
double z = fabs(x);
|
double z = fabs(x);
|
||||||
|
@ -74,8 +72,7 @@ asinh(x)
|
||||||
|
|
||||||
#ifndef HAVE_ATANH
|
#ifndef HAVE_ATANH
|
||||||
double
|
double
|
||||||
atanh(x)
|
atanh(double x)
|
||||||
double x;
|
|
||||||
{
|
{
|
||||||
int neg = x < 0;
|
int neg = x < 0;
|
||||||
double z = fabs(x);
|
double z = fabs(x);
|
||||||
|
|
|
@ -24,8 +24,7 @@
|
||||||
#define BADEXIT -1
|
#define BADEXIT -1
|
||||||
|
|
||||||
int
|
int
|
||||||
dup2(fd1, fd2)
|
dup2(int fd1, int fd2)
|
||||||
int fd1, fd2;
|
|
||||||
{
|
{
|
||||||
#if defined(HAVE_FCNTL) && defined(F_DUPFD)
|
#if defined(HAVE_FCNTL) && defined(F_DUPFD)
|
||||||
if (fd1 != fd2) {
|
if (fd1 != fd2) {
|
||||||
|
|
|
@ -25,8 +25,7 @@ static double q_gamma(double, double, double);
|
||||||
|
|
||||||
/* Incomplete gamma function
|
/* Incomplete gamma function
|
||||||
1 / Gamma(a) * Int_0^x exp(-t) t^(a-1) dt */
|
1 / Gamma(a) * Int_0^x exp(-t) t^(a-1) dt */
|
||||||
static double p_gamma(a, x, loggamma_a)
|
static double p_gamma(double a, double x, double loggamma_a)
|
||||||
double a, x, loggamma_a;
|
|
||||||
{
|
{
|
||||||
int k;
|
int k;
|
||||||
double result, term, previous;
|
double result, term, previous;
|
||||||
|
@ -45,8 +44,7 @@ static double p_gamma(a, x, loggamma_a)
|
||||||
|
|
||||||
/* Incomplete gamma function
|
/* Incomplete gamma function
|
||||||
1 / Gamma(a) * Int_x^inf exp(-t) t^(a-1) dt */
|
1 / Gamma(a) * Int_x^inf exp(-t) t^(a-1) dt */
|
||||||
static double q_gamma(a, x, loggamma_a)
|
static double q_gamma(double a, double x, double loggamma_a)
|
||||||
double a, x, loggamma_a;
|
|
||||||
{
|
{
|
||||||
int k;
|
int k;
|
||||||
double result, w, temp, previous;
|
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 */
|
#define LOG_PI_OVER_2 0.572364942924700087071713675675 /* log_e(PI)/2 */
|
||||||
|
|
||||||
double erf(x)
|
double erf(double x)
|
||||||
double x;
|
|
||||||
{
|
{
|
||||||
if (!finite(x)) {
|
if (!finite(x)) {
|
||||||
if (isnan(x)) return x; /* erf(NaN) = NaN */
|
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);
|
else return - p_gamma(0.5, x * x, LOG_PI_OVER_2);
|
||||||
}
|
}
|
||||||
|
|
||||||
double erfc(x)
|
double erfc(double x)
|
||||||
double x;
|
|
||||||
{
|
{
|
||||||
if (!finite(x)) {
|
if (!finite(x)) {
|
||||||
if (isnan(x)) return x; /* erfc(NaN) = NaN */
|
if (isnan(x)) return x; /* erfc(NaN) = NaN */
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
/* public domain rewrite of finite(3) */
|
/* public domain rewrite of finite(3) */
|
||||||
|
|
||||||
int
|
int
|
||||||
finite(n)
|
finite(double n)
|
||||||
double n;
|
|
||||||
{
|
{
|
||||||
return !isnan(n) && !isinf(n);
|
return !isnan(n) && !isinf(n);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,7 @@
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
double hypot(x,y)
|
double hypot(double x, double y)
|
||||||
double x, y;
|
|
||||||
{
|
{
|
||||||
if (x < 0) x = -x;
|
if (x < 0) x = -x;
|
||||||
if (y < 0) y = -y;
|
if (y < 0) y = -y;
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
/* public domain rewrite of isnan(3) */
|
/* public domain rewrite of isnan(3) */
|
||||||
|
|
||||||
static int double_ne();
|
static int double_ne(double n1, double n2);
|
||||||
|
|
||||||
int
|
int
|
||||||
isnan(n)
|
isnan(double n)
|
||||||
double n;
|
|
||||||
{
|
{
|
||||||
return double_ne(n, n);
|
return double_ne(n, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
double_ne(n1, n2)
|
double_ne(double n1, double n2)
|
||||||
double n1, n2;
|
|
||||||
{
|
{
|
||||||
return n1 != n2;
|
return n1 != n2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,7 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
strcasecmp(p1, p2)
|
strcasecmp(const char *p1, const char *p2)
|
||||||
char *p1, *p2;
|
|
||||||
{
|
{
|
||||||
while (*p1 && *p2) {
|
while (*p1 && *p2) {
|
||||||
if (toupper(*p1) != toupper(*p2))
|
if (toupper(*p1) != toupper(*p2))
|
||||||
|
|
|
@ -6,8 +6,7 @@ extern char *sys_errlist[];
|
||||||
static char msg[50];
|
static char msg[50];
|
||||||
|
|
||||||
char *
|
char *
|
||||||
strerror(error)
|
strerror(int error)
|
||||||
int error;
|
|
||||||
{
|
{
|
||||||
if (error <= sys_nerr && error > 0) {
|
if (error <= sys_nerr && error > 0) {
|
||||||
return sys_errlist[error];
|
return sys_errlist[error];
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
/* public domain rewrite of strncasecmp(3) */
|
/* public domain rewrite of strncasecmp(3) */
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
strncasecmp(p1, p2, len)
|
strncasecmp(const char *p1, const char *p2, size_t len)
|
||||||
char *p1;
|
|
||||||
char *p2;
|
|
||||||
int len;
|
|
||||||
{
|
{
|
||||||
while (len != 0) {
|
while (len != 0) {
|
||||||
if (toupper(*p1) != toupper(*p2)) {
|
if (toupper(*p1) != toupper(*p2)) {
|
||||||
|
|
|
@ -3,13 +3,10 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
long
|
long
|
||||||
strtol(nptr, endptr, base)
|
strtol(const char *nptr, char **endptr, int base)
|
||||||
char *nptr;
|
|
||||||
char **endptr;
|
|
||||||
int base;
|
|
||||||
{
|
{
|
||||||
long result;
|
long result;
|
||||||
char *p = nptr;
|
const char *p = nptr;
|
||||||
|
|
||||||
while (isspace(*p)) {
|
while (isspace(*p)) {
|
||||||
p++;
|
p++;
|
||||||
|
@ -23,7 +20,7 @@ strtol(nptr, endptr, base)
|
||||||
result = strtoul(p, endptr, base);
|
result = strtoul(p, endptr, base);
|
||||||
}
|
}
|
||||||
if (endptr != 0 && *endptr == p) {
|
if (endptr != 0 && *endptr == p) {
|
||||||
*endptr = nptr;
|
*endptr = (char *)nptr;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
* (100 for non-digit characters).
|
* (100 for non-digit characters).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static char cvtIn[] = {
|
static const char cvtIn[] = {
|
||||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* '0' - '9' */
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* '0' - '9' */
|
||||||
100, 100, 100, 100, 100, 100, 100, /* punctuation */
|
100, 100, 100, 100, 100, 100, 100, /* punctuation */
|
||||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, /* 'A' - 'Z' */
|
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, /* 'A' - 'Z' */
|
||||||
|
@ -53,22 +53,22 @@ static char cvtIn[] = {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
unsigned long int
|
unsigned long int
|
||||||
strtoul(string, endPtr, base)
|
strtoul(
|
||||||
char *string; /* String of ASCII digits, possibly
|
const char *string, /* String of ASCII digits, possibly
|
||||||
* preceded by white space. For bases
|
* preceded by white space. For bases
|
||||||
* greater than 10, either lower- or
|
* greater than 10, either lower- or
|
||||||
* upper-case digits may be used.
|
* 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. */
|
* 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
|
* than 37. If 0, then the base is chosen
|
||||||
* from the leading characters of string:
|
* from the leading characters of string:
|
||||||
* "0x" means hex, "0" means octal, anything
|
* "0x" means hex, "0" means octal, anything
|
||||||
* else means decimal.
|
* else means decimal.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
register char *p;
|
register const char *p;
|
||||||
register unsigned long int result = 0;
|
register unsigned long int result = 0;
|
||||||
register unsigned digit;
|
register unsigned digit;
|
||||||
int anyDigits = 0;
|
int anyDigits = 0;
|
||||||
|
@ -177,7 +177,7 @@ strtoul(string, endPtr, base)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endPtr != 0) {
|
if (endPtr != 0) {
|
||||||
*endPtr = p;
|
*endPtr = (char *)p;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in a new issue