posixfile.cpp: remove redundant realpath() call #13845
Open
+1
−7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Commit 1bd116c makes use of the allocating mode of
realpath()
by duplicating therealpath()
invocation already done (i.e. with the same input path). In practice, if therealpath()
invocation withnullptr
fails, therealpath()
invocation with a destination buffer is very likely to fail in the same way.Hence drop the
realpath()
invocation with a destination buffer, and move therealpath()
invocation withnullptr
in the existingif
/else if
chain to maintain the existingbehaviour
.Since
path_buffer
now is needed only for the fallbackgetcwd()
invocation, move it in the inner scope where it is used. Since the usage ofgetcwd()
already has a growing buffer logic, make the initial buffer size shorter, which should be enough to get current working directory already at the first attempt in most of the cases.