Skip to content

Commit

Permalink
git_fopen: fix a sparse 'not declared' warning
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ramsay-jones authored and gitster committed May 26, 2017
1 parent d2bbb7c commit b0a642a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions compat/fopen.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
* The order of the following two lines is important.
*
* FREAD_READS_DIRECTORIES is undefined before including git-compat-util.h
* SUPPRESS_FOPEN_REDEFINITION is defined before including git-compat-util.h
* to avoid the redefinition of fopen within git-compat-util.h. This is
* necessary since fopen is a macro on some platforms which may be set
* based on compiler options. For example, on AIX fopen is set to fopen64
* when _LARGE_FILES is defined. The previous technique of merely undefining
* fopen after including git-compat-util.h is inadequate in this case.
*/
#undef FREAD_READS_DIRECTORIES
#define SUPPRESS_FOPEN_REDEFINITION
#include "../git-compat-util.h"

FILE *git_fopen(const char *path, const char *mode)
Expand Down
10 changes: 6 additions & 4 deletions git-compat-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,10 +689,12 @@ char *gitstrdup(const char *s);
#endif

#ifdef FREAD_READS_DIRECTORIES
#ifdef fopen
#undef fopen
#endif
#define fopen(a,b) git_fopen(a,b)
# if !defined(SUPPRESS_FOPEN_REDEFINITION)
# ifdef fopen
# undef fopen
# endif
# define fopen(a,b) git_fopen(a,b)
# endif
extern FILE *git_fopen(const char*, const char*);
#endif

Expand Down

0 comments on commit b0a642a

Please sign in to comment.