1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Move strtoint() to common

Several places used similar code to convert a string to an int, so take
the function that we already had and make it globally available.

Reviewed-by: Michael Paquier <michael@paquier.xyz>
This commit is contained in:
Peter Eisentraut
2018-03-13 10:21:09 -04:00
parent 6cf86f4354
commit 17bb625017
9 changed files with 39 additions and 49 deletions

View File

@@ -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;
}