diff options
author | Karel Zak | 2010-04-01 16:17:17 +0200 |
---|---|---|
committer | Karel Zak | 2010-04-01 16:17:17 +0200 |
commit | 7771431278f32e7c89c4f42c5aaa9b4137f467ed (patch) | |
tree | 28455b088649da1672b9fb2ade1130f7515d81b1 /include/writeall.h | |
parent | libblkid: avoid probing CDs for RAID (diff) | |
download | kernel-qcow2-util-linux-7771431278f32e7c89c4f42c5aaa9b4137f467ed.tar.gz kernel-qcow2-util-linux-7771431278f32e7c89c4f42c5aaa9b4137f467ed.tar.xz kernel-qcow2-util-linux-7771431278f32e7c89c4f42c5aaa9b4137f467ed.zip |
mkswap: move write_all() to include/writeall.h
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'include/writeall.h')
-rw-r--r-- | include/writeall.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/include/writeall.h b/include/writeall.h new file mode 100644 index 000000000..a04496d8f --- /dev/null +++ b/include/writeall.h @@ -0,0 +1,25 @@ +#ifndef UTIL_LINUX_WRITEALL_H +#define UTIL_LINUX_WRITEALL_H + +#include <string.h> +#include <unistd.h> +#include <errno.h> + +static inline int write_all(int fd, const void *buf, size_t count) +{ + while(count) { + ssize_t tmp; + + errno = 0; + tmp = write(fd, buf, count); + if (tmp > 0) { + count -= tmp; + if (count) + buf += tmp; + } else if (errno != EINTR && errno != EAGAIN) + return -1; + } + return 0; +} + +#endif /* UTIL_LINUX_WRITEALL_H */ |