Skip to content

Commit 18a4f6b

Browse files
pcloudsgitster
authored andcommitted
git-compat-util: work around fileno(fp) that is a macro
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]>
1 parent 0d0ac38 commit 18a4f6b

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ all::
427427
#
428428
# Define HAVE_GETDELIM if your system has the getdelim() function.
429429
#
430+
# Define FILENO_IS_A_MACRO if fileno() is a macro, not a real function.
431+
#
430432
# Define PAGER_ENV to a SP separated VAR=VAL pairs to define
431433
# default environment variables to be passed when a pager is spawned, e.g.
432434
#
@@ -1773,6 +1775,11 @@ ifdef HAVE_WPGMPTR
17731775
BASIC_CFLAGS += -DHAVE_WPGMPTR
17741776
endif
17751777

1778+
ifdef FILENO_IS_A_MACRO
1779+
COMPAT_CFLAGS += -DFILENO_IS_A_MACRO
1780+
COMPAT_OBJS += compat/fileno.o
1781+
endif
1782+
17761783
ifeq ($(TCLTK_PATH),)
17771784
NO_TCLTK = NoThanks
17781785
endif

compat/fileno.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#define COMPAT_CODE
2+
#include "../git-compat-util.h"
3+
4+
int git_fileno(FILE *stream)
5+
{
6+
return fileno(stream);
7+
}

config.mak.uname

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ ifeq ($(uname_S),FreeBSD)
221221
HAVE_BSD_KERN_PROC_SYSCTL = YesPlease
222222
PAGER_ENV = LESS=FRX LV=-c MORE=FRX
223223
FREAD_READS_DIRECTORIES = UnfortunatelyYes
224+
FILENO_IS_A_MACRO = UnfortunatelyYes
224225
endif
225226
ifeq ($(uname_S),OpenBSD)
226227
NO_STRCASESTR = YesPlease
@@ -233,6 +234,7 @@ ifeq ($(uname_S),OpenBSD)
233234
HAVE_BSD_SYSCTL = YesPlease
234235
HAVE_BSD_KERN_PROC_SYSCTL = YesPlease
235236
PROCFS_EXECUTABLE_PATH = /proc/curproc/file
237+
FILENO_IS_A_MACRO = UnfortunatelyYes
236238
endif
237239
ifeq ($(uname_S),MirBSD)
238240
NO_STRCASESTR = YesPlease

git-compat-util.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,14 @@ struct tm *git_gmtime_r(const time_t *, struct tm *);
12201220
#define getc_unlocked(fh) getc(fh)
12211221
#endif
12221222

1223+
#ifdef FILENO_IS_A_MACRO
1224+
int git_fileno(FILE *stream);
1225+
# ifndef COMPAT_CODE
1226+
# undef fileno
1227+
# define fileno(p) git_fileno(p)
1228+
# endif
1229+
#endif
1230+
12231231
/*
12241232
* Our code often opens a path to an optional file, to work on its
12251233
* contents when we can successfully open it. We can ignore a failure

0 commit comments

Comments
 (0)