bug-gnulib
[Top][All Lists]
Advanced

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

Re: fdopen on MSVC


From: Bruno Haible
Subject: Re: fdopen on MSVC
Date: Tue, 27 Sep 2011 00:40:47 +0200
User-agent: KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; )

Hi Eric,

> If fdopen(-1,"r") returns anything besides NULL in the first place, then 
> that is a bug in fdopen().

Nope. POSIX:2008 says in
<http://pubs.opengroup.org/onlinepubs/9699919799/functions/fdopen.html>:

  "The fdopen() function MAY fail if:
      [EBADF]
          The fildes argument is not a valid file descriptor."

This means, fdopen(-1,"r") is also allowed to return a pointer to a stream,
that will try to read from an invalid file descriptor at each read operation.
The unit test is verifying that these read operations will fail with EBADF.

>    {
>      FILE *fp = fdopen (-1, "r");
>      if (fp != NULL)
>        {
>          errno = 0;
>          ASSERT (fclose (fp) == EOF);
>          ASSERT (errno == EBADF);
>        }
>    }
> 
> since fp should be NULL at this point, and thus a compliant system won't 
> be testing fclose() behavior in the first place.

On glibc systems (and probably many others as well), the invalid file
descriptor is already caught by fdopen(). But there is no guarantee that
all systems do this.

Bruno
-- 
In memoriam Pavlos Bakoyannis <http://en.wikipedia.org/wiki/Pavlos_Bakoyannis>



reply via email to

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