Skip to content

Commit

Permalink
Removes checks and work-arounds for strtoll and strtoull (#769)
Browse files Browse the repository at this point in the history
* Removes checks and work-arounds for strtoll and strtoull

* Removes CMake checks for strtoll and strtoull
  • Loading branch information
derobins authored Jun 18, 2021
1 parent 2e7750f commit a91c626
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 139 deletions.
6 changes: 0 additions & 6 deletions config/cmake/H5pubconf.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@

Expand Down
2 changes: 0 additions & 2 deletions config/cmake_ext_mod/ConfigureChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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])

## ----------------------------------------------------------------------
Expand Down
6 changes: 1 addition & 5 deletions src/H5private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
125 changes: 0 additions & 125 deletions src/H5system.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit a91c626

Please sign in to comment.