aboutsummaryrefslogtreecommitdiff
path: root/src/common/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/string.c')
-rw-r--r--src/common/string.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/common/string.c b/src/common/string.c
index 0e3557076a1..a45e9b88580 100644
--- a/src/common/string.c
+++ b/src/common/string.c
@@ -41,3 +41,18 @@ pg_str_endswith(const char *str, const char *end)
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;
+}