Implement access control for the dccp sender.
[paraslash.git] / gui_common.c
1 /*
2  * Copyright (C) 2006-2008 Andre Noll <maan@systemlinux.org>
3  *
4  * Licensed under the GPL v2. For licencing details see COPYING.
5  */
6
7 /** \file gui_common.c Functions used by the guis of paraslash. */
8
9
10 #include <sys/types.h>
11 #include <dirent.h>
12
13 #include "para.h"
14 #include "string.h"
15 #include "fd.h"
16
17 int para_open_audiod_pipe(char *cmd)
18 {
19         int fds[3] = {0, 1, 0};
20         pid_t pid;
21         int ret = para_exec_cmdline_pid(&pid, cmd, fds);
22         if (ret < 0)
23                 return ret;
24         ret = mark_fd_nonblocking(fds[1]);
25         if (ret > 0)
26                 return fds[1];
27         close(fds[1]);
28         return ret;
29 }
30
31 int read_audiod_pipe(int fd, line_handler_t *line_handler)
32 {
33         static char buf[4096];
34         const ssize_t bufsize = sizeof(buf) - 1;
35         static ssize_t loaded;
36         ssize_t ret;
37
38         if (loaded >= bufsize)
39                 loaded = 0;
40         ret = read(fd, buf + loaded, bufsize - loaded);
41         if (ret > 0) {
42                 loaded += ret;
43                 buf[loaded] = '\0';
44                 loaded = for_each_line(buf, loaded, line_handler, NULL);
45         }
46         return ret;
47 }