aboutsummaryrefslogtreecommitdiffstats
path: root/libasn1parser/asn1parser.c
diff options
context:
space:
mode:
Diffstat (limited to 'libasn1parser/asn1parser.c')
-rw-r--r--libasn1parser/asn1parser.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/libasn1parser/asn1parser.c b/libasn1parser/asn1parser.c
index f59d1afe..bd712b3c 100644
--- a/libasn1parser/asn1parser.c
+++ b/libasn1parser/asn1parser.c
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
@@ -184,3 +185,21 @@ _asn1p_fix_modules(asn1p_t *a, const char *fname) {
}
+int
+asn1p_atoi(const char *ptr, asn1c_integer_t *value) {
+ errno = 0; /* Clear the error code */
+
+ if(sizeof(*value) <= sizeof(int)) {
+ *value = strtol(ptr, 0, 10);
+ } else {
+#ifdef HAVE_STRTOIMAX
+ *value = strtoimax(ptr, 0, 10);
+#elif HAVE_STRTOLL
+ *value = strtoll(ptr, 0, 10);
+#else
+ *value = strtol(ptr, 0, 10);
+#endif
+ }
+
+ return errno == 0 ? 0 : -1;
+}