socket: Improve fortify with clang
[glibc.git] / intl / tst-gettext6.c
blobf8fa28b1ee89798a072a4d93186c5bc43e0f2790
1 /* Test that gettext() in multithreaded applications works correctly.
2 Copyright (C) 2008-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #include <libintl.h>
20 #include <locale.h>
21 #include <pthread.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <sys/wait.h>
25 #include <unistd.h>
27 pthread_barrier_t b;
29 static void *
30 tf (void *arg)
32 pthread_barrier_wait (&b);
33 return gettext ("Operation not permitted");
36 int
37 test (void)
39 pthread_t th[4];
40 unsetenv ("LANGUAGE");
41 unsetenv ("OUTPUT_CHARSET");
42 textdomain ("tstgettext6");
43 bindtextdomain ("tstgettext6", OBJPFX "domaindir");
44 setlocale (LC_ALL, "ja_JP.UTF-8");
45 pthread_barrier_init (&b, NULL, 4);
46 for (int i = 0; i < 4; i++)
47 if (pthread_create (&th[i], NULL, tf, NULL))
49 puts ("pthread_create failed");
50 return 1;
52 for (int i = 0; i < 4; i++)
53 pthread_join (th[i], NULL);
54 return 0;
57 int
58 main (void)
60 for (int i = 0; i < 300; i++)
62 pid_t p = fork ();
63 if (p == -1)
65 printf ("fork failed: %m\n");
66 return 1;
68 if (p == 0)
69 _exit (test ());
70 int status;
71 wait (&status);
72 if (WIFEXITED (status) && WEXITSTATUS (status) != 0)
74 printf ("child exited with %d\n", WEXITSTATUS (status));
75 return 1;
77 else if (WIFSIGNALED (status))
79 printf ("child killed by signal %d\n", WTERMSIG (status));
80 return 1;
83 return 0;