From 03ec980f269c8222eaeeb3bbae8c3cab20595bfd Mon Sep 17 00:00:00 2001
From: Přemysl Janouch
Date: Sun, 13 Jul 2014 05:56:30 +0200
Subject: Add a strtoul() wrapper
---
src/common.c | 9 +++++++++
src/zyklonb.c | 6 ++----
2 files changed, 11 insertions(+), 4 deletions(-)
(limited to 'src')
diff --git a/src/common.c b/src/common.c
index fcb9742..8ec6646 100644
--- a/src/common.c
+++ b/src/common.c
@@ -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)
{
diff --git a/src/zyklonb.c b/src/zyklonb.c
index a57b8c4..3d8d388 100644
--- a/src/zyklonb.c
+++ b/src/zyklonb.c
@@ -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");
--
cgit v1.2.3-70-g09d2