add private atoi function
authorLaurent Mazet <laurent.mazet@thalesgroup.com>
Mon, 5 Dec 2022 12:57:45 +0000 (13:57 +0100)
committerLaurent Mazet <laurent.mazet@thalesgroup.com>
Mon, 5 Dec 2022 12:57:45 +0000 (13:57 +0100)
atoi.c [new file with mode: 0644]
atoi.h [new file with mode: 0644]

diff --git a/atoi.c b/atoi.c
new file mode 100644 (file)
index 0000000..fd3fedd
--- /dev/null
+++ b/atoi.c
@@ -0,0 +1,23 @@
+#include "atoi.h"
+
+int myatoi (char *str)
+{
+    int i = 0;
+    int s = 1;
+
+    if (*str == '-') {
+        s = 0;
+       str++;
+    }
+
+    while (*str != 0) {
+        if ((*str <'0') || (*str > '9')) {
+            return 0;
+        }
+        i = i * 10 + (int)(*(str++) - '0');
+    }
+
+    return (s) ? i : -i;
+}
+
+/* vim: set ts=4 sw=4 et */
diff --git a/atoi.h b/atoi.h
new file mode 100644 (file)
index 0000000..74d58c3
--- /dev/null
+++ b/atoi.h
@@ -0,0 +1,8 @@
+#ifndef __ATOI_H__
+#define __ATOI_H__
+
+int myatoi (char *str);
+
+#endif /* __ATOI_H__ */
+
+/* vim: set ts=4 sw=4 et */