summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2011-09-02 12:18:50 +0200
committerLars-Dominik Braun <lars@6xq.net>2011-09-02 12:18:50 +0200
commitac45dc448186ebe8c70d87c3a0ad79dd6dae19a3 (patch)
treeea8c26e76ba5aaf6da0488d9d6d73d56156103c8
parent4212b0eac58fb9b926a9dafe4fd76fa886af81b4 (diff)
downloadpianobar-windows-ac45dc448186ebe8c70d87c3a0ad79dd6dae19a3.tar.gz
pianobar-windows-ac45dc448186ebe8c70d87c3a0ad79dd6dae19a3.tar.bz2
pianobar-windows-ac45dc448186ebe8c70d87c3a0ad79dd6dae19a3.zip
Use fprintf instead of snprintf
- Output size not limited by buffer size - No local buffer needed
-rw-r--r--src/ui.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/ui.c b/src/ui.c
index 84117bb..0f74c2b 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -808,17 +808,19 @@ void BarUiStartEventCmd (const BarSettings_t *settings, const char *type,
BarUiMsg (settings, MSG_ERR, "Cannot fork eventcmd. (%s)\n", strerror (errno));
} else {
/* parent */
- int status, printfret;
- char pipeBuf[1024];
+ int status;
PianoStation_t *songStation = NULL;
+ FILE *pipeWriteFd;
close (pipeFd[0]);
+ pipeWriteFd = fdopen (pipeFd[1], "w");
+
if (curSong != NULL && stations != NULL && curStation->isQuickMix) {
songStation = PianoFindStationById (stations, curSong->stationId);
}
- printfret = snprintf (pipeBuf, sizeof (pipeBuf),
+ fprintf (pipeWriteFd,
"artist=%s\n"
"title=%s\n"
"album=%s\n"
@@ -848,9 +850,6 @@ void BarUiStartEventCmd (const BarSettings_t *settings, const char *type,
curSong == NULL ? PIANO_RATE_NONE : curSong->rating,
curSong == NULL ? "" : curSong->detailUrl
);
- assert (printfret < sizeof (pipeBuf));
-
- write (pipeFd[1], pipeBuf, strlen (pipeBuf));
if (stations != NULL) {
/* send station list */
@@ -860,23 +859,21 @@ void BarUiStartEventCmd (const BarSettings_t *settings, const char *type,
settings->sortOrder);
assert (sortedStations != NULL);
- snprintf (pipeBuf, sizeof (pipeBuf), "stationCount=%zd\n", stationCount);
- write (pipeFd[1], pipeBuf, strlen (pipeBuf));
+ fprintf (pipeWriteFd, "stationCount=%zd\n", stationCount);
for (size_t i = 0; i < stationCount; i++) {
const PianoStation_t *currStation = sortedStations[i];
- printfret = snprintf (pipeBuf, sizeof (pipeBuf), "station%zd=%s\n", i,
+ fprintf (pipeWriteFd, "station%zd=%s\n", i,
currStation->name);
- assert (printfret < sizeof (pipeBuf));
- write (pipeFd[1], pipeBuf, strlen (pipeBuf));
}
free (sortedStations);
} else {
- const char *msg = "stationCount=0\n";
- write (pipeFd[1], msg, strlen (msg));
+ const char * const msg = "stationCount=0\n";
+ fwrite (msg, sizeof (*msg), strlen (msg), pipeWriteFd);
}
- close (pipeFd[1]);
+ /* closes pipeFd[1] as well */
+ fclose (pipeWriteFd);
/* wait to get rid of the zombie */
waitpid (chld, &status, 0);
}