summaryrefslogtreecommitdiffstats
path: root/gl/nl_langinfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'gl/nl_langinfo.c')
-rw-r--r--gl/nl_langinfo.c124
1 files changed, 93 insertions, 31 deletions
diff --git a/gl/nl_langinfo.c b/gl/nl_langinfo.c
index 131166fd..0180c26a 100644
--- a/gl/nl_langinfo.c
+++ b/gl/nl_langinfo.c
@@ -1,6 +1,6 @@
1/* nl_langinfo() replacement: query locale dependent information. 1/* nl_langinfo() replacement: query locale dependent information.
2 2
3 Copyright (C) 2007-2023 Free Software Foundation, Inc. 3 Copyright (C) 2007-2025 Free Software Foundation, Inc.
4 4
5 This file is free software: you can redistribute it and/or modify 5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as 6 it under the terms of the GNU Lesser General Public License as
@@ -30,7 +30,12 @@
30#endif 30#endif
31 31
32#if REPLACE_NL_LANGINFO && !NL_LANGINFO_MTSAFE 32#if REPLACE_NL_LANGINFO && !NL_LANGINFO_MTSAFE
33# if defined _WIN32 && !defined __CYGWIN__ 33
34# if AVOID_ANY_THREADS
35
36/* The option '--disable-threads' explicitly requests no locking. */
37
38# elif defined _WIN32 && !defined __CYGWIN__
34 39
35# define WIN32_LEAN_AND_MEAN /* avoid including junk */ 40# define WIN32_LEAN_AND_MEAN /* avoid including junk */
36# include <windows.h> 41# include <windows.h>
@@ -51,6 +56,7 @@
51# include <threads.h> 56# include <threads.h>
52 57
53# endif 58# endif
59
54#endif 60#endif
55 61
56/* nl_langinfo() must be multithread-safe. To achieve this without using 62/* nl_langinfo() must be multithread-safe. To achieve this without using
@@ -70,6 +76,8 @@
70static char * 76static char *
71ctype_codeset (void) 77ctype_codeset (void)
72{ 78{
79 /* This function is only used on platforms which don't have uselocale().
80 Therefore we don't need to look at the per-thread locale first, here. */
73 static char result[2 + 10 + 1]; 81 static char result[2 + 10 + 1];
74 char buf[2 + 10 + 1]; 82 char buf[2 + 10 + 1];
75 char locale[SETLOCALE_NULL_MAX]; 83 char locale[SETLOCALE_NULL_MAX];
@@ -146,11 +154,15 @@ ctype_codeset (void)
146 "thread5 disturbed by threadN!", even when threadN invokes only 154 "thread5 disturbed by threadN!", even when threadN invokes only
147 nl_langinfo (CODESET); 155 nl_langinfo (CODESET);
148 nl_langinfo (CRNCYSTR); 156 nl_langinfo (CRNCYSTR);
149 Similarly on Solaris 10. */ 157 Similarly on Solaris 10 and macOS 26. */
150 158
151# if !NL_LANGINFO_MTSAFE /* Solaris */ 159# if !NL_LANGINFO_MTSAFE /* macOS, Solaris */
152 160
153# define ITEMS (MAXSTRMSG + 1) 161# ifdef __sun /* Solaris */
162# define ITEMS (MAXSTRMSG + 1)
163# else /* macOS */
164# define ITEMS (CRNCYSTR + 20)
165# endif
154# define MAX_RESULT_LEN 80 166# define MAX_RESULT_LEN 80
155 167
156static char * 168static char *
@@ -184,7 +196,12 @@ nl_langinfo_unlocked (nl_item item)
184/* Prohibit renaming this symbol. */ 196/* Prohibit renaming this symbol. */
185# undef gl_get_nl_langinfo_lock 197# undef gl_get_nl_langinfo_lock
186 198
187# if defined _WIN32 && !defined __CYGWIN__ 199# if AVOID_ANY_THREADS
200
201/* The option '--disable-threads' explicitly requests no locking. */
202# define nl_langinfo_with_lock nl_langinfo_unlocked
203
204# elif defined _WIN32 && !defined __CYGWIN__
188 205
189extern __declspec(dllimport) CRITICAL_SECTION *gl_get_nl_langinfo_lock (void); 206extern __declspec(dllimport) CRITICAL_SECTION *gl_get_nl_langinfo_lock (void);
190 207
@@ -304,6 +321,24 @@ rpl_nl_langinfo (nl_item item)
304 item = item - ALTMON_1 + MON_1; 321 item = item - ALTMON_1 + MON_1;
305 break; 322 break;
306# endif 323# endif
324# if GNULIB_defined_ABALTMON
325 case ABALTMON_1:
326 case ABALTMON_2:
327 case ABALTMON_3:
328 case ABALTMON_4:
329 case ABALTMON_5:
330 case ABALTMON_6:
331 case ABALTMON_7:
332 case ABALTMON_8:
333 case ABALTMON_9:
334 case ABALTMON_10:
335 case ABALTMON_11:
336 case ABALTMON_12:
337 /* We don't ship the appropriate localizations with gnulib. Therefore,
338 treat ABALTMON_i like ABMON_i. */
339 item = item - ABALTMON_1 + ABMON_1;
340 break;
341# endif
307# if GNULIB_defined_ERA 342# if GNULIB_defined_ERA
308 case ERA: 343 case ERA:
309 /* The format is not standardized. In glibc it is a sequence of strings 344 /* The format is not standardized. In glibc it is a sequence of strings
@@ -449,7 +484,7 @@ nl_langinfo (nl_item item)
449 { 484 {
450 static char const months[][sizeof "September"] = { 485 static char const months[][sizeof "September"] = {
451 "January", "February", "March", "April", "May", "June", "July", 486 "January", "February", "March", "April", "May", "June", "July",
452 "September", "October", "November", "December" 487 "August", "September", "October", "November", "December"
453 }; 488 };
454 case MON_1: 489 case MON_1:
455 case MON_2: 490 case MON_2:
@@ -497,30 +532,57 @@ nl_langinfo (nl_item item)
497 return result[item - ALTMON_1]; 532 return result[item - ALTMON_1];
498 } 533 }
499 } 534 }
500 case ABMON_1: 535 {
501 case ABMON_2: 536 static char const abmonths[][sizeof "Jan"] = {
502 case ABMON_3: 537 "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
503 case ABMON_4: 538 "Aug", "Sep", "Oct", "Nov", "Dec"
504 case ABMON_5: 539 };
505 case ABMON_6: 540 case ABMON_1:
506 case ABMON_7: 541 case ABMON_2:
507 case ABMON_8: 542 case ABMON_3:
508 case ABMON_9: 543 case ABMON_4:
509 case ABMON_10: 544 case ABMON_5:
510 case ABMON_11: 545 case ABMON_6:
511 case ABMON_12: 546 case ABMON_7:
512 { 547 case ABMON_8:
513 static char result[12][30]; 548 case ABMON_9:
514 static char const abmonths[][sizeof "Jan"] = { 549 case ABMON_10:
515 "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", 550 case ABMON_11:
516 "Sep", "Oct", "Nov", "Dec" 551 case ABMON_12:
517 }; 552 {
518 tmm.tm_mon = item - ABMON_1; 553 static char result[12][30];
519 if (!strftime (buf, sizeof result[0], "%b", &tmm)) 554 tmm.tm_mon = item - ABMON_1;
520 return (char *) abmonths[item - ABMON_1]; 555 if (!strftime (buf, sizeof result[0], "%b", &tmm))
521 strcpy (result[item - ABMON_1], buf); 556 return (char *) abmonths[item - ABMON_1];
522 return result[item - ABMON_1]; 557 strcpy (result[item - ABMON_1], buf);
523 } 558 return result[item - ABMON_1];
559 }
560 case ABALTMON_1:
561 case ABALTMON_2:
562 case ABALTMON_3:
563 case ABALTMON_4:
564 case ABALTMON_5:
565 case ABALTMON_6:
566 case ABALTMON_7:
567 case ABALTMON_8:
568 case ABALTMON_9:
569 case ABALTMON_10:
570 case ABALTMON_11:
571 case ABALTMON_12:
572 {
573 static char result[12][50];
574 tmm.tm_mon = item - ABALTMON_1;
575 /* The platforms without nl_langinfo() don't support strftime with
576 %Ob. We don't even need to try. */
577 #if 0
578 if (!strftime (buf, sizeof result[0], "%Ob", &tmm))
579 #endif
580 if (!strftime (buf, sizeof result[0], "%b", &tmm))
581 return (char *) abmonths[item - ABALTMON_1];
582 strcpy (result[item - ABALTMON_1], buf);
583 return result[item - ABALTMON_1];
584 }
585 }
524 case ERA: 586 case ERA:
525 return (char *) ""; 587 return (char *) "";
526 case ALT_DIGITS: 588 case ALT_DIGITS: