X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=gui_common.c;h=dc3450a8410b3002e6a4e41f0a548d2f8efd8e9f;hp=07cab16fe211c740c7a25a484e1fee5271490498;hb=32facbd1b7948f146515e53194cfd4f33c54353f;hpb=418339759697ff6884e77c809805645c5f4db5b5;ds=sidebyside diff --git a/gui_common.c b/gui_common.c index 07cab16f..dc3450a8 100644 --- a/gui_common.c +++ b/gui_common.c @@ -1,19 +1,38 @@ +/* + * Copyright (C) 2006-2007 Andre Noll + * + * Licensed under the GPL v2. For licencing details see COPYING. + */ + +/** \file gui_common.c Functions used by the guis of paraslash. */ + + +#include +#include + #include "para.h" +#include "string.h" +#include "fd.h" extern const char *status_item_list[NUM_STAT_ITEMS]; - int para_open_audiod_pipe(char *cmd) { int fds[3] = {0, 1, 0}; pid_t pid; - return para_exec_cmdline_pid(&pid, cmd, fds) > 0? - fds[1] : -1; + int ret = para_exec_cmdline_pid(&pid, cmd, fds); + if (ret < 0) + return ret; + ret = mark_fd_nonblock(fds[1]); + if (ret > 0) + return fds[1]; + close(fds[1]); + return ret; } -int read_audiod_pipe(int fd, void (*line_handler)(char *) ) +int read_audiod_pipe(int fd, line_handler_t *line_handler) { - static char buf[STRINGSIZE]; + static char buf[4096]; const ssize_t bufsize = sizeof(buf) - 1; static ssize_t loaded; ssize_t ret; @@ -24,7 +43,7 @@ int read_audiod_pipe(int fd, void (*line_handler)(char *) ) if (ret > 0) { loaded += ret; buf[loaded] = '\0'; - loaded = for_each_line(buf, loaded, line_handler); + loaded = for_each_line(buf, loaded, line_handler, NULL); } return ret; }