├── auteur ├── get_next_line.fr.pdf ├── README.md ├── libft ├── ft_putchar.c ├── ft_putchar_fd.c ├── ft_isascii.c ├── ft_isdigit.c ├── ft_isprint.c ├── ft_putendl.c ├── ft_tolower.c ├── ft_toupper.c ├── ft_bzero.c ├── ft_isalpha.c ├── ft_memdel.c ├── ft_putendl_fd.c ├── ft_strdel.c ├── ft_isalnum.c ├── ft_strcmp.c ├── ft_strlen.c ├── ft_putstr.c ├── ft_putstr_fd.c ├── ft_strcpy.c ├── ft_strequ.c ├── ft_strclr.c ├── ft_strnequ.c ├── ft_striter.c ├── ft_memset.c ├── ft_strcat.c ├── ft_striteri.c ├── ft_putnbr.c ├── ft_memcpy.c ├── ft_strncpy.c ├── ft_memchr.c ├── ft_strncmp.c ├── ft_strncat.c ├── ft_putnbr_fd.c ├── ft_strrchr.c ├── ft_memalloc.c ├── ft_memmove.c ├── ft_strchr.c ├── ft_strmap.c ├── ft_memcmp.c ├── ft_strdup.c ├── ft_strnew.c ├── ft_strstr.c ├── ft_strsub.c ├── ft_memccpy.c ├── ft_strmapi.c ├── ft_strnstr.c ├── ft_strlcat.c ├── ft_atoi.c ├── ft_strjoin.c ├── ft_strtrim.c ├── ft_itoa.c ├── Makefile ├── ft_strsplit.c └── includes │ └── libft.h ├── get_next_line.h └── get_next_line.c /auteur: -------------------------------------------------------------------------------- 1 | aliandie 2 | -------------------------------------------------------------------------------- /get_next_line.fr.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/artemys/Get-next-line/HEAD/get_next_line.fr.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Get-next-line 2 | 2eme projet pour l'école 42 : les variables statiques. 3 | Fonction en c qui permet de lire une ligne terminée par une retour à la ligne depuis un file descriptor. 4 | Sujet : get_next_line.fr.pdf 5 | -------------------------------------------------------------------------------- /libft/ft_putchar.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/04 17:42:05 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 15:42:30 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /libft/ft_putchar_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/07 16:09:00 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 15:42:40 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar_fd(char c, int fd) 16 | { 17 | write (fd, &c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /libft/ft_isascii.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isascii.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/04 11:39:29 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 14:09:01 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isascii(int c) 14 | { 15 | if (c >= 0 && c <= 0177) 16 | return (1); 17 | else 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /libft/ft_isdigit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isdigit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/04 10:09:38 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 14:09:36 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isdigit(int c) 14 | { 15 | if (c >= '0' && c <= '9') 16 | return (1); 17 | else 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /libft/ft_isprint.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isprint.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/04 11:59:00 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 14:10:05 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isprint(int c) 14 | { 15 | if (c >= ' ' && c <= '~') 16 | return (1); 17 | else 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /libft/ft_putendl.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putendl.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/04 17:54:51 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 15:46:12 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putendl(char const *s) 16 | { 17 | ft_putstr(s); 18 | ft_putchar('\n'); 19 | } 20 | -------------------------------------------------------------------------------- /libft/ft_tolower.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_tolower.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/03 17:38:08 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 15:59:07 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_tolower(int c) 14 | { 15 | while (c >= 65 && c <= 90) 16 | { 17 | c = c + 32; 18 | } 19 | return (c); 20 | } 21 | -------------------------------------------------------------------------------- /libft/ft_toupper.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_toupper.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/03 17:18:20 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 16:03:27 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_toupper(int c) 14 | { 15 | while (c >= 97 && c <= 122) 16 | { 17 | c = c - 32; 18 | } 19 | return (c); 20 | } 21 | -------------------------------------------------------------------------------- /libft/ft_bzero.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_bzero.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/03 14:53:34 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 17:34:28 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | void ft_bzero(void *s, size_t n) 17 | { 18 | ft_memset(s, '\0', n); 19 | } 20 | -------------------------------------------------------------------------------- /libft/ft_isalpha.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalpha.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/04 09:55:53 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 14:08:37 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_isalpha(int c) 14 | { 15 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) 16 | return (1); 17 | else 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /libft/ft_memdel.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memdel.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/09 14:37:51 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 14:37:50 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_memdel(void **ap) 16 | { 17 | if (ap != NULL) 18 | { 19 | free(*ap); 20 | *ap = NULL; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /libft/ft_putendl_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putendl_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/09 13:56:36 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 15:43:07 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putendl_fd(char const *s, int fd) 16 | { 17 | ft_putstr_fd(s, fd); 18 | ft_putchar_fd('\n', fd); 19 | } 20 | -------------------------------------------------------------------------------- /libft/ft_strdel.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdel.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/12 15:47:50 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/19 15:59:48 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_strdel(char **as) 16 | { 17 | if (as != NULL) 18 | { 19 | free(*as); 20 | *as = NULL; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /libft/ft_isalnum.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_isalnum.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/04 10:19:07 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 17:35:01 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_isalnum(int c) 16 | { 17 | if (ft_isdigit(c) == 1 || ft_isalpha(c) == 1) 18 | return (1); 19 | else 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /libft/ft_strcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/05 18:44:10 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 15:44:15 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_strcmp(const char *s1, const char *s2) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (s1[i] && s1[i] == s2[i]) 19 | i++; 20 | return (s1[i] - s2[i]); 21 | } 22 | -------------------------------------------------------------------------------- /libft/ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/03 15:58:09 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 15:45:29 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | size_t ft_strlen(const char *s) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (s[i] != '\0') 21 | { 22 | i++; 23 | } 24 | return (i); 25 | } 26 | -------------------------------------------------------------------------------- /libft/ft_putstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/04 17:38:23 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 15:43:34 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putstr(char const *s) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (s[i] != '\0') 21 | { 22 | ft_putchar(s[i]); 23 | i++; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /libft/ft_putstr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/07 16:48:22 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 14:49:18 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putstr_fd(char const *s, int fd) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (s[i] != '\0') 21 | { 22 | ft_putchar_fd(s[i], fd); 23 | i++; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /libft/ft_strcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/03 18:37:06 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 14:54:01 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | char *ft_strcpy(char *dst, const char *src) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (src[i] != '\0') 19 | { 20 | dst[i] = src[i]; 21 | i++; 22 | } 23 | dst[i] = '\0'; 24 | return (dst); 25 | } 26 | -------------------------------------------------------------------------------- /libft/ft_strequ.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strequ.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/10 15:52:50 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/19 13:36:22 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_strequ(char const *s1, char const *s2) 16 | { 17 | if (!s1 || !s2) 18 | return (0); 19 | if (ft_strcmp(s1, s2) == 0) 20 | return (1); 21 | else 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /libft/ft_strclr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strclr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/05 12:59:23 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 14:53:05 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_strclr(char *s) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | if (s != NULL) 21 | { 22 | while (s[i] != '\0') 23 | { 24 | s[i] = '\0'; 25 | i++; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /libft/ft_strnequ.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnequ.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/10 16:04:10 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/19 14:06:53 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_strnequ(char const *s1, char const *s2, size_t n) 16 | { 17 | if (!s1 || !s2) 18 | return (0); 19 | if (ft_strncmp(s1, s2, n) == 0) 20 | return (1); 21 | else 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /libft/ft_striter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_striter.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/09 14:50:48 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 14:59:22 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_striter(char *s, void (*f)(char *)) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | if (f == NULL || s == NULL) 21 | return ; 22 | while (s[i]) 23 | { 24 | (*f)(&s[i]); 25 | i++; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /libft/ft_memset.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memset.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/03 12:50:13 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 14:44:42 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void *ft_memset(void *b, int c, size_t len) 16 | { 17 | size_t i; 18 | char *str; 19 | 20 | str = (char*)b; 21 | i = 0; 22 | while (i < len) 23 | { 24 | str[i] = (char)c; 25 | i++; 26 | } 27 | return (str); 28 | } 29 | -------------------------------------------------------------------------------- /get_next_line.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/14 14:12:23 by aliandie #+# #+# */ 9 | /* Updated: 2014/12/05 11:21:23 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef GET_NEXT_LINE_H 14 | # define GET_NEXT_LINE_H 15 | # define BUFF_SIZE 6 16 | # include "libft.h" 17 | # include 18 | # include 19 | # include 20 | # include 21 | 22 | int get_next_line(int const fd, char **line); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /libft/ft_strcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/04 15:47:02 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 14:49:45 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | char *ft_strcat(char *s1, const char *s2) 14 | { 15 | int i; 16 | int j; 17 | 18 | j = 0; 19 | i = 0; 20 | while (s1[i] != '\0') 21 | i++; 22 | while (s2[j] != '\0') 23 | { 24 | s1[i] = s2[j]; 25 | i++; 26 | j++; 27 | } 28 | s1[i] = '\0'; 29 | return (s1); 30 | } 31 | -------------------------------------------------------------------------------- /libft/ft_striteri.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_striteri.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/09 15:03:20 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/19 13:51:50 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | void ft_striteri(char *s, void (*f)(unsigned int, char *)) 17 | { 18 | unsigned int i; 19 | 20 | i = 0; 21 | if (!f || s == NULL) 22 | return ; 23 | while (s[i]) 24 | { 25 | (*f)(i, &s[i]); 26 | i++; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /libft/ft_putnbr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/04 18:44:01 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 14:47:06 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putnbr(int n) 16 | { 17 | if (n < 0) 18 | { 19 | n = -n; 20 | ft_putchar('-'); 21 | } 22 | if (n >= 10) 23 | { 24 | ft_putnbr(n / 10); 25 | ft_putnbr(n % 10); 26 | } 27 | else 28 | { 29 | n = n + '0'; 30 | ft_putchar(n); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /libft/ft_memcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/03 15:17:28 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 14:35:08 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void *ft_memcpy(void *dst, const void *src, size_t n) 16 | { 17 | size_t i; 18 | char *strd; 19 | char *strs; 20 | 21 | i = 0; 22 | strd = (char*)dst; 23 | strs = (char*)src; 24 | while (i < n) 25 | { 26 | strd[i] = strs[i]; 27 | i++; 28 | } 29 | return (strd); 30 | } 31 | -------------------------------------------------------------------------------- /libft/ft_strncpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/03 19:12:56 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 15:13:03 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strncpy(char *dst, const char *src, size_t n) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while (i < n && src[i] != '\0') 21 | { 22 | dst[i] = src[i]; 23 | i++; 24 | } 25 | while (i < n) 26 | { 27 | dst[i] = '\0'; 28 | i++; 29 | } 30 | return (dst); 31 | } 32 | -------------------------------------------------------------------------------- /libft/ft_memchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/07 13:31:23 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 14:31:30 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void *ft_memchr(const void *s, int c, size_t n) 16 | { 17 | size_t i; 18 | unsigned char *str; 19 | 20 | str = (unsigned char*)s; 21 | i = 0; 22 | while (i < n) 23 | { 24 | if (str[i] == (unsigned char)c) 25 | return (&str[i]); 26 | i++; 27 | } 28 | return (NULL); 29 | } 30 | -------------------------------------------------------------------------------- /libft/ft_strncmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/05 19:05:57 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 15:11:46 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_strncmp(const char *s1, const char *s2, size_t n) 16 | { 17 | size_t i; 18 | 19 | i = 0; 20 | while ((s1[i] || s2[i]) && (i < n)) 21 | { 22 | if (s1[i] < s2[i]) 23 | return (-1); 24 | if (s1[i] > s2[i]) 25 | return (1); 26 | i++; 27 | } 28 | return (0); 29 | } 30 | -------------------------------------------------------------------------------- /libft/ft_strncat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/04 16:24:20 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 15:10:21 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strncat(char *s1, const char *s2, size_t n) 16 | { 17 | size_t i; 18 | size_t j; 19 | 20 | i = 0; 21 | j = 0; 22 | while (s1[i] != '\0') 23 | i++; 24 | while (j != n) 25 | { 26 | s1[i] = s2[j]; 27 | j++; 28 | i++; 29 | } 30 | s1[i] = '\0'; 31 | return (s1); 32 | } 33 | -------------------------------------------------------------------------------- /libft/ft_putnbr_fd.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr_fd.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/09 14:00:32 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 14:49:02 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | void ft_putnbr_fd(int n, int fd) 16 | { 17 | if (n < 0) 18 | { 19 | n = -n; 20 | ft_putchar_fd('-', fd); 21 | } 22 | if (n >= 10) 23 | { 24 | ft_putnbr_fd(n / 10, fd); 25 | ft_putnbr_fd(n % 10, fd); 26 | } 27 | else 28 | { 29 | n = n + '0'; 30 | ft_putchar_fd(n, fd); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /libft/ft_strrchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strrchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/06 20:43:02 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 15:20:23 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strrchr(const char *s, int c) 16 | { 17 | int j; 18 | char *str; 19 | 20 | str = (char*)s; 21 | j = ft_strlen(str); 22 | if ((char)c == '\0') 23 | return (&str[j]); 24 | while (j > 0) 25 | { 26 | j--; 27 | if (str[j] == (char)c) 28 | return (&str[j]); 29 | } 30 | return (NULL); 31 | } 32 | -------------------------------------------------------------------------------- /libft/ft_memalloc.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memalloc.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/09 14:05:18 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/21 11:56:37 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | void *ft_memalloc(size_t size) 17 | { 18 | char *ptr; 19 | size_t i; 20 | 21 | ptr = (char *)malloc(sizeof(char) * size); 22 | i = 0; 23 | if (ptr == NULL) 24 | return (NULL); 25 | while (i < size) 26 | { 27 | ptr[i] = 0; 28 | i++; 29 | } 30 | ptr = (void*)ptr; 31 | return (ptr); 32 | } 33 | -------------------------------------------------------------------------------- /libft/ft_memmove.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memmove.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/07 12:00:48 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 17:47:14 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | void *ft_memmove(void *dst, const void *src, size_t n) 17 | { 18 | char *strd; 19 | char *strc; 20 | 21 | if (dst <= src) 22 | return (ft_memcpy(dst, src, n)); 23 | strd = (char*)dst; 24 | strc = (char*)src; 25 | while (n) 26 | { 27 | n--; 28 | strd[n] = strc[n]; 29 | } 30 | return (dst); 31 | } 32 | -------------------------------------------------------------------------------- /libft/ft_strchr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strchr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/06 19:28:45 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 17:35:37 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strchr(const char *s, int c) 16 | { 17 | int i; 18 | char *str; 19 | 20 | i = 0; 21 | str = (char*)s; 22 | if (str == NULL) 23 | return (NULL); 24 | while (str[i] != '\0') 25 | { 26 | if (str[i] == (char)c) 27 | return (&str[i]); 28 | i++; 29 | } 30 | if ((char)c == '\0') 31 | return (&str[i]); 32 | return (NULL); 33 | } 34 | -------------------------------------------------------------------------------- /libft/ft_strmap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strmap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/09 15:12:30 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/19 14:02:22 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strmap(char const *s, char (*f)(char)) 16 | { 17 | char *str; 18 | int i; 19 | 20 | i = 0; 21 | if (!f || !s) 22 | return (NULL); 23 | str = ft_memalloc(ft_strlen(s)); 24 | if (str == NULL) 25 | return (NULL); 26 | while (s[i]) 27 | { 28 | str[i] = (*f)(s[i]); 29 | i++; 30 | } 31 | str[i] = '\0'; 32 | return (str); 33 | } 34 | -------------------------------------------------------------------------------- /libft/ft_memcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/07 14:12:39 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 14:33:55 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_memcmp(const void *s1, const void *s2, size_t n) 16 | { 17 | size_t i; 18 | unsigned char *str1; 19 | unsigned char *str2; 20 | 21 | i = 0; 22 | str1 = (unsigned char*)s1; 23 | str2 = (unsigned char*)s2; 24 | while (i < n) 25 | { 26 | if (str1[i] != str2[i]) 27 | return (str1[i] - str2[i]); 28 | i++; 29 | } 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /libft/ft_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/03 16:55:09 by aliandie #+# #+# */ 9 | /* Updated: 2014/12/03 14:01:01 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include "libft.h" 16 | 17 | char *ft_strdup(const char *s) 18 | { 19 | char *str; 20 | int i; 21 | 22 | i = 0; 23 | str = (char*)malloc(sizeof(char) * (ft_strlen(s) + 1)); 24 | if (str == NULL) 25 | return (NULL); 26 | while (s[i] != '\0') 27 | { 28 | str[i] = s[i]; 29 | i++; 30 | } 31 | str[i] = '\0'; 32 | return (str); 33 | } 34 | -------------------------------------------------------------------------------- /libft/ft_strnew.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnew.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/05 12:41:02 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/19 14:24:30 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | char *ft_strnew(size_t size) 18 | { 19 | size_t i; 20 | char *str; 21 | 22 | i = 0; 23 | if (size == 0 || size == SIZE_MAX) 24 | return (NULL); 25 | str = (char*)malloc(sizeof(char) * size + 1); 26 | if (str == NULL) 27 | return (NULL); 28 | while (i <= size) 29 | { 30 | str[i] = '\0'; 31 | i++; 32 | } 33 | return (str); 34 | } 35 | -------------------------------------------------------------------------------- /libft/ft_strstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/06 12:25:33 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 16:00:31 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | #include 15 | 16 | char *ft_strstr(const char *s1, const char *s2) 17 | { 18 | int i; 19 | char *str; 20 | char *str2; 21 | 22 | i = 0; 23 | str = (char*)s1; 24 | str2 = (char*)s2; 25 | if (s2[0] == '\0') 26 | return (str); 27 | while (str[i]) 28 | { 29 | if (ft_strncmp(&str[i], str2, ft_strlen(str2)) == 0) 30 | return (&str[i]); 31 | i++; 32 | } 33 | return (NULL); 34 | } 35 | -------------------------------------------------------------------------------- /libft/ft_strsub.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strsub.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/12/05 11:01:54 by aliandie #+# #+# */ 9 | /* Updated: 2014/12/05 11:02:06 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | #include 15 | 16 | char *ft_strsub(char const *s, unsigned int start, size_t len) 17 | { 18 | char *sub; 19 | size_t i; 20 | 21 | i = 0; 22 | if (!s) 23 | return (NULL); 24 | sub = (char *)malloc(sizeof(char) * (len + 1)); 25 | if (sub == NULL) 26 | return (NULL); 27 | while (i != len) 28 | { 29 | sub[i] = s[i + start]; 30 | i++; 31 | } 32 | sub[i] = '\0'; 33 | return (sub); 34 | } 35 | -------------------------------------------------------------------------------- /libft/ft_memccpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_memccpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/12 13:54:00 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 14:29:23 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void *ft_memccpy(void *dst, const void *src, int c, size_t n) 16 | { 17 | size_t i; 18 | char *strd; 19 | char *strs; 20 | 21 | i = 0; 22 | if (dst == NULL || src == NULL) 23 | return (NULL); 24 | strd = (char*)dst; 25 | strs = (char*)src; 26 | while (i < n) 27 | { 28 | strd[i] = strs[i]; 29 | if (strs[i] == (unsigned char)c) 30 | return (&strd[i + 1]); 31 | i++; 32 | } 33 | return (NULL); 34 | } 35 | -------------------------------------------------------------------------------- /libft/ft_strmapi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strmapi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/09 15:55:17 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/19 14:03:38 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) 16 | { 17 | char *str; 18 | unsigned int i; 19 | 20 | i = 0; 21 | if (!s || !f) 22 | return (NULL); 23 | str = ft_memalloc(ft_strlen(s)); 24 | if (str == NULL) 25 | return (NULL); 26 | if (f == NULL) 27 | return (ft_strdup(s)); 28 | while (s[i]) 29 | { 30 | str[i] = (*f)(i, s[i]); 31 | i++; 32 | } 33 | str[i] = '\0'; 34 | return (str); 35 | } 36 | -------------------------------------------------------------------------------- /libft/ft_strnstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strnstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/06 14:55:27 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 15:18:39 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | char *ft_strnstr(const char *s1, const char *s2, size_t n) 16 | { 17 | int i; 18 | char *str; 19 | char *str2; 20 | int l; 21 | 22 | i = 0; 23 | str = (char*)s1; 24 | str2 = (char*)s2; 25 | if (s2[0] == '\0') 26 | return (str); 27 | l = ft_strlen(s2); 28 | while (str[i] && i <= (int)n - l) 29 | { 30 | if (ft_strncmp(&str[i], str2, l) == 0) 31 | return (&str[i]); 32 | i++; 33 | } 34 | return (NULL); 35 | } 36 | -------------------------------------------------------------------------------- /libft/ft_strlcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/11 12:27:15 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 15:06:05 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | #include 15 | 16 | size_t ft_strlcat(char *dst, const char *src, size_t size) 17 | { 18 | size_t i; 19 | size_t len_dst; 20 | 21 | len_dst = ft_strlen(dst); 22 | i = 0; 23 | if (size <= len_dst) 24 | return (size + ft_strlen(src)); 25 | while (len_dst + i < (size - 1) && src[i] != '\0') 26 | { 27 | dst[i + len_dst] = src[i]; 28 | i++; 29 | } 30 | dst[i + len_dst] = '\0'; 31 | return (len_dst + strlen(src)); 32 | } 33 | -------------------------------------------------------------------------------- /libft/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/05 15:52:17 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 14:06:09 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_atoi(const char *str) 16 | { 17 | int nb; 18 | int i; 19 | int negative; 20 | 21 | i = 0; 22 | nb = 0; 23 | negative = 0; 24 | while (str[i] == ' ' || str[i] == '\t' || str[i] == '\n' 25 | || str[i] == '\v' || str[i] == '\f' || str[i] == '\r') 26 | i++; 27 | if (str[i] == '+' || str[i] == '-') 28 | { 29 | if (str[i] == '-') 30 | negative = 1; 31 | i++; 32 | } 33 | while (ft_isdigit(str[i]) == 1) 34 | { 35 | nb = nb * 10 + str[i] - '0'; 36 | i++; 37 | } 38 | if (negative == 1) 39 | nb = -nb; 40 | return (nb); 41 | } 42 | -------------------------------------------------------------------------------- /libft/ft_strjoin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strjoin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/05 10:28:28 by aliandie #+# #+# */ 9 | /* Updated: 2014/12/03 14:18:10 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | #include 15 | #include 16 | 17 | char *ft_strjoin(char const *s1, char const *s2) 18 | { 19 | char *str; 20 | int i; 21 | int j; 22 | int len; 23 | 24 | i = 0; 25 | j = 0; 26 | if (!s1 || !s2) 27 | return (NULL); 28 | len = ft_strlen(s1) + ft_strlen(s2); 29 | str = (char*)malloc(sizeof(char) * (len + 1)); 30 | if (str == NULL) 31 | return (NULL); 32 | while (s1[i] != '\0') 33 | { 34 | str[i] = s1[i]; 35 | i++; 36 | } 37 | while (s2[j] != '\0') 38 | { 39 | str[j + i] = s2[j]; 40 | j++; 41 | } 42 | str[i + j] = '\0'; 43 | return (str); 44 | } 45 | -------------------------------------------------------------------------------- /libft/ft_strtrim.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strtrim.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/09 16:28:45 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/13 15:58:21 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "libft.h" 15 | 16 | char *ft_strtrim(char const *s) 17 | { 18 | int start; 19 | int end; 20 | char *str; 21 | int i; 22 | 23 | i = 0; 24 | start = 0; 25 | if (s == NULL) 26 | return (NULL); 27 | end = ft_strlen(s) - 1; 28 | while (s[start] == ' ' || s[start] == '\t' || s[start] == '\n') 29 | start++; 30 | while ((s[end] == ' ' || s[end] == '\t' || s[end] == '\n') && start <= end) 31 | end--; 32 | str = ft_memalloc(end - start + 1); 33 | if (str == NULL) 34 | return (NULL); 35 | while (start <= end) 36 | { 37 | str[i] = s[start]; 38 | i++; 39 | start++; 40 | } 41 | str[i] = '\0'; 42 | return (str); 43 | } 44 | -------------------------------------------------------------------------------- /libft/ft_itoa.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_itoa.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/12 19:01:30 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/19 15:59:24 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | #include 15 | 16 | static int ft_cntsize(int n) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | if (n < 0) 22 | i++; 23 | while (n != 0) 24 | { 25 | n = n / 10; 26 | i++; 27 | } 28 | return (i); 29 | } 30 | 31 | char *ft_itoa(int n) 32 | { 33 | char *str; 34 | int j; 35 | int i; 36 | 37 | if (n == 0) 38 | return (ft_strdup("0")); 39 | j = ft_cntsize(n); 40 | i = n; 41 | if (n == -2147483648) 42 | return (ft_strdup("-2147483648")); 43 | str = (char*)malloc(sizeof(char) * (j + 1)); 44 | if (str == NULL) 45 | return (NULL); 46 | str[j] = '\0'; 47 | while (j--) 48 | { 49 | if (n < 0) 50 | n = -n; 51 | str[j] = (n % 10 + '0'); 52 | n = n / 10; 53 | } 54 | if (i < 0) 55 | str[0] = '-'; 56 | return (str); 57 | } 58 | -------------------------------------------------------------------------------- /get_next_line.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get_next_line.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/12/01 15:47:34 by aliandie #+# #+# */ 9 | /* Updated: 2014/12/03 16:11:54 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "get_next_line.h" 14 | 15 | int checkerror(int fd, char **str, char **line) 16 | { 17 | if (fd == -1 || line == NULL) 18 | return (-1); 19 | if (!*str) 20 | { 21 | if (!(*str = (char*)malloc(sizeof(char) * (BUFF_SIZE + 1)))) 22 | return (-1); 23 | } 24 | return (0); 25 | } 26 | 27 | char *readline(char *str, int fd) 28 | { 29 | char buff[BUFF_SIZE + 1]; 30 | int ret; 31 | 32 | while ((ret = read(fd, buff, BUFF_SIZE)) > 0) 33 | { 34 | buff[ret] = '\0'; 35 | str = ft_strjoin(str, buff); 36 | } 37 | return (str); 38 | } 39 | 40 | int get_next_line(int const fd, char **line) 41 | { 42 | static char *str; 43 | int i; 44 | 45 | if (checkerror(fd, &str, line) == -1) 46 | return (-1); 47 | if (*str) 48 | ft_strcpy(*line, str); 49 | str = readline(str, fd); 50 | i = 0; 51 | if (str[i]) 52 | { 53 | while (str[i] != '\n' && str[i]) 54 | i++; 55 | if (i == 0) 56 | (*line) = ft_strdup(""); 57 | else 58 | { 59 | (*line) = ft_strsub(str, 0, i); 60 | str = &str[i + 1]; 61 | } 62 | return (1); 63 | } 64 | else 65 | (*line) = ft_strdup(""); 66 | return (0); 67 | } 68 | -------------------------------------------------------------------------------- /libft/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: aliandie +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2014/11/13 17:14:25 by aliandie #+# #+# # 9 | # Updated: 2014/11/21 15:49:28 by aliandie ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | 14 | 15 | NAME = libft.a 16 | 17 | GCC = gcc -Wall -Werror -Wextra 18 | 19 | SRC += ft_atoi.c 20 | SRC += ft_bzero.c 21 | SRC += ft_isalnum.c 22 | SRC += ft_tolower.c 23 | SRC += ft_toupper.c 24 | SRC += ft_memcpy.c 25 | SRC += ft_memdel.c 26 | SRC += ft_memmove.c 27 | SRC += ft_memset.c 28 | SRC += ft_memccpy.c 29 | SRC += ft_memalloc.c 30 | SRC += ft_memchr.c 31 | SRC += ft_memcmp.c 32 | SRC += ft_putstr_fd.c 33 | SRC += ft_strlcat.c 34 | SRC += ft_strstr.c 35 | SRC += ft_strcat.c 36 | SRC += ft_strlen.c 37 | SRC += ft_strsub.c 38 | SRC += ft_strchr.c 39 | SRC += ft_strrchr.c 40 | SRC += ft_strmap.c 41 | SRC += ft_strclr.c 42 | SRC += ft_strmapi.c 43 | SRC += ft_isalpha.c 44 | SRC += ft_strcmp.c 45 | SRC += ft_strncat.c 46 | SRC += ft_isascii.c 47 | SRC += ft_putchar.c 48 | SRC += ft_strcpy.c 49 | SRC += ft_strncmp.c 50 | SRC += ft_isdigit.c 51 | SRC += ft_putchar_fd.c 52 | SRC += ft_strdel.c 53 | SRC += ft_strncpy.c 54 | SRC += ft_isprint.c 55 | SRC += ft_putendl.c 56 | SRC += ft_strdup.c 57 | SRC += ft_strnequ.c 58 | SRC += ft_itoa.c 59 | SRC += ft_putendl_fd.c 60 | SRC += ft_strequ.c 61 | SRC += ft_strnew.c 62 | SRC += ft_putnbr.c 63 | SRC += ft_strtrim.c 64 | SRC += ft_strnstr.c 65 | SRC += ft_putnbr_fd.c 66 | SRC += ft_striter.c 67 | SRC += ft_striteri.c 68 | SRC += ft_putstr.c 69 | SRC += ft_strjoin.c 70 | SRC += ft_strsplit.c 71 | SRC += ft_isprint.c 72 | SRC += ft_isalpha.c 73 | 74 | OBJ += $(subst .c,.o,$(SRC)) 75 | 76 | INC += -I includes/ 77 | 78 | all: $(NAME) 79 | 80 | $(NAME): $(OBJ) 81 | ar rc $@ $^ 82 | ranlib $@ 83 | 84 | %.o: %.c 85 | $(GCC) $(INC) -o $@ -c $< 86 | 87 | clean: 88 | rm -rf $(OBJ) 89 | 90 | fclean: clean 91 | rm -rf $(NAME) 92 | 93 | re: fclean all 94 | 95 | -------------------------------------------------------------------------------- /libft/ft_strsplit.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strsplit.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/11 15:42:02 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/19 14:38:59 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "libft.h" 14 | 15 | int ft_cntword(char const *str, char c) 16 | { 17 | int i; 18 | int j; 19 | 20 | i = 0; 21 | j = 0; 22 | while (str[i] == c) 23 | i++; 24 | if (str[i]) 25 | j++; 26 | while (str[i]) 27 | { 28 | while (str[i] == c) 29 | { 30 | i++; 31 | if (str[i] != c && str[i]) 32 | j++; 33 | } 34 | i++; 35 | } 36 | return (j); 37 | } 38 | 39 | int ft_cntl(char const *str, char c, int start) 40 | { 41 | int i; 42 | 43 | i = 0; 44 | if (str[start] == '\0') 45 | { 46 | return (i); 47 | } 48 | while (str[start] != c && str[start]) 49 | { 50 | i++; 51 | start++; 52 | } 53 | return (i); 54 | } 55 | 56 | char *ft_taballoc(char const *src, char c, int start) 57 | { 58 | int i; 59 | char *str; 60 | 61 | i = 0; 62 | str = (char*)malloc(sizeof(char) * (ft_cntl(src, c, start) + 1)); 63 | if (str == NULL) 64 | return (NULL); 65 | while (src[start] && src[start] != c) 66 | { 67 | str[i] = src[start]; 68 | i++; 69 | start++; 70 | } 71 | str[i] = '\0'; 72 | return (str); 73 | } 74 | 75 | char **ft_tabfill(char const *s, char c, int j, char **tab) 76 | { 77 | int i; 78 | 79 | i = 0; 80 | while (s[i] == c) 81 | i++; 82 | tab[j] = ft_taballoc(s, c, i); 83 | j++; 84 | while (s[i]) 85 | { 86 | while (s[i] == c) 87 | { 88 | i++; 89 | if (s[i] != c && s[i]) 90 | { 91 | tab[j] = ft_taballoc(s, c, i); 92 | j++; 93 | } 94 | } 95 | i++; 96 | } 97 | return (tab); 98 | } 99 | 100 | char **ft_strsplit(char const *s, char c) 101 | { 102 | int j; 103 | char **tab; 104 | 105 | j = 0; 106 | if (s == NULL) 107 | return (NULL); 108 | if (c == '\0') 109 | return (NULL); 110 | tab = (char**)malloc(sizeof(char*) * (ft_cntword(s, c) + 1)); 111 | if (tab == NULL) 112 | return (NULL); 113 | tab[ft_cntword(s, c)] = '\0'; 114 | ft_tabfill(s, c, j, tab); 115 | if (tab[0][0] == '\0') 116 | tab[0] = NULL; 117 | return (tab); 118 | } 119 | -------------------------------------------------------------------------------- /libft/includes/libft.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* libft.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: aliandie +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2014/11/04 17:56:11 by aliandie #+# #+# */ 9 | /* Updated: 2014/11/19 16:21:19 by aliandie ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef LIBFT_H 14 | # define LIBFT_H 15 | 16 | # include 17 | # include 18 | 19 | void *ft_memset(void *b, int c, size_t len); 20 | void ft_bzero(void *s, size_t n); 21 | void *ft_memcpy(void *dst, const void *src, size_t n); 22 | void *ft_memccpy(void *dst, const void *src, int c, size_t n); 23 | void *ft_memmove(void *dst, const void *src, size_t n); 24 | void *ft_memchr(const void *s, int c, size_t n); 25 | int ft_memcmp(const void *s1, const void *s2, size_t n); 26 | size_t ft_strlen(const char *s); 27 | char *ft_strdup(const char *s); 28 | char *ft_strcpy(char *dst, const char *src); 29 | char *ft_strncpy(char *dst, const char *src, size_t n); 30 | char *ft_strcat(char *s1, const char *s2); 31 | char *ft_strncat(char *s1, const char *s2, size_t n); 32 | size_t ft_strlcat(char *dst, const char *src, size_t size); 33 | char *ft_strchr(const char *s, int c); 34 | char *ft_strrchr(const char *s, int c); 35 | char *ft_strstr(const char*s1, const char *s2); 36 | int ft_strcmp(const char *s1, const char *s2); 37 | int ft_strncmp(const char *s1, const char *s2, size_t n); 38 | int ft_atoi(const char *str); 39 | int ft_isalpha(int c); 40 | int ft_isdigit(int c); 41 | int ft_isalnum(int c); 42 | int ft_isascii(int c); 43 | int ft_isprint(int c); 44 | int ft_toupper(int c); 45 | int ft_tolower(int c); 46 | void *ft_memalloc(size_t size); 47 | void ft_memdel(void **ap); 48 | char *ft_strnew(size_t size); 49 | void ft_strdel(char **as); 50 | void ft_strclr(char *s); 51 | void ft_striter(char *s, void (*f)(char *)); 52 | void ft_striteri(char *s, void (*f)(unsigned int, char *)); 53 | char *ft_strmap(char const *s, char (*f)(char)); 54 | char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); 55 | int ft_strequ(char const *s1, char const *s2); 56 | int ft_strnequ(char const *s1, char const *s2, size_t n); 57 | char *ft_strsub(char const *s, unsigned int strat, size_t len); 58 | char *ft_strjoin(char const *s1, char const *s2); 59 | char *ft_strtrim(char const *s); 60 | char **ft_strsplit(char const *s, char c); 61 | char *ft_itoa(int n); 62 | void ft_putchar(char c); 63 | void ft_putstr(char const *s); 64 | void ft_putendl(char const *s); 65 | void ft_putnbr(int n); 66 | char *ft_strnstr(const char*s1, const char *s2, size_t n); 67 | void ft_putchar_fd(char c, int fd); 68 | void ft_putchar_fd(char c, int fd); 69 | void ft_putstr_fd(char const *s, int fd); 70 | void ft_putendl_fd(char const *s, int fd); 71 | void ft_putnbr_fd(int n, int fd); 72 | 73 | #endif 74 | --------------------------------------------------------------------------------