summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libft/Makefile3
-rw-r--r--libft/include/libft.h3
-rw-r--r--libft/src/ft_strclen.c24
-rw-r--r--libft/src/ft_strlen.c2
-rw-r--r--src/b_unset.c4
5 files changed, 32 insertions, 4 deletions
diff --git a/libft/Makefile b/libft/Makefile
index ac06d94..7b1c22c 100644
--- a/libft/Makefile
+++ b/libft/Makefile
@@ -24,6 +24,8 @@ SRCS_NAME += ft_memchr.c
SRCS_NAME += ft_memlchr.c
SRCS_NAME += ft_memcmp.c
SRCS_NAME += ft_strlen.c
+SRCS_NAME += ft_strclen.c
+SRCS_NAME += ft_strnlen.c
SRCS_NAME += ft_isalpha.c
SRCS_NAME += ft_isdigit.c
SRCS_NAME += ft_isalnum.c
@@ -71,7 +73,6 @@ SRCS_NAME += ft_putstr.c
SRCS_NAME += ft_putendl.c
SRCS_NAME += ft_putnbr.c
SRCS_NAME += ft_putnbr_base.c
-SRCS_NAME += ft_strnlen.c
SRCS_NAME += ft_strcat.c
SRCS_NAME += ft_strcmp.c
SRCS_NAME += ft_isspace.c
diff --git a/libft/include/libft.h b/libft/include/libft.h
index 6513693..0cd5ed1 100644
--- a/libft/include/libft.h
+++ b/libft/include/libft.h
@@ -148,9 +148,10 @@ int ft_strcmp(const char *s1, const char *s2);
long ft_memlchr(const void *s, int c, size_t n);
long ft_strlchr(const char *s, int c);
size_t ft_strlen(const char *s);
+size_t ft_strclen(const char *s, int c);
+size_t ft_strnlen(const char *s, size_t size);
size_t ft_strlcpy(char *dst, const char *src, size_t size);
size_t ft_strlcat(char *dst, const char *src, size_t size);
-size_t ft_strnlen(const char *s, size_t size);
double ft_sqrt(double x);
/*
diff --git a/libft/src/ft_strclen.c b/libft/src/ft_strclen.c
new file mode 100644
index 0000000..fe88ca5
--- /dev/null
+++ b/libft/src/ft_strclen.c
@@ -0,0 +1,24 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strclen.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/02/14 17:07:12 by rbousset #+# #+# */
+/* Updated: 2020/02/14 17:07:12 by rbousset ### ########lyon.fr */
+/* */
+/* ************************************************************************** */
+
+#include <stddef.h>
+
+size_t
+ ft_strclen(const char *s, int c)
+{
+ const char *ptr;
+
+ ptr = s;
+ while (ptr != NULL && *ptr != '\0' && *ptr != c)
+ ptr++;
+ return (ptr - s);
+}
diff --git a/libft/src/ft_strlen.c b/libft/src/ft_strlen.c
index 90f5110..2b26bf0 100644
--- a/libft/src/ft_strlen.c
+++ b/libft/src/ft_strlen.c
@@ -18,7 +18,7 @@ size_t
const char *ptr;
ptr = s;
- while (ptr && *ptr)
+ while (ptr != NULL && *ptr != '\0')
ptr++;
return (ptr - s);
}
diff --git a/src/b_unset.c b/src/b_unset.c
index 598db92..03fd2a8 100644
--- a/src/b_unset.c
+++ b/src/b_unset.c
@@ -65,6 +65,8 @@ static void
if (i == skip)
{
i += 1;
+ if (msh->envp[i] == NULL)
+ break ;
skipped = 1;
}
if (!(nenvp[i - skipped] = ft_strdup(msh->envp[i])))
@@ -85,7 +87,7 @@ static t_bool
i = 0;
while (msh->envp[i] != NULL)
{
- if (ft_strncmp(arg, msh->envp[i], ft_strlen(arg)) == 0)
+ if (ft_strncmp(arg, msh->envp[i], ft_strclen(msh->envp[i], '=')) == 0)
{
b_realloc_env(i, msh);
return (TRUE);