dev/c/ipc/typeserver.c

33 lines
588 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
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;
}