X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=inline;f=wrapper.c;h=93562f03eef21b26945d2d9bbdc96818f4de6567;hb=20642801e44a03362d1809644bf4da6473636529;hp=4e04f7661b4943059243fa5f8a33baeec4a96583;hpb=fa4946b5532ff911565c882892a715616c22cdec;p=git.git diff --git a/wrapper.c b/wrapper.c index 4e04f7661..93562f03e 100644 --- a/wrapper.c +++ b/wrapper.c @@ -133,6 +133,44 @@ ssize_t xwrite(int fd, const void *buf, size_t len) } } +ssize_t read_in_full(int fd, void *buf, size_t count) +{ + char *p = buf; + ssize_t total = 0; + + while (count > 0) { + ssize_t loaded = xread(fd, p, count); + if (loaded <= 0) + return total ? total : loaded; + count -= loaded; + p += loaded; + total += loaded; + } + + return total; +} + +ssize_t write_in_full(int fd, const void *buf, size_t count) +{ + const char *p = buf; + ssize_t total = 0; + + while (count > 0) { + ssize_t written = xwrite(fd, p, count); + if (written < 0) + return -1; + if (!written) { + errno = ENOSPC; + return -1; + } + count -= written; + p += written; + total += written; + } + + return total; +} + int xdup(int fd) { int ret = dup(fd);