diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-07-24 18:46:39 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-07-24 18:46:58 +0200 |
| commit | 83edb77d74bb339f3e1324a51039c78ac503db90 (patch) | |
| tree | 1e69b9330430438fa499f94e864dcfb4d83ea007 /bsq/srcs/helper.c | |
| parent | 5bab06313e71e9827baa426a02bbaf2a00b4e6a0 (diff) | |
| download | piscine-83edb77d74bb339f3e1324a51039c78ac503db90.tar.gz piscine-83edb77d74bb339f3e1324a51039c78ac503db90.tar.bz2 piscine-83edb77d74bb339f3e1324a51039c78ac503db90.zip | |
bsq and c13 passed
Diffstat (limited to 'bsq/srcs/helper.c')
| -rw-r--r-- | bsq/srcs/helper.c | 62 |
1 files changed, 0 insertions, 62 deletions
diff --git a/bsq/srcs/helper.c b/bsq/srcs/helper.c deleted file mode 100644 index d1fe8bc..0000000 --- a/bsq/srcs/helper.c +++ /dev/null @@ -1,62 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* helper.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2019/07/19 15:19:53 by cacharle #+# #+# */ -/* Updated: 2019/07/19 15:19:56 by cacharle ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include <unistd.h> -#include <stdlib.h> -#include <fcntl.h> -#include "include.h" - -int read_file(int fildes, char **file) -{ - char buf[BUF_SIZE]; - int file_size; - int read_size; - - file_size = 0; - while ((read_size = read(fildes, buf, BUF_SIZE))) - { - if (read_size < 0) - return (-1); - *file = ft_memcat(*file, buf, file_size, read_size); - file_size += read_size; - } - return (file_size); -} - -char *ft_memcat(char *file, char buf[BUF_SIZE], int file_size, - int read_size) -{ - int i; - char *file_clone; - - if ((file_clone = malloc(sizeof(char) * (file_size + 1))) == NULL) - return (NULL); - i = -1; - while (++i < file_size) - file_clone[i] = file[i]; - free(file); - if ((file = malloc(sizeof(char) * (file_size + read_size + 1))) == NULL) - return (NULL); - i = 0; - while (i < file_size) - { - file[i] = file_clone[i]; - i++; - } - free(file_clone); - while (i < file_size + read_size) - { - file[i] = buf[i - file_size]; - i++; - } - return (file); -} |
