diff options
Diffstat (limited to 'libinstaller')
-rw-r--r-- | libinstaller/advio.c | 1 | ||||
-rw-r--r-- | libinstaller/syslxcom.c | 64 | ||||
-rw-r--r-- | libinstaller/syslxcom.h | 2 | ||||
-rw-r--r-- | libinstaller/syslxrw.c | 84 | ||||
-rw-r--r-- | libinstaller/syslxrw.h | 20 |
5 files changed, 106 insertions, 65 deletions
diff --git a/libinstaller/advio.c b/libinstaller/advio.c index 66e477ed..e282e11c 100644 --- a/libinstaller/advio.c +++ b/libinstaller/advio.c @@ -32,6 +32,7 @@ #include <sys/stat.h> #include <sys/types.h> #include "syslxint.h" +#include "syslxrw.h" #include "syslxcom.h" /* diff --git a/libinstaller/syslxcom.c b/libinstaller/syslxcom.c index 57f13cda..efc6474d 100644 --- a/libinstaller/syslxcom.c +++ b/libinstaller/syslxcom.c @@ -32,6 +32,7 @@ #include <sys/vfs.h> #include "linuxioctl.h" +#include "syslxrw.h" #include "syslxcom.h" #include "syslxfs.h" @@ -47,69 +48,6 @@ int fs_type; #define SECTOR_SHIFT 9 -static void die(const char *msg) -{ - fputs(msg, stderr); - exit(1); -} - -/* - * read/write wrapper functions - */ -ssize_t xpread(int fd, void *buf, size_t count, off_t offset) -{ - char *bufp = (char *)buf; - ssize_t rv; - ssize_t done = 0; - - while (count) { - rv = pread(fd, bufp, count, offset); - if (rv == 0) { - die("short read"); - } else if (rv == -1) { - if (errno == EINTR) { - continue; - } else { - die(strerror(errno)); - } - } else { - bufp += rv; - offset += rv; - done += rv; - count -= rv; - } - } - - return done; -} - -ssize_t xpwrite(int fd, const void *buf, size_t count, off_t offset) -{ - const char *bufp = (const char *)buf; - ssize_t rv; - ssize_t done = 0; - - while (count) { - rv = pwrite(fd, bufp, count, offset); - if (rv == 0) { - die("short write"); - } else if (rv == -1) { - if (errno == EINTR) { - continue; - } else { - die(strerror(errno)); - } - } else { - bufp += rv; - offset += rv; - done += rv; - count -= rv; - } - } - - return done; -} - /* * Set and clear file attributes */ diff --git a/libinstaller/syslxcom.h b/libinstaller/syslxcom.h index 8b3b4614..90d3966c 100644 --- a/libinstaller/syslxcom.h +++ b/libinstaller/syslxcom.h @@ -4,8 +4,6 @@ #include "syslinux.h" extern const char *program; -ssize_t xpread(int fd, void *buf, size_t count, off_t offset); -ssize_t xpwrite(int fd, const void *buf, size_t count, off_t offset); void clear_attributes(int fd); void set_attributes(int fd); int sectmap(int fd, sector_t *sectors, int nsectors); diff --git a/libinstaller/syslxrw.c b/libinstaller/syslxrw.c new file mode 100644 index 00000000..86876e8c --- /dev/null +++ b/libinstaller/syslxrw.c @@ -0,0 +1,84 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2010 Intel Corp. - All Rights Reserved + * Copyright 2015 Paulo Alcantara <pcacjr@zytor.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, Inc., 53 Temple Place Ste 330, + * Boston MA 02111-1307, USA; either version 2 of the License, or + * (at your option) any later version; incorporated herein by reference. + * + * ----------------------------------------------------------------------- */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <fcntl.h> +#include <unistd.h> + +#include "syslxrw.h" + +static void die(const char *msg) +{ + fputs(msg, stderr); + exit(1); +} + +/* + * read/write wrapper functions + */ +ssize_t xpread(int fd, void *buf, size_t count, off_t offset) +{ + char *bufp = (char *)buf; + ssize_t rv; + ssize_t done = 0; + + while (count) { + rv = pread(fd, bufp, count, offset); + if (rv == 0) { + die("short read"); + } else if (rv == -1) { + if (errno == EINTR) { + continue; + } else { + die(strerror(errno)); + } + } else { + bufp += rv; + offset += rv; + done += rv; + count -= rv; + } + } + + return done; +} + +ssize_t xpwrite(int fd, const void *buf, size_t count, off_t offset) +{ + const char *bufp = (const char *)buf; + ssize_t rv; + ssize_t done = 0; + + while (count) { + rv = pwrite(fd, bufp, count, offset); + if (rv == 0) { + die("short write"); + } else if (rv == -1) { + if (errno == EINTR) { + continue; + } else { + die(strerror(errno)); + } + } else { + bufp += rv; + offset += rv; + done += rv; + count -= rv; + } + } + + return done; +} diff --git a/libinstaller/syslxrw.h b/libinstaller/syslxrw.h new file mode 100644 index 00000000..d3ae3c29 --- /dev/null +++ b/libinstaller/syslxrw.h @@ -0,0 +1,20 @@ +/* ----------------------------------------------------------------------- * + * + * Copyright 2010 Intel Corp. - All Rights Reserved + * Copyright 2015 Paulo Alcantara <pcacjr@zytor.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, Inc., 53 Temple Place Ste 330, + * Boston MA 02111-1307, USA; either version 2 of the License, or + * (at your option) any later version; incorporated herein by reference. + * + * ----------------------------------------------------------------------- */ + +#ifndef _H_SYSLXRW_ +#define _H_SYSLXRW_ + +ssize_t xpread(int fd, void *buf, size_t count, off_t offset); +ssize_t xpwrite(int fd, const void *buf, size_t count, off_t offset); + +#endif /* _H_SYSLXRW_ */ |