diff options
| author | ne_mene <[email protected]> | 2026-03-01 14:11:22 +0100 |
|---|---|---|
| committer | ne_mene <[email protected]> | 2026-03-01 14:11:22 +0100 |
| commit | 6f1203a2990aa00e145d640b0814908ed661cb4e (patch) | |
| tree | caa72547194575a64677e5aec3d5302e5c7494e0 /src/pipe.c | |
| parent | afd081618ddcd7ee0e76858dafb4fb41cb00251a (diff) | |
tsarc and named pipe
Diffstat (limited to 'src/pipe.c')
| -rw-r--r-- | src/pipe.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/pipe.c b/src/pipe.c new file mode 100644 index 0000000..88006a4 --- /dev/null +++ b/src/pipe.c @@ -0,0 +1,61 @@ +#include "pipe.h" +#include <stdio.h> +#include <fcntl.h> +#include <unistd.h> +#include <sys/stat.h> +#include <ctype.h> + +FILE *named_pipe; + +void init_pipe() { + mkfifo(PIPE_PATH, 0666); + named_pipe = fopen(PIPE_PATH, "r"); +} + +void await_change() { + char buff[1024]; + while (1) { + if (!fgets(buff, sizeof(buff), named_pipe)) { + fclose(named_pipe); + named_pipe = fopen(PIPE_PATH, "r"); // This blocks, 0% CPU, yay + continue; + } + break; + } + printf("Received: %s\n", buff); + + int argc = 0, chr_on = 0, i = 0; + char argv[4][256]; + + while (argc < 4) { + char chr = buff[i]; + if (chr == '\0') { + break; + } + + if (isspace(chr)) { + if (chr_on == 0) { + i++; + continue; + } + + argv[argc][chr_on] = '\0'; + argc++; + chr_on = 0; + + } else { + argv[argc][chr_on] = chr; + chr_on++; + } + + i++; + } + make_change(argv, argc); +} + +void make_change(char argv[MAX_ARGS][MAX_ARG_LEN], int argc) { + printf("Making change with:\n"); + for (int i = 0; i < argc; i++) { + printf("Arg %d: %s\n", i + 1, argv[i]); + } +} |
