aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--extlinux/extlinux.c18
-rw-r--r--mtools/syslinux.c30
-rw-r--r--unix/syslinux.c18
3 files changed, 33 insertions, 33 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;
diff --git a/mtools/syslinux.c b/mtools/syslinux.c
index 2db0a752..d7ff0a89 100644
--- a/mtools/syslinux.c
+++ b/mtools/syslinux.c
@@ -44,12 +44,18 @@ char *device; /* Device to install to */
pid_t mypid;
off_t filesystem_offset = 0; /* Offset of filesystem */
-void usage(void)
+void __attribute__((noreturn)) usage(void)
{
fprintf(stderr, "Usage: %s [-sf] [-o offset] device\n", program);
exit(1);
}
+void __attribute__((noreturn)) die(const char *msg)
+{
+ fprintf(stderr, "%s: %s\n", program, msg);
+ exit(1);
+}
+
/*
* read/write wrapper functions
*/
@@ -62,14 +68,12 @@ ssize_t xpread(int fd, void *buf, size_t count, off_t offset)
while ( count ) {
rv = pread(fd, bufp, count, offset);
if ( rv == 0 ) {
- fprintf(stderr, "%s: short read\n", program);
- exit(1);
+ die("short read");
} else if ( rv == -1 ) {
if ( errno == EINTR ) {
continue;
} else {
- perror(program);
- exit(1);
+ die(strerror(errno));
}
} else {
bufp += rv;
@@ -82,23 +86,21 @@ 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)
{
- char *bufp = (char *)buf;
+ const char *bufp = (const char *)buf;
ssize_t rv;
ssize_t done = 0;
while ( count ) {
rv = pwrite(fd, bufp, count, offset);
if ( rv == 0 ) {
- fprintf(stderr, "%s: short write\n", program);
- exit(1);
+ die("short write");
} else if ( rv == -1 ) {
if ( errno == EINTR ) {
continue;
} else {
- perror(program);
- exit(1);
+ die(strerror(errno));
}
} else {
bufp += rv;
@@ -194,8 +196,7 @@ int main(int argc, char *argv[])
* Check to see that what we got was indeed an MS-DOS boot sector/superblock
*/
if( (errmsg = syslinux_check_bootsect(sectbuf)) ) {
- fprintf(stderr, "%s: %s\n", program, errmsg);
- exit(1);
+ die(errmsg);
}
/*
@@ -233,8 +234,7 @@ int main(int argc, char *argv[])
(fwrite(syslinux_ldlinux, 1, syslinux_ldlinux_len, mtp)
!= syslinux_ldlinux_len) ||
(status = pclose(mtp), !WIFEXITED(status) || WEXITSTATUS(status)) ) {
- fprintf(stderr, "%s: failed to create ldlinux.sys\n", program);
- exit(1);
+ die("failed to create ldlinux.sys");
}
status = system("mattrib +r +h +s s:ldlinux.sys");
diff --git a/unix/syslinux.c b/unix/syslinux.c
index 276990da..32e9dded 100644
--- a/unix/syslinux.c
+++ b/unix/syslinux.c
@@ -104,25 +104,24 @@ void __attribute__((noreturn)) die(const char *msg)
*/
ssize_t xpread(int fd, void *buf, size_t count, off_t offset)
{
- char *p = buf;
+ char *bufp = (char *)buf;
ssize_t rv;
ssize_t done = 0;
while ( count ) {
- rv = pread(fd, p, 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;
- p += rv;
count -= rv;
}
}
@@ -132,25 +131,24 @@ 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)
{
- const char *p = buf;
+ const char *bufp = (const char *)buf;
ssize_t rv;
ssize_t done = 0;
while ( count ) {
- rv = pwrite(fd, p, 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;
- p += rv;
count -= rv;
}
}