summaryrefslogtreecommitdiff
path: root/libbb/safe_strtol.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/safe_strtol.c')
-rw-r--r--libbb/safe_strtol.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/libbb/safe_strtol.c b/libbb/safe_strtol.c
index ecc1667..2e8fa95 100644
--- a/libbb/safe_strtol.c
+++ b/libbb/safe_strtol.c
@@ -74,3 +74,37 @@ int safe_strtoul(char *arg, unsigned long* value)
}
#endif
+#ifdef L_safe_strtoll
+int safe_strtoll(char *arg, long long* value)
+{
+ char *endptr;
+ int errno_save = errno;
+
+ assert(arg!=NULL);
+ errno = 0;
+ *value = strtoll(arg, &endptr, 0);
+ if (errno != 0 || *endptr!='\0' || endptr==arg) {
+ return 1;
+ }
+ errno = errno_save;
+ return 0;
+}
+#endif
+
+#ifdef L_safe_strtoull
+int safe_strtoull(char *arg, unsigned long long* value)
+{
+ char *endptr;
+ int errno_save = errno;
+
+ assert(arg!=NULL);
+ errno = 0;
+ *value = strtoull(arg, &endptr, 0);
+ if (errno != 0 || *endptr!='\0' || endptr==arg) {
+ return 1;
+ }
+ errno = errno_save;
+ return 0;
+}
+#endif
+