SCR/SCR1.2/TP11/read_file.c
2023-01-10 17:17:47 +01:00

25 lines
439 B
C

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#define SZBUF 256
int main(int argc, char *argv[]){
int fs, n;
char buf[SZBUF];
if (argc < 2){
fprintf(stderr, "Usage : %s <SRC_FILE>\n", argv[0]);
exit(1);
}
fs = open(argv[1], O_RDONLY);
if (fs == -1){
perror("File opening fails");
exit(2);
}
while (n = read(fs, buf, SZBUF))
write(1, buf, n);
close(fs);
exit(0);
return EXIT_SUCCESS;
}