1 /* Test program, used by the intl-thread-1 test.
2 Copyright (C) 2005-2007, 2009-2010, 2013, 2018-2019 Free Software Foundation, Inc.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16
17 /* Written by Bruno Haible <haible@clisp.cons.org>, 2005, 2018. */
18
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
22
23 #include <locale.h>
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <string.h>
27
28 #if USE_POSIX_THREADS && HAVE_WORKING_USELOCALE
29
30 #include <pthread.h>
31
32 #if USE_SYSTEM_LIBINTL
33 # include <libintl.h>
34 #else
35 /* Make sure we use the included libintl, not the system's one. */
36 # undef _LIBINTL_H
37 # include "libgnuintl.h"
38 #endif
39
40 /* Name of locale to use in thread1. */
41 const char *locale_name_1;
42
43 /* Set to 1 if the program is not behaving correctly. */
44 int result;
45
46 void *
47 thread1_execution (void *arg)
48 {
49 char *s;
50
51 uselocale (newlocale (LC_ALL_MASK, locale_name_1, NULL));
52
53 /* Here we expect translated output. */
54
55 s = gettext ("cheese");
56 puts (s);
57 if (strcmp (s, "fromage"))
58 {
59 fprintf (stderr, "thread 1 call 1 returned: %s\n", s);
60 result = 1;
61 }
62
63 return NULL;
64 }
65
66 int
67 main (int argc, char *argv[])
68 {
69 pthread_t thread1;
70
71 locale_name_1 = argv[1];
72
73 unsetenv ("LANGUAGE");
74 unsetenv ("OUTPUT_CHARSET");
75 textdomain ("tstthread");
76 bindtextdomain ("tstthread", "in-th-1");
77 result = 0;
78
79 if (pthread_create (&thread1, NULL, &thread1_execution, NULL))
80 exit (2);
81 if (pthread_join (thread1, NULL))
82 exit (3);
83
84 return result;
85 }
86
87 #else
88
89 /* This test is not executed. */
90
91 int
92 main (void)
93 {
94 return 77;
95 }
96
97 #endif