diff options
author | Lars-Dominik Braun <PromyLOPh@lavabit.com> | 2009-04-11 12:05:51 +0200 |
---|---|---|
committer | Lars-Dominik Braun <PromyLOPh@lavabit.com> | 2009-04-11 12:05:51 +0200 |
commit | d5969cabc44375026d97f7f3d92e019782cdc331 (patch) | |
tree | 8495274e927c6179b556604d9aaddf9c8f951b94 | |
parent | 71d9447316133c8e447ca7538d9533e1ef61e0eb (diff) | |
download | pianobar-windows-d5969cabc44375026d97f7f3d92e019782cdc331.tar.gz pianobar-windows-d5969cabc44375026d97f7f3d92e019782cdc331.tar.bz2 pianobar-windows-d5969cabc44375026d97f7f3d92e019782cdc331.zip |
Don't mix low-level read() and stdio
...as suggested by
> man fgetc
-rw-r--r-- | src/main.c | 19 |
1 files changed, 11 insertions, 8 deletions
@@ -70,6 +70,7 @@ int main (int argc, char **argv) { /* polls */ /* FIXME: max path length? */ char ctlPath[1024]; + FILE *ctlFd = NULL; struct pollfd polls[2]; nfds_t pollsLen = 0; char buf = '\0'; @@ -91,11 +92,13 @@ int main (int argc, char **argv) { polls[0].fd = fileno (stdin); polls[0].events = POLLIN; ++pollsLen; + BarGetXdgConfigDir (PACKAGE "/ctl", ctlPath, sizeof (ctlPath)); - /* FIXME: O_RDONLY blocks while opening :/ */ - polls[1].fd = open (ctlPath, O_RDWR); - polls[1].events = POLLIN; - if (polls[1].fd != -1) { + /* FIXME: why is r_+_ required? */ + ctlFd = fopen (ctlPath, "r+"); + if (ctlFd != NULL) { + polls[1].fd = fileno (ctlFd); + polls[1].events = POLLIN; ++pollsLen; BarUiMsg (MSG_INFO, "Control fifo at %s opened\n", ctlPath); } @@ -248,9 +251,9 @@ int main (int argc, char **argv) { * 1000ms == 1s => refresh time display every second */ if (poll (polls, pollsLen, 1000) > 0) { if (polls[0].revents & POLLIN) { - read (fileno (stdin), &buf, sizeof (buf)); + buf = fgetc (stdin); } else if (polls[1].revents & POLLIN) { - read (polls[1].fd, &buf, sizeof (buf)); + buf = fgetc (ctlFd); } curShortcut = settings.keys; /* don't show what the user enters here, we could disable @@ -283,8 +286,8 @@ int main (int argc, char **argv) { free (player.url); pthread_join (playerThread, NULL); } - if (polls[1].fd != -1) { - close (polls[1].fd); + if (ctlFd != NULL) { + fclose (ctlFd); } PianoDestroy (&ph); WardrobeDestroy (&wh); |