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