diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-29 19:18:30 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-09-29 19:18:30 +0200 |
commit | 4ede84d4ab98c75ed8655607fe64c205b79ed986 (patch) | |
tree | 6f9d5113400faf13a778de0f09c0203c7939b93f /libft/src | |
parent | Norm update (diff) | |
download | 42-minishell-4ede84d4ab98c75ed8655607fe64c205b79ed986.tar.gz 42-minishell-4ede84d4ab98c75ed8655607fe64c205b79ed986.tar.bz2 42-minishell-4ede84d4ab98c75ed8655607fe64c205b79ed986.tar.xz 42-minishell-4ede84d4ab98c75ed8655607fe64c205b79ed986.tar.zst 42-minishell-4ede84d4ab98c75ed8655607fe64c205b79ed986.zip |
libft norm in progress
Diffstat (limited to '')
-rw-r--r-- | libft/src/ft_nrealloc.c | 13 | ||||
-rw-r--r-- | libft/src/ft_nstr.c | 9 | ||||
-rw-r--r-- | libft/src/ft_printf.c | 8 | ||||
-rw-r--r-- | libft/src/ft_printf_cat_output.c | 9 | ||||
-rw-r--r-- | libft/src/ft_printf_flag_to_atoi.c | 7 | ||||
-rw-r--r-- | libft/src/ft_printf_get_flags.c | 5 | ||||
-rw-r--r-- | libft/src/ft_printf_get_s_putlen.c | 3 | ||||
-rw-r--r-- | libft/src/ft_printf_get_width_nstr.c | 6 |
8 files changed, 27 insertions, 33 deletions
diff --git a/libft/src/ft_nrealloc.c b/libft/src/ft_nrealloc.c index 7369b42..a949def 100644 --- a/libft/src/ft_nrealloc.c +++ b/libft/src/ft_nrealloc.c @@ -14,25 +14,28 @@ #include <stddef.h> #include <stdlib.h> -void - *ft_nrealloc(void *ptr, size_t oldsize, size_t newsize) +void *ft_nrealloc(void *ptr, size_t oldsize, size_t newsize) { void *nptr; - if (ptr == NULL) + if (ptr == NULL && newsize > 0) { if ((ptr = malloc(newsize)) == NULL) + { return (NULL); + } return (ptr); } - else if (!newsize) + else if (newsize == 0) { ft_memdel((void*)&ptr); return (NULL); } if ((nptr = malloc(newsize)) == NULL) + { return (ptr); - ft_memcpy(nptr, ptr, oldsize); + } + (void)ft_memcpy(nptr, ptr, oldsize); ft_memdel((void*)&ptr); return (nptr); } diff --git a/libft/src/ft_nstr.c b/libft/src/ft_nstr.c index 7b09053..823e1b8 100644 --- a/libft/src/ft_nstr.c +++ b/libft/src/ft_nstr.c @@ -13,15 +13,14 @@ #include <stdlib.h> #include <stddef.h> -char - *ft_nstr(size_t size) +char *ft_nstr(size_t size) { - char *str; - size_t i; + char *str; + size_t i; i = 0; size += 1; - if (!(str = (char*)malloc((size) * sizeof(char)))) + if ((str = (char*)malloc((size) * sizeof(char))) == NULL) return (NULL); while (i < size) { diff --git a/libft/src/ft_printf.c b/libft/src/ft_printf.c index ec1922f..1f63acf 100644 --- a/libft/src/ft_printf.c +++ b/libft/src/ft_printf.c @@ -16,8 +16,7 @@ #include <stdarg.h> #include <unistd.h> -static int - ft_printf_return(t_printflist *pflist) +static int ft_printf_return(t_printflist *pflist) { int ret; @@ -28,14 +27,13 @@ static int return (ret); } -int - ft_printf(const char *format, ...) +int ft_printf(const char *format, ...) { t_printflist *pflist; va_list arg; int pos; - if (!format) + if (format == NULL) return (-1); if ((pos = ft_strlchr(format, '%')) < 0) return (ft_putstr(format)); diff --git a/libft/src/ft_printf_cat_output.c b/libft/src/ft_printf_cat_output.c index f340109..720fe5a 100644 --- a/libft/src/ft_printf_cat_output.c +++ b/libft/src/ft_printf_cat_output.c @@ -14,16 +14,15 @@ #include <stddef.h> #include <unistd.h> -void - ft_printf_cat_output(char *src, size_t len, t_printflist *pflist) +void ft_printf_cat_output(char *src, size_t len, t_printflist *pflist) { size_t dst_len; dst_len = pflist->fulllen; pflist->output = (char*)ft_nrealloc(pflist->output, - (dst_len + 1) * sizeof(char), - (dst_len + len + 1) * sizeof(char)); - ft_memcpy(pflist->output + dst_len, src, len); + (dst_len + 1) * sizeof(char), + (dst_len + len + 1) * sizeof(char)); + (void)ft_memcpy(pflist->output + dst_len, src, len * sizeof(char)); *(pflist->output + dst_len + len) = '\0'; pflist->fulllen += len; } diff --git a/libft/src/ft_printf_flag_to_atoi.c b/libft/src/ft_printf_flag_to_atoi.c index 2f3c6e7..56b3ed8 100644 --- a/libft/src/ft_printf_flag_to_atoi.c +++ b/libft/src/ft_printf_flag_to_atoi.c @@ -14,16 +14,15 @@ #include <stddef.h> #include <stdlib.h> -char - *ft_printf_flag_to_atoi(char *str) +char *ft_printf_flag_to_atoi(char *str) { char *nstr; char *nnstr; int len; - while (*str != '.' && *str) + while (*str != '.' && *str != '\0') str++; - while (*str != '-' && *str) + while (*str != '-' && *str != '\0') str--; len = ft_strlchr(str, ' '); nnstr = ft_substr(str, 0, len); diff --git a/libft/src/ft_printf_get_flags.c b/libft/src/ft_printf_get_flags.c index ca49206..e6ba0de 100644 --- a/libft/src/ft_printf_get_flags.c +++ b/libft/src/ft_printf_get_flags.c @@ -21,8 +21,7 @@ ** Also puts actual conv into pflist->actconv */ -char - *ft_printf_get_flags(const char *format, int pos, t_printflist *pflist) +char *ft_printf_get_flags(const char *format, int pos, t_printflist *pflist) { int i; char *nstr; @@ -32,7 +31,7 @@ char while (!ft_ischarset(FT_PRINTF_CONV_CHARSET, *(format + pos + i + 1)) && *(format + pos + i + 1)) i++; - if (!(fullflag = (char*)malloc((i + 1) * sizeof(char)))) + if ((fullflag = (char*)malloc((i + 1) * sizeof(char))) == NULL) return (NULL); ft_memcpy(fullflag, nstr = ft_substr(format, pos + 1, i), i); ft_memdel((void**)&nstr); diff --git a/libft/src/ft_printf_get_s_putlen.c b/libft/src/ft_printf_get_s_putlen.c index 3f26a90..a97ea84 100644 --- a/libft/src/ft_printf_get_s_putlen.c +++ b/libft/src/ft_printf_get_s_putlen.c @@ -12,8 +12,7 @@ #include <libft.h> -int - ft_printf_get_s_putlen(char *str, t_printflist *pflist) +int ft_printf_get_s_putlen(char *str, t_printflist *pflist) { int ret; diff --git a/libft/src/ft_printf_get_width_nstr.c b/libft/src/ft_printf_get_width_nstr.c index 2aec3b8..22a942e 100644 --- a/libft/src/ft_printf_get_width_nstr.c +++ b/libft/src/ft_printf_get_width_nstr.c @@ -14,8 +14,7 @@ #include <stdlib.h> #include <stdarg.h> -int - ft_printf_fetch_width(va_list arg, char *nstr, t_printflist *pflist) +int ft_printf_fetch_width(va_list arg, char *nstr, t_printflist *pflist) { int ret; char *str; @@ -44,8 +43,7 @@ int return (ret); } -char - *ft_printf_get_width_nstr(char *str, t_printflist *pflist) +char *ft_printf_get_width_nstr(char *str, t_printflist *pflist) { (ft_strlchr(pflist->fullflag, '+') >= 0) ? (pflist->isaplus = 1) : 0; (*(pflist->fullflag) == '+' && *(pflist->fullflag + 1)) ? (str += 1) : 0; |