aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2008-09-18 04:07:26 -0700
committerEric Wong <normalperson@yhbt.net>2008-09-18 04:07:26 -0700
commitba4f62f7d241e2837111102a4dda0c917d544c99 (patch)
tree9e13723577247216b9b407bf31eb8bc1510fa2aa
parent3cd645c97f8a026541b911c2cbb3c2e294903208 (diff)
downloadmpd-ba4f62f7d241e2837111102a4dda0c917d544c99.tar.gz
mpd-ba4f62f7d241e2837111102a4dda0c917d544c99.tar.xz
mpd-ba4f62f7d241e2837111102a4dda0c917d544c99.zip
fdprintf and vfdprintf get error handling
-rw-r--r--src/myfprintf.c32
-rw-r--r--src/myfprintf.h4
2 files changed, 22 insertions, 14 deletions
diff --git a/src/myfprintf.c b/src/myfprintf.c
index 200c80334..aa452dfa1 100644
--- a/src/myfprintf.c
+++ b/src/myfprintf.c
@@ -24,22 +24,25 @@
#define BUFFER_LENGTH MPD_PATH_MAX+1024
-static void blockingWrite(const int fd, const char *string, size_t len)
+static ssize_t blocking_write(int fd, const char *string, size_t len)
{
+ const char *base = string;
+
while (len) {
ssize_t ret = xwrite(fd, string, len);
- if (ret == (ssize_t)len)
- return;
- if (ret >= 0) {
- len -= ret;
- string += ret;
- continue;
+ if (ret < 0)
+ return -1;
+ if (!ret) {
+ errno = ENOSPC;
+ return -1;
}
- return; /* error */
+ len -= ret;
+ string += ret;
}
+ return string - base;
}
-void vfdprintf(const int fd, const char *fmt, va_list args)
+ssize_t vfdprintf(const int fd, const char *fmt, va_list args)
{
char buffer[BUFFER_LENGTH];
char *buf = buffer;
@@ -50,14 +53,19 @@ void vfdprintf(const int fd, const char *fmt, va_list args)
if (fd == STDERR_FILENO ||
fd == STDOUT_FILENO ||
client_print(fd, buf, len) < 0)
- blockingWrite(fd, buf, len);
+ return blocking_write(fd, buf, len);
+ return len;
}
-mpd_fprintf void fdprintf(const int fd, const char *fmt, ...)
+mpd_fprintf ssize_t fdprintf(const int fd, const char *fmt, ...)
{
va_list args;
+ ssize_t ret;
+
va_start(args, fmt);
- vfdprintf(fd, fmt, args);
+ ret = vfdprintf(fd, fmt, args);
va_end(args);
+
+ return ret;
}
diff --git a/src/myfprintf.h b/src/myfprintf.h
index 393a22a08..cb8a0a9f9 100644
--- a/src/myfprintf.h
+++ b/src/myfprintf.h
@@ -22,7 +22,7 @@
#include "gcc.h"
#include "os_compat.h"
-mpd_fprintf void fdprintf(const int fd, const char *fmt, ...);
-void vfdprintf(const int fd, const char *fmt, va_list arglist);
+mpd_fprintf ssize_t fdprintf(const int fd, const char *fmt, ...);
+ssize_t vfdprintf(const int fd, const char *fmt, va_list arglist);
#endif