setlocale_null.h 3.4 KB

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