diff options
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); |
