10
10
*
11
11
*
12
12
* IDENTIFICATION
13
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.16 1997/09/18 20:22:15 momjian Exp $
13
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/numutils.c,v 1.17 1997/11/17 16:26:27 thomas Exp $
14
14
*
15
15
*-------------------------------------------------------------------------
16
16
*/
17
17
#include <stdio.h> /* for sprintf() */
18
18
#include <errno.h>
19
19
#include <math.h>
20
+ #ifdef HAVE_LIMITS
21
+ #include <limits.h>
22
+ #endif
20
23
#include "postgres.h"
21
24
#include "utils/builtins.h" /* where the declarations go */
22
25
#ifndef HAVE_MEMMOVE
26
29
#endif
27
30
#include <port-protos.h> /* ecvt(), fcvt() */
28
31
32
+ #ifndef INT_MAX
33
+ #define INT_MAX (0x7FFFFFFFL)
34
+ #endif
35
+ #ifndef INT_MIN
36
+ #define INT_MIN (-0x80000000L)
37
+ #endif
38
+ #ifndef SHRT_MAX
39
+ #define SHRT_MAX (0x7FFF)
40
+ #endif
41
+ #ifndef SHRT_MIN
42
+ #define SHRT_MIN (-0x8000)
43
+ #endif
44
+ #ifndef SCHAR_MAX
45
+ #define SCHAR_MAX (0x7F)
46
+ #endif
47
+ #ifndef SCHAR_MIN
48
+ #define SCHAR_MIN (-0x80)
49
+ #endif
50
+
29
51
int32
30
52
pg_atoi (char * s , int size , int c )
31
53
{
@@ -46,37 +68,37 @@ pg_atoi(char *s, int size, int c)
46
68
case sizeof (int32 ):
47
69
#ifdef HAS_LONG_LONG
48
70
/* won't get ERANGE on these with 64-bit longs... */
49
- if (l < -0x80000000L )
71
+ if (l < INT_MIN )
50
72
{
51
73
errno = ERANGE ;
52
74
elog (WARN , "pg_atoi: error reading \"%s\": %m" , s );
53
75
}
54
- if (l > 0x7fffffffL )
76
+ if (l > INT_MAX )
55
77
{
56
78
errno = ERANGE ;
57
79
elog (WARN , "pg_atoi: error reading \"%s\": %m" , s );
58
80
}
59
81
#endif /* HAS_LONG_LONG */
60
82
break ;
61
83
case sizeof (int16 ):
62
- if (l < -0x8000 )
84
+ if (l < SHRT_MIN )
63
85
{
64
86
errno = ERANGE ;
65
87
elog (WARN , "pg_atoi: error reading \"%s\": %m" , s );
66
88
}
67
- if (l > 0x7fff )
89
+ if (l > SHRT_MAX )
68
90
{
69
91
errno = ERANGE ;
70
92
elog (WARN , "pg_atoi: error reading \"%s\": %m" , s );
71
93
}
72
94
break ;
73
95
case sizeof (int8 ):
74
- if (l < -0x80 )
96
+ if (l < SCHAR_MIN )
75
97
{
76
98
errno = ERANGE ;
77
99
elog (WARN , "pg_atoi: error reading \"%s\": %m" , s );
78
100
}
79
- if (l > 0x7f )
101
+ if (l > SCHAR_MAX )
80
102
{
81
103
errno = ERANGE ;
82
104
elog (WARN , "pg_atoi: error reading \"%s\": %m" , s );
0 commit comments