Locale and strerror in libgcj's native code...

David Daney ddaney@avtrex.com
Wed Aug 11 17:18:00 GMT 2004

In several places within the native code in libgcj, we have constructs
like this:

throw new IOException (JvNewStringUTF (strerror (errno)));


throw new IOException (JvNewStringLatin1 (strerror (errno)));

According to my reading of the man pages, strerror returns a string
according to the LC_MESSAGES encoding.

This means that the actual encoding is not known until runtime.  So at
compile time it is impossible to know which JvNewString* function to
use.  It seems to me that using a mix (as we currently do) is clearly
wrong and only works in with ASCII encoding.

Perhaps we should have a JvNewStringLocale(const char *) that assumes
the encoding is as specified by LC_MESSAGES.

For the time being, I am using JvNewStringUTF as that seems to be what
my Fedora Core 1 system defaults to.

David Daney.

More information about the Java mailing list