aboutsummaryrefslogtreecommitdiffstats
path: root/extlinux/extlinux.c
diff options
context:
space:
mode:
authorhpa <hpa>2005-01-04 03:27:43 +0000
committerhpa <hpa>2005-01-04 03:27:43 +0000
commit7e6cb2d0ace1cd889b7336dbaf24ed1f79fbd29e (patch)
treef898b60fe31fafb887eeae702fed355fb29dcb64 /extlinux/extlinux.c
parent662c4d8395bca94debef65550a055bf2961452d8 (diff)
downloadsyslinux-elf-7e6cb2d0ace1cd889b7336dbaf24ed1f79fbd29e.tar.gz
syslinux-elf-7e6cb2d0ace1cd889b7336dbaf24ed1f79fbd29e.tar.xz
syslinux-elf-7e6cb2d0ace1cd889b7336dbaf24ed1f79fbd29e.zip
Fix xpread/xpwrite; call die() when we're dead to make sure we clean up
Diffstat (limited to 'extlinux/extlinux.c')
-rw-r--r--extlinux/extlinux.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/extlinux/extlinux.c b/extlinux/extlinux.c
index 9c221569..20b580cf 100644
--- a/extlinux/extlinux.c
+++ b/extlinux/extlinux.c
@@ -186,25 +186,26 @@ void __attribute__((noreturn)) die(const char *msg)
}
/*
- * pread() and pwrite() augmented with retry on short access or EINTR.
+ * 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, buf, count, offset);
+ rv = pread(fd, bufp, count, offset);
if ( rv == 0 ) {
die("short read");
} else if ( rv == -1 ) {
if ( errno == EINTR ) {
continue;
} else {
- perror(program);
- exit(1);
+ die(strerror(errno));
}
} else {
+ bufp += rv;
offset += rv;
done += rv;
count -= rv;
@@ -214,23 +215,24 @@ ssize_t xpread(int fd, void *buf, size_t count, off_t offset)
return done;
}
-ssize_t xpwrite(int fd, void *buf, size_t count, off_t offset)
+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, buf, count, offset);
+ rv = pwrite(fd, bufp, count, offset);
if ( rv == 0 ) {
die("short write");
} else if ( rv == -1 ) {
if ( errno == EINTR ) {
continue;
} else {
- perror(program);
- exit(1);
+ die(strerror(errno));
}
} else {
+ bufp += rv;
offset += rv;
done += rv;
count -= rv;