This is the mail archive of the
libc-alpha@sourceware.cygnus.com
mailing list for the glibc project.
Re: fdopen and errno
Momchil 'Velco' Velikov wrote:
> Mark Kettenis wrote:
> > to indicate the error. Thus for Unix98 compatibility we should
> > probably set errno. It looks as if we already detect EBADF and ENOMEM (I
> > don't think we will ever encounter a condition that should generate
> > EMFILE in glibc), and EINVAL in the case of a totally bogus mode
> > specification. We should probably set errno to EINVAL as well if the
> > stream mode doesn't match the access mode.
> I'd suggest to set the errno to EBADF in order to be consistent
> with other functions, which report an error on incompatible open mode.
> Some of these functions are read(2) and write(2).
> Also, stdio sets EBADF in this case.
> IMHO, EINVAL is more applicable to bogus arguments, e.g. mode == "ix".
It would be more informative if fdopen() could distinguish between the cases:
EBADF - Not an open file descriptor
EACCES - Requested access mode incompatible with file descriptor mode
Although unfortunately read(2), write(2) don't make any such distinction.
Ben