in reply to Re^5: how are ARGV and filename strings represented?
in thread how are ARGV and filename strings represented?
I think it would be very nice to have a facility to know how to encode filesystem strings, and a library that performs that job so that doing it right is easier than not
The problem is that at least some filesystems just don't care about encoding:
There are many more filesystems, but I think these are still commonly in use on personal computers and PC-based servers.
As you can see, only a few filesystems use some variant of Unicode encoding for the filenames. The others use just bytes, with some "forbidden" values (eFAT), in some encoding that can not be derived from the filesystem. Userspace may decide to use UTF-8 or some legacy encoding on those filesystems.
As long as we stay in user space (as opposed to kernel space), we don't have to care much about the encoding. Converting the encoding is the job of the operating system. Legacy filesystems have their encoding set via mount options or the like.
Systems like Linux and the *BSDs just don't care about encoding, they treat filenames as null-terminated collections of bytes, just like Unix did since 1970. Modern Windows can treat filenames as Unicode when using the "wide API" (function names ending in a capital W) where all strings are using UCS-2 or UTF-16. When using the "ASCII API" (function names ending in a capital A), strings are using some legacy 8-bit encoding based on ASCII, the actual encoding used depends on user and regional settings. Plan 9 from Bell Labs used UTF-8 for the entire API. (I don't know how Apple handles filenames in their APIs.)
So, how should your proposed library handle file names?
On Windows, it should use the "wide API", period. Everything is Unicode (UTF-16/UCS-2). Same for Plan 9, but using UTF-8 encoding.
Linux and the BSDs? Everything is a null-terminated collection of bytes, maybe UTF-8, maybe some legacy encoding, and maybe also depending on where in the filesystem you are. How should your library handle that?
Oh, and let's not forget that Android is technically Linux, with a lot of custom user-space on top.
Mac OS X? I don't know the APIs, but it inherited a lot from Unix. So it propably looks like Unix.
I completely omitted other command line parameters, the environment, and I/O via STDIN/STDOUT/STDERR. Command line and environment are more or less just an API thing, like filenames. I/O is completely different. It lacks any information about the encoding and is treated as a byte stream on Unix. Windows treats it as a character stream with an unspecified 8-bit encoding, converting line endings as needed, but not characters.
See also Re^7: any use of 'use locale'? (source encoding).
Alexander
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: how are ARGV and filename strings represented?
by choroba (Cardinal) on May 05, 2024 at 15:11 UTC | |
|
Re^7: how are ARGV and filename strings represented?
by ikegami (Patriarch) on May 05, 2024 at 13:33 UTC | |
by afoken (Chancellor) on May 05, 2024 at 14:30 UTC | |
by NERDVANA (Priest) on May 08, 2024 at 02:07 UTC | |
by ikegami (Patriarch) on May 05, 2024 at 22:37 UTC | |
|
Re^7: how are ARGV and filename strings represented?
by afoken (Chancellor) on Oct 01, 2024 at 23:47 UTC | |
by jeffenstein (Hermit) on Oct 02, 2024 at 08:10 UTC | |
by afoken (Chancellor) on Oct 02, 2024 at 18:08 UTC |