Skip to content

Commit 3adf9fd

Browse files
peffgitster
authored andcommitted
configure.ac: loosen FREAD_READS_DIRECTORIES test program
We added an FREAD_READS_DIRECTORIES Makefile knob long ago in cba2252 (Add compat/fopen.c which returns NULL on attempt to open directory, 2008-02-08) to handle systems where reading from a directory returned garbage. This works by catching the problem at the fopen() stage and returning NULL. More recently, we found that there is a class of systems (including Linux) where fopen() succeeds but fread() fails. Since the solution is the same (having fopen return NULL), they use the same Makefile knob as of e2d90fd (config.mak.uname: set FREAD_READS_DIRECTORIES for Linux and FreeBSD, 2017-05-03). This works fine except for one thing: the autoconf test in configure.ac to set FREAD_READS_DIRECTORIES actually checks whether fread succeeds. Which means that on Linux systems, the knob isn't set (and we even override the config.mak.uname default). t1308 catches the failure. We can fix this by tweaking the autoconf test to cover both cases. In theory we might care about the distinction between the traditional "fread reads directories" case and the new "fopen opens directories". But since our solution catches the problem at the fopen stage either way, we don't actually need to know the difference. The "fopen" case is a superset. This does mean the FREAD_READS_DIRECTORIES name is slightly misleading. Probably FOPEN_OPENS_DIRECTORIES would be more accurate. But it would be disruptive to simply change the name (people's existing build configs would fail), and it's not worth the complexity of handling both. Let's just add a comment in the knob description. Reported-by: Øyvind A. Holm <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e5b3134 commit 3adf9fd

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ all::
1919
# have been written to the final string if enough space had been available.
2020
#
2121
# Define FREAD_READS_DIRECTORIES if you are on a system which succeeds
22-
# when attempting to read from an fopen'ed directory.
22+
# when attempting to read from an fopen'ed directory (or even to fopen
23+
# it at all).
2324
#
2425
# Define NO_OPENSSL environment variable if you do not have OpenSSL.
2526
# This also implies BLK_SHA1.

configure.ac

+2-2
Original file line numberDiff line numberDiff line change
@@ -865,9 +865,9 @@ AC_CACHE_CHECK([whether system succeeds to read fopen'ed directory],
865865
[
866866
AC_RUN_IFELSE(
867867
[AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
868-
[[char c;
868+
[[
869869
FILE *f = fopen(".", "r");
870-
return f && fread(&c, 1, 1, f)]])],
870+
return f)]])],
871871
[ac_cv_fread_reads_directories=no],
872872
[ac_cv_fread_reads_directories=yes])
873873
])

0 commit comments

Comments
 (0)