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:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user