diff options
| author | nass1pro <nass1pro@gmail.com> | 2020-06-09 19:48:34 +0200 |
|---|---|---|
| committer | nass1pro <nass1pro@gmail.com> | 2020-06-13 11:31:00 +0200 |
| commit | 579a26f5593039ffbbd1a81e45ecf0ef8797cb5d (patch) | |
| tree | c5b6761db98e27d15bab3fb45ba9e0a646cf06e0 /test_mini/libft/src/mem | |
| parent | 9fabc25a980550afc6337fd729632462f2680daa (diff) | |
| download | minishell-579a26f5593039ffbbd1a81e45ecf0ef8797cb5d.tar.gz minishell-579a26f5593039ffbbd1a81e45ecf0ef8797cb5d.tar.bz2 minishell-579a26f5593039ffbbd1a81e45ecf0ef8797cb5d.zip | |
add lexer
add single quote
Diffstat (limited to 'test_mini/libft/src/mem')
| -rw-r--r-- | test_mini/libft/src/mem/ft_bzero.c | 18 | ||||
| -rw-r--r-- | test_mini/libft/src/mem/ft_calloc.c | 23 | ||||
| -rw-r--r-- | test_mini/libft/src/mem/ft_memalloc.c | 18 | ||||
| -rw-r--r-- | test_mini/libft/src/mem/ft_memccpy.c | 31 | ||||
| -rw-r--r-- | test_mini/libft/src/mem/ft_memchr.c | 26 | ||||
| -rw-r--r-- | test_mini/libft/src/mem/ft_memcmp.c | 30 | ||||
| -rw-r--r-- | test_mini/libft/src/mem/ft_memcpy.c | 33 | ||||
| -rw-r--r-- | test_mini/libft/src/mem/ft_memdel.c | 21 | ||||
| -rw-r--r-- | test_mini/libft/src/mem/ft_memmem.c | 58 | ||||
| -rw-r--r-- | test_mini/libft/src/mem/ft_memmove.c | 35 | ||||
| -rw-r--r-- | test_mini/libft/src/mem/ft_memset.c | 31 | ||||
| -rw-r--r-- | test_mini/libft/src/mem/ft_memset_pattern4.c | 26 | ||||
| -rw-r--r-- | test_mini/libft/src/mem/ft_memswap.c | 29 |
13 files changed, 379 insertions, 0 deletions
diff --git a/test_mini/libft/src/mem/ft_bzero.c b/test_mini/libft/src/mem/ft_bzero.c new file mode 100644 index 0000000..d179af0 --- /dev/null +++ b/test_mini/libft/src/mem/ft_bzero.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_bzero.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 09:50:10 by cacharle #+# #+# */ +/* Updated: 2019/11/20 03:29:26 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_bzero(void *s, size_t n) +{ + ft_memset(s, 0, n); +} diff --git a/test_mini/libft/src/mem/ft_calloc.c b/test_mini/libft/src/mem/ft_calloc.c new file mode 100644 index 0000000..24501bf --- /dev/null +++ b/test_mini/libft/src/mem/ft_calloc.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_calloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 12:45:37 by cacharle #+# #+# */ +/* Updated: 2019/11/21 01:05:53 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_calloc(size_t count, size_t size) +{ + void *mem; + + if ((mem = malloc(count * size)) == NULL) + return (NULL); + ft_bzero(mem, count * size); + return (mem); +} diff --git a/test_mini/libft/src/mem/ft_memalloc.c b/test_mini/libft/src/mem/ft_memalloc.c new file mode 100644 index 0000000..5aab2ec --- /dev/null +++ b/test_mini/libft/src/mem/ft_memalloc.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memalloc.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:07:14 by cacharle #+# #+# */ +/* Updated: 2019/11/20 03:28:56 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memalloc(size_t size) +{ + return (ft_calloc(size, 1)); +} diff --git a/test_mini/libft/src/mem/ft_memccpy.c b/test_mini/libft/src/mem/ft_memccpy.c new file mode 100644 index 0000000..8ce656a --- /dev/null +++ b/test_mini/libft/src/mem/ft_memccpy.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memccpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:01:53 by cacharle #+# #+# */ +/* Updated: 2020/01/17 10:54:03 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memccpy(void *dest, const void *src, int c, size_t n) +{ + size_t i; + t_ftbyte *cast_dest; + t_ftbyte *cast_src; + + cast_dest = (t_ftbyte*)dest; + cast_src = (t_ftbyte*)src; + i = -1; + while (++i < n) + { + cast_dest[i] = cast_src[i]; + if (cast_dest[i] == (unsigned char)c) + return (cast_dest + i + 1); + } + return (NULL); +} diff --git a/test_mini/libft/src/mem/ft_memchr.c b/test_mini/libft/src/mem/ft_memchr.c new file mode 100644 index 0000000..4fd8689 --- /dev/null +++ b/test_mini/libft/src/mem/ft_memchr.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memchr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 09:55:31 by cacharle #+# #+# */ +/* Updated: 2020/02/13 04:28:00 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memchr(const void *s, int c, size_t n) +{ + size_t i; + t_ftbyte *cast_s; + + cast_s = (t_ftbyte*)s; + i = -1; + while (++i < n) + if (cast_s[i] == (unsigned char)c) + return (cast_s + i); + return (NULL); +} diff --git a/test_mini/libft/src/mem/ft_memcmp.c b/test_mini/libft/src/mem/ft_memcmp.c new file mode 100644 index 0000000..233d796 --- /dev/null +++ b/test_mini/libft/src/mem/ft_memcmp.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 09:56:44 by cacharle #+# #+# */ +/* Updated: 2020/01/17 10:54:15 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_memcmp(const void *s1, const void *s2, size_t n) +{ + size_t i; + t_ftbyte *cast_s1; + t_ftbyte *cast_s2; + + cast_s1 = (t_ftbyte*)s1; + cast_s2 = (t_ftbyte*)s2; + if (n == 0) + return (0); + i = -1; + while (++i < n) + if (cast_s1[i] != cast_s2[i]) + return (cast_s1[i] - cast_s2[i]); + return (0); +} diff --git a/test_mini/libft/src/mem/ft_memcpy.c b/test_mini/libft/src/mem/ft_memcpy.c new file mode 100644 index 0000000..d0ef008 --- /dev/null +++ b/test_mini/libft/src/mem/ft_memcpy.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:00:07 by cacharle #+# #+# */ +/* Updated: 2020/01/17 10:39:04 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memcpy(void *dest, const void *src, size_t n) +{ + long int *long_dest; + const long int *long_src; + + if (dest == src) + return (dest); + while (n % 8 > 0) + { + n--; + ((t_ftbyte*)dest)[n] = ((t_ftbyte*)src)[n]; + } + long_dest = dest; + long_src = src; + n /= 8; + while (n-- > 0) + long_dest[n] = long_src[n]; + return (dest); +} diff --git a/test_mini/libft/src/mem/ft_memdel.c b/test_mini/libft/src/mem/ft_memdel.c new file mode 100644 index 0000000..2b21f33 --- /dev/null +++ b/test_mini/libft/src/mem/ft_memdel.c @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memdel.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:00:56 by cacharle #+# #+# */ +/* Updated: 2019/11/20 03:22:41 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_memdel(void **ap) +{ + if (ap == NULL) + return ; + free(*ap); + *ap = NULL; +} diff --git a/test_mini/libft/src/mem/ft_memmem.c b/test_mini/libft/src/mem/ft_memmem.c new file mode 100644 index 0000000..fa1446c --- /dev/null +++ b/test_mini/libft/src/mem/ft_memmem.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmem.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/13 01:54:55 by cacharle #+# #+# */ +/* Updated: 2020/02/13 21:04:46 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_mem.h" + +#define BAD_TABLE_SIZE 256 + +static void st_bad_table_init(size_t bad_table[BAD_TABLE_SIZE], + const char *little, size_t little_len) +{ + size_t i; + + i = 0; + while (i < BAD_TABLE_SIZE) + bad_table[i++] = little_len; + i = 0; + while (i < little_len - 1) + { + bad_table[(int)little[i]] = little_len - i - 1; + i++; + } +} + +static int st_memcmp_end(const void *s1, const void *s2, size_t n) +{ + while (n-- > 0) + if (*(t_ftbyte*)(s1 + n) != *(t_ftbyte*)(s2 + n)) + return (*(t_ftbyte*)(s1 + n) - *(t_ftbyte*)(s2 + n)); + return (0); +} + +void *ft_memmem(const void *big, size_t big_len, + const void *little, size_t little_len) +{ + size_t i; + size_t bad_table[BAD_TABLE_SIZE]; + + if (big_len < little_len || little_len == 0 || big_len == 0) + return (NULL); + st_bad_table_init(bad_table, little, little_len); + i = 0; + while (i <= big_len - little_len) + { + if (st_memcmp_end(big + i, little, little_len) == 0) + return ((void*)big + i); + i += bad_table[*(t_ftbyte*)(big + i + little_len - 1)]; + } + return (NULL); +} diff --git a/test_mini/libft/src/mem/ft_memmove.c b/test_mini/libft/src/mem/ft_memmove.c new file mode 100644 index 0000000..2f794fd --- /dev/null +++ b/test_mini/libft/src/mem/ft_memmove.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memmove.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:03:21 by cacharle #+# #+# */ +/* Updated: 2020/01/17 10:39:26 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memmove(void *dst, const void *src, size_t len) +{ + long int *long_dst; + const long int *long_src; + void *dst_copy; + + if (dst >= src) + return (ft_memcpy(dst, src, len)); + dst_copy = dst; + while (len % 8 > 0) + { + len--; + *(t_ftbyte*)dst++ = *(t_ftbyte*)src++; + } + long_dst = dst; + long_src = src; + len /= 8; + while (len-- > 0) + *long_dst++ = *long_src++; + return (dst_copy); +} diff --git a/test_mini/libft/src/mem/ft_memset.c b/test_mini/libft/src/mem/ft_memset.c new file mode 100644 index 0000000..89f53ff --- /dev/null +++ b/test_mini/libft/src/mem/ft_memset.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:01:23 by cacharle #+# #+# */ +/* Updated: 2020/01/17 10:39:10 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void *ft_memset(void *s, int c, size_t n) +{ + long int buf; + long int *long_s; + + c = (unsigned char)c; + while (n % 8 > 0) + *((t_ftbyte*)s + --n) = c; + buf = (long int)c | (long int)c << 8 | (long int)c << 16 + | (long int)c << 24 | (long int)c << 32 | (long int)c << 40 + | (long int)c << 48 | (long int)c << 56; + n /= 8; + long_s = s; + while (n > 0) + long_s[--n] = buf; + return (s); +} diff --git a/test_mini/libft/src/mem/ft_memset_pattern4.c b/test_mini/libft/src/mem/ft_memset_pattern4.c new file mode 100644 index 0000000..112ce6d --- /dev/null +++ b/test_mini/libft/src/mem/ft_memset_pattern4.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memset_pattern4.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/13 03:06:41 by cacharle #+# #+# */ +/* Updated: 2020/02/13 19:58:10 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft_mem.h" + +void ft_memset_pattern4(void *b, const void *pattern4, size_t len) +{ + int i; + + i = len / 4; + while (i-- > 0) + ((int*)b)[i] = *(int*)pattern4; + i = len % 4; + len -= len % 4; + while (i-- > 0) + ((t_ftbyte*)b)[len + i] = ((t_ftbyte*)pattern4)[i]; +} diff --git a/test_mini/libft/src/mem/ft_memswap.c b/test_mini/libft/src/mem/ft_memswap.c new file mode 100644 index 0000000..8661fda --- /dev/null +++ b/test_mini/libft/src/mem/ft_memswap.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_memswap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/01/19 07:56:43 by cacharle #+# #+# */ +/* Updated: 2020/02/10 02:55:52 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +void ft_memswap(void *a, void *b, size_t size) +{ + t_ftbyte tmp; + t_ftbyte *cast_a; + t_ftbyte *cast_b; + + cast_a = (t_ftbyte*)a; + cast_b = (t_ftbyte*)b; + while (size-- > 0) + { + tmp = cast_a[size]; + cast_a[size] = cast_b[size]; + cast_b[size] = tmp; + } +} |
