//Demonstration of named pipes
//Write opens a pipe then it writes into the pipe
#include <stdio.h>
#include <stdlib.h>
//Pipe call
#include <fcntl.h>
//mknod call
#include <sys/types.h>
#include <sys/stat.h>
#define BUFLEN 100
//Prototypes
int main (void);
void input(char *);
//Var's
//Filedescritpor
int fdes;
int a,i;
char *s, buffer[BUFLEN];
int main(void)
{
/*
Creates a FIFO-File with the rights read/write
for the user and read for others.
*/
mknod("pipe1",S_IFIFO | 0666,0);
/*
Opens a pipe. This process can only write into a pipe. If its opend successfull open() gives the filedescriptor back otherwise -1.
*/
if((fdes=open("pipe1",O_WRONLY))==-1){
puts("Error couldn't open pipe");
exit(-1);
}
//Writes the buffer into the FIFO file
input(buffer);
if((i=write(fdes,buffer,BUFLEN)) !=BUFLEN) {
printf("Error couldn't write");
exit(-1);
}
//Now we have to close the FIFO File
close(fdes);
exit(0);
}
//Get input?:0
void input(char *buffer)
{
printf("Enter a String(max 100 Chars):");
buffer = gets(buffer);
}