1 /* Determine name of the currently selected locale.
2 Copyright (C) 1995-2024 Free Software Foundation, Inc.
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.
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.
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/>. */
17 /* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
18 optimizes away the locale == NULL tests below in duplocale() and freelocale(),
19 or xlclang reports -Wtautological-pointer-compare warnings for these tests.
21 #define _GL_ARG_NONNULL(params)
26 #include "localename.h"
33 #include "flexmember.h"
34 #include "glthread/lock.h"
35 #include "thread-optim.h"
38 /* Define a local struniq() function. */
42 gl_locale_name_thread (int category
, const char *categoryname
)
44 if (category
== LC_ALL
)
45 /* Invalid argument. */
47 const char *name
= gl_locale_name_thread_unsafe (category
, categoryname
);
49 return struniq (name
);
54 gl_locale_name_posix (int category
, const char *categoryname
)
56 if (category
== LC_ALL
)
57 /* Invalid argument. */
59 const char *name
= gl_locale_name_posix_unsafe (category
, categoryname
);
61 return struniq (name
);
65 /* Determine the current locale's name, and canonicalize it into XPG syntax
66 language[_territory][.codeset][@modifier]
67 The codeset part in the result is not reliable; the locale_charset()
68 should be used for codeset information instead.
69 The result must not be freed; it is statically allocated. */
72 gl_locale_name (int category
, const char *categoryname
)
76 if (category
== LC_ALL
)
77 /* Invalid argument. */
80 retval
= gl_locale_name_thread (category
, categoryname
);
84 retval
= gl_locale_name_posix (category
, categoryname
);
88 return gl_locale_name_default ();