Page MenuHomeFreeBSD

realpath: Improve prev_len logic
ClosedPublic

Authored by des on Wed, Mar 18, 1:33 PM.

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 Not Applicable
Unit
Tests Not Applicable

Event Timeline

des requested review of this revision.Wed, Mar 18, 1:33 PM
kevans added a subscriber: kevans.
kevans added inline comments.
lib/libc/stdlib/realpath.3
84 ↗(On Diff #173850)

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.Thu, Mar 19, 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.Thu, Mar 19, 12:30 AM
This revision is now accepted and ready to land.Thu, Mar 19, 12:31 AM
This revision was automatically updated to reflect the committed changes.