diff options
author | Junio C Hamano <gitster@pobox.com> | 2008-07-20 16:13:05 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2008-07-20 17:17:09 -0700 |
commit | 559e840b74dbbf39633aa68627937a5f7a6d4145 (patch) | |
tree | 5d7104780be71a36cbccccd4de20c9363ee97a92 /wrapper.c | |
parent | 7df1709c36ff93f56636ab11db612dedb0d2bed0 (diff) | |
download | git-559e840b74dbbf39633aa68627937a5f7a6d4145.tar.gz |
Move read_in_full() and write_in_full() to wrapper.c
A few compat/* layer functions call these functions, but we would really
want to keep them thin, without depending too much on the libgit proper.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'wrapper.c')
-rw-r--r-- | wrapper.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -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); |