remove GPL from the files to be converted by grutatxt
[paraslash.git] / gui_common.c
1 #include "para.h"
2 #include "fd.h"
3
4 extern const char *status_item_list[NUM_STAT_ITEMS];
5
6 int para_open_audiod_pipe(char *cmd)
7 {
8 int fds[3] = {0, 1, 0};
9 pid_t pid;
10 int ret = para_exec_cmdline_pid(&pid, cmd, fds);
11 if (ret < 0)
12 return ret;
13 ret = mark_fd_nonblock(fds[1]);
14 if (ret > 0)
15 return fds[1];
16 close(fds[1]);
17 return ret;
18 }
19
20 int read_audiod_pipe(int fd, void (*line_handler)(char *) )
21 {
22 static char buf[4096];
23 const ssize_t bufsize = sizeof(buf) - 1;
24 static ssize_t loaded;
25 ssize_t ret;
26
27 if (loaded >= bufsize)
28 loaded = 0;
29 ret = read(fd, buf + loaded, bufsize - loaded);
30 if (ret > 0) {
31 loaded += ret;
32 buf[loaded] = '\0';
33 loaded = for_each_line(buf, loaded, line_handler);
34 }
35 return ret;
36 }