Repository navigation
Description
Problem
path_dirname_len removes the separator immediately before a basename, preserving a root only when the separator is at index zero. A drive root such as C:\ has its separator at index two, so a file immediately below that root produces the prefix C: instead of C:\.
path_dirname_copy copies that prefix unchanged. This changes the meaning of the result: a Windows drive-relative path is not the root directory of that drive.
Code references:
- std/path/analyze.wave — path_basename_start and path_dirname_len
- std/path/copy.wave — path_dirname_copy
- std/path/core.wave — existing separator and path policy
- Microsoft: Windows file path formats and drive-relative paths
Source-derived regression cases
Use an adequately sized output buffer so capacity handling is not the cause of failure.
| Input | Current directory prefix | Expected under Windows path semantics |
|---|---|---|
C:\config.ini |
C: |
C:\ |
C:/config.ini |
C: |
C:/ |
C:\dir\config.ini |
C:\dir |
C:\dir |
/config.ini |
/ |
/ |
For C:\config.ini, the basename starts at index 3. The scan removes the separator at index 2 and returns length 2; it must retain the three-byte drive root. These are regression inputs derived from the current code, not a recorded native Windows execution.
Scope
Preserve the root boundary when computing directory-prefix lengths under Windows path semantics. Keep length calculation and copying consistent, including the returned byte count and NUL terminator.
Do not implement the fix by interpreting every second-character colon as a drive. Use a valid drive prefix and keep target-specific behavior explicit. POSIX filename interpretation should not acquire Windows drive semantics accidentally.
Completion criteria
- Windows drive-rooted inputs retain the root separator for both
\and/forms. - Cover uppercase and lowercase drive letters, files directly below the root, and ordinary nested directories.
- Keep drive-relative inputs distinct from drive-rooted inputs; never turn
C:config.iniinto a fully qualified root path. - Assert directory-prefix length, exact copied bytes, returned length, and NUL termination in runnable regressions.
- Include exact-fit and insufficient-capacity cases for the newly preserved drive-root result, without writing past the destination.
- Preserve POSIX roots, ordinary relative names, and existing non-root directory results under the applicable path policy.
- Keep public signatures unchanged and document the root-preservation behavior briefly.
Related: #529 owns path_is_abs classification. This issue owns dirname generation, which does not call that classifier. #521 owns the separate insufficient-capacity dot fallback, and #592 owns trailing-separator basename behavior. Do not expand this fix into those independent changes.
Activity
Fix numeric lowering and standard-library boundary handling (wavefnd#707