mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +03:00
Modify int8 to not depend on sscanf(), and fix configure's test
for int8 support. configure now checks only snprintf() for int8 support, not sprintf and sscanf as it used to. The reason for doing this is that if we are supplying our own snprintf code (which does handle long long int), we now only need working long long support in the compiler not in the platform's C library. I have verified that int8 now passes regression test on HPUX 9, and I think it should work on SunOS 4.1.* and other older platforms if gcc is used.
This commit is contained in:
@ -37,17 +37,31 @@ int64 *
|
||||
int8in(char *str)
|
||||
{
|
||||
int64 *result = palloc(sizeof(int64));
|
||||
char *ptr = str;
|
||||
int64 tmp = 0;
|
||||
int sign = 1;
|
||||
|
||||
if (!PointerIsValid(str))
|
||||
elog(ERROR, "Bad (null) int8 external representation", NULL);
|
||||
|
||||
if (sscanf(str, INT64_FORMAT, result) != 1)
|
||||
/* Do our own scan, rather than relying on sscanf which might be
|
||||
* broken for long long. NOTE: this will not detect int64 overflow...
|
||||
* but sscanf doesn't either...
|
||||
*/
|
||||
while (*ptr && isspace(*ptr)) /* skip leading spaces */
|
||||
ptr++;
|
||||
if (*ptr == '-') /* handle sign */
|
||||
sign = -1, ptr++;
|
||||
else if (*ptr == '+')
|
||||
ptr++;
|
||||
if (! isdigit(*ptr)) /* require at least one digit */
|
||||
elog(ERROR, "Bad int8 external representation '%s'", str);
|
||||
while (*ptr && isdigit(*ptr)) /* process digits */
|
||||
tmp = tmp * 10 + (*ptr++ - '0');
|
||||
if (*ptr) /* trailing junk? */
|
||||
elog(ERROR, "Bad int8 external representation '%s'", str);
|
||||
|
||||
#if FALSE
|
||||
elog(ERROR, "64-bit integers are not supported", NULL);
|
||||
result = NULL;
|
||||
#endif
|
||||
*result = (sign < 0) ? -tmp : tmp;
|
||||
|
||||
return result;
|
||||
} /* int8in() */
|
||||
|
Reference in New Issue
Block a user