[PATCH v2 04/21] wrapper.c: add warn_on_fopen_errors()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@xxxxxxxxx>
---
 dir.c             |  3 +--
 git-compat-util.h |  2 ++
 wrapper.c         | 10 ++++++++++
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/dir.c b/dir.c
index f451bfa48c..8218a24962 100644
--- a/dir.c
+++ b/dir.c
@@ -745,8 +745,7 @@ static int add_excludes(const char *fname, const char *base, int baselen,
 
 	fd = open(fname, O_RDONLY);
 	if (fd < 0 || fstat(fd, &st) < 0) {
-		if (errno != ENOENT)
-			warn_on_inaccessible(fname);
+		warn_on_fopen_errors(fname);
 		if (0 <= fd)
 			close(fd);
 		if (!check_index ||
diff --git a/git-compat-util.h b/git-compat-util.h
index bd04564a69..c5b59c23e8 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -1099,6 +1099,8 @@ 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);
+/* Warn on an inaccessible file if errno indicates this is an error */
+int warn_on_fopen_errors(const char *path);
 
 #ifdef GMTIME_UNRELIABLE_ERRORS
 struct tm *git_gmtime(const time_t *);
diff --git a/wrapper.c b/wrapper.c
index d837417709..20c25e7e65 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -418,6 +418,16 @@ FILE *fopen_for_writing(const char *path)
 	return ret;
 }
 
+int warn_on_fopen_errors(const char *path)
+{
+	if (errno != ENOENT && errno != ENOTDIR) {
+		warn_on_inaccessible(path);
+		return -1;
+	}
+
+	return 0;
+}
+
 int xmkstemp(char *template)
 {
 	int fd;
-- 
2.11.0.157.gd943d85




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]