Skip to content

Preserve Windows drive roots when computing path directory names #677

Closed

Description

@LunaStev

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:

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.ini into 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

  1. added
    bug
    help wanted
    needs testing
    cross-platform
    on Sep 21, 2026
  2. self-assigned this
    on Sep 24, 2026
  3. added a commit that references this issue on Sep 24, 2026
    01955d7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugcross-platformhelp wantedneeds testing

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions