diff options
author | Russell Belfer <arrbee@arrbee.com> | 2012-03-07 04:14:31 +0400 |
---|---|---|
committer | Russell Belfer <arrbee@arrbee.com> | 2012-03-07 04:27:13 +0400 |
commit | ae9e29fde7e7d1c0c3e95bdabbb5c96fc71b1c71 (patch) | |
tree | 65d8215f898fc30b579b72d815e6adc78823dd6c /src/fileops.h | |
parent | cb8a79617b15e347f26d21cedde0f2b8670c1876 (diff) |
Migrating diff to new error handling
Ended up migrating a bunch of upstream functions as well
including vector, attr_file, and odb in order to get this
to work right.
Diffstat (limited to 'src/fileops.h')
-rw-r--r-- | src/fileops.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/fileops.h b/src/fileops.h index ab57b6f38..c2ba8ffc8 100644 --- a/src/fileops.h +++ b/src/fileops.h @@ -77,6 +77,20 @@ extern int git_futils_mktmp(git_buf *path_out, const char *filename); extern int git_futils_mv_withpath(const char *from, const char *to, const mode_t dirmode); /** + * Open a file readonly and set error if needed + */ +GIT_INLINE(int) git_futils_open_ro(const char *path) +{ + int fd = p_open(path, O_RDONLY); + if (fd < 0) { + if (errno == ENOENT) + fd = GIT_ENOTFOUND; + giterr_set(GITERR_OS, "Failed to open '%s'", path); + } + return fd; +} + +/** * Get the filesize in bytes of a file */ extern git_off_t git_futils_filesize(git_file fd); |