|
7 | 7 | * Portions Copyright (c) 1994, Regents of the University of California |
8 | 8 | * |
9 | 9 | * IDENTIFICATION |
10 | | - * $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.35 2001/10/25 14:10:06 tgl Exp $ |
| 10 | + * $Header: /cvsroot/pgsql/src/backend/utils/adt/int8.c,v 1.36 2001/11/24 19:57:06 tgl Exp $ |
11 | 11 | * |
12 | 12 | *------------------------------------------------------------------------- |
13 | 13 | */ |
|
26 | 26 | #defineINT64_FORMAT "%ld" |
27 | 27 | #endif |
28 | 28 |
|
| 29 | +#ifdefHAVE_LL_CONSTANTS |
| 30 | +#defineINT64CONST(x) ((int64) x##LL) |
| 31 | +#else |
| 32 | +#defineINT64CONST(x) ((int64) x) |
| 33 | +#endif |
| 34 | + |
29 | 35 | #defineMAXINT8LEN25 |
30 | 36 |
|
31 | 37 | #ifndefINT_MAX |
@@ -69,8 +75,23 @@ int8in(PG_FUNCTION_ARGS) |
69 | 75 | */ |
70 | 76 | while (*ptr&&isspace((unsignedchar)*ptr))/* skip leading spaces */ |
71 | 77 | ptr++; |
72 | | -if (*ptr=='-')/* handle sign */ |
73 | | -sign=-1,ptr++; |
| 78 | +/* handle sign */ |
| 79 | +if (*ptr=='-') |
| 80 | +{ |
| 81 | +ptr++; |
| 82 | +sign=-1; |
| 83 | +/* |
| 84 | + * Do an explicit check for INT64_MIN. Ugly though this is, it's |
| 85 | + * cleaner than trying to get the loop below to handle it portably. |
| 86 | + */ |
| 87 | +#ifndefINT64_IS_BUSTED |
| 88 | +if (strcmp(ptr,"9223372036854775808")==0) |
| 89 | +{ |
| 90 | +result=-INT64CONST(0x7fffffffffffffff)-1; |
| 91 | +PG_RETURN_INT64(result); |
| 92 | +} |
| 93 | +#endif |
| 94 | +} |
74 | 95 | elseif (*ptr=='+') |
75 | 96 | ptr++; |
76 | 97 | if (!isdigit((unsignedchar)*ptr))/* require at least one digit */ |
|