Portability changes from Uli Drepper. [!STDC_HEADERS && !defined(NULL)] Define NULL.

This commit is contained in:
Jim Meyering 1995-07-17 13:34:12 +00:00
parent 787429e3f0
commit e09675ddfb

View File

@ -17,55 +17,77 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave, not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */ Cambridge, MA 02139, USA. */
#include <ctype.h> #ifdef HAVE_CONFIG_H
#include <limits.h> # include <config.h>
#include <stddef.h> #endif
#include <stdlib.h>
#include <errno.h>
#include "../locale/localeinfo.h"
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#ifdef STDC_HEADERS
# include <stddef.h>
# include <stdlib.h>
#else
# ifndef NULL
# define NULL 0
# endif
#endif
#ifdef _LIBC
# define USE_NUMBER_GROUPING
#endif
#ifdef USE_NUMBER_GROUPING
# include "../locale/localeinfo.h"
#endif
/* Nonzero if we are defining `strtoul' or `strtouq', operating on /* Nonzero if we are defining `strtoul' or `strtouq', operating on
unsigned integers. */ unsigned integers. */
#ifndef UNSIGNED #ifndef UNSIGNED
#define UNSIGNED 0 # define UNSIGNED 0
#define INT LONG int # define INT LONG int
#else #else
#define strtol strtoul # define strtol strtoul
#define INT unsigned LONG int # define INT unsigned LONG int
#endif #endif
/* If QUAD is defined, we are defining `strtoq' or `strtouq', /* If QUAD is defined, we are defining `strtoq' or `strtouq',
operating on `long long int's. */ operating on `long long int's. */
#ifdef QUAD #ifdef QUAD
#if UNSIGNED # if UNSIGNED
#define strtoul strtouq # define strtoul strtouq
# else
# define strtol strtoq
# endif
# define LONG long long
# undef LONG_MIN
# define LONG_MIN LONG_LONG_MIN
# undef LONG_MAX
# define LONG_MAX LONG_LONG_MAX
# undef ULONG_MAX
# define ULONG_MAX ULONG_LONG_MAX
# if __GNUC__ == 2 && __GNUC_MINOR__ < 7
/* Work around gcc bug with using this constant. */
static const unsigned long long int maxquad = ULONG_LONG_MAX;
# undef ULONG_MAX
# define ULONG_MAX maxquad
# endif
#else #else
#define strtol strtoq # define LONG long
#endif
#define LONG long long
#undef LONG_MIN
#define LONG_MIN LONG_LONG_MIN
#undef LONG_MAX
#define LONG_MAX LONG_LONG_MAX
#undef ULONG_MAX
#define ULONG_MAX ULONG_LONG_MAX
#if __GNUC__ == 2 && __GNUC_MINOR__ < 7
/* Work around gcc bug with using this constant. */
static const unsigned long long int maxquad = ULONG_LONG_MAX;
#undef ULONG_MAX
#define ULONG_MAX maxquad
#endif #endif
#ifdef __STDC__
# define INTERNAL(x) INTERNAL1(x)
# define INTERNAL1(x) __##x##_internal
#else #else
#define LONG long # define INTERNAL(x) __/**/x/**/_internal
#endif #endif
#ifdef USE_NUMBER_GROUPING
#define INTERNAL(x) INTERNAL1(x)
#define INTERNAL1(x) __##x##_internal
/* This file defines a function to check for correct grouping. */ /* This file defines a function to check for correct grouping. */
#include "grouping.h" # include "grouping.h"
#endif
/* Convert NPTR to an `unsigned long int' or `long int' in base BASE. /* Convert NPTR to an `unsigned long int' or `long int' in base BASE.
@ -91,6 +113,7 @@ INTERNAL (strtol) (nptr, endptr, base, group)
const char *save, *end; const char *save, *end;
int overflow; int overflow;
#ifdef USE_NUMBER_GROUPING
/* The thousands character of the current locale. */ /* The thousands character of the current locale. */
wchar_t thousands; wchar_t thousands;
/* The numeric grouping specification of the current locale, /* The numeric grouping specification of the current locale,
@ -114,7 +137,7 @@ INTERNAL (strtol) (nptr, endptr, base, group)
} }
else else
grouping = NULL; grouping = NULL;
#endif
if (base < 0 || base == 1 || base > 36) if (base < 0 || base == 1 || base > 36)
base = 10; base = 10;
@ -162,6 +185,7 @@ INTERNAL (strtol) (nptr, endptr, base, group)
/* Save the pointer so we can check later if anything happened. */ /* Save the pointer so we can check later if anything happened. */
save = s; save = s;
#ifdef USE_NUMBER_GROUPING
if (group) if (group)
{ {
/* Find the end of the digit string and check its grouping. */ /* Find the end of the digit string and check its grouping. */
@ -176,6 +200,7 @@ INTERNAL (strtol) (nptr, endptr, base, group)
end = correctly_grouped_prefix (s, end, thousands, grouping); end = correctly_grouped_prefix (s, end, thousands, grouping);
} }
else else
#endif
end = NULL; end = NULL;
cutoff = ULONG_MAX / (unsigned LONG int) base; cutoff = ULONG_MAX / (unsigned LONG int) base;
@ -214,7 +239,7 @@ INTERNAL (strtol) (nptr, endptr, base, group)
if (endptr != NULL) if (endptr != NULL)
*endptr = (char *) s; *endptr = (char *) s;
#if !UNSIGNED #if !UNSIGNED
/* Check for a value that is within the range of /* Check for a value that is within the range of
`unsigned LONG int', but outside the range of `LONG int'. */ `unsigned LONG int', but outside the range of `LONG int'. */
if (i > (negative ? if (i > (negative ?
@ -225,7 +250,7 @@ INTERNAL (strtol) (nptr, endptr, base, group)
if (overflow) if (overflow)
{ {
errno = ERANGE; errno = ERANGE;
#if UNSIGNED #if UNSIGNED
return ULONG_MAX; return ULONG_MAX;
#else #else
return negative ? LONG_MIN : LONG_MAX; return negative ? LONG_MIN : LONG_MAX;
@ -244,7 +269,9 @@ noconv:
/* External user entry point. */ /* External user entry point. */
#ifdef weak_symbol
weak_symbol (strtol) weak_symbol (strtol)
#endif
INT INT
strtol (nptr, endptr, base) strtol (nptr, endptr, base)