this post was submitted on 24 Sep 2023
34 points (92.5% liked)

Programming

17667 readers
260 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 2 years ago
MODERATORS
top 4 comments
sorted by: hot top controversial new old
[–] [email protected] 20 points 1 year ago* (last edited 1 year ago)

How are we still not past three-splitting content…

It's not as shit as twitter UI/UX/Accessibility - but this mastodon split-post doesn't make me feel much better.

/edit: Actually, it's a 5-split.


I'll do what lemmy-post-OP didn't and copy the content for accessibility:

Ashley Gullen:

If you thought JavaScript was a mess, here's what it takes to pass a file path to a Windows API in C++: 🧵

  1. Windows uses UTF-16, but most modern software uses UTF-8
  2. Converting UTF-8 to UTF-16 requires calling MultiByteToWideChar twice (once for size, second to convert)
  3. Alternatively you can set the process code page to UTF-8 and call the 'A' variant API directly, but only sometimes, and only with Windows 10 v1903+, and you might still have to change the system locale setting and reboot
  4. Now you can pass a file path! But...
  5. The path is limited to MAX_PATH (260 chars)
  6. Unless you prefix the path with \\?\
  7. However using \\?\ disables automatic conversion of / to \ in the path (and some other normalization)
  8. Alternatively set a reg key LongPathsEnabled, but only with Windows 10 v1607+ and the app needs to opt in to longPathAware, and changing the registry might need a reboot
  9. Even then not all Windows APIs support longer paths, e.g. PathCanonicalize. Swap for PathCchCanonicalizeEx with PATHCCH_ALLOW_LONG_PATHS, etc. Check docs per API.
  10. Congratulations, your app can pass a long file path to Windows! But the shell still doesn't support long paths. So your app can write to long paths, but you can't access them with Windows Explorer. Even in Windows 11.
  11. If the API returns a path, do all that in reverse.

I probably missed a few other details and quirks.

References:

See also individual APIs e.g. https://learn.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-pathcanonicalizea

Unrelated promotional text and link

[–] [email protected] 5 points 1 year ago (2 children)

I assume this is not thr case for Linux

[–] [email protected] 20 points 1 year ago* (last edited 1 year ago)

Linux APIs are 8bit, instead of 16bit, however the filesystem encoding can be anything if the user wants.

In practice we all use UTF-8 but correct software has to encode to the correct one just in case.

There is also still a max path length, but it’s longer like 4096.

[–] [email protected] 7 points 1 year ago* (last edited 1 year ago)

It's better and worse at the same time: it just doesn't bother with it for the most part. If you have files named with UTF-8 characters, and run it with a locale that uses an ISO-whatever charset, it just displays them wrong. As long as the byte is not a zero or an ASCII forward slash, it'll take it.

There's still a path length limit but it's bigger: 255 bytes for filenames and 4096 bytes for a whole path. That's bytes, not characters. So if you use UTF-16 like on Windows, those numbers are halved.

That said, it's assumed to be UTF-8 these days and should be interpreted as UTF-8, nobody uses non-UTF-8 locales anymore. But you technically can.