dev/c/ipc/typeserver.c

33 lines
588 B
C
Raw Normal View History

2012-03-20 00:47:18 +04:00
/*
Named Pipe Demo by Andrei Borovsky <borovsky@tochka.ru>.
This code is freeware.
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#define FIFO_NAME "./fifofile"
int main(int argc, char * argv[])
{
FILE * f;
char ch;
mkfifo(FIFO_NAME, 0600);
f = fopen(FIFO_NAME, "w");
if (f == NULL)
{
printf("Не удалось открыть файл\n");
return -1;
}
do
{
ch = getchar();
fputc(ch, f);
if (ch == 10) fflush(f);
} while (ch != 'q');
fclose(f);
unlink(FIFO_NAME);
return 0;
}