or1k: Add prctl wrapper to unwrap variadic args
[glibc.git] / sysdeps / pthread / tst-basic6.c
blob0e8406f5ce7ca928b85bcd46f505fc73e188358c
1 /* Copyright (C) 2003-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library 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 GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #include <pthread.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <unistd.h>
25 static char *p;
27 static pthread_barrier_t b;
28 #define BT \
29 e = pthread_barrier_wait (&b); \
30 if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD) \
31 { \
32 puts ("barrier_wait failed"); \
33 exit (1); \
37 static void *
38 tf (void *a)
40 int e;
42 BT;
44 char *p2 = getcwd (NULL, 0);
45 if (p2 == NULL)
47 puts ("2nd getcwd failed");
48 exit (1);
51 if (strcmp (p, p2) != 0)
53 printf ("initial cwd mismatch: \"%s\" vs \"%s\"\n", p, p2);
54 exit (1);
57 free (p);
58 free (p2);
60 if (chdir ("..") != 0)
62 puts ("chdir failed");
63 exit (1);
66 p = getcwd (NULL, 0);
67 if (p == NULL)
69 puts ("getcwd failed");
70 exit (1);
73 return a;
77 int
78 do_test (void)
80 if (pthread_barrier_init (&b, NULL, 2) != 0)
82 puts ("barrier_init failed");
83 exit (1);
86 pthread_t th;
87 if (pthread_create (&th, NULL, tf, NULL) != 0)
89 puts ("create failed");
90 exit (1);
93 p = getcwd (NULL, 0);
94 if (p == NULL)
96 puts ("getcwd failed");
97 exit (1);
100 int e;
103 if (pthread_join (th, NULL) != 0)
105 puts ("join failed");
106 exit (1);
109 char *p2 = getcwd (NULL, 0);
110 if (p2 == NULL)
112 puts ("2nd getcwd failed");
113 exit (1);
116 if (strcmp (p, p2) != 0)
118 printf ("cwd after chdir mismatch: \"%s\" vs \"%s\"\n", p, p2);
119 exit (1);
122 free (p);
123 free (p2);
125 return 0;
129 #define TEST_FUNCTION do_test ()
130 #include "../test-skeleton.c"