From: Karel Zak Date: Thu, 1 Apr 2010 14:17:17 +0000 (+0200) Subject: mkswap: move write_all() to include/writeall.h X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7771431278f32e7c89c4f42c5aaa9b4137f467ed;p=util-linux mkswap: move write_all() to include/writeall.h Signed-off-by: Karel Zak --- diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c index 2bf07ddb..54951991 100644 --- a/disk-utils/mkswap.c +++ b/disk-utils/mkswap.c @@ -53,6 +53,7 @@ #include "blkdev.h" #include "pathnames.h" #include "wholedisk.h" +#include "writeall.h" #ifdef HAVE_LIBUUID # ifdef HAVE_UUID_UUID_H @@ -370,24 +371,6 @@ check_mount(void) { return 1; } - -static 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; -} - static void zap_bootbits(int fd, const char *devname, int force) { diff --git a/include/Makefile.am b/include/Makefile.am index 65e447d5..067523d7 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -23,4 +23,5 @@ dist_noinst_HEADERS = \ crc32.h \ mangle.h \ strtosize.h \ - xstrncpy.h + xstrncpy.h \ + writeall.h diff --git a/include/writeall.h b/include/writeall.h new file mode 100644 index 00000000..a04496d8 --- /dev/null +++ b/include/writeall.h @@ -0,0 +1,25 @@ +#ifndef UTIL_LINUX_WRITEALL_H +#define UTIL_LINUX_WRITEALL_H + +#include +#include +#include + +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 */