-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspeak.c
More file actions
34 lines (28 loc) · 660 Bytes
/
speak.c
File metadata and controls
34 lines (28 loc) · 660 Bytes
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
/* FIFO write "speak"
* October 28, 2021 */
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#define FIFO_NAME "pipe.fifo"
/* Use with tick.c */
int main(void) {
char s[300];
int num, fd;
mknod(FIFO_NAME, S_IFIFO | 0666, 0);
printf("Waiting for readers\n");
fd = open(FIFO_NAME, O_WRONLY);
printf("Got a reader - type some stuff\n");
while (strcmp(fgets(s, sizeof(s), stdin), "\n") != 0) {
if ((num = write(fd, s, strlen(s))) == -1)
perror("write");
else
printf("Speak: Wrote %d bytes\n", num);
}
close(fd);
return 0;
}