mirror of
https://github.com/sheumann/hush.git
synced 2024-08-20 04:28:57 +00:00
xread/write can use full_read/write (smaller code)
This commit is contained in:
parent
2d5ca60bfb
commit
88ca067690
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user