Subject: Re: [boost] Environment Variables Library?
From: Peter Dimov (lists_at_[hidden])
Date: 2015-05-24 14:08:08


Bjørn Roald wrote:
> > On POSIX, programs have to use the char* functions, because they don't
> > encode/decode and therefore guarantee a perfect round-trip.
>
> Right, but I question how much value that perfect round-trip has if the
> consumer have to guess the encoding. That is basically saying that I kept
> the encoding, therefore I am happy even if I may have lost the correct
> value.

You don't need to guess the encoding. When you get the contents of an
environment variable that identifies a file, you can then pass the string
exactly as-is to fopen, and it works regardless of encoding. That's because
POSIX functions are completely encoding-agnostic; they use null-terminated
byte sequences and do not interpret them as characters.

Of course, if you want to print the string, you need to guess an encoding.