Last active
August 12, 2023 14:07
-
-
Save paulido/5d9f919e6ebcb14a7e831a647106c305 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
int main(int argc, char *args[]){ | |
if(argc != 2){ | |
printf("syntaxe incorrecte"); | |
return EXIT_FAILURE; | |
} | |
int nb_read, t_write, size = 1024; | |
int *buffer = malloc(sizeof(int)*size); | |
int nb_write; | |
int descriptor = open(args[1], O_RDONLY); | |
if(descriptor < 0){ | |
printf("impossible lire le fichier"); | |
return EXIT_FAILURE; | |
} | |
do{ | |
nb_read = read(descriptor, buffer, size); | |
t_write = 0; | |
do{ | |
nb_write = write(STDOUT_FILENO, (const void *)buffer, nb_read); | |
t_write += nb_write; | |
}while(nb_write < nb_read); | |
}while( nb_read > 0); | |
close(descriptor); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is an implementation of the cat function on UNIX like systems