[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fdopendir closes the file descriptor on MinGW

From: David Grayson
Subject: Re: fdopendir closes the file descriptor on MinGW
Date: Sun, 22 Mar 2015 01:51:45 -0700

On Wed, Mar 18, 2015 at 9:16 AM, Eli Zaretskii <address@hidden> wrote:
> Another aside: I think you are making your life much harder by using
> these kludges.  The recommended way of building GNU software with
> MinGW is to use the MSYS Bash and tools, including MSYS Make.

You were right Eli.  Your comment made me try harder to find a good
development environment for Windows.  I tried the tools available at
mingw.org and they didn't seem very good or up-to-date.  However, I
got lucky and stumbled across http://msys2.github.io/ and that seems
like the right thing to use.  I have started writing up the things I
learned about MSYS2 here, in case anyone is interested:


Now that I know how to compile programs in the MSYS2 environment, and
these programs can use the POSIX emulation provided by msys-2.0.dll, I
am much less interested in fixing up Gnulib to work better on MinGW.
People who want to compile typical GNU utilities like grep should
probably just use MSYS2 instead of MinGW. Although MSYS and MSYS2 are
not mentioned in the Gnulib manual, I suspect they similar enough to
Cygwin that most of the things said about Cygiwn will apply to them.

However, here is a small patch for Gnulib that adds a test to make
sure that fdopendir does not close the file descriptor.  I hereby
release it into public domain.

(I hope it's formatted correctly and isn't messed up by Gmail's line wrapping.)

--- a/tests/test-fdopendir.c
+++ b/tests/test-fdopendir.c
@@ -64,11 +64,11 @@ main (int argc _GL_UNUSED, char *argv[])
   fd = open (".", O_RDONLY);
   ASSERT (0 <= fd);
   d = fdopendir (fd);
-  /* We know that fd is now out of our reach, but it is not specified
-     whether it is closed now or at the closedir.  We also can't
-     guarantee whether dirfd returns fd, some other descriptor, or
-     -1.  */
   ASSERT (d);
+  /* fdopendir should not close fd. */
+  ASSERT (dup2 (fd, fd) == fd);
+  /* We can't guarantee whether dirfd returns fd,
+     some other descriptor, or -1. */
   ASSERT (closedir (d) == 0);
   /* Now we can guarantee that fd must be closed.  */
   errno = 0;


reply via email to

[Prev in Thread] Current Thread [Next in Thread]