Hi Junio, On Wed, 10 Jun 2020, Junio C Hamano wrote: > Han-Wen Nienhuys <hanwenn@xxxxxxxxx> writes: > > > There is also: > > > > reftable/stack_test.c:27:7: error: incompatible pointer types > > initializing 'PREC_DIR *' with an expression of type 'DIR *' > > [-Werror,-Wincompatible-pointer-types] > > DIR *dir = fdopendir(fd); > > > > on OSX. What is the proper dialect for reading out a directory within > > the git source code? opendir and fdopendir are POSIX, so I'm surprised > > this fails. > > I am reasonably sure we use opendir() to iterate over existing files > and subdirectories in a directory (e.g. in the codepaths to > enumerate loose object files in .git/objects/??/ directories). > > I do not offhand know we also use fdopendir() elsewhere. I strongly > suspect we do not. Perhaps some platforms do POSIX.1-2001 but not > ready for POSIX.1-2008 or something silly like that? We don't. We also do not use `unlinkat()`. And we generally use `remove_dir_recursively()` instead of implementing a separate version of it that only handles one directory level ;-) This is what I needed in Git for Windows' `shears/pu` branch to make it compile again: -- snipsnap -- Subject: [PATCH] fixup??? Add reftable library Rather than causing a build failure e.g. on Windows, where `fdopendir()` and `unlinkat()` just is not a thing, and rather than re-inventing `remove_dir_recursively()`, let's just use the perfectly fine library function we already have for that purpose. Signed-off-by: Johannes Schindelin <johannes.schindelin@xxxxxx> --- reftable/stack_test.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/reftable/stack_test.c b/reftable/stack_test.c index ffcc1e42819a..4dadc39bf45f 100644 --- a/reftable/stack_test.c +++ b/reftable/stack_test.c @@ -17,23 +17,20 @@ license that can be found in the LICENSE file or at #include "reftable.h" #include "test_framework.h" #include "reftable-tests.h" +#include "dir.h" #include <sys/types.h> #include <dirent.h> static void clear_dir(const char *dirname) { - int fd = open(dirname, O_DIRECTORY, 0); - DIR *dir = fdopendir(fd); - struct dirent *ent = NULL; + struct strbuf buf = STRBUF_INIT; - assert(fd >= 0); + strbuf_addstr(&buf, dirname); + if (remove_dir_recursively(&buf, 0) < 0) + die("Could not remove '%s'", dirname); - while ((ent = readdir(dir)) != NULL) { - unlinkat(fd, ent->d_name, 0); - } - closedir(dir); - rmdir(dirname); + strbuf_release(&buf); } static void test_read_file(void) -- 2.27.0.windows.1