Skip to content

zig fmt rejects paths using forward slash instead of backslash on Windows #2668

Open

Description

@ErikMcClure

For some reason, attempting to use zig fmt will fail on windows if the path uses / instead of \:

PS D:\test> zig version
0.4.0+6d73e5de
PS D:\test> zig fmt ./src/schema.zig      
unable to open './src/schema.zig': error.BadPathName
PS D:\test> zig fmt .\src\schema.zig
PS D:\test>

No other part of zig cares if you use / or \ on windows (but linux will only accept /), so this seems like an oversight.

Activity

  1. FireFox317 commented on Jun 13, 2019

    @FireFox317
    Contributor

    Well, in the standard library of Zig it is mentioned that / is disallowed and since zig fmt is self-hosted and uses the std library it is not allowed. The following is said in the std/os/windows.zig:

    // > File I/O functions in the Windows API convert "/" to "" as part of
    // > converting the name to an NT-style name, except when using the "\?"
    // > prefix as detailed in the following sections.
    // from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation
    // Because we want the larger maximum path length for absolute paths, we
    // disallow forward slashes in zig std lib file functions on Windows.

    Maybe we should also disallow / in the rest of the compiler.

  2. ErikMcClure commented on Jun 14, 2019

    @ErikMcClure
    Author

    I would argue that this goes against how most tools in windows operate, which is accepting both / and \ in the file path arguments. However, as long as the behavior Zig chooses is consistent, it doesn't really matter.

  3. andrewrk commented on Jun 14, 2019

    @andrewrk
    Member

    I don't remember writing that comment, I'm going to audit this code

  4. added
    standard library
    on Jun 16, 2019
  5. added this to the 0.6.0 milestone on Jun 16, 2019
  6. emekoi commented on Jun 16, 2019

    @emekoi
    Contributor

    i'm pretty sure this is because zig isn't escaping the \ in the path name.

  7. added
    os-windows
    on Jan 7, 2020
  8. modified the milestones: 0.6.0, 0.7.0 on Jan 7, 2020
  9. BarabasGitHub commented on Mar 28, 2020

    @BarabasGitHub
    Contributor

    // Because we want the larger maximum path length for absolute paths, we
    // disallow forward slashes in zig std lib file functions on Windows.

    Ehm... just convert \ to /? It already has to copy and convert to utf16 anyway.

    It has to be handled somewhere at least.

  10. added a commit that references this issue on Apr 6, 2020
  11. modified the milestones: 0.7.0, 0.8.0 on Oct 30, 2020
  12. modified the milestones: 0.8.0, 0.9.0 on Nov 6, 2020
  13. modified the milestones: 0.9.0, 0.10.0 on May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    os-windowsstandard libraryzig fmt

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions