{"thread":{"id":"45907","subject":"[PATCH v2] git_fopen: fix a sparse 'not declared' warning","startedAt":"2017-05-08T20:46:03Z","lastAt":"2017-05-08T20:46:03Z","messageCount":1,"participants":["Ramsay Jones"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"319116","messageId":"2bf7d61e-c70f-a033-5cb2-2a66ac6fe459@ramsayjones.plus.com","threadId":"45907","inReplyTo":null,"subject":"[PATCH v2] git_fopen: fix a sparse 'not declared' warning","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2017-05-08T20:45:56Z","receivedAt":"2017-05-08T20:46:03Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\nIf git is built with the FREAD_READS_DIRECTORIES build variable set, this\nwould cause sparse to issue a 'not declared, should it be static?' warning\non Linux. This is a result of the method employed by 'compat/fopen.c' to\nsuppress the (possible) redefinition of the (system) fopen macro, which\nalso removes the extern declaration of the git_fopen function.\n\nIn order to suppress the warning, introduce a new macro to suppress the\ndefinition (or possibly the re-definition) of the fopen symbol as a macro\noverride. This new macro (SUPPRESS_FOPEN_REDEFINITION) is only defined in\n'compat/fopen.c', just prior to the inclusion of the 'git-compat-util.h'\nheader file.\n\nSigned-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>\n---\n\nHi Junio,\n\nI noticed the \"What's cooking\" entry for Duy's 'nd/fopen-errors'\nbranch 'needs to resurrect' this patch, so I re-worded the commit\nmessage (because commit 8f4f6e53d2 is no more ...) so that it could\nstand alone. (or on the new re-rolled branch).\n\nThanks.\n\nATB,\nRamsay Jones\n\n compat/fopen.c    |  4 ++--\n git-compat-util.h | 10 ++++++----\n 2 files changed, 8 insertions(+), 6 deletions(-)\n\ndiff --git a/compat/fopen.c b/compat/fopen.c\nindex b5ca142fe..107b3e818 100644\n--- a/compat/fopen.c\n+++ b/compat/fopen.c\n@@ -1,14 +1,14 @@\n /*\n  *  The order of the following two lines is important.\n  *\n- *  FREAD_READS_DIRECTORIES is undefined before including git-compat-util.h\n+ *  SUPPRESS_FOPEN_REDEFINITION is defined before including git-compat-util.h\n  *  to avoid the redefinition of fopen within git-compat-util.h. This is\n  *  necessary since fopen is a macro on some platforms which may be set\n  *  based on compiler options. For example, on AIX fopen is set to fopen64\n  *  when _LARGE_FILES is defined. The previous technique of merely undefining\n  *  fopen after including git-compat-util.h is inadequate in this case.\n  */\n-#undef FREAD_READS_DIRECTORIES\n+#define SUPPRESS_FOPEN_REDEFINITION\n #include \"../git-compat-util.h\"\n \n FILE *git_fopen(const char *path, const char *mode)\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex df7b41524..33e06cac1 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -694,10 +694,12 @@ char *gitstrdup(const char *s);\n #endif\n \n #ifdef FREAD_READS_DIRECTORIES\n-#ifdef fopen\n-#undef fopen\n-#endif\n-#define fopen(a,b) git_fopen(a,b)\n+# if !defined(SUPPRESS_FOPEN_REDEFINITION)\n+#  ifdef fopen\n+#   undef fopen\n+#  endif\n+#  define fopen(a,b) git_fopen(a,b)\n+# endif\n extern FILE *git_fopen(const char*, const char*);\n #endif\n \n-- \n2.12.0\n"}]}