[Bug 283014] POSIX issue 7: fileno should be able to fail with EBADF

[email protected]
Newsgroups gmane.os.freebsd.devel.standards
Message-ID <[email protected]/bugzilla/>
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=283014

            Bug ID: 283014
           Summary: POSIX issue 7: fileno should be able to fail with
                    EBADF
           Product: Base System
           Version: CURRENT
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: standards
          Assignee: [email protected]
          Reporter: [email protected]

Nitpicky issue.  Currently, FreeBSD's fileno() does not set errno.

POSIX issue 6 added an optional EBADF errno, so no problem there.

Issue 7 added a mandatory EBADF:
> RETURN VALUE
> 
> ... Otherwise, the value -1 shall be returned and errno set to indicate the error.
> 
> ERRORS
>
> The fileno() function shall fail if:
>
> [EBADF]
> The stream is not associated with a file.

https://pubs.opengroup.org/onlinepubs/9799919799/functions/fileno.html

(Issue 8 did not alter fileno.)


Code example, in case it's helpful:
```
$ cat bad-fileno.c 
#include <errno.h>
#include <stdio.h>

int
main(void) {
        FILE * s;
        int rc;

        /* Get an invalid stream. */
        s = fopen("/dev/null", "r");
        fclose(s);

        /* Set errno to an arbitrary value. */
        errno = 123;
        printf("errno: %i\n", errno);

        /* errno is still that arbitrary value; rc is correct. */
        rc = fileno(s);
        printf("rc %i, errno: %i\n", rc, errno);
}
$ clang -Weverything bad-fileno.c && ./a.out 
errno: 123
rc -1, errno: 123
$
```

-- 
You are receiving this mail because:
You are the assignee for the bug.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.