git_fopen: fix a sparse 'not declared' warning

If git is built with the FREAD_READS_DIRECTORIES build variable set, this would cause sparse to issue a 'not declared, should it be static?' warning on Linux. This is a result of the method employed by 'compat/fopen.c' to suppress the (possible) redefinition of the (system) fopen macro, which also removes the extern declaration of the git_fopen function. In order to suppress the warning, introduce a new macro to suppress the definition (or possibly the re-definition) of the fopen symbol as a macro override. This new macro (SUPPRESS_FOPEN_REDEFINITION) is only defined in 'compat/fopen.c', just prior to the inclusion of the 'git-compat-util.h' header file. Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ramsay Jones committed May 8, 2017 at 21:45 UTC b0a642ac4624740187212aecec62b35a2eab38cb
2 files changed +8 -6
compat/fopen.c
+2 -2
@@ -1,14 +1,14 @@
1 /*
2 * The order of the following two lines is important.
3 *
4 - * FREAD_READS_DIRECTORIES is undefined before including git-compat-util.h
4 + * SUPPRESS_FOPEN_REDEFINITION is defined before including git-compat-util.h
5 * to avoid the redefinition of fopen within git-compat-util.h. This is
6 * necessary since fopen is a macro on some platforms which may be set
7 * based on compiler options. For example, on AIX fopen is set to fopen64
8 * when _LARGE_FILES is defined. The previous technique of merely undefining
9 * fopen after including git-compat-util.h is inadequate in this case.
10 */
11 -#undef FREAD_READS_DIRECTORIES
11 +#define SUPPRESS_FOPEN_REDEFINITION
12 #include "../git-compat-util.h"
13
14 FILE *git_fopen(const char *path, const char *mode)
git-compat-util.h
+6 -4
@@ -689,10 +689,12 @@ char *gitstrdup(const char *s);
689 #endif
690
691 #ifdef FREAD_READS_DIRECTORIES
692 -#ifdef fopen
693 -#undef fopen
694 -#endif
695 -#define fopen(a,b) git_fopen(a,b)
692 +# if !defined(SUPPRESS_FOPEN_REDEFINITION)
693 +# ifdef fopen
694 +# undef fopen
695 +# endif
696 +# define fopen(a,b) git_fopen(a,b)
697 +# endif
698 extern FILE *git_fopen(const char*, const char*);
699 #endif
700