| 1 |
/* Determine name of the currently selected locale. |
| 2 |
Copyright (C) 1995-2025 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is free software: you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU Lesser General Public License as |
| 6 |
published by the Free Software Foundation; either version 2.1 of the |
| 7 |
License, or (at your option) any later version. |
| 8 |
|
| 9 |
This file is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU Lesser General Public License for more details. |
| 13 |
|
| 14 |
You should have received a copy of the GNU Lesser General Public License |
| 15 |
along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
| 16 |
|
| 17 |
/* Written by Ulrich Drepper <[email protected]>, 1995. */ |
| 18 |
|
| 19 |
#include <config.h> |
| 20 |
|
| 21 |
/* Specification. */ |
| 22 |
#include "localename.h" |
| 23 |
|
| 24 |
#include <stdlib.h> |
| 25 |
#include <string.h> |
| 26 |
|
| 27 |
const char * |
| 28 |
gl_locale_name_environ (_GL_UNUSED int category, const char *categoryname) |
| 29 |
{ |
| 30 |
const char *retval; |
| 31 |
|
| 32 |
/* Setting of LC_ALL overrides all other. */ |
| 33 |
retval = getenv ("LC_ALL"); |
| 34 |
if (retval != NULL && retval[0] != '\0') |
| 35 |
return retval; |
| 36 |
/* Next comes the name of the desired category. */ |
| 37 |
retval = getenv (categoryname); |
| 38 |
if (retval != NULL && retval[0] != '\0') |
| 39 |
return retval; |
| 40 |
/* Last possibility is the LANG environment variable. */ |
| 41 |
retval = getenv ("LANG"); |
| 42 |
if (retval != NULL && retval[0] != '\0') |
| 43 |
{ |
| 44 |
#if HAVE_CFPREFERENCESCOPYAPPVALUE |
| 45 |
/* Mac OS X 10.2 or newer. |
| 46 |
Ignore invalid LANG value set by the Terminal application. */ |
| 47 |
if (strcmp (retval, "UTF-8") != 0) |
| 48 |
#endif |
| 49 |
#if defined __CYGWIN__ |
| 50 |
/* Cygwin. |
| 51 |
Ignore dummy LANG value set by ~/.profile. */ |
| 52 |
if (strcmp (retval, "C.UTF-8") != 0) |
| 53 |
#endif |
| 54 |
return retval; |
| 55 |
} |
| 56 |
|
| 57 |
return NULL; |
| 58 |
} |