Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / locale / getlocalename_l.c
blob7060c8df5952bf01ce668920a3c3a4cb51a5c402
1 /*
2 FUNCTION
3 <<getlocalename_l>>---create or modify a locale object
5 INDEX
6 getlocalename_l
8 INDEX
9 _getlocalename_l_r
11 SYNOPSIS
12 #include <locale.h>
13 locale_t getlocalename_l(int <[category]>, locale_t <[locobj]>);
15 locale_t _getlocalename_l_r(void *<[reent]>, int <[category]>,
16 locale_t <[locobj]>);
18 DESCRIPTION
19 The <<getlocalename_l>> function shall return the locale name for the
20 given locale category of the locale object locobj, or of the global
21 locale if locobj is the special locale object LC_GLOBAL_LOCALE.
23 The category argument specifies the locale category to be queried. If
24 the value is LC_ALL or is not a supported locale category value (see
25 <<setlocale>>), <<getlocalename_l>> shall fail.
27 The behavior is undefined if the locobj argument is neither the special
28 locale object LC_GLOBAL_LOCALE nor a valid locale object handle.
30 RETURNS
31 Upon successful completion, <<getlocalename_l>> shall return a pointer
32 to a string containing the locale name; otherwise, a null pointer shall
33 be returned.
35 If locobj is LC_GLOBAL_LOCALE, the returned string pointer might be
36 invalidated or the string content might be overwritten by a subsequent
37 call in the same thread to <<getlocalename_l>> with LC_GLOBAL_LOCALE;
38 the returned string pointer might also be invalidated if the calling
39 thread is terminated. Otherwise, the returned string pointer and content
40 shall remain valid until the locale object locobj is used in a call to
41 <<freelocale>> or as the base argument in a successful call to
42 <<newlocale>>.
44 No errors are defined.
46 PORTABILITY
47 <<getlocalename_l>> is POSIX-1.2008 since Base Specification Issue 8
50 #include <newlib.h>
51 #include "setlocale.h"
53 const char *
54 _getlocalename_l_r (struct _reent *ptr, int category, struct __locale_t *locobj)
56 if (category <= LC_ALL || category > LC_MESSAGES)
57 return NULL;
58 #ifndef _MB_CAPABLE
59 return "C";
60 #else
61 if (locobj == LC_GLOBAL_LOCALE)
63 /* getlocalename_l is supposed to return the value in a
64 thread-safe manner. This requires to copy over the
65 category string into thread-local storage. */
66 strcpy (_REENT_GETLOCALENAME_L_BUF (ptr),
67 __get_global_locale ()->categories[category]);
69 return locobj->categories[category];
70 #endif
73 const char *
74 getlocalename_l (int category, struct __locale_t *locobj)
76 return _getlocalename_l_r (_REENT, category, locobj);