Skip to content

Instantly share code, notes, and snippets.

@Artoria2e5
Created May 19, 2021 02:48
Show Gist options
  • Save Artoria2e5/8ecf02091b6603806d372e2af8937055 to your computer and use it in GitHub Desktop.
Save Artoria2e5/8ecf02091b6603806d372e2af8937055 to your computer and use it in GitHub Desktop.
glob(3) for winpaths

Instead of writing stuff I decided to chicken out and talk.

Anyways, Windows paths use \ as the path separator. You might see it as horrible (it is), but for globbing it is actually fine since ? and * are disallowed in filenames. You will still need to escape [ and the extglob (, but recall that | is disallowed too so you can just use that as the escape character.

You may or may not need to have a compile step to convert this glob into actual glob(7). For that you just replace all instances of \ with /, and all instances of | with \. The drivename handling will depend on the environment at hand; for Cygwin-based systems, you have:

  • (\\\\\?\)^([A-Z]): becomes /proc/cygdrive/$2
  • ^\\\\: becomes //

This replacement with cygdrive will inflate the string size and make it impossible to do it in-place, so I recommend not doing it if possible.

@Artoria2e5
Copy link
Author

why am I going thru my own gists?

well. I've got the code written out at https://cygwin.com/pipermail/cygwin-patches/2021q2/011367.html. I got lost in code review as one always do. there might even be a Cygwin GitHub PR I'm too ashamed to link to, which contains more mentions to this stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment