summaryrefslogtreecommitdiffstats
path: root/libft/src
diff options
context:
space:
mode:
Diffstat (limited to 'libft/src')
-rw-r--r--libft/src/ft_split.c27
-rw-r--r--libft/src/ft_sprintf.c6
-rw-r--r--libft/src/ft_sqrt.c3
-rw-r--r--libft/src/ft_strcat.c3
-rw-r--r--libft/src/ft_strchr.c3
-rw-r--r--libft/src/ft_strclen.c3
-rw-r--r--libft/src/ft_strcmp.c3
-rw-r--r--libft/src/ft_strdup.c7
-rw-r--r--libft/src/ft_strjoin.c4
-rw-r--r--libft/src/ft_strlcat.c5
-rw-r--r--libft/src/ft_strlchr.c3
-rw-r--r--libft/src/ft_strlcpy.c3
-rw-r--r--libft/src/ft_strlen.c3
-rw-r--r--libft/src/ft_strmapi.c7
-rw-r--r--libft/src/ft_strncmp.c5
-rw-r--r--libft/src/ft_strnlen.c5
-rw-r--r--libft/src/ft_strnstr.c7
-rw-r--r--libft/src/ft_strrchr.c5
-rw-r--r--libft/src/ft_strsubst.c3
-rw-r--r--libft/src/ft_strsubst_s.c8
-rw-r--r--libft/src/ft_strtok.c3
-rw-r--r--libft/src/ft_strtok_r.c12
-rw-r--r--libft/src/ft_strtrim.c5
23 files changed, 52 insertions, 81 deletions
diff --git a/libft/src/ft_split.c b/libft/src/ft_split.c
index 34cd57a..a5e1189 100644
--- a/libft/src/ft_split.c
+++ b/libft/src/ft_split.c
@@ -15,8 +15,7 @@
#include <stdlib.h>
#include <inttypes.h>
-static size_t
- ft_count_words(const char *s, char c)
+static size_t ft_count_words(const char *s, char c)
{
size_t i;
size_t count;
@@ -41,8 +40,7 @@ static size_t
return (count);
}
-static size_t
- ft_splitlen(const char *str, char c)
+static size_t ft_splitlen(const char *str, char c)
{
size_t i;
@@ -52,8 +50,7 @@ static size_t
return (i);
}
-static char
- *ft_splitdup(const char *str, char c)
+static char *ft_splitdup(const char *str, char c)
{
char *word;
size_t i;
@@ -70,8 +67,7 @@ static char
return (word);
}
-static char
- **ft_splitfree(char **best_split, size_t j)
+static char **ft_splitfree(char **best_split, size_t j)
{
while (j > 0)
{
@@ -82,8 +78,7 @@ static char
return (NULL);
}
-char
- **ft_split(const char *s, char c)
+char **ft_split(const char *s, char c)
{
char **best_split;
size_t i;
@@ -91,16 +86,16 @@ char
i = 0;
j = 0;
- if (!(best_split = (char **)malloc((ft_count_words(s, c) + 1)
- * sizeof(char *))))
+ if ((best_split = (char **)malloc((ft_count_words(s, c) + 1)
+ * sizeof(char *))) == NULL)
return (NULL);
- while (s[i])
+ while (s[i] != '\0')
{
- while (s[i] == c && s[i])
+ while (s[i] == c && s[i] != '\0')
i++;
- while (s[i] != c && s[i])
+ while (s[i] != c && s[i] != '\0')
{
- if (!(best_split[j] = ft_splitdup(s + i, c)))
+ if ((best_split[j] = ft_splitdup(s + i, c)) == NULL)
return (ft_splitfree(best_split, j));
i += ft_splitlen(s + i, c);
j++;
diff --git a/libft/src/ft_sprintf.c b/libft/src/ft_sprintf.c
index 8413505..4b7049a 100644
--- a/libft/src/ft_sprintf.c
+++ b/libft/src/ft_sprintf.c
@@ -16,8 +16,7 @@
#include <stdarg.h>
#include <unistd.h>
-static int
- ft_printf_return(char *str, t_printflist *pflist)
+static int ft_printf_return(char *str, t_printflist *pflist)
{
int ret;
@@ -29,8 +28,7 @@ static int
return (ret);
}
-int
- ft_sprintf(char *str, const char *format, ...)
+int ft_sprintf(char *str, const char *format, ...)
{
t_printflist *pflist;
va_list arg;
diff --git a/libft/src/ft_sqrt.c b/libft/src/ft_sqrt.c
index ed69117..1b73e30 100644
--- a/libft/src/ft_sqrt.c
+++ b/libft/src/ft_sqrt.c
@@ -12,8 +12,7 @@
#include <limits.h>
-double
- ft_sqrt(double x)
+double ft_sqrt(double x)
{
double i;
diff --git a/libft/src/ft_strcat.c b/libft/src/ft_strcat.c
index b43e439..3bec86f 100644
--- a/libft/src/ft_strcat.c
+++ b/libft/src/ft_strcat.c
@@ -10,8 +10,7 @@
/* */
/* ************************************************************************** */
-char
- *ft_strcat(char *s1, const char *s2)
+char *ft_strcat(char *s1, const char *s2)
{
int i;
int j;
diff --git a/libft/src/ft_strchr.c b/libft/src/ft_strchr.c
index 1f2e745..76bab14 100644
--- a/libft/src/ft_strchr.c
+++ b/libft/src/ft_strchr.c
@@ -12,8 +12,7 @@
#include <stddef.h>
-char
- *ft_strchr(const char *s, int c)
+char *ft_strchr(const char *s, int c)
{
char ch;
diff --git a/libft/src/ft_strclen.c b/libft/src/ft_strclen.c
index fe88ca5..86a272d 100644
--- a/libft/src/ft_strclen.c
+++ b/libft/src/ft_strclen.c
@@ -12,8 +12,7 @@
#include <stddef.h>
-size_t
- ft_strclen(const char *s, int c)
+size_t ft_strclen(const char *s, int c)
{
const char *ptr;
diff --git a/libft/src/ft_strcmp.c b/libft/src/ft_strcmp.c
index 4122ab2..8ade6bf 100644
--- a/libft/src/ft_strcmp.c
+++ b/libft/src/ft_strcmp.c
@@ -13,8 +13,7 @@
#include <libft.h>
#include <stddef.h>
-int
- ft_strcmp(const char *s1, const char *s2)
+int ft_strcmp(const char *s1, const char *s2)
{
size_t i;
diff --git a/libft/src/ft_strdup.c b/libft/src/ft_strdup.c
index ab5b5c1..7de0674 100644
--- a/libft/src/ft_strdup.c
+++ b/libft/src/ft_strdup.c
@@ -13,18 +13,17 @@
#include <libft.h>
#include <stdlib.h>
-char
- *ft_strdup(const char *s1)
+char *ft_strdup(const char *s1)
{
char *n_str;
size_t slen;
size_t i;
slen = ft_strlen(s1);
- if (!(n_str = (char*)malloc((slen + 1) * sizeof(char))))
+ if ((n_str = (char*)malloc((slen + 1) * sizeof(char))) == NULL)
return (NULL);
i = 0;
- while (s1[i])
+ while (s1[i] != '\0')
{
n_str[i] = s1[i];
i++;
diff --git a/libft/src/ft_strjoin.c b/libft/src/ft_strjoin.c
index 90650d0..5ecc98a 100644
--- a/libft/src/ft_strjoin.c
+++ b/libft/src/ft_strjoin.c
@@ -11,9 +11,9 @@
/* ************************************************************************** */
#include <libft.h>
+#include <stddef.h>
-char
- *ft_strjoin(const char *s1, const char *s2)
+char *ft_strjoin(const char *s1, const char *s2)
{
char *str;
size_t i;
diff --git a/libft/src/ft_strlcat.c b/libft/src/ft_strlcat.c
index b9feae1..c0c9e29 100644
--- a/libft/src/ft_strlcat.c
+++ b/libft/src/ft_strlcat.c
@@ -13,10 +13,9 @@
#include <libft.h>
#include <stddef.h>
-size_t
- ft_strlcat(char *dst, const char *src, size_t size)
+size_t ft_strlcat(char *dst, const char *src, size_t size)
{
- size_t dst_len;
+ size_t dst_len;
dst_len = ft_strnlen(dst, size);
if (dst_len == size)
diff --git a/libft/src/ft_strlchr.c b/libft/src/ft_strlchr.c
index 228aa89..cfbd9b5 100644
--- a/libft/src/ft_strlchr.c
+++ b/libft/src/ft_strlchr.c
@@ -13,8 +13,7 @@
#include <libft.h>
#include <stddef.h>
-long
- ft_strlchr(const char *s, int c)
+long ft_strlchr(const char *s, int c)
{
const size_t len = ft_strlen(s);
const size_t rem = ft_strlen(ft_strchr(s, c));
diff --git a/libft/src/ft_strlcpy.c b/libft/src/ft_strlcpy.c
index 5076a69..b7b97ed 100644
--- a/libft/src/ft_strlcpy.c
+++ b/libft/src/ft_strlcpy.c
@@ -13,8 +13,7 @@
#include <libft.h>
#include <stddef.h>
-size_t
- ft_strlcpy(char *dst, const char *src, size_t size)
+size_t ft_strlcpy(char *dst, const char *src, size_t size)
{
size_t src_len;
diff --git a/libft/src/ft_strlen.c b/libft/src/ft_strlen.c
index 2b26bf0..0275db8 100644
--- a/libft/src/ft_strlen.c
+++ b/libft/src/ft_strlen.c
@@ -12,8 +12,7 @@
#include <stddef.h>
-size_t
- ft_strlen(const char *s)
+size_t ft_strlen(const char *s)
{
const char *ptr;
diff --git a/libft/src/ft_strmapi.c b/libft/src/ft_strmapi.c
index fe455c1..6821802 100644
--- a/libft/src/ft_strmapi.c
+++ b/libft/src/ft_strmapi.c
@@ -12,8 +12,7 @@
#include <libft.h>
-char
- *ft_strmapi(const char *s, char (*f)(unsigned int, char))
+char *ft_strmapi(const char *s, char (*f)(unsigned int, char))
{
unsigned int i;
char *nstr;
@@ -22,9 +21,9 @@ char
return (NULL);
i = 0;
nstr = (char *)ft_calloc(ft_strlen(s) + 1, sizeof(char));
- if (!nstr)
+ if (nstr == NULL)
return (NULL);
- while (s[i])
+ while (s[i] != '\0')
{
nstr[i] = (*f)(i, s[i]);
i++;
diff --git a/libft/src/ft_strncmp.c b/libft/src/ft_strncmp.c
index 30a4562..2df9f46 100644
--- a/libft/src/ft_strncmp.c
+++ b/libft/src/ft_strncmp.c
@@ -12,15 +12,14 @@
#include <stddef.h>
-int
- ft_strncmp(const char *s1, const char *s2, size_t n)
+int ft_strncmp(const char *s1, const char *s2, size_t n)
{
size_t i;
i = 0;
while (s1[i] == s2[i] && i < n - 1)
{
- if (!s1[i] && !s2[i])
+ if (s1[i] == '\0' && s2[i] == '\0')
return (0);
i++;
}
diff --git a/libft/src/ft_strnlen.c b/libft/src/ft_strnlen.c
index 325fa0d..f51989b 100644
--- a/libft/src/ft_strnlen.c
+++ b/libft/src/ft_strnlen.c
@@ -12,12 +12,11 @@
#include <stddef.h>
-size_t
- ft_strnlen(const char *s, size_t size)
+size_t ft_strnlen(const char *s, size_t size)
{
const char *ptr = s;
- while (size > 0 && *ptr)
+ while (size > 0 && *ptr != '\0')
{
size--;
ptr++;
diff --git a/libft/src/ft_strnstr.c b/libft/src/ft_strnstr.c
index 58e1d0e..615320e 100644
--- a/libft/src/ft_strnstr.c
+++ b/libft/src/ft_strnstr.c
@@ -14,8 +14,7 @@
#include <stddef.h>
#include <inttypes.h>
-char
- *ft_strnstr(const char *haystack, const char *needle, size_t len)
+char *ft_strnstr(const char *haystack, const char *needle, size_t len)
{
unsigned long i;
unsigned long j;
@@ -25,14 +24,14 @@ char
hay_ptr = (char*)haystack;
nee_ptr = (char*)needle;
i = 0;
- if (!nee_ptr[0])
+ if (nee_ptr[0] == '\0')
return (hay_ptr);
while (hay_ptr[i] && i < len)
{
j = 0;
while (nee_ptr[j] == hay_ptr[i + j] && (i + j) < len)
{
- if (!nee_ptr[j + 1])
+ if (nee_ptr[j + 1] == '\0')
return (hay_ptr + i);
j++;
}
diff --git a/libft/src/ft_strrchr.c b/libft/src/ft_strrchr.c
index 1ebbdc3..d9a5466 100644
--- a/libft/src/ft_strrchr.c
+++ b/libft/src/ft_strrchr.c
@@ -13,15 +13,14 @@
#include <libft.h>
#include <stddef.h>
-char
- *ft_strrchr(const char *s, int c)
+char *ft_strrchr(const char *s, int c)
{
size_t i;
i = ft_strlen(s);
while (s[i] != c)
{
- if (!i)
+ if (i == 0)
return (NULL);
i--;
}
diff --git a/libft/src/ft_strsubst.c b/libft/src/ft_strsubst.c
index 3c5c643..14349ce 100644
--- a/libft/src/ft_strsubst.c
+++ b/libft/src/ft_strsubst.c
@@ -13,8 +13,7 @@
#include <libft.h>
#include <stdlib.h>
-char
- *ft_strsubst(char *str, const char *pattern, const char *subst)
+char *ft_strsubst(char *str, const char *pattern, const char *subst)
{
size_t nlen;
char *nstr;
diff --git a/libft/src/ft_strsubst_s.c b/libft/src/ft_strsubst_s.c
index ea61610..9e43907 100644
--- a/libft/src/ft_strsubst_s.c
+++ b/libft/src/ft_strsubst_s.c
@@ -14,8 +14,7 @@
#include <stdint.h>
#include <stdlib.h>
-int8_t
- ft_strsubst_s(char *str, const char *pattern, const char *subst)
+int8_t ft_strsubst_s(char *str, const char *pattern, const char *subst)
{
char *ptr;
@@ -23,9 +22,10 @@ int8_t
return (1);
(void)ft_memmove(str + ((ptr - str) + ft_strlen(subst)),
str + ((ptr - str) + ft_strlen(pattern)),
- ft_strlen(str + ((ptr - str) + ft_strlen(pattern))) + 1);
+ (ft_strlen(str + ((ptr - str) + ft_strlen(pattern))) + 1)
+ * sizeof(char));
(void)ft_memmove(str + (ptr - str),
subst,
- ft_strlen(subst));
+ ft_strlen(subst) * sizeof(char));
return (0);
}
diff --git a/libft/src/ft_strtok.c b/libft/src/ft_strtok.c
index e4fde5e..7d931d0 100644
--- a/libft/src/ft_strtok.c
+++ b/libft/src/ft_strtok.c
@@ -12,8 +12,7 @@
#include <libft.h>
-char
- *ft_strtok(char *s, const char *delim)
+char *ft_strtok(char *s, const char *delim)
{
static char *last;
diff --git a/libft/src/ft_strtok_r.c b/libft/src/ft_strtok_r.c
index f3411cc..6d9fa40 100644
--- a/libft/src/ft_strtok_r.c
+++ b/libft/src/ft_strtok_r.c
@@ -12,8 +12,7 @@
#include <libft.h>
-static t_stok
- ft_cont(char *s, const char *delim)
+static t_stok ft_cont(char *s, const char *delim)
{
t_stok stok;
t_bool inc;
@@ -38,8 +37,7 @@ static t_stok
return (stok);
}
-static char
- *ft_scan_ret(char *s, char **last, char *tok, t_stok stok)
+static char *ft_scan_ret(char *s, char **last, char *tok, t_stok stok)
{
if ((stok.sc = *stok.spanp++) == stok.c)
{
@@ -65,8 +63,7 @@ static char
return (NULL);
}
-static char
- *ft_scan_tok(char *s, const char *delim, char **last, t_stok stok)
+static char *ft_scan_tok(char *s, const char *delim, char **last, t_stok stok)
{
char *tok;
char *ret;
@@ -83,8 +80,7 @@ static char
}
}
-char
- *ft_strtok_r(char *s, const char *delim, char **last)
+char *ft_strtok_r(char *s, const char *delim, char **last)
{
t_stok stok;
diff --git a/libft/src/ft_strtrim.c b/libft/src/ft_strtrim.c
index 69fd95a..22c54a6 100644
--- a/libft/src/ft_strtrim.c
+++ b/libft/src/ft_strtrim.c
@@ -12,13 +12,12 @@
#include <libft.h>
-char
- *ft_strtrim(const char *s1, const char *set)
+char *ft_strtrim(const char *s1, const char *set)
{
size_t len;
len = 0;
- if (!s1 || !set)
+ if (s1 == NULL || set == NULL)
return (NULL);
while (*s1 && ft_strchr(set, *s1))
s1++;