@@ -4385,45 +4385,31 @@ enc_alias_search(char_u *name)
43854385
43864386#if defined(FEAT_MBYTE ) || defined(PROTO )
43874387
4388- #ifdef HAVE_LANGINFO_H
4389- # include <langinfo.h>
4390- #endif
4388+ # ifdef HAVE_LANGINFO_H
4389+ # include <langinfo.h>
4390+ # endif
43914391
4392+ # ifndef FEAT_GUI_W32
43924393/*
4393- * Get the canonicalized encoding of the current locale.
4394+ * Get the canonicalized encoding from the specified locale string "locale"
4395+ * or from the environment variables LC_ALL, LC_CTYPE and LANG.
43944396 * Returns an allocated string when successful, NULL when not.
43954397 */
43964398 char_u *
4397- enc_locale ( void )
4399+ enc_locale_env ( char * locale )
43984400{
4399- #ifndef WIN3264
4400- char * s ;
4401+ char * s = locale ;
44014402 char * p ;
44024403 int i ;
4403- #endif
44044404 char buf [50 ];
4405- #ifdef WIN3264
4406- long acp = GetACP ();
44074405
4408- if (acp == 1200 )
4409- STRCPY (buf , "ucs-2le" );
4410- else if (acp == 1252 ) /* cp1252 is used as latin1 */
4411- STRCPY (buf , "latin1" );
4412- else
4413- sprintf (buf , "cp%ld" , acp );
4414- #else
4415- # ifdef HAVE_NL_LANGINFO_CODESET
4416- if ((s = nl_langinfo (CODESET )) == NULL || * s == NUL )
4417- # endif
4418- # if defined(HAVE_LOCALE_H ) || defined(X_LOCALE )
4419- if ((s = setlocale (LC_CTYPE , NULL )) == NULL || * s == NUL )
4420- # endif
4421- if ((s = getenv ("LC_ALL" )) == NULL || * s == NUL )
4422- if ((s = getenv ("LC_CTYPE" )) == NULL || * s == NUL )
4423- s = getenv ("LANG" );
4406+ if (s == NULL || * s == NUL )
4407+ if ((s = getenv ("LC_ALL" )) == NULL || * s == NUL )
4408+ if ((s = getenv ("LC_CTYPE" )) == NULL || * s == NUL )
4409+ s = getenv ("LANG" );
44244410
44254411 if (s == NULL || * s == NUL )
4426- return FAIL ;
4412+ return NULL ;
44274413
44284414 /* The most generic locale format is:
44294415 * language[_territory][.codeset][@modifier][+special][,[sponsor][_revision]]
@@ -4458,12 +4444,46 @@ enc_locale(void)
44584444 break ;
44594445 }
44604446 buf [i ] = NUL ;
4461- #endif
44624447
44634448 return enc_canonize ((char_u * )buf );
44644449}
4450+ # endif
4451+
4452+ /*
4453+ * Get the canonicalized encoding of the current locale.
4454+ * Returns an allocated string when successful, NULL when not.
4455+ */
4456+ char_u *
4457+ enc_locale (void )
4458+ {
4459+ # ifdef WIN3264
4460+ char buf [50 ];
4461+ long acp = GetACP ();
4462+
4463+ if (acp == 1200 )
4464+ STRCPY (buf , "ucs-2le" );
4465+ else if (acp == 1252 ) /* cp1252 is used as latin1 */
4466+ STRCPY (buf , "latin1" );
4467+ else
4468+ sprintf (buf , "cp%ld" , acp );
4469+
4470+ return enc_canonize ((char_u * )buf );
4471+ # else
4472+ char * s ;
4473+
4474+ # ifdef HAVE_NL_LANGINFO_CODESET
4475+ if ((s = nl_langinfo (CODESET )) == NULL || * s == NUL )
4476+ # endif
4477+ # if defined(HAVE_LOCALE_H ) || defined(X_LOCALE )
4478+ if ((s = setlocale (LC_CTYPE , NULL )) == NULL || * s == NUL )
4479+ # endif
4480+ s = NULL ;
4481+
4482+ return enc_locale_env (s );
4483+ # endif
4484+ }
44654485
4466- #if defined(WIN3264 ) || defined(PROTO ) || defined(FEAT_CYGWIN_WIN32_CLIPBOARD )
4486+ # if defined(WIN3264 ) || defined(PROTO ) || defined(FEAT_CYGWIN_WIN32_CLIPBOARD )
44674487/*
44684488 * Convert an encoding name to an MS-Windows codepage.
44694489 * Returns zero if no codepage can be figured out.
@@ -4490,7 +4510,7 @@ encname2codepage(char_u *name)
44904510 return cp ;
44914511 return 0 ;
44924512}
4493- #endif
4513+ # endif
44944514
44954515# if defined(USE_ICONV ) || defined(PROTO )
44964516
0 commit comments