libs/libc/locale: Add getlocalename_l().

POSIX.1-2024 adds getlocalename_l(), which returns the name of the
locale of one category of a locale object.  NuttX supports only the "C"
locale, so the function returns "C" for every valid category, and NULL
with errno set to EINVAL for an invalid one.  It is built with
CONFIG_LIBC_LOCALE, like the other locale functions.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
This commit is contained in:
Marco Casaroli 2026-10-08 22:01:47 +02:00 • committed by Xiang Xiao
parent 314348cafe
commit dcc3b7b384
4 changed files with 71 additions and 2 deletions

View file

@ -117,6 +117,7 @@ locale_t duplocale(locale_t locobj);
void freelocale(locale_t locobj);
locale_t uselocale(locale_t newloc);
FAR const char *getlocalename_l(int category, locale_t locobj);
#undef EXTERN
#ifdef __cplusplus

View file

@ -33,5 +33,6 @@ if(CONFIG_LIBC_LOCALE)
lib_gettext.c
lib_langinfo.c
lib_iconv.c
lib_maxlocale.c)
lib_maxlocale.c
lib_getlocalename_l.c)
endif()

View file

@ -27,7 +27,7 @@ ifeq ($(CONFIG_LIBC_LOCALE),y)
CSRCS += lib_duplocale.c lib_freelocale.c lib_localeconv.c
CSRCS += lib_newlocale.c lib_setlocale.c lib_uselocale.c
CSRCS += lib_catalog.c lib_gettext.c lib_langinfo.c lib_iconv.c
CSRCS += lib_maxlocale.c
CSRCS += lib_maxlocale.c lib_getlocalename_l.c
# Add the locale directory to the build

View file

@ -0,0 +1,67 @@
/****************************************************************************
* libs/libc/locale/lib_getlocalename_l.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <errno.h>
#include <locale.h>
#include <stddef.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: getlocalename_l
*
* Description:
* Return the name of the locale of one category of a locale object
* (POSIX.1-2024). LC_GLOBAL_LOCALE means the global locale. NuttX
* supports only the "C" locale, so every category of every locale is
* "C".
*
* Input Parameters:
* category - LC_CTYPE, LC_NUMERIC, ... (not LC_ALL)
* locobj - A locale object, or LC_GLOBAL_LOCALE
*
* Returned Value:
* The name of the locale, or NULL with errno set to EINVAL if the
* category is not valid.
*
****************************************************************************/
FAR const char *getlocalename_l(int category, locale_t locobj)
{
UNUSED(locobj);
if (category < 0 || category >= LC_ALL)
{
set_errno(EINVAL);
return NULL;
}
return "C";
}