diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-07-21 15:26:32 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-07-21 15:26:32 +0200 |
| commit | 23ad79e8b41c25bb4992d103d29a17612a52e351 (patch) | |
| tree | 9de3cde07cc38e59f08885171e9f99eeab8ab71b /c10 | |
| parent | 8b6e91bdb56bc01a588718472546f2a88e750b48 (diff) | |
| download | piscine-23ad79e8b41c25bb4992d103d29a17612a52e351.tar.gz piscine-23ad79e8b41c25bb4992d103d29a17612a52e351.tar.bz2 piscine-23ad79e8b41c25bb4992d103d29a17612a52e351.zip | |
c10 done, c11 on going, rush02 probably finished, bsq start
Diffstat (limited to 'c10')
| -rw-r--r-- | c10/bonjour.c | 38 | ||||
| -rw-r--r-- | c10/ex00/main.c | 39 | ||||
| -rw-r--r-- | c10/ex02/include.h | 5 |
3 files changed, 53 insertions, 29 deletions
diff --git a/c10/bonjour.c b/c10/bonjour.c new file mode 100644 index 0000000..1b6f283 --- /dev/null +++ b/c10/bonjour.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* bonjour.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/20 17:20:22 by cacharle #+# #+# */ +/* Updated: 2019/07/20 17:31:22 by cacharle ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../includes/ft.h" + +int main(int argc, char **argv) +{ + int fd; + char buff[BUFF_SIZE + 1]; + int ret; + if (argc < 2) + write(2, "File name missing.\n", 19); + else if (argc > 2) + write(2, "Too many arguments.\n", 20); + else + { + fd = open(argv[1], O_RDONLY); + if (fd == -1) + { + write(2, "Cannot read file.\n", 18); + return (1); + } + while ((ret = read(fd, buff, BUFF_SIZE))) + write(1, buff, ret); + if (close(fd)) + return (1); + } + return (0); +} diff --git a/c10/ex00/main.c b/c10/ex00/main.c index 0cc4470..67fefe6 100644 --- a/c10/ex00/main.c +++ b/c10/ex00/main.c @@ -6,53 +6,38 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/11 18:06:43 by cacharle #+# #+# */ -/* Updated: 2019/07/19 06:33:07 by cacharle ### ########.fr */ +/* Updated: 2019/07/20 17:26:47 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include <unistd.h> #include <fcntl.h> -#include <stdio.h> -#define BUFFER_SIZE 1024 - -int read_write_file(int fildes) -{ - char buf[BUFFER_SIZE]; - int read_size; - - while ((read_size = read(fildes, buf, BUFFER_SIZE)) != 0) - { - if (read_size < 0) - return (-1); - write(STDOUT_FILENO, buf, read_size); - } - return (0); -} +#define BUF_SIZE 64 int main(int argc, char **argv) { int fildes; + int read_size; + char buf[BUF_SIZE + 1]; - if (argc == 1) + if (argc < 2) { - write(STDERR_FILENO, "File name missing.\n", 20); + write(STDERR_FILENO, "File name missing.\n", 19); return (1); } - else if (argc > 2) + if (argc > 2) { - write(STDERR_FILENO, "Too many arguments.\n", 21); + write(STDERR_FILENO, "Too many arguments.\n", 20); return (1); } - if ((fildes = open(argv[1], O_RDONLY)) < 0) + if ((fildes = open(argv[1], O_RDONLY)) == -1) { write(STDERR_FILENO, "Cannot read file.\n", 18); return (1); } - if ((read_write_file(fildes)) < 0) - { - write(STDERR_FILENO, "Cannot read file.\n", 18); + while ((read_size = read(fildes, buf, BUF_SIZE))) + write(STDOUT_FILENO, buf, read_size); + if (close(fildes)) return (1); - } - close(fildes); return (0); } diff --git a/c10/ex02/include.h b/c10/ex02/include.h index d37df25..f806cec 100644 --- a/c10/ex02/include.h +++ b/c10/ex02/include.h @@ -6,7 +6,7 @@ /* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/07/16 15:26:12 by cacharle #+# #+# */ -/* Updated: 2019/07/19 06:59:18 by cacharle ### ########.fr */ +/* Updated: 2019/07/19 07:06:04 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,8 @@ int print_tail(char *filename, int tail_size, int argc, int good_counter); int print_file_tail(int fildes, int tail_size); int read_file(int fildes, char **file); -char *ft_memcat(char *file, char buf[BUF_SIZE], int file_size, int read_size); +char *ft_memcat(char *file, char buf[BUF_SIZE], int file_size, + int read_size); /* ** helper.c |
