git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] git-compat-util: undefine fileno if defined

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 12, 2019, 16:56 UTC
Message-ID
<xmqqwom5djyk.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20190212134537.GA26137@ash>
Duy Nguyen <pclouds@gmail.com> writes:
Show 13 quoted lines
> So, how about something like this? A teeny bit longer than your
> version, but I think it's easier to control long term.
>
> -- 8< --
> diff --git a/Makefile b/Makefile
> index 0e13a5b469..44cfc63fc4 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -433,6 +433,8 @@ all::
>  #
>  # Define HAVE_GETDELIM if your system has the getdelim() function.
>  #
> +# Define FILENO_IS_A_MACRO is fileno() is a macro, not a real function.
s/is fileno() is/if filno() is/;
I agree with the direction of this patch takes us.

I have a mixed feeling about the COMPAT_CODE macro trick (presumably you did not want to include stdio.h directly for "FILE *" and instead follow the usual "the first header included is the compat-util" pattern; I was imagining that we'd liberally include system headers inside compat/ directory. If we can agree on reusing this single macro to control conditional in git-compat-util.h when a similar need arises in the future, this may be a good solution.

Show 72 quoted lines
> +#
>  # 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.
>  #
> @@ -1800,6 +1802,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
> diff --git a/compat/fileno.c b/compat/fileno.c
> new file mode 100644
> index 0000000000..7b105f4cd7
> --- /dev/null
> +++ b/compat/fileno.c
> @@ -0,0 +1,7 @@
> +#define COMPAT_CODE
> +#include "../git-compat-util.h"
> +
> +int git_fileno(FILE *stream)
> +{
> +	return fileno(stream);
> +}
> diff --git a/config.mak.uname b/config.mak.uname
> index 786bb2f913..01f62674a4 100644
> --- a/config.mak.uname
> +++ b/config.mak.uname
> @@ -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
> @@ -234,6 +235,7 @@ ifeq ($(uname_S),OpenBSD)
>  	HAVE_BSD_KERN_PROC_SYSCTL = YesPlease
>  	PROCFS_EXECUTABLE_PATH = /proc/curproc/file
>  	FREAD_READS_DIRECTORIES = UnfortunatelyYes
> +	FILENO_IS_A_MACRO = UnfortunatelyYes
>  endif
>  ifeq ($(uname_S),MirBSD)
>  	NO_STRCASESTR = YesPlease
> diff --git a/git-compat-util.h b/git-compat-util.h
> index 29a19902aa..6573808ebd 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -1234,6 +1234,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
> -- 8< --
>
> --
> Duy
Previous: Duy NguyenNext: Dan McGregor
Message 12 of 16 in “http: cast result to FILE *”
  1. http: cast result to FILE *Dan McGregor, Feb 1, 2019
  2. Junio C HamanoFeb 1, 2019
  3. Duy NguyenFeb 2, 2019
  4. Johannes SchindelinFeb 4, 2019
  5. Duy NguyenFeb 4, 2019
  6. Junio C HamanoFeb 4, 2019
  7. Dan McGregorFeb 5, 2019
  8. git-compat-util: undefine fileno if definedDan McGregor, Feb 9, 2019
  9. Junio C HamanoFeb 9, 2019
  10. Duy NguyenFeb 12, 2019
  11. Duy NguyenFeb 12, 2019
  12. Junio C HamanoFeb 12, 2019
  13. Dan McGregorFeb 16, 2019
  14. Junio C HamanoMay 8, 2019
  15. Duy NguyenMay 8, 2019
  16. Junio C HamanoMay 8, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.