Commit | Line | Data |
---|---|---|
503d4b46 KW |
1 | ?RCS: $Id$ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 2017 Karl Williamson | |
4 | ?RCS: | |
5 | ?RCS: You may distribute under the terms of either the GNU General Public | |
6 | ?RCS: License or the Artistic License, as specified in the README file. | |
7 | ?RCS: | |
dfb37ae1 | 8 | ?MAKE:d_nl_langinfo_l d_thread_safe_nl_langinfo_l: Compile cat rm_try Oldconfig \ |
70bf069f | 9 | i_pthread i_stdlib i_langinfo i_locale \ |
503d4b46 KW |
10 | usethreads run |
11 | ?MAKE: -pick add $@ %< | |
dfb37ae1 KW |
12 | ?S:d_nl_langinfo_l: |
13 | ?S: This variable contains the eventual value of the | |
14 | ?S: HAS_NL_LANGINFO_L symbol, which indicates if the | |
15 | ?S: nl_langinfo_l() function exists. | |
16 | ?S:. | |
503d4b46 KW |
17 | ?S:d_thread_safe_nl_langinfo_l: |
18 | ?S: This variable contains the eventual value of the | |
19 | ?S: HAS_THREAD_SAFE_NL_LANGINFO_L symbol, which indicates if the | |
20 | ?S: nl_langinfo_l() function exists and is thread-safe. | |
21 | ?S:. | |
dfb37ae1 KW |
22 | ?C:HAS_NL_LANGINFO_L: |
23 | ?C: This symbol, when defined, indicates presence of the nl_langinfo_l() | |
24 | ?C: function | |
25 | ?C:. | |
503d4b46 KW |
26 | ?C:HAS_THREAD_SAFE_NL_LANGINFO_L: |
27 | ?C: This symbol, when defined, indicates presence of the nl_langinfo_l() | |
28 | ?C: function, and that it is thread-safe. | |
29 | ?C:. | |
dfb37ae1 | 30 | ?H:#$d_nl_langinfo_l HAS_NL_LANGINFO_L /**/ |
503d4b46 KW |
31 | ?H:#$d_thread_safe_nl_langinfo_l HAS_THREAD_SAFE_NL_LANGINFO_L /**/ |
32 | ?H:. | |
33 | ?F:!try | |
dfb37ae1 | 34 | : check for nl_langinfo_l item |
503d4b46 KW |
35 | $cat <<EOM |
36 | ||
dfb37ae1 | 37 | Checking to see if you have nl_langinfo_l(), and that it is thread-safe |
503d4b46 KW |
38 | EOM |
39 | ?X: Despite claiming that nl_langinfo_l() is thread-safe, the POSIX 2008 | |
40 | ?X: standard allows for a non-safe implementation: | |
41 | ?X: | |
42 | ?X: "nl_langinfo_l() uses an internal per-thread buffer, and nl_langinfo() | |
43 | ?X: uses (in all threads) the same buffer that nl_langinfo_l() uses in the | |
44 | ?X: initial thread. There can be interactions, but only when | |
45 | ?X: nl_langinfo_l() is called in the initial thread" | |
46 | ?X: | |
503d4b46 KW |
47 | ?X: This program calls nl_langinfo_l(), then creates a thread, calling plain |
48 | ?X: nl_langinfo() from within it, then sees if the buffer in the original | |
49 | ?X: thread was changed. | |
50 | $cat >try.c <<EOCP | |
51 | #$i_stdlib I_STDLIB | |
52 | #ifdef I_STDLIB | |
53 | # include <stdlib.h> | |
54 | #endif | |
70bf069f | 55 | #include <string.h> |
503d4b46 KW |
56 | #$i_langinfo I_LANGINFO |
57 | #ifdef I_LANGINFO | |
58 | # include <langinfo.h> | |
59 | #endif | |
60 | #$i_pthread I_PTHREAD | |
61 | #ifdef I_PTHREAD | |
62 | # include <pthread.h> | |
63 | #endif | |
64 | #$i_locale I_LOCALE | |
65 | #ifdef I_LOCALE | |
66 | # include <locale.h> | |
67 | #endif | |
68 | ||
69 | void * | |
70 | thread_start(void * arg) | |
71 | { | |
72 | nl_langinfo(RADIXCHAR); | |
73 | } | |
220ac080 | 74 | |
503d4b46 | 75 | int main() { |
01584c77 MBT |
76 | char * main_buffer; |
77 | char save_main_buffer[1000]; | |
78 | pthread_t subthread; | |
79 | pthread_attr_t attr; | |
503d4b46 | 80 | |
01584c77 | 81 | main_buffer = nl_langinfo_l(CODESET, newlocale(LC_ALL_MASK, "C", 0)); |
503d4b46 | 82 | |
01584c77 MBT |
83 | /* If too large for our generous allowance, just assume we don't have |
84 | * it. */ | |
85 | if (strlen(main_buffer) >= sizeof(save_main_buffer)) { | |
86 | exit(1); | |
87 | } | |
503d4b46 | 88 | |
01584c77 | 89 | strcpy(save_main_buffer, main_buffer); |
503d4b46 | 90 | |
01584c77 MBT |
91 | if (pthread_attr_init(&attr) != 0) { |
92 | exit(1); | |
93 | } | |
503d4b46 | 94 | |
01584c77 MBT |
95 | if (pthread_create(&subthread, &attr, thread_start, NULL) != 0) { |
96 | exit(1); | |
97 | } | |
503d4b46 | 98 | |
01584c77 MBT |
99 | if (pthread_join(subthread, NULL) != 0) { |
100 | exit(1); | |
101 | } | |
102 | ||
103 | exit(! (strcmp(main_buffer, save_main_buffer) == 0)); | |
503d4b46 KW |
104 | } |
105 | EOCP | |
106 | case "$usethreads" in | |
107 | define) | |
01584c77 MBT |
108 | set try |
109 | if eval $compile; then | |
110 | echo "Your system has nl_langinfo_l()..." >&4 | |
dfb37ae1 KW |
111 | d_nl_langinfo_l="$define" |
112 | echo "$d_nl_langinfo_l" >&4 | |
01584c77 MBT |
113 | if $run ./try; then |
114 | echo "and it is thread-safe (just as I'd hoped)." >&4 | |
115 | d_thread_safe_nl_langinfo_l="$define" | |
116 | echo "$d_thread_safe_nl_langinfo_l" >&4 | |
117 | else | |
dfb37ae1 | 118 | echo "but it isn't thread-safe." >&4 |
01584c77 MBT |
119 | fi |
120 | else | |
121 | echo "your system does not have nl_langinfo_l()" >&4 | |
122 | fi | |
123 | ;; | |
503d4b46 | 124 | *) echo "Since threads aren't selected, we won't bother looking for nl_langinfo_l()" >&4 |
ad82f5bf | 125 | esac |
dfb37ae1 KW |
126 | if test X"$d_nl_langinfo_l" = X; then |
127 | d_nl_langinfo_l="$undef" | |
128 | fi | |
ad82f5bf AC |
129 | if test X"$d_thread_safe_nl_langinfo_l" = X; then |
130 | d_thread_safe_nl_langinfo_l="$undef" | |
131 | fi | |
503d4b46 KW |
132 | $rm_try |
133 |