emacs-devel
[Top][All Lists]
Advanced

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

Re: Compiling in mingw-ucrt runtime


From: Bruno Haible
Subject: Re: Compiling in mingw-ucrt runtime
Date: Sun, 25 Feb 2024 15:11:22 +0100

Eli Zaretskii wrote:
> > > OK, but I asked also about the value of errno _after_ fclose is called
> > > and fails.  It's important for understanding why it fails.

On native Windows, the value of errno, after fclose() fails, is undefined.
See here in the Gnulib documentation:
https://www.gnu.org/software/gnulib/manual/html_node/fclose.html

and here in the Microsoft documentation:
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fclose-fcloseall
(it sets errno only if the argument was a NULL pointer).

> > int
> > close_stream (FILE *stream)
> > {
> >   ...
> >   if (prev_fail || (fclose_fail && (some_pending || errno != EBADF)))
> >     {
> >       if (! fclose_fail)
> >         errno = 0;
> >       return EOF;
> >     }
> > 
> >   return 0;
> > }

This code assumes that errno has a reasonable value after fclose() fails,
and is thus not portable to native Windows.

Let me see what I can do about it on the Gnulib side...

> Why does fclose fail, leaving errno at -1?

I cannot tell why fclose() failed in the first place.

Bruno






reply via email to

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