@@ -85,94 +85,6 @@ decimalLength64(const uint64 v)
85
85
return t + (v >= PowersOfTen [t ]);
86
86
}
87
87
88
- /*
89
- * pg_atoi: convert string to integer
90
- *
91
- * allows any number of leading or trailing whitespace characters.
92
- *
93
- * 'size' is the sizeof() the desired integral result (1, 2, or 4 bytes).
94
- *
95
- * c, if not 0, is a terminator character that may appear after the
96
- * integer (plus whitespace). If 0, the string must end after the integer.
97
- *
98
- * Unlike plain atoi(), this will throw ereport() upon bad input format or
99
- * overflow.
100
- */
101
- int32
102
- pg_atoi (const char * s , int size , int c )
103
- {
104
- long l ;
105
- char * badp ;
106
-
107
- /*
108
- * Some versions of strtol treat the empty string as an error, but some
109
- * seem not to. Make an explicit test to be sure we catch it.
110
- */
111
- if (s == NULL )
112
- elog (ERROR , "NULL pointer" );
113
- if (* s == 0 )
114
- ereport (ERROR ,
115
- (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
116
- errmsg ("invalid input syntax for type %s: \"%s\"" ,
117
- "integer" , s )));
118
-
119
- errno = 0 ;
120
- l = strtol (s , & badp , 10 );
121
-
122
- /* We made no progress parsing the string, so bail out */
123
- if (s == badp )
124
- ereport (ERROR ,
125
- (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
126
- errmsg ("invalid input syntax for type %s: \"%s\"" ,
127
- "integer" , s )));
128
-
129
- switch (size )
130
- {
131
- case sizeof (int32 ):
132
- if (errno == ERANGE
133
- #if defined(HAVE_LONG_INT_64 )
134
- /* won't get ERANGE on these with 64-bit longs... */
135
- || l < INT_MIN || l > INT_MAX
136
- #endif
137
- )
138
- ereport (ERROR ,
139
- (errcode (ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE ),
140
- errmsg ("value \"%s\" is out of range for type %s" , s ,
141
- "integer" )));
142
- break ;
143
- case sizeof (int16 ):
144
- if (errno == ERANGE || l < SHRT_MIN || l > SHRT_MAX )
145
- ereport (ERROR ,
146
- (errcode (ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE ),
147
- errmsg ("value \"%s\" is out of range for type %s" , s ,
148
- "smallint" )));
149
- break ;
150
- case sizeof (int8 ):
151
- if (errno == ERANGE || l < SCHAR_MIN || l > SCHAR_MAX )
152
- ereport (ERROR ,
153
- (errcode (ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE ),
154
- errmsg ("value \"%s\" is out of range for 8-bit integer" , s )));
155
- break ;
156
- default :
157
- elog (ERROR , "unsupported result size: %d" , size );
158
- }
159
-
160
- /*
161
- * Skip any trailing whitespace; if anything but whitespace remains before
162
- * the terminating character, bail out
163
- */
164
- while (* badp && * badp != c && isspace ((unsigned char ) * badp ))
165
- badp ++ ;
166
-
167
- if (* badp && * badp != c )
168
- ereport (ERROR ,
169
- (errcode (ERRCODE_INVALID_TEXT_REPRESENTATION ),
170
- errmsg ("invalid input syntax for type %s: \"%s\"" ,
171
- "integer" , s )));
172
-
173
- return (int32 ) l ;
174
- }
175
-
176
88
/*
177
89
* Convert input string to a signed 16 bit integer.
178
90
*
0 commit comments