summaryrefslogtreecommitdiff
path: root/src/string_to_uint.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/string_to_uint.h')
-rw-r--r--src/string_to_uint.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/string_to_uint.h b/src/string_to_uint.h
new file mode 100644
index 000000000..3eb9c8e70
--- /dev/null
+++ b/src/string_to_uint.h
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2001-2018 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#ifndef STRACE_STRING_TO_UINT_H
+# define STRACE_STRING_TO_UINT_H
+
+# include <limits.h>
+
+# include "kernel_types.h"
+
+extern long long
+string_to_uint_ex(const char *str, char **endptr,
+ unsigned long long max_val, const char *accepted_ending);
+
+static inline long long
+string_to_uint_upto(const char *const str, const unsigned long long max_val)
+{
+ return string_to_uint_ex(str, NULL, max_val, NULL);
+}
+
+static inline int
+string_to_uint(const char *str)
+{
+ return string_to_uint_upto(str, INT_MAX);
+}
+
+static inline long
+string_to_ulong(const char *str)
+{
+ return string_to_uint_upto(str, LONG_MAX);
+}
+
+static inline kernel_long_t
+string_to_kulong(const char *str)
+{
+ return string_to_uint_upto(str, ((kernel_ulong_t) -1ULL) >> 1);
+}
+
+static inline long long
+string_to_ulonglong(const char *str)
+{
+ return string_to_uint_upto(str, LLONG_MAX);
+}
+
+#endif /* !STRACE_STRING_TO_UINT_H */