getutxent implementation for Linux/s390-32.
[glibc/history.git] / intl / tst-gettext4.c
bloba82446d14c2009c206980a5ab151783d03564d7c
1 /* Test that gettext() in multithreaded applications works correctly if
2 different threads operate in different locales with the same encoding.
3 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Bruno Haible <bruno@clisp.org>, 2005.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 02111-1307 USA. */
22 #include <libintl.h>
23 #include <locale.h>
24 #include <pthread.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
29 /* Set to 1 if the program is not behaving correctly. */
30 int result;
32 /* Denotes which thread should run next. */
33 int flipflop;
34 /* Lock and wait queue used to switch between the threads. */
35 pthread_mutex_t lock;
36 pthread_cond_t waitqueue;
38 /* Waits until the flipflop has a given value.
39 Before the call, the lock is unlocked. After the call, it is locked. */
40 static void
41 waitfor (int value)
43 if (pthread_mutex_lock (&lock))
44 exit (10);
45 while (flipflop != value)
46 if (pthread_cond_wait (&waitqueue, &lock))
47 exit (11);
50 /* Sets the flipflop to a given value.
51 Before the call, the lock is locked. After the call, it is unlocked. */
52 static void
53 setto (int value)
55 flipflop = value;
56 if (pthread_cond_signal (&waitqueue))
57 exit (20);
58 if (pthread_mutex_unlock (&lock))
59 exit (21);
62 void *
63 thread1_execution (void *arg)
65 char *s;
67 waitfor (1);
68 uselocale (newlocale (LC_ALL_MASK, "de_DE.ISO-8859-1", NULL));
69 setto (2);
71 waitfor (1);
72 s = gettext ("beauty");
73 puts (s);
74 if (strcmp (s, "Sch\366nheit"))
76 fprintf (stderr, "thread 1 call 1 returned: %s\n", s);
77 result = 1;
79 setto (2);
81 waitfor (1);
82 s = gettext ("beauty");
83 puts (s);
84 if (strcmp (s, "Sch\366nheit"))
86 fprintf (stderr, "thread 1 call 2 returned: %s\n", s);
87 result = 1;
89 setto (2);
91 return NULL;
94 void *
95 thread2_execution (void *arg)
97 char *s;
99 waitfor (2);
100 uselocale (newlocale (LC_ALL_MASK, "fr_FR.ISO-8859-1", NULL));
101 setto (1);
103 waitfor (2);
104 s = gettext ("beauty");
105 puts (s);
106 if (strcmp (s, "beaut\351"))
108 fprintf (stderr, "thread 2 call 1 returned: %s\n", s);
109 result = 1;
111 setto (1);
113 waitfor (2);
114 s = gettext ("beauty");
115 puts (s);
116 if (strcmp (s, "beaut\351"))
118 fprintf (stderr, "thread 2 call 2 returned: %s\n", s);
119 result = 1;
121 setto (1);
123 return NULL;
127 main (void)
129 pthread_t thread1;
130 pthread_t thread2;
132 unsetenv ("LANGUAGE");
133 unsetenv ("OUTPUT_CHARSET");
134 textdomain ("multithread");
135 bindtextdomain ("multithread", OBJPFX "domaindir");
136 result = 0;
138 flipflop = 1;
139 if (pthread_mutex_init (&lock, NULL))
140 exit (2);
141 if (pthread_cond_init (&waitqueue, NULL))
142 exit (2);
143 if (pthread_create (&thread1, NULL, &thread1_execution, NULL))
144 exit (2);
145 if (pthread_create (&thread2, NULL, &thread2_execution, NULL))
146 exit (2);
147 if (pthread_join (thread2, NULL))
148 exit (3);
150 return result;