Page MenuHomeFreeBSD

realpath: Improve prev_len logic
ClosedPublic

Authored by des on Mar 18 2026, 1:33 PM.
Tags
None
Referenced Files
F166853409: D55914.diff
Mon, Aug 17, 3:36 AM
Unknown Object (File)
Wed, Aug 12, 6:08 PM
Unknown Object (File)
Mon, Aug 10, 7:39 AM
Unknown Object (File)
Sun, Aug 9, 4:29 PM
Unknown Object (File)
Sun, Aug 9, 3:42 PM
Unknown Object (File)
Sun, Aug 9, 3:42 PM
Unknown Object (File)
Sun, Aug 9, 2:53 AM
Unknown Object (File)
Sat, Aug 8, 2:59 AM
Subscribers

Details

Summary
  • Save prev_len after having checked for and appended a trailing slash, not before. This requires us to back up if we end up returning a partial result, but previously we would sometimes return a partial result with a trailing slash and sometimes without.
  • Replace strlcat() with a faster strlcpy() since we know exactly how far into the buffer we are.

MFC after: 1 week
Sponsored by: Klara, Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 71482
Build 68365: arc lint + arc unit

Event Timeline

des requested review of this revision.Mar 18 2026, 1:33 PM
kevans added a subscriber: kevans.
kevans added inline comments.
lib/libc/stdlib/realpath.3
84

I'd be tempted to rephrase this just a little more, because right now the implied part is the important part:

or a pointer to a null-terminated string that the caller must
.Xr free 3
if it was.
This revision is now accepted and ready to land.Mar 19 2026, 12:14 AM

I'm also tempted to drop the CAVEATS section, which does not seem useful as realpath(3) was standardized by POSIX in 1994 and I'm sure Solaris / Illumos also always returns an absolute path.

Split man page changes off into D55928

This revision now requires review to proceed.Mar 19 2026, 12:30 AM
This revision is now accepted and ready to land.Mar 19 2026, 12:31 AM
This revision was automatically updated to reflect the committed changes.