diff options
Diffstat (limited to 'src')
96 files changed, 3096 insertions, 0 deletions
diff --git a/src/ft_asprintf.c b/src/ft_asprintf.c new file mode 100644 index 0000000..5eb62d9 --- /dev/null +++ b/src/ft_asprintf.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_asprintf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/21 02:30:33 by cacharle #+# #+# */ +/* Updated: 2019/11/21 03:43:08 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_asprintf(char **ret, const char *format, ...) +{ + int vret; + va_list ap; + + va_start(ap, format); + vret = ft_vasprintf(ret, format, ap); + va_end(ap); + return (vret); +} diff --git a/src/ft_atoi.c b/src/ft_atoi.c new file mode 100644 index 0000000..bfba860 --- /dev/null +++ b/src/ft_atoi.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 09:46:16 by cacharle #+# #+# */ +/* Updated: 2019/11/20 01:43:18 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +#define MIN_INT -2147483648 +#define MAX_INT 2147483647 + +int ft_atoi(const char *str) +{ + unsigned int nb; + int i; + int is_negative; + + while (*str == ' ' || *str == '\t' || *str == '\n' + || *str == '\v' || *str == '\f' || *str == '\r') + str++; + is_negative = 0; + if (*str == '-' || *str == '+') + if (*str++ == '-') + is_negative = 1; + i = 0; + nb = 0; + while (ft_isdigit(str[i])) + { + if (!is_negative && nb > (unsigned int)MAX_INT) + return (-1); + else if (nb > (unsigned int)MIN_INT) + return (0); + nb *= 10; + nb += str[i++] & 0x0F; + } + return ((int)(is_negative ? -nb : nb)); +} diff --git a/src/ft_bzero.c b/src/ft_bzero.c new file mode 100644 index 0000000..d179af0 --- /dev/null +++ b/src/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/src/ft_calloc.c b/src/ft_calloc.c new file mode 100644 index 0000000..24501bf --- /dev/null +++ b/src/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/src/ft_dprintf.c b/src/ft_dprintf.c new file mode 100644 index 0000000..8e60970 --- /dev/null +++ b/src/ft_dprintf.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_dprintf.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/11/21 02:29:11 by cacharle #+# #+# */ +/* Updated: 2019/11/21 03:42:05 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_dprintf(int fd, const char *format, ...) +{ + int ret; + va_list ap; + + va_start(ap, format); + ret = ft_vdprintf(fd, format, ap); + va_end(ap); + return (ret); +} diff --git a/src/ft_isalnum.c b/src/ft_isalnum.c new file mode 100644 index 0000000..1ee1e0f --- /dev/null +++ b/src/ft_isalnum.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalnum.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 09:41:40 by cacharle #+# #+# */ +/* Updated: 2019/10/07 09:41:56 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +int ft_isalnum(int c) +{ + return (ft_isalpha(c) || ft_isdigit(c)); +} diff --git a/src/ft_isalpha.c b/src/ft_isalpha.c new file mode 100644 index 0000000..6f155b4 --- /dev/null +++ b/src/ft_isalpha.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isalpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 09:54:52 by cacharle #+# #+# */ +/* Updated: 2019/10/20 13:01:13 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isalpha(int c) +{ + return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); +} diff --git a/src/ft_isascii.c b/src/ft_isascii.c new file mode 100644 index 0000000..51dcd1c --- /dev/null +++ b/src/ft_isascii.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isascii.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 09:54:30 by cacharle #+# #+# */ +/* Updated: 2019/10/20 13:03:23 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#define MAX_CHAR ((1 << 7) - 1) + +int ft_isascii(int c) +{ + return (c >= 0 && c <= MAX_CHAR); +} diff --git a/src/ft_isdigit.c b/src/ft_isdigit.c new file mode 100644 index 0000000..f8a5850 --- /dev/null +++ b/src/ft_isdigit.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isdigit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:41:20 by cacharle #+# #+# */ +/* Updated: 2019/10/07 10:41:25 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isdigit(int c) +{ + return (c >= '0' && c <= '9'); +} diff --git a/src/ft_isprint.c b/src/ft_isprint.c new file mode 100644 index 0000000..c311709 --- /dev/null +++ b/src/ft_isprint.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_isprint.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 09:52:09 by cacharle #+# #+# */ +/* Updated: 2019/10/20 13:03:36 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_isprint(int c) +{ + return (c >= ' ' && c <= '~'); +} diff --git a/src/ft_itoa.c b/src/ft_itoa.c new file mode 100644 index 0000000..166e278 --- /dev/null +++ b/src/ft_itoa.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_itoa.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/10/07 10:19:56 by cacharle #+# #+# */ +/* Updated: 2019/11/20 03:13:10 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "libft.h" + +char *ft_itoa(int n) +{ + char *str; + int len; + unsigned int u_nbr; + + len = n < 0 || n == 0 ? 1 : 0; + u_nbr = n < 0 ? -n : n; + while (u_nbr > 0) + { + u_nbr /= 10; + len++; + } + if ((str = ft_strnew(len)) == |
