Branch
Hash :
81ee5a4e
Author :
Date :
2025-02-22T18:11:38
getlocalename_l-unsafe: New module. * lib/getlocalename_l-unsafe.h: New file, based on lib/getlocalename_l.c. * lib/getlocalename_l-unsafe.c: New file. * lib/getlocalename_l.c: Most code moved to lib/getlocalename_l-unsafe.c. (getlocalename_l): Implement based on getlocalename_l_unsafe. * m4/getlocalename_l.m4 (gl_FUNC_GETLOCALENAME_L_UNSAFE, gl_PREREQ_GETLOCALENAME_L_UNSAFE): New macros. (gl_FUNC_GETLOCALENAME_L_SIMPLE): Require gl_FUNC_GETLOCALENAME_L_UNSAFE. (gl_PREREQ_GETLOCALENAME_L_SIMPLE): Now empty. * modules/getlocalename_l-unsafe: New file. * modules/getlocalename_l-simple (Files): Remove lib/localename-table.h, lib/localename-table.c, m4/intl-thread-locale.m4. (Depends-on): Add getlocalename_l-unsafe. Remove setlocale-messages, setlocale-null, free-posix. (Makefile.am): Don't compile localename-table.c.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
/* Return name of a single locale category.
Copyright (C) 1995-2025 Free Software Foundation, Inc.
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <config.h>
/* Specification. */
#include <locale.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include "getlocalename_l-unsafe.h"
#include "flexmember.h"
#include "glthread/lock.h"
#include "thread-optim.h"
/* Define a local struniq() function. */
#include "struniq.h"
const char *
getlocalename_l (int category, locale_t locale)
{
if (category == LC_ALL)
/* Unsupported in this simple implementation. */
abort ();
struct string_with_storage ret = getlocalename_l_unsafe (category, locale);
/* Return the result as a string of indefinite extent.
In the case (ret.storage == STORAGE_GLOBAL) this is required because
POSIX says that
"the returned string pointer might be invalidated or the string content
might be overwritten by a subsequent call in the same thread to
getlocalename_l() with LC_GLOBAL_LOCALE"
and a setlocale_null call in a different thread would also invalidate
the result. For the other cases, it's a convenience to avoid undefined
behaviour in the calling program. */
return (ret.storage != STORAGE_INDEFINITE
? struniq (ret.value)
: ret.value);
}