HomeFreeBSD

touch: Fix setting time of created file if fstat() fails

Description

touch: Fix setting time of created file if fstat() fails

Previously, if creating the file and fstat() fails, we would've ended up
calling utimensat() on that file anyways with whatever was in sb. Not
that this is an error likely to happen...

We don't check for the return value of close() as we aren't writing
anything to the file and the file is always created on success of
open().

Reviewed by: kevans
Approved by: kevans
Fixes: cb54c500d0e1 ("touch: don't leak descriptor if fstat(2) fails")
Sponsored by: Klara, Inc.
Differential Revision: https://reviews.freebsd.org/D55117
MFC after: 1 week

Details

Provenance
obiwacAuthored on Feb 4 2026, 8:58 PM
Reviewer
rGcb54c500d0e1: touch: don't leak descriptor if fstat(2) fails
Differential Revision
D55117: touch: Fix setting time of created file if fstat() fails
Parents
rGcc702c78f70f: Unbreak the build
Branches
Unknown
Tags
Unknown