diff options
author | Andreas Ericsson <ae@op5.se> | 2008-11-23 22:37:55 +0100 |
---|---|---|
committer | Shawn O. Pearce <spearce@spearce.org> | 2008-12-02 09:17:23 -0800 |
commit | ec250c6e18e56d12714f9010e1b15e5feec5f473 (patch) | |
tree | eb815f96b04732b893bc17c209665b211e3cab0f /src/fileops.c | |
parent | 42c07750c431b6bd77c6a9e1ff4997285932e352 (diff) | |
download | libgit2-ec250c6e18e56d12714f9010e1b15e5feec5f473.tar.gz |
Remove config.h and make fileops an internal API
Since it doesn't make sense to make the disk access stuff
portable *AND* public (that's a job for each application
imo), we can take a shortcut and just support unixy stuff
for now and get away with coding most of it as macros.
Since we go with an internal API for starters and only
provide higher-level API's to the libgit users, we'll be
ok with this approach.
Signed-off-by: Andreas Ericsson <ae@op5.se>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'src/fileops.c')
-rw-r--r-- | src/fileops.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/fileops.c b/src/fileops.c new file mode 100644 index 000000000..1ca0fbb08 --- /dev/null +++ b/src/fileops.c @@ -0,0 +1,49 @@ +#include "fileops.h" + +int gitfo_read(git_file fd, void *buf, size_t cnt) +{ + char *b = buf; + while (cnt) { + ssize_t r = read(fd, b, cnt); + if (r < 0) { + if (errno == EINTR || errno == EAGAIN) + continue; + return -1; + } + if (!r) { + errno = EPIPE; + return -1; + } + cnt -= r; + b += r; + } + return GIT_SUCCESS; +} + +int gitfo_write(git_file fd, void *buf, size_t cnt) +{ + char *b = buf; + while (cnt) { + ssize_t r = write(fd, b, cnt); + if (r < 0) { + if (errno == EINTR || errno == EAGAIN) + continue; + return -1; + } + if (!r) { + errno = EPIPE; + return -1; + } + cnt -= r; + b += r; + } + return GIT_SUCCESS; +} + +off_t gitfo_size(git_file fd) +{ + gitfo_statbuf sb; + if (fstat(fd, &sb)) + return -1; + return sb.st_size; +} |