summaryrefslogtreecommitdiff
path: root/src/fileops.c
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2008-12-30 23:26:38 -0800
committerShawn O. Pearce <spearce@spearce.org>2008-12-30 23:29:23 -0800
commit7dd8a9f71052cc12f8dd9c1eec2e99afbf08df76 (patch)
treecf5f7235b9c9689b133f6ea12015720b411329bd /src/fileops.c
parent64a47c01426a36cdb7e598d17018d5791e54bb97 (diff)
downloadlibgit2-7dd8a9f71052cc12f8dd9c1eec2e99afbf08df76.tar.gz
Set GIT_EOSERR when the OS errno should be consulted
This error code indicates the OS error code has a better value describing the last error, as it is likely a network or local file IO problem identified by a C library function call. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'src/fileops.c')
-rw-r--r--src/fileops.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/fileops.c b/src/fileops.c
index 6522d02a7..1dd35dc8e 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -1,6 +1,18 @@
#include "common.h"
#include "fileops.h"
+int gitfo_open(const char *path, int flags)
+{
+ int fd = open(path, flags);
+ return fd >= 0 ? fd : git_os_error();
+}
+
+int gitfo_creat(const char *path, int mode)
+{
+ int fd = creat(path, mode);
+ return fd >= 0 ? fd : git_os_error();
+}
+
int gitfo_read(git_file fd, void *buf, size_t cnt)
{
char *b = buf;
@@ -9,11 +21,11 @@ int gitfo_read(git_file fd, void *buf, size_t cnt)
if (r < 0) {
if (errno == EINTR || errno == EAGAIN)
continue;
- return -1;
+ return git_os_error();
}
if (!r) {
errno = EPIPE;
- return -1;
+ return git_os_error();
}
cnt -= r;
b += r;
@@ -29,11 +41,11 @@ int gitfo_write(git_file fd, void *buf, size_t cnt)
if (r < 0) {
if (errno == EINTR || errno == EAGAIN)
continue;
- return -1;
+ return git_os_error();
}
if (!r) {
errno = EPIPE;
- return -1;
+ return git_os_error();
}
cnt -= r;
b += r;
@@ -43,9 +55,9 @@ int gitfo_write(git_file fd, void *buf, size_t cnt)
off_t gitfo_size(git_file fd)
{
- gitfo_statbuf sb;
+ struct stat sb;
if (fstat(fd, &sb))
- return -1;
+ return git_os_error();
return sb.st_size;
}
@@ -166,7 +178,7 @@ int gitfo_close_cached(gitfo_cache *ioc)
git_file fd;
if (gitfo_flush_cached(ioc) < 0)
- return -1;
+ return GIT_ERROR;
fd = ioc->fd;
free(ioc->cache);
@@ -201,7 +213,7 @@ int git_foreach_dirent(const char *wd, int (*fn)(void *, const char *), void *ar
dir = opendir(wd);
if (!dir)
- return GIT_ERROR;
+ return git_os_error();
while ((de = readdir(dir))) {
size_t de_len;