mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
use setlocale() before nl_langinfo()
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37057 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d606538c6f
commit
bb57e65aa2
1 changed files with 12 additions and 1 deletions
|
@ -48,6 +48,9 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#if HAVE_LOCALE_H
|
||||
#include <locale.h>
|
||||
#endif
|
||||
#if HAVE_LANGINFO_CODESET
|
||||
#include <langinfo.h>
|
||||
#endif
|
||||
|
@ -2558,11 +2561,19 @@ GSPrivateDefaultCStringEncoding()
|
|||
|
||||
if (natEnc == GSUndefinedEncoding)
|
||||
{
|
||||
|
||||
/* Encoding not set */
|
||||
#if HAVE_LANGINFO_CODESET
|
||||
char *old;
|
||||
/* Take it from the system locale information. */
|
||||
[gnustep_global_lock lock];
|
||||
/* Initialise locale system by setting current locale from
|
||||
* environment and then resetting it. Must be done before
|
||||
* any call to nl_langinfo()
|
||||
*/
|
||||
if (0 != (old = setlocale(LC_CTYPE, "")))
|
||||
{
|
||||
setlocale(LC_CTYPE, old);
|
||||
}
|
||||
strncpy(encbuf, nl_langinfo(CODESET), sizeof(encbuf)-1);
|
||||
encbuf[sizeof(encbuf)-1] = '\0';
|
||||
[gnustep_global_lock unlock];
|
||||
|
|
Loading…
Reference in a new issue