aboutsummaryrefslogtreecommitdiff
path: root/src/str/ft_atoi_strict.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-01-16 00:51:22 +0100
committerCharles <sircharlesaze@gmail.com>2020-01-16 00:51:22 +0100
commitae1412fdc283e442a0869aa7d63778449a7e5cfe (patch)
tree0f5d5ff124129b3f085ce94d3004622c0d041323 /src/str/ft_atoi_strict.c
parente8a7d07f1c99b5ce6210603d88098580af95fb13 (diff)
downloadlibft-ae1412fdc283e442a0869aa7d63778449a7e5cfe.tar.gz
libft-ae1412fdc283e442a0869aa7d63778449a7e5cfe.tar.bz2
libft-ae1412fdc283e442a0869aa7d63778449a7e5cfe.zip
Features toggle to avoid bloat and unauthorized functions, config file, script to generate a rendu branch
Diffstat (limited to 'src/str/ft_atoi_strict.c')
-rw-r--r--src/str/ft_atoi_strict.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/str/ft_atoi_strict.c b/src/str/ft_atoi_strict.c
new file mode 100644
index 0000000..6156b03
--- /dev/null
+++ b/src/str/ft_atoi_strict.c
@@ -0,0 +1,39 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strict_atoi.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/01/15 10:06:29 by cacharle #+# #+# */
+/* Updated: 2020/01/15 14:09:03 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+#include <stdio.h>
+int ft_strict_atoi(const char *s)
+{
+ char *end;
+ long ret;
+
+ if (*s != '-' && !ft_isdigit(*s))
+ {
+ errno = EINVAL;
+ return (0);
+ }
+ errno = 0;
+ ret = ft_strtol(s, &end, 10);
+ if (errno == ERANGE || ret > INT_MAX || ret < INT_MIN)
+ {
+ errno = ERANGE;
+ return (0);
+ }
+ if (*end != '\0')
+ {
+ errno = EINVAL;
+ return (0);
+ }
+ return (ret);
+}