feat(libc): implement dirname #3261
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3261"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T04:01:49Z.
What
Implement the missing
dirnamepath operation with FreeBSD-style handling of empty paths, trailing slashes, root paths, and paths without a parent component. It accepts aconst char*, returns the result in thread-local storage, and leaves the caller's input unchanged, so string literals are safe. The missing import is listed in #1578.This re-submits the reviewed implementation from closed #1761 after the title evidence changed. Porpoise (PPSA99764) now reaches
dirnameafter #3190–#3192 and stops at NIDE4wZaG1zSFcon Linux and Windows.dirnameremains absent on currentmain, and no other open PR implements it.Tested
Linux x86-64, GCC 12.2, Release, current
main(7f1dc965): clean CMake configuration; builtguest_string_tests;guest_stringspassed (1/1). The cases include literal input, unchanged input, and an overlong path returning null with errno 63.python3 tools/check_conventions.py --base upstream/mainandgit diff upstream/main...HEAD --checkpass.Windows and PS5 hardware were not tested.
Checklist
main; no other open PR implements this functionImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T04:02:09Z.
Progress report (
7f1dc96→bde2167)📈 System libraries: 86.01% (+0.01%, +1 implemented functions)
✅ 1 implemented
dirname_nid_postfixImported from boykopovar/AnyPS5. Originally posted by sktharunbalaji13-cmd on 2026-10-11T04:24:54Z.
I independently compared the implementation's behavior with the FreeBSD
dirnamereference and didn't find a return-value mismatch in the cases I checked. Thanks for keeping the implementation focused.One small test-coverage suggestion: could we add cases such as
one//two→oneand/one//two→/one? These exercise multiple iterations of the repeated-separator collapse loop, which doesn't appear to be covered by the current assertions.The single-root path
/and a trailing-slash path such asfoo/would also be useful explicit boundary tests.I couldn't compile the C++ target in my local environment, so this is a test-coverage suggestion rather than a claim that the implementation is defective.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T04:41:39Z.
Added the requested
dirnameboundary coverage in commitdbb2b8381:one//twoone/one//two/one//foo/.Built
guest_string_testswith GCC 12.2 Release and ranguest_strings(1/1 passed). The conventions check andgit diff --checkalso pass. The existing PR CI will rerun on this head.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T05:05:51Z.
dirnamewrites into the caller's string and returns it (StringExtensions.cpp:51,:60). Please copy the result into athread_localbuffer and leavepathuntouched, the waybasename_nid_postfixabove it does (too long:errno63 and null). That is FreeBSD 11'schar *dirname(const char *); a title passing a literal would fault on the write here. The test should then check thatone/two///is unchanged after the call.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T05:12:38Z.
Updated this PR to match FreeBSD's
dirname(const char*)contract:one/two///is unchanged.basename_nid_postfix.After rebasing onto current
main(7f1dc965), a clean Linux GCC 12.2 Release build ofguest_string_testssucceeded andguest_stringspasses (1/1). The conventions check andgit diff --checkpass.Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-11T07:19:53Z.
Additional platform validation of standalone PR head
bde216731e4efd6c49021c0f22add8679b4e4182(2026-10-11):Windows: passed — Windows 11, WinLibs GCC 15.2.0 UCRT/POSIX/SEH r7; CMake 4.3.1 / Ninja; Release,
BUILD_TESTING=ON.1 checks, 0 failures, 0 CTest skips. Built the selected targets and dependencies; this is focused validation, not a full build or full-suite run.
Checks:
guest_strings.Command after building:
ctest --test-dir <build> --verbose --no-tests=error --timeout 30 -R "^guest_strings$".No title/gameplay validation. These results cover the standalone head, not a merge with current main.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:25:36Z.
Checked the FreeBSD
dirname(const char *)contract (input untouched, thread-local result, empty/NULL →., trailing and repeated separators, root), theerrno63 path matchingbasename, and that the new test fails to link without the change. Builtguest_string_testsand ran the libs ctest scope on currentmain(66/66 pass,guest_stringsincluded). Dean's earlier request is addressed. Merging.