summaryrefslogtreecommitdiffstats
path: root/xwrite.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2007-07-06 15:42:57 -0700
committerH. Peter Anvin <hpa@zytor.com>2007-07-06 15:42:57 -0700
commitcaba1e82891eb4b419b1ac9fef6e774104acafe2 (patch)
tree0cafc2965f5571e2a289da89ed1ec75798568d05 /xwrite.c
downloadlib-caba1e82891eb4b419b1ac9fef6e774104acafe2.tar.gz
lib-caba1e82891eb4b419b1ac9fef6e774104acafe2.tar.xz
lib-caba1e82891eb4b419b1ac9fef6e774104acafe2.zip
Initial commit: collection of useful functions
Diffstat (limited to 'xwrite.c')
-rw-r--r--xwrite.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/xwrite.c b/xwrite.c
new file mode 100644
index 0000000..80a754a
--- /dev/null
+++ b/xwrite.c
@@ -0,0 +1,28 @@
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+ssize_t xwrite(int fd, const void *buf, size_t count)
+{
+ const char *p = buf;
+ ssize_t out = 0;
+ ssize_t rv;
+
+ while (count) {
+ rv = write(fd, p, count);
+ if (rv == -1) {
+ if (errno == EINTR || errno == EAGAIN)
+ continue;
+ return out ? out : -1; /* Error */
+ } else if (rv == 0) {
+ return out; /* EOF */
+ }
+
+ p += rv;
+ out += rv;
+ count -= rv;
+ }
+
+ return out;
+}
+