universally apply our cflags (no vsx, no altivec..)
[glibc.git] / fbtl / tst-basic6.c
1 /* Copyright (C) 2003-2013 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
4
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.
9
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.
14
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 <http://www.gnu.org/licenses/>. */
18
19 #include <pthread.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24
25
26 static char *p;
27
28 static pthread_barrier_t b;
29 #define BT \
30 e = pthread_barrier_wait (&b); \
31 if (e != 0 && e != PTHREAD_BARRIER_SERIAL_THREAD) \
32 { \
33 puts ("barrier_wait failed"); \
34 exit (1); \
35 }
36
37
38 static void *
39 tf (void *a)
40 {
41 int e;
42
43 BT;
44
45 char *p2 = getcwd (NULL, 0);
46 if (p2 == NULL)
47 {
48 puts ("2nd getcwd failed");
49 exit (1);
50 }
51
52 if (strcmp (p, p2) != 0)
53 {
54 printf ("initial cwd mismatch: \"%s\" vs \"%s\"\n", p, p2);
55 exit (1);
56 }
57
58 free (p);
59 free (p2);
60
61 if (chdir ("..") != 0)
62 {
63 puts ("chdir failed");
64 exit (1);
65 }
66
67 p = getcwd (NULL, 0);
68 if (p == NULL)
69 {
70 puts ("getcwd failed");
71 exit (1);
72 }
73
74 return a;
75 }
76
77
78 int
79 do_test (void)
80 {
81 if (pthread_barrier_init (&b, NULL, 2) != 0)
82 {
83 puts ("barrier_init failed");
84 exit (1);
85 }
86
87 pthread_t th;
88 if (pthread_create (&th, NULL, tf, NULL) != 0)
89 {
90 puts ("create failed");
91 exit (1);
92 }
93
94 p = getcwd (NULL, 0);
95 if (p == NULL)
96 {
97 puts ("getcwd failed");
98 exit (1);
99 }
100
101 int e;
102 BT;
103
104 if (pthread_join (th, NULL) != 0)
105 {
106 puts ("join failed");
107 exit (1);
108 }
109
110 char *p2 = getcwd (NULL, 0);
111 if (p2 == NULL)
112 {
113 puts ("2nd getcwd failed");
114 exit (1);
115 }
116
117 if (strcmp (p, p2) != 0)
118 {
119 printf ("cwd after chdir mismatch: \"%s\" vs \"%s\"\n", p, p2);
120 exit (1);
121 }
122
123 free (p);
124 free (p2);
125
126 return 0;
127 }
128
129
130 #define TEST_FUNCTION do_test ()
131 #include "../test-skeleton.c"