commit 9b5eb89e9504b5d1080bee48b8de8a3d2c789ce8
parent 5ab84dfd1b077a945e263c51bd8d60e853846522
Author: Brian Swetland <swetland@frotz.net>
Date: Thu, 12 Dec 2013 11:33:43 -0800
simplify copyx, ensuring writesize is equal to readsize or buffersize
Diffstat:
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/util.c b/util.c
@@ -53,17 +53,13 @@ int writex(int fd, void *_data, size_t len) {
}
int copyx(int fin, int fout, size_t len, u8 *buf, size_t max) {
- ssize_t r;
while (len > 0) {
- r = read(fin, buf, max > len ? len : max);
- if (r < 0) {
- if (errno == EINTR)
- continue;
+ size_t xfer = max > len ? len : max;
+ if (readx(fin, buf, xfer))
return -1;
- }
- if (writex(fout, buf, r))
+ if (writex(fout, buf, xfer))
return -1;
- len -= r;
+ len -= xfer;
}
return 0;
}