HomeFreeBSD

libc: Improve POSIX conformance of dirfd()

Description

libc: Improve POSIX conformance of dirfd()

POSIX states that dirfd() should set errno to EINVAL and return -1 if
dirp does not refer to a valid directory stream. Our interpretation is
that this applies if dirp is null or the file descriptor associated
with it is negative.

MFC after: 1 week
Sponsored by: Klara, Inc.
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D55025

(cherry picked from commit 5074d5c9845e142883cdbb9ad212be66e57615d0)

libc: Fix missing include

Although not needed on FreeBSD due to namespace pollution, we should
technically #include <stddef.h> to secure a definition of NULL.

Fixes: 5074d5c9845e ("libc: Improve POSIX conformance of dirfd()")
(cherry picked from commit 1c00d5a3b234ef937d848956027e9de5ea8010f9)

Details

Provenance
desAuthored on Feb 2 2026, 3:46 PM
Reviewer
markj
Differential Revision
D55025: libc: Improve POSIX conformance of dirfd()
Parents
rGb614c9893fa3: libc: Clean up *dir() code
Branches
Unknown
Tags
Unknown