From 3b8dcc64a73b25b67d4eb242e0e58ca5bc6dbb7c Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 20 Jan 2010 18:08:49 +0100 Subject: [PATCH] =?utf8?q?src/common.[ch]:=20Implement=20=E2=80=9Cstrtoder?= =?utf8?q?ive=E2=80=9D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Simplifies error handling. --- src/common.c | 18 ++++++++++++++++++ src/common.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/common.c b/src/common.c index 3695a9b7..8c2aeaea 100644 --- a/src/common.c +++ b/src/common.c @@ -1142,3 +1142,21 @@ int service_name_to_port_number (const char *service_name) return (service_number); return (-1); } /* int service_name_to_port_number */ + +int strtoderive (const char *string, derive_t *ret_value) /* {{{ */ +{ + derive_t tmp; + char *endptr; + + if ((string == NULL) || (ret_value == NULL)) + return (EINVAL); + + errno = 0; + endptr = NULL; + tmp = (derive_t) strtoll (string, &endptr, /* base = */ 0); + if ((endptr == string) || (errno != 0)) + return (-1); + + *ret_value = tmp; + return (0); +} /* }}} int strtoderive */ diff --git a/src/common.h b/src/common.h index 2d5c7945..fc809f21 100644 --- a/src/common.h +++ b/src/common.h @@ -289,4 +289,6 @@ counter_t counter_diff (counter_t old_value, counter_t new_value); * (in the range [1-65535]). Returns less than zero on error. */ int service_name_to_port_number (const char *service_name); +int strtoderive (const char *string, derive_t *ret_value); + #endif /* COMMON_H */ -- 2.11.0