Skip to content

Commit

Permalink
git-compat-util: work around fileno(fp) that is a macro
Browse files Browse the repository at this point in the history
On various BSD's, fileno(fp) is implemented as a macro that directly
accesses the fields in the FILE * object, which breaks a function that
accepts a "void *fp" parameter and calls fileno(fp) and expect it to
work.

Work it around by adding a compile-time knob FILENO_IS_A_MACRO that
inserts a real helper function in the middle of the callchain.

Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
pclouds authored and gitster committed Feb 12, 2019
1 parent 0d0ac38 commit 18a4f6b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ all::
#
# Define HAVE_GETDELIM if your system has the getdelim() function.
#
# Define FILENO_IS_A_MACRO if fileno() is a macro, not a real function.
#
# Define PAGER_ENV to a SP separated VAR=VAL pairs to define
# default environment variables to be passed when a pager is spawned, e.g.
#
Expand Down Expand Up @@ -1773,6 +1775,11 @@ ifdef HAVE_WPGMPTR
BASIC_CFLAGS += -DHAVE_WPGMPTR
endif

ifdef FILENO_IS_A_MACRO
COMPAT_CFLAGS += -DFILENO_IS_A_MACRO
COMPAT_OBJS += compat/fileno.o
endif

ifeq ($(TCLTK_PATH),)
NO_TCLTK = NoThanks
endif
Expand Down
7 changes: 7 additions & 0 deletions compat/fileno.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#define COMPAT_CODE
#include "../git-compat-util.h"

int git_fileno(FILE *stream)
{
return fileno(stream);
}
2 changes: 2 additions & 0 deletions config.mak.uname
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ ifeq ($(uname_S),FreeBSD)
HAVE_BSD_KERN_PROC_SYSCTL = YesPlease
PAGER_ENV = LESS=FRX LV=-c MORE=FRX
FREAD_READS_DIRECTORIES = UnfortunatelyYes
FILENO_IS_A_MACRO = UnfortunatelyYes
endif
ifeq ($(uname_S),OpenBSD)
NO_STRCASESTR = YesPlease
Expand All @@ -233,6 +234,7 @@ ifeq ($(uname_S),OpenBSD)
HAVE_BSD_SYSCTL = YesPlease
HAVE_BSD_KERN_PROC_SYSCTL = YesPlease
PROCFS_EXECUTABLE_PATH = /proc/curproc/file
FILENO_IS_A_MACRO = UnfortunatelyYes
endif
ifeq ($(uname_S),MirBSD)
NO_STRCASESTR = YesPlease
Expand Down
8 changes: 8 additions & 0 deletions git-compat-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,14 @@ struct tm *git_gmtime_r(const time_t *, struct tm *);
#define getc_unlocked(fh) getc(fh)
#endif

#ifdef FILENO_IS_A_MACRO
int git_fileno(FILE *stream);
# ifndef COMPAT_CODE
# undef fileno
# define fileno(p) git_fileno(p)
# endif
#endif

/*
* Our code often opens a path to an optional file, to work on its
* contents when we can successfully open it. We can ignore a failure
Expand Down

0 comments on commit 18a4f6b

Please sign in to comment.