Skip to content

Commit b0a642a

Browse files
ramsay-jonesgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d2bbb7c commit b0a642a

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

compat/fopen.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*
22
* The order of the following two lines is important.
33
*
4-
* FREAD_READS_DIRECTORIES is undefined before including git-compat-util.h
4+
* SUPPRESS_FOPEN_REDEFINITION is defined before including git-compat-util.h
55
* to avoid the redefinition of fopen within git-compat-util.h. This is
66
* necessary since fopen is a macro on some platforms which may be set
77
* based on compiler options. For example, on AIX fopen is set to fopen64
88
* when _LARGE_FILES is defined. The previous technique of merely undefining
99
* fopen after including git-compat-util.h is inadequate in this case.
1010
*/
11-
#undef FREAD_READS_DIRECTORIES
11+
#define SUPPRESS_FOPEN_REDEFINITION
1212
#include "../git-compat-util.h"
1313

1414
FILE *git_fopen(const char *path, const char *mode)

git-compat-util.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -689,10 +689,12 @@ char *gitstrdup(const char *s);
689689
#endif
690690

691691
#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
696698
extern FILE *git_fopen(const char*, const char*);
697699
#endif
698700

0 commit comments

Comments
 (0)