Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Nov 2024 21:11:50 +0000
From:      bugzilla-noreply@freebsd.org
To:        standards@FreeBSD.org
Subject:   [Bug 283014] POSIX issue 7: fileno should be able to fail with EBADF
Message-ID:  <bug-283014-99@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D283014

            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: standards@FreeBSD.org
          Reporter: gperciva@tarsnap.com

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
>=20
> ... Otherwise, the value -1 shall be returned and errno set to indicate t=
he error.
>=20
> 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=20
#include <errno.h>
#include <stdio.h>

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

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

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

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

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-283014-99>