From 7771431278f32e7c89c4f42c5aaa9b4137f467ed Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 1 Apr 2010 16:17:17 +0200 Subject: [PATCH] mkswap: move write_all() to include/writeall.h Signed-off-by: Karel Zak --- disk-utils/mkswap.c | 19 +------------------ include/Makefile.am | 3 ++- include/writeall.h | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 include/writeall.h 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 */ -- 2.39.5