long num;
char *end = NULL;
- if (str != NULL && *str != '\0') {
- errno = 0;
- num = strtol(str, &end, 10);
- if (errno == 0 && str != end && end != NULL && *end == '\0')
- return num;
- }
+ if (str != NULL && *str != '\0') {
+ errno = 0;
+ num = strtol(str, &end, 10);
+ if (errno == 0 && str != end && end != NULL && *end == '\0')
+ return num;
+ }
error(EXIT_FAILURE, errno, "%s: '%s'", errmesg, str);
- return 0;
+ return 0;
}
+
/*
* same as strtod(3) but exit on failure instead of returning crap
*/
double num;
char *end = NULL;
- if (str != NULL && *str != '\0') {
- errno = 0;
- num = strtod(str, &end);
- if (errno == 0 && str != end && end != NULL && *end == '\0')
- return num;
- }
+ if (str != NULL && *str != '\0') {
+ errno = 0;
+ num = strtod(str, &end);
+ if (errno == 0 && str != end && end != NULL && *end == '\0')
+ return num;
+ }
error(EXIT_FAILURE, errno, "%s: '%s'", errmesg, str);
return 0;
}