diff options
author | Jeff King <peff@peff.net> | 2016-11-02 09:06:30 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-11-02 19:49:35 -0700 |
commit | f8481cf1dbbfc6fb39a2aea44dd2ef6b51592919 (patch) | |
tree | bdb1dde1174d693aa164cee31f6d82966870b568 | |
parent | be5a750939c212bc0781ffa04fabcfd2b2bd744e (diff) | |
download | git-f8481cf1dbbfc6fb39a2aea44dd2ef6b51592919.tar.gz |
add open_nofollow() helper
Some callers of open() would like to optionally use
O_NOFOLLOW, but it is not available on all platforms. We
could abstract this by publicly defining O_NOFOLLOW to 0 on
those platforms, but that leaves us no room for any
workarounds (e.g., by checking the file type via lstat()).
Instead, let's abstract it into its own function. We don't
implement any workarounds here, but it it would be easy to
add them later.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | git-compat-util.h | 3 | ||||
-rw-r--r-- | wrapper.c | 8 |
2 files changed, 11 insertions, 0 deletions
diff --git a/git-compat-util.h b/git-compat-util.h index 87237b092b..a2cc33ebc4 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -1080,6 +1080,9 @@ int access_or_die(const char *path, int mode, unsigned flag); /* Warn on an inaccessible file that ought to be accessible */ void warn_on_inaccessible(const char *path); +/* Open with O_NOFOLLOW, if available on this platform */ +int open_nofollow(const char *path, int flags); + #ifdef GMTIME_UNRELIABLE_ERRORS struct tm *git_gmtime(const time_t *); struct tm *git_gmtime_r(const time_t *, struct tm *); @@ -679,3 +679,11 @@ void sleep_millisec(int millisec) { poll(NULL, 0, millisec); } + +#ifndef O_NOFOLLOW +#define O_NOFOLLOW 0 +#endif +int open_nofollow(const char *path, int flags) +{ + return open(path, flags | O_NOFOLLOW); +} |