1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| #include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
main (void)
{
char *tube = "tube";
char mot[21];
int wr=0;
if(mkfifo (tube, 0666) ==0) /* creation tube avec droit lecture/ecriture*/
{
printf("ok");
}
else
{
if(errno == EEXIST) printf("fichier existe deja \n");
else printf("probl");
}
wr=open(tube,O_WRONLY | O_NDELAY);
if(wr<0)
{
printf("error a l'ouverture");
}
else
{
printf("inserez un mot a envoyer");
scanf("%s",mot);
if(write(tube,mot,strlen(mot))<0)
{
printf("erreur ecriture");
}
else
{
puts(mot);
}
}
close(wr);
return (0);
} |