diff options
| -rw-r--r-- | ft_calloc.c | 4 | ||||
| -rw-r--r-- | ft_memmove.c | 36 | ||||
| -rw-r--r-- | libft.h | 2 | ||||
| -rw-r--r-- | pre2019_subject.en.pdf (renamed from libft.en.pdf) | bin | 1455686 -> 1455686 bytes |
4 files changed, 20 insertions, 22 deletions
diff --git a/ft_calloc.c b/ft_calloc.c index a6d88a0..0cdce92 100644 --- a/ft_calloc.c +++ b/ft_calloc.c @@ -17,6 +17,10 @@ void *ft_calloc(size_t count, size_t size) { void *mem; + if (count == 0 || size == 0) + { + return (NULL); + } if ((mem = malloc(count * size)) == NULL) return (NULL); ft_bzero(mem, count * size); diff --git a/ft_memmove.c b/ft_memmove.c index 185fd36..d5d6789 100644 --- a/ft_memmove.c +++ b/ft_memmove.c @@ -12,32 +12,24 @@ #include <stdlib.h> #include <string.h> - -#define BUF_SIZE (2 << 12) +#include "libft.h" void *ft_memmove(void *dst, const void *src, size_t len) { - size_t i; - size_t j; - size_t k; - unsigned char tmp[BUF_SIZE]; + size_t i; + t_byte *dst_cast; + t_byte *src_cast; if (dst == NULL && src == NULL) return (NULL); - i = 0; - while (i < len) - { - j = 0; - while (j < BUF_SIZE && i < len) - { - tmp[j] = ((unsigned char*)src)[i]; - j++; - i++; - } - k = -1; - while (++k < j) - ((unsigned char*)dst)[k] = tmp[k]; - i++; - } - return (dst); + dst_cast = (t_byte*)dst; + src_cast = (t_byte*)src; + i = -1; + if (dst_cast < src_cast) + while (++i < len) + dst_cast[i] = src_cast[i]; + else + while (len-- > 0) + dst_cast[len] = src_cast[len]; + return (dst); } @@ -18,6 +18,8 @@ # define TRUE 1 # define FALSE 0 +typedef unsigned char t_byte; + typedef struct s_list { void *content; diff --git a/libft.en.pdf b/pre2019_subject.en.pdf Binary files differindex e5bee09..e5bee09 100644 --- a/libft.en.pdf +++ b/pre2019_subject.en.pdf |
