mirror of
https://github.com/HDFGroup/hdf5.git
synced 2024-11-21 01:04:10 +08:00
Removes checks and work-arounds for strtoll and strtoull (#769)
* Removes checks and work-arounds for strtoll and strtoull * Removes CMake checks for strtoll and strtoull
This commit is contained in:
parent
2e7750f837
commit
a91c626c29
@ -349,12 +349,6 @@
|
||||
/* Define to 1 if you have the <string.h> header file. */
|
||||
#cmakedefine H5_HAVE_STRING_H @H5_HAVE_STRING_H@
|
||||
|
||||
/* Define to 1 if you have the `strtoll' function. */
|
||||
#cmakedefine H5_HAVE_STRTOLL @H5_HAVE_STRTOLL@
|
||||
|
||||
/* Define to 1 if you have the `strtoull' function. */
|
||||
#cmakedefine H5_HAVE_STRTOULL @H5_HAVE_STRTOULL@
|
||||
|
||||
/* Define if struct text_info is defined */
|
||||
#cmakedefine H5_HAVE_STRUCT_TEXT_INFO @H5_HAVE_STRUCT_TEXT_INFO@
|
||||
|
||||
|
@ -494,8 +494,6 @@ CHECK_FUNCTION_EXISTS (sigprocmask ${HDF_PREFIX}_HAVE_SIGPROCMASK)
|
||||
CHECK_FUNCTION_EXISTS (snprintf ${HDF_PREFIX}_HAVE_SNPRINTF)
|
||||
CHECK_FUNCTION_EXISTS (srandom ${HDF_PREFIX}_HAVE_SRANDOM)
|
||||
CHECK_FUNCTION_EXISTS (strdup ${HDF_PREFIX}_HAVE_STRDUP)
|
||||
CHECK_FUNCTION_EXISTS (strtoll ${HDF_PREFIX}_HAVE_STRTOLL)
|
||||
CHECK_FUNCTION_EXISTS (strtoull ${HDF_PREFIX}_HAVE_STRTOULL)
|
||||
CHECK_FUNCTION_EXISTS (symlink ${HDF_PREFIX}_HAVE_SYMLINK)
|
||||
CHECK_FUNCTION_EXISTS (system ${HDF_PREFIX}_HAVE_SYSTEM)
|
||||
|
||||
|
@ -2030,7 +2030,6 @@ AC_CHECK_FUNCS([frexpl gethostname getrusage gettimeofday])
|
||||
AC_CHECK_FUNCS([lstat rand_r random setsysinfo])
|
||||
AC_CHECK_FUNCS([signal longjmp setjmp siglongjmp sigsetjmp sigprocmask])
|
||||
AC_CHECK_FUNCS([snprintf srandom strdup symlink system])
|
||||
AC_CHECK_FUNCS([strtoll strtoull])
|
||||
AC_CHECK_FUNCS([tmpfile asprintf vasprintf vsnprintf waitpid])
|
||||
|
||||
## ----------------------------------------------------------------------
|
||||
|
@ -1526,11 +1526,7 @@ H5_DLL void HDsrand(unsigned int seed);
|
||||
#define HDstrtol(S, R, N) strtol(S, R, N)
|
||||
#endif /* HDstrtol */
|
||||
#ifndef HDstrtoll
|
||||
#ifdef H5_HAVE_STRTOLL
|
||||
#define HDstrtoll(S, R, N) strtoll(S, R, N)
|
||||
#else
|
||||
H5_DLL int64_t HDstrtoll(const char *s, const char **rest, int base);
|
||||
#endif /* H5_HAVE_STRTOLL */
|
||||
#endif /* HDstrtoll */
|
||||
#ifndef HDstrtoul
|
||||
#define HDstrtoul(S, R, N) strtoul(S, R, N)
|
||||
@ -1631,7 +1627,7 @@ H5_DLL int64_t HDstrtoll(const char *s, const char **rest, int base);
|
||||
#ifdef H5_HAVE_VASPRINTF
|
||||
#define HDvasprintf(RET, FMT, A) vasprintf(RET, FMT, A)
|
||||
#else
|
||||
H5_DLL int HDvasprintf(char **bufp, const char *fmt, va_list _ap);
|
||||
H5_DLL int HDvasprintf(char **bufp, const char *fmt, va_list _ap);
|
||||
#endif /* H5_HAVE_VASPRINTF */
|
||||
#endif /* HDvasprintf */
|
||||
#ifndef HDva_arg
|
||||
|
125
src/H5system.c
125
src/H5system.c
@ -96,131 +96,6 @@ HDvasprintf(char **bufp, const char *fmt, va_list _ap)
|
||||
}
|
||||
#endif /* H5_HAVE_VASPRINTF */
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: HDstrtoll
|
||||
*
|
||||
* Purpose: Converts the string S to an int64_t value according to the
|
||||
* given BASE, which must be between 2 and 36 inclusive, or be
|
||||
* the special value zero.
|
||||
*
|
||||
* The string must begin with an arbitrary amount of white space
|
||||
* (as determined by isspace(3c)) followed by a single optional
|
||||
* `+' or `-' sign. If BASE is zero or 16 the string may then
|
||||
* include a `0x' or `0X' prefix, and the number will be read in
|
||||
* base 16; otherwise a zero BASE is taken as 10 (decimal)
|
||||
* unless the next character is a `0', in which case it is taken
|
||||
* as 8 (octal).
|
||||
*
|
||||
* The remainder of the string is converted to an int64_t in the
|
||||
* obvious manner, stopping at the first character which is not
|
||||
* a valid digit in the given base. (In bases above 10, the
|
||||
* letter `A' in either upper or lower case represetns 10, `B'
|
||||
* represents 11, and so forth, with `Z' representing 35.)
|
||||
*
|
||||
* If REST is not null, the address of the first invalid
|
||||
* character in S is stored in *REST. If there were no digits
|
||||
* at all, the original value of S is stored in *REST. Thus, if
|
||||
* *S is not `\0' but **REST is `\0' on return the entire string
|
||||
* was valid.
|
||||
*
|
||||
* Return: Success: The result.
|
||||
*
|
||||
* Failure: If the input string does not contain any
|
||||
* digits then zero is returned and REST points
|
||||
* to the original value of S. If an overflow
|
||||
* or underflow occurs then the maximum or
|
||||
* minimum possible value is returned and the
|
||||
* global `errno' is set to ERANGE. If BASE is
|
||||
* incorrect then zero is returned.
|
||||
*
|
||||
* Programmer: Robb Matzke
|
||||
* Thursday, April 9, 1998
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef HDstrtoll
|
||||
int64_t
|
||||
HDstrtoll(const char *s, const char **rest, int base)
|
||||
{
|
||||
int64_t sign = 1, acc = 0;
|
||||
hbool_t overflow = FALSE;
|
||||
|
||||
errno = 0;
|
||||
if (!s || (base && (base < 2 || base > 36))) {
|
||||
if (rest)
|
||||
*rest = s;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Skip white space */
|
||||
while (HDisspace(*s))
|
||||
s++;
|
||||
|
||||
/* Optional minus or plus sign */
|
||||
if ('+' == *s) {
|
||||
s++;
|
||||
}
|
||||
else if ('-' == *s) {
|
||||
sign = -1;
|
||||
s++;
|
||||
}
|
||||
|
||||
/* Zero base prefix */
|
||||
if (0 == base && '0' == *s && ('x' == s[1] || 'X' == s[1])) {
|
||||
base = 16;
|
||||
s += 2;
|
||||
}
|
||||
else if (0 == base && '0' == *s) {
|
||||
base = 8;
|
||||
s++;
|
||||
}
|
||||
else if (0 == base) {
|
||||
base = 10;
|
||||
}
|
||||
|
||||
/* Digits */
|
||||
while ((base <= 10 && *s >= '0' && *s < '0' + base) ||
|
||||
(base > 10 && ((*s >= '0' && *s <= '9') || (*s >= 'a' && *s < 'a' + base - 10) ||
|
||||
(*s >= 'A' && *s < 'A' + base - 10)))) {
|
||||
if (!overflow) {
|
||||
int64_t digit = 0;
|
||||
|
||||
if (*s >= '0' && *s <= '9')
|
||||
digit = *s - '0';
|
||||
else if (*s >= 'a' && *s <= 'z')
|
||||
digit = (*s - 'a') + 10;
|
||||
else
|
||||
digit = (*s - 'A') + 10;
|
||||
|
||||
if (acc * base + digit < acc) {
|
||||
overflow = TRUE;
|
||||
}
|
||||
else {
|
||||
acc = acc * base + digit;
|
||||
}
|
||||
}
|
||||
s++;
|
||||
}
|
||||
|
||||
/* Overflow */
|
||||
if (overflow) {
|
||||
if (sign > 0) {
|
||||
acc = ((uint64_t)1 << (8 * sizeof(int64_t) - 1)) - 1;
|
||||
}
|
||||
else {
|
||||
acc = (int64_t)((uint64_t)1 << (8 * sizeof(int64_t) - 1));
|
||||
}
|
||||
errno = ERANGE;
|
||||
}
|
||||
|
||||
/* Return values */
|
||||
acc *= sign;
|
||||
if (rest)
|
||||
*rest = s;
|
||||
return acc;
|
||||
} /* end HDstrtoll() */
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: HDrand/HDsrand
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user