summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7ca7633)
raw | patch | inline | side by side (parent: 7ca7633)
author | Florian Forster <octo@huhu.verplant.org> | |
Wed, 20 Jan 2010 17:08:49 +0000 (18:08 +0100) | ||
committer | Florian Forster <octo@huhu.verplant.org> | |
Wed, 20 Jan 2010 17:08:49 +0000 (18:08 +0100) |
Simplifies error handling.
src/common.c | patch | blob | history | |
src/common.h | patch | blob | history |
diff --git a/src/common.c b/src/common.c
index 3695a9b794406c9ea4e8d76a135cad5d2eb93767..8c2aeaea653aefe0f5380783175b4cb75e10fde2 100644 (file)
--- a/src/common.c
+++ b/src/common.c
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 2d5c7945f44b0e5448c33c7880487f1e57b0f4e6..fc809f2173d91a1e0c000052a00861e00e267af0 100644 (file)
--- a/src/common.h
+++ b/src/common.h
* (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 */