Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-06-13 23:47:09 +0300
committerJunio C Hamano <gitster@pobox.com>2017-06-13 23:47:09 +0300
commitb9a7d55d938a81eb6268196b789d573437492100 (patch)
tree637c6e3452e5b81394faf99f0a4a24ce73c801e8 /wrapper.c
parent9743f18f3fef0b77b8715cba256a740a7238f761 (diff)
parente5b313442ab7c700d0851e9dbe7d2b029e3893e5 (diff)
Merge branch 'nd/fopen-errors'
We often try to open a file for reading whose existence is optional, and silently ignore errors from open/fopen; report such errors if they are not due to missing files. * nd/fopen-errors: mingw_fopen: report ENOENT for invalid file names mingw: verify that paths are not mistaken for remote nicknames log: fix memory leak in open_next_file() rerere.c: move error_errno() closer to the source system call print errno when reporting a system call error wrapper.c: make warn_on_inaccessible() static wrapper.c: add and use fopen_or_warn() wrapper.c: add and use warn_on_fopen_errors() config.mak.uname: set FREAD_READS_DIRECTORIES for Darwin, too config.mak.uname: set FREAD_READS_DIRECTORIES for Linux and FreeBSD clone: use xfopen() instead of fopen() use xfopen() in more places git_fopen: fix a sparse 'not declared' warning
Diffstat (limited to 'wrapper.c')
-rw-r--r--wrapper.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/wrapper.c b/wrapper.c
index 708e98a965..4632c7d4c0 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -418,6 +418,32 @@ FILE *fopen_for_writing(const char *path)
return ret;
}
+static void warn_on_inaccessible(const char *path)
+{
+ warning_errno(_("unable to access '%s'"), path);
+}
+
+int warn_on_fopen_errors(const char *path)
+{
+ if (errno != ENOENT && errno != ENOTDIR) {
+ warn_on_inaccessible(path);
+ return -1;
+ }
+
+ return 0;
+}
+
+FILE *fopen_or_warn(const char *path, const char *mode)
+{
+ FILE *fp = fopen(path, mode);
+
+ if (fp)
+ return fp;
+
+ warn_on_fopen_errors(path);
+ return NULL;
+}
+
int xmkstemp(char *template)
{
int fd;
@@ -576,11 +602,6 @@ int remove_or_warn(unsigned int mode, const char *file)
return S_ISGITLINK(mode) ? rmdir_or_warn(file) : unlink_or_warn(file);
}
-void warn_on_inaccessible(const char *path)
-{
- warning_errno(_("unable to access '%s'"), path);
-}
-
static int access_error_is_ok(int err, unsigned flag)
{
return (is_missing_file_error(err) ||