From: Laurent Mazet Date: Mon, 5 Dec 2022 12:57:45 +0000 (+0100) Subject: add private atoi function X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=252c83800b0b0d038212c916a4e48f2ab0060f4c;p=compress.git add private atoi function --- diff --git a/atoi.c b/atoi.c new file mode 100644 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 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 */