diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 1999-02-03 00:18:53 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 1999-02-03 00:18:53 +0000 |
commit | 724119a979f8f28c9e2acf92b95ef0c476768e65 (patch) | |
tree | 34e63bc02d5b8764ce311c0c0a61cbb9e360dccc /src/backend/utils/adt/int8.c | |
parent | 4090d17fee7f6028e6e969d1a32d84fed67803e4 (diff) | |
download | postgresql-724119a979f8f28c9e2acf92b95ef0c476768e65.tar.gz postgresql-724119a979f8f28c9e2acf92b95ef0c476768e65.zip |
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.
Diffstat (limited to 'src/backend/utils/adt/int8.c')
-rw-r--r-- | src/backend/utils/adt/int8.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c index 4ffdcbf225b..f97b352bf2c 100644 --- a/src/backend/utils/adt/int8.c +++ b/src/backend/utils/adt/int8.c @@ -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() */ |