Add a strtoul() wrapper

This commit is contained in:
Přemysl Eric Janouch 2014-07-13 05:56:30 +02:00
parent 51909edc76
commit 03ec980f26
2 changed files with 11 additions and 4 deletions

View File

@ -1417,6 +1417,15 @@ set_boolean_if_valid (bool *out, const char *s)
return true;
}
static bool
xstrtoul (unsigned long *out, const char *s, int base)
{
char *end;
errno = 0;
*out = strtoul (s, &end, base);
return errno == 0 && !*end && end != s;
}
static bool
read_line (FILE *fp, struct str *s)
{

View File

@ -1418,10 +1418,8 @@ irc_try_reconnect (struct bot_context *ctx)
const char *delay_str = str_map_find (&ctx->config, "reconnect_delay");
hard_assert (delay_str != NULL); // We have a default value for this
char *end_ptr;
errno = 0;
long delay = strtol (delay_str, &end_ptr, 10);
if (errno != 0 || end_ptr == delay_str || *end_ptr)
unsigned long delay;
if (!xstrtoul (&delay, delay_str, 10))
{
print_error ("invalid configuration value for `%s'",
"reconnect_delay");