Add getlocalename_l(3).
This commit is contained in:
parent
8618c1adf5
commit
8f68ea49ce
3 changed files with 51 additions and 5 deletions
|
@ -64,12 +64,29 @@ struct lconv
|
||||||
#define LC_ALL 6
|
#define LC_ALL 6
|
||||||
#define LC_NUM_CATEGORIES LC_ALL
|
#define LC_NUM_CATEGORIES LC_ALL
|
||||||
|
|
||||||
|
#if __USE_SORTIX || __USE_POSIX
|
||||||
|
#define LC_GLOBAL_LOCALE ((locale_t) -1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if __USE_SORTIX || __USE_POSIX
|
||||||
|
#ifndef __locale_t_defined
|
||||||
|
#define __locale_t_defined
|
||||||
|
/* TODO: figure out what this does and typedef it properly. This is just a
|
||||||
|
temporary assignment. */
|
||||||
|
typedef int __locale_t;
|
||||||
|
typedef __locale_t locale_t;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char* setlocale(int category, const char* locale);
|
char* setlocale(int category, const char* locale);
|
||||||
struct lconv* localeconv(void);
|
struct lconv* localeconv(void);
|
||||||
|
#if __USE_SORTIX || 202405L <= __USE_POSIX
|
||||||
|
const char* getlocalename_l(int, locale_t);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
|
|
29
libc/locale/getlocalename_l.c
Normal file
29
libc/locale/getlocalename_l.c
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024 Jonas 'Sortie' Termansen.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*
|
||||||
|
* locale/getlocalename_l.c
|
||||||
|
* Get locale name.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <locale.h>
|
||||||
|
|
||||||
|
extern char* __current_locales[LC_NUM_CATEGORIES];
|
||||||
|
|
||||||
|
const char* getlocalename_l(int cat, locale_t locale)
|
||||||
|
{
|
||||||
|
assert(locale == LC_GLOBAL_LOCALE);
|
||||||
|
return __current_locales[cat] ? __current_locales[cat] : (char*) "C";
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2014, 2015 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2012, 2014, 2015, 2024 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
static char* current_locales[LC_NUM_CATEGORIES] = { NULL };
|
char* __current_locales[LC_NUM_CATEGORIES] = { NULL };
|
||||||
|
|
||||||
char* setlocale(int category, const char* locale)
|
char* setlocale(int category, const char* locale)
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,7 @@ char* setlocale(int category, const char* locale)
|
||||||
int from = category != LC_ALL ? category : 0;
|
int from = category != LC_ALL ? category : 0;
|
||||||
int to = category != LC_ALL ? category : LC_NUM_CATEGORIES - 1;
|
int to = category != LC_ALL ? category : LC_NUM_CATEGORIES - 1;
|
||||||
if ( !locale )
|
if ( !locale )
|
||||||
return current_locales[to] ? current_locales[to] : (char*) "C";
|
return __current_locales[to] ? __current_locales[to] : (char*) "C";
|
||||||
for ( int i = from; i <= to; i++ )
|
for ( int i = from; i <= to; i++ )
|
||||||
{
|
{
|
||||||
if ( !(new_strings[i] = strdup(locale)) )
|
if ( !(new_strings[i] = strdup(locale)) )
|
||||||
|
@ -44,8 +44,8 @@ char* setlocale(int category, const char* locale)
|
||||||
}
|
}
|
||||||
for ( int i = from; i <= to; i++ )
|
for ( int i = from; i <= to; i++ )
|
||||||
{
|
{
|
||||||
free(current_locales[i]);
|
free(__current_locales[i]);
|
||||||
current_locales[i] = new_strings[i];
|
__current_locales[i] = new_strings[i];
|
||||||
}
|
}
|
||||||
return (char*) locale;
|
return (char*) locale;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue