A minor change.
authorLukas Jiriste <ljiriste@student.42prague.com>
Wed, 28 Jun 2023 19:25:07 +0000 (21:25 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Wed, 28 Jun 2023 19:25:07 +0000 (21:25 +0200)
ex02/sources/main.c

index 89c8644b348a6b8d5712e1b9d7f6fa33e595f6a0..35edb104275f154fbacee64c764163af7fbdd76a 100644 (file)
@@ -6,7 +6,7 @@
 /*   By: ljiriste <marvin@42.fr>                    +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2023/06/27 14:05:49 by ljiriste          #+#    #+#             */
-/*   Updated: 2023/06/27 17:28:04 by ljiriste         ###   ########.fr       */
+/*   Updated: 2023/06/28 21:24:50 by ljiriste         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -32,10 +32,12 @@ void        std_input_mode(void)
        return ;
 }
 
-void   tail_file(char *file_name, char *proc_name, unsigned int char_count);
+void   write_last_chars(int fd, unsigned int fl, unsigned int chars)
+{
+
+void   tail_file(char *file_name, char *proc_name, unsigned int char_count)
 {
        int                             fd;
-       char                    c;
        unsigned int    file_length;
 
        fd = open(file_name, O_RDWR);
@@ -51,9 +53,7 @@ void  tail_file(char *file_name, char *proc_name, unsigned int char_count);
        else
        {
                file_length = file_length(file_name);
-
-               while (read(fd, &c, 1) > 0)
-                       write(1, &c, 1);
+               write_last_chars(fd, file_length, char_count);
                close(fd);
        }
 }