#include <ctype.h>
+#include "common/string.h"
#include "nodes/pg_list.h"
#include "nodes/readfuncs.h"
#include "nodes/value.h"
{
/*
* Yes. Figure out whether it is integral or float; this requires
- * both a syntax check and a range check. strtol() can do both for us.
- * We know the token will end at a character that strtol will stop at,
+ * both a syntax check and a range check. strtoint() can do both for us.
+ * We know the token will end at a character that strtoint will stop at,
* so we do not need to modify the string.
*/
- long val;
char *endptr;
errno = 0;
- val = strtol(token, &endptr, 10);
- if (endptr != token + length || errno == ERANGE ||
- /* check for overflow of int */
- val != (int) val)
+ (void) strtoint(token, &endptr, 10);
+ if (endptr != token + length || errno == ERANGE)
return T_Float;
return T_Integer;
}
#include <ctype.h>
#include <unistd.h>
+#include "common/string.h"
#include "parser/gramparse.h"
#include "parser/parser.h" /* only needed for GUC variables */
#include "parser/scansup.h"
static int
process_integer_literal(const char *token, YYSTYPE *lval)
{
- long val;
+ int val;
char *endptr;
errno = 0;
- val = strtol(token, &endptr, 10);
- if (*endptr != '\0' || errno == ERANGE ||
- /* check for overflow of int */
- val != (int) val)
+ val = strtoint(token, &endptr, 10);
+ if (*endptr != '\0' || errno == ERANGE)
{
/* integer too large, treat it as a float */
lval->str = pstrdup(token);
#include "access/htup_details.h"
#include "access/xact.h"
#include "catalog/pg_type.h"
+#include "common/string.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "nodes/nodeFuncs.h"
static const datetkn *abbrevcache[MAXDATEFIELDS] = {NULL};
-/*
- * strtoint --- just like strtol, but returns int not long
- */
-static int
-strtoint(const char *nptr, char **endptr, int base)
-{
- long val;
-
- val = strtol(nptr, endptr, base);
-#ifdef HAVE_LONG_INT_64
- if (val != (long) ((int32) val))
- errno = ERANGE;
-#endif
- return (int) val;
-}
-
-
/*
* Calendar time to Julian date conversions.
* Julian date is commonly used in astronomical applications,
str += slen - elen;
return strcmp(str, end) == 0;
}
+
+
+/*
+ * strtoint --- just like strtol, but returns int not long
+ */
+int
+strtoint(const char *restrict str, char **restrict endptr, int base)
+{
+ long val;
+
+ val = strtol(str, endptr, base);
+ if (val != (int) val)
+ errno = ERANGE;
+ return (int) val;
+}
#define COMMON_STRING_H
extern bool pg_str_endswith(const char *str, const char *end);
+extern int strtoint(const char *restrict str, char **restrict endptr, int base);
#endif /* COMMON_STRING_H */
/pgstrcasecmp.c
/rint.c
/snprintf.c
+/string.c
/strnlen.c
OBJS= numeric.o datetime.o common.o dt_common.o timestamp.o interval.o \
pgstrcasecmp.o \
$(filter rint.o snprintf.o strnlen.o, $(LIBOBJS)) \
+ string.o \
$(WIN32RES)
all: all-lib
pgstrcasecmp.c rint.c snprintf.c strnlen.c: % : $(top_srcdir)/src/port/%
rm -f $@ && $(LN_S) $< .
+string.c: % : $(top_srcdir)/src/common/%
+ rm -f $@ && $(LN_S) $< .
+
install: all installdirs install-lib
installdirs: installdirs-lib
uninstall: uninstall-lib
clean distclean: clean-lib
- rm -f $(OBJS) pgstrcasecmp.c rint.c snprintf.c strnlen.c
+ rm -f $(OBJS) pgstrcasecmp.c rint.c snprintf.c strnlen.c string.c
maintainer-clean: distclean maintainer-clean-lib
#error -ffast-math is known to break this code
#endif
+#include "common/string.h"
+
#include "extern.h"
#include "dt.h"
#include "pgtypes_error.h"
#include "pgtypes_interval.h"
-/* copy&pasted from .../src/backend/utils/adt/datetime.c */
-static int
-strtoint(const char *nptr, char **endptr, int base)
-{
- long val;
-
- val = strtol(nptr, endptr, base);
-#ifdef HAVE_LONG_INT_64
- if (val != (long) ((int32) val))
- errno = ERANGE;
-#endif
- return (int) val;
-}
-
/* copy&pasted from .../src/backend/utils/adt/datetime.c
* and changesd struct pg_tm to struct tm
*/
#include <ctype.h>
#include <limits.h>
+#include "common/string.h"
+
#include "extern.h"
#include "preproc.h"
}
return PARAM;
}
<C,SQL>{integer} {
- long val;
+ int val;
char* endptr;
errno = 0;
- val = strtol((char *)yytext, &endptr,10);
- if (*endptr != '\0' || errno == ERANGE ||
- /* check for overflow of int */
- val != (int) val)
+ val = strtoint(yytext, &endptr, 10);
+ if (*endptr != '\0' || errno == ERANGE)
{
errno = 0;
base_yylval.str = mm_strdup(yytext);