summaryrefslogtreecommitdiffhomepage
path: root/libbb
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-12 22:44:13 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-12 22:44:13 +0000
commit88ca06769028e442bf873b270c176ca0e9f021f8 (patch)
tree5df56293dd5b0266ae5964ef5dad5e8b2794f121 /libbb
parent2d5ca60bfb66e0ba7340ab9b4696b872f00adf7c (diff)
xread/write can use full_read/write (smaller code)
Diffstat (limited to 'libbb')
-rw-r--r--libbb/full_read.c2
-rw-r--r--libbb/full_write.c2
-rw-r--r--libbb/xfuncs.c16
3 files changed, 8 insertions, 12 deletions
diff --git a/libbb/full_read.c b/libbb/full_read.c
index b5837d5bd..068d16698 100644
--- a/libbb/full_read.c
+++ b/libbb/full_read.c
@@ -24,7 +24,7 @@ ssize_t full_read(int fd, void *buf, size_t len)
total = 0;
- while (len > 0) {
+ while (len) {
cc = safe_read(fd, buf, len);
if (cc < 0)
diff --git a/libbb/full_write.c b/libbb/full_write.c
index d812d04b4..563f4a851 100644
--- a/libbb/full_write.c
+++ b/libbb/full_write.c
@@ -23,7 +23,7 @@ ssize_t full_write(int fd, const void *buf, size_t len)
total = 0;
- while (len > 0) {
+ while (len) {
cc = safe_write(fd, buf, len);
if (cc < 0)
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index d22cd279a..efc919491 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -113,24 +113,20 @@ int xopen3(const char *pathname, int flags, int mode)
// Die with an error message if we can't read the entire buffer.
void xread(int fd, void *buf, size_t count)
{
- while (count) {
- ssize_t size = safe_read(fd, buf, count);
- if (size < 1)
+ if (count) {
+ ssize_t size = full_read(fd, buf, count);
+ if (size != count)
bb_error_msg_and_die("short read");
- count -= size;
- buf = ((char *) buf) + size;
}
}
// Die with an error message if we can't write the entire buffer.
void xwrite(int fd, void *buf, size_t count)
{
- while (count) {
- ssize_t size = safe_write(fd, buf, count);
- if (size < 1)
+ if (count) {
+ ssize_t size = full_write(fd, buf, count);
+ if (size != count)
bb_error_msg_and_die("short write");
- count -= size;
- buf = ((char *) buf) + size;
}
}