1*09d4459fSDaniel Fojt /* Query the name of the current global locale. 2*09d4459fSDaniel Fojt Copyright (C) 2019-2020 Free Software Foundation, Inc. 3*09d4459fSDaniel Fojt 4*09d4459fSDaniel Fojt This program is free software: you can redistribute it and/or modify 5*09d4459fSDaniel Fojt it under the terms of the GNU General Public License as published by 6*09d4459fSDaniel Fojt the Free Software Foundation; either version 3 of the License, or 7*09d4459fSDaniel Fojt (at your option) any later version. 8*09d4459fSDaniel Fojt 9*09d4459fSDaniel Fojt This program is distributed in the hope that it will be useful, 10*09d4459fSDaniel Fojt but WITHOUT ANY WARRANTY; without even the implied warranty of 11*09d4459fSDaniel Fojt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12*09d4459fSDaniel Fojt GNU General Public License for more details. 13*09d4459fSDaniel Fojt 14*09d4459fSDaniel Fojt You should have received a copy of the GNU General Public License 15*09d4459fSDaniel Fojt along with this program. If not, see <https://www.gnu.org/licenses/>. */ 16*09d4459fSDaniel Fojt 17*09d4459fSDaniel Fojt /* Written by Bruno Haible <bruno@clisp.org>, 2019. */ 18*09d4459fSDaniel Fojt 19*09d4459fSDaniel Fojt #ifndef _SETLOCALE_NULL_H 20*09d4459fSDaniel Fojt #define _SETLOCALE_NULL_H 21*09d4459fSDaniel Fojt 22*09d4459fSDaniel Fojt #include <stddef.h> 23*09d4459fSDaniel Fojt 24*09d4459fSDaniel Fojt #include "arg-nonnull.h" 25*09d4459fSDaniel Fojt 26*09d4459fSDaniel Fojt 27*09d4459fSDaniel Fojt #ifdef __cplusplus 28*09d4459fSDaniel Fojt extern "C" { 29*09d4459fSDaniel Fojt #endif 30*09d4459fSDaniel Fojt 31*09d4459fSDaniel Fojt 32*09d4459fSDaniel Fojt /* Recommended size of a buffer for a locale name for a single category. 33*09d4459fSDaniel Fojt On glibc systems, you can have locale names that are relative file names; 34*09d4459fSDaniel Fojt assume a maximum length 256. 35*09d4459fSDaniel Fojt In native Windows, in 2018 the longest locale name was of length 58 36*09d4459fSDaniel Fojt ("FYRO Macedonian_Former Yugoslav Republic of Macedonia.1251"). */ 37*09d4459fSDaniel Fojt #define SETLOCALE_NULL_MAX (256+1) 38*09d4459fSDaniel Fojt 39*09d4459fSDaniel Fojt /* Recommended size of a buffer for a locale name with all categories. 40*09d4459fSDaniel Fojt On glibc systems, you can have locale names that are relative file names; 41*09d4459fSDaniel Fojt assume maximum length 256 for each. There are 12 categories; so, the 42*09d4459fSDaniel Fojt maximum total length is 148+12*256. 43*09d4459fSDaniel Fojt In native Windows, there are 5 categories, and the maximum total length is 44*09d4459fSDaniel Fojt 55+5*58. */ 45*09d4459fSDaniel Fojt #define SETLOCALE_NULL_ALL_MAX (148+12*256+1) 46*09d4459fSDaniel Fojt 47*09d4459fSDaniel Fojt /* setlocale_null_r (CATEGORY, BUF, BUFSIZE) is like setlocale (CATEGORY, NULL), 48*09d4459fSDaniel Fojt except that 49*09d4459fSDaniel Fojt - it is guaranteed to be multithread-safe, 50*09d4459fSDaniel Fojt - it returns the resulting locale category name or locale name in the 51*09d4459fSDaniel Fojt user-supplied buffer BUF, which must be BUFSIZE bytes long. 52*09d4459fSDaniel Fojt The recommended minimum buffer size is 53*09d4459fSDaniel Fojt - SETLOCALE_NULL_MAX for CATEGORY != LC_ALL, and 54*09d4459fSDaniel Fojt - SETLOCALE_NULL_ALL_MAX for CATEGORY == LC_ALL. 55*09d4459fSDaniel Fojt The return value is an error code: 0 if the call is successful, EINVAL if 56*09d4459fSDaniel Fojt CATEGORY is invalid, or ERANGE if BUFSIZE is smaller than the length needed 57*09d4459fSDaniel Fojt size (including the trailing NUL byte). In the latter case, a truncated 58*09d4459fSDaniel Fojt result is returned in BUF, but still NUL-terminated if BUFSIZE > 0. 59*09d4459fSDaniel Fojt For this call to be multithread-safe, *all* calls to 60*09d4459fSDaniel Fojt setlocale (CATEGORY, NULL) in all other threads must have been converted 61*09d4459fSDaniel Fojt to use setlocale_null_r or setlocale_null as well, and the other threads 62*09d4459fSDaniel Fojt must not make other setlocale invocations (since changing the global locale 63*09d4459fSDaniel Fojt has side effects on all threads). */ 64*09d4459fSDaniel Fojt extern int setlocale_null_r (int category, char *buf, size_t bufsize) 65*09d4459fSDaniel Fojt _GL_ARG_NONNULL ((2)); 66*09d4459fSDaniel Fojt 67*09d4459fSDaniel Fojt /* setlocale_null (CATEGORY) is like setlocale (CATEGORY, NULL), except that 68*09d4459fSDaniel Fojt it is guaranteed to be multithread-safe. 69*09d4459fSDaniel Fojt The return value is NULL if CATEGORY is invalid. 70*09d4459fSDaniel Fojt For this call to be multithread-safe, *all* calls to 71*09d4459fSDaniel Fojt setlocale (CATEGORY, NULL) in all other threads must have been converted 72*09d4459fSDaniel Fojt to use setlocale_null_r or setlocale_null as well, and the other threads 73*09d4459fSDaniel Fojt must not make other setlocale invocations (since changing the global locale 74*09d4459fSDaniel Fojt has side effects on all threads). */ 75*09d4459fSDaniel Fojt extern const char *setlocale_null (int category); 76*09d4459fSDaniel Fojt 77*09d4459fSDaniel Fojt 78*09d4459fSDaniel Fojt #ifdef __cplusplus 79*09d4459fSDaniel Fojt } 80*09d4459fSDaniel Fojt #endif 81*09d4459fSDaniel Fojt 82*09d4459fSDaniel Fojt #endif /* _SETLOCALE_NULL_H */ 83