Ajouter 'concurrence.c'

This commit is contained in:
valarche 2021-09-17 14:12:54 +02:00
parent 3234b52588
commit 84e34696e4

35
concurrence.c Normal file
View File

@ -0,0 +1,35 @@
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
int desc_read, desc_write;
char c;
int main(int argc, char *argv[]) {
if (argc != 3) {
printf("Deux noms de fichiers comme arguments\n");
exit(1);
}
if ((desc_read = open(argv[1], O_RDONLY)) == -1) {
perror(argv[1]);
exit(1);
}
if ((desc_write = open(argv[2], O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
perror(argv[2]);
exit(1);
}
for(;;) {
if (read(desc_read, &c, 1) != 1) exit(0);
write(desc_write, &c, 1);
}
close(desc_read);
close(desc_write);
return EXIT_SUCCESS;
}