+ wxString encname;
+
+#ifdef __WIN32__
+ // FIXME: what is the error return value for GetACP()?
+ UINT codepage = ::GetACP();
+ encname.Printf(_T("windows-%u"), codepage);
+#elif defined(__UNIX_LIKE__)
+
+#if defined(HAVE_LANGINFO_H) && defined(CODESET)
+ // GNU libc provides current character set this way (this conforms
+ // to Unix98)
+ char *oldLocale = strdup(setlocale(LC_CTYPE, NULL));
+ setlocale(LC_CTYPE, "");
+ char *alang = nl_langinfo(CODESET);
+ setlocale(LC_CTYPE, oldLocale);
+ free(oldLocale);
+ if (alang)
+ {
+ encname = wxConvLibc.cMB2WX(alang);
+ }
+ else
+#endif // HAVE_LANGINFO_H
+ {
+ // if we can't get at the character set directly, try to see if it's in
+ // the environment variables (in most cases this won't work, but I was
+ // out of ideas)
+ wxChar *lang = wxGetenv(wxT("LC_ALL"));
+ wxChar *dot = lang ? wxStrchr(lang, wxT('.')) : (wxChar *)NULL;
+ if (!dot)
+ {
+ lang = wxGetenv(wxT("LC_CTYPE"));
+ if ( lang )
+ dot = wxStrchr(lang, wxT('.'));
+ }
+ if (!dot)
+ {
+ lang = wxGetenv(wxT("LANG"));
+ if ( lang )
+ dot = wxStrchr(lang, wxT('.'));
+ }
+
+ if ( dot )
+ {
+ encname = dot+1;
+ }
+ }
+#endif // Win32/Unix
+
+ return encname;