Copy-edit NEWS and fixup ChangeLog entries.
[glibc.git] / nptl / tst-sem13.c
blob068d79e85e993b081a21450314f4c7fa3b728d74
1 #include <errno.h>
2 #include <semaphore.h>
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <pthread.h>
6 #include <internaltypes.h>
9 static int
10 do_test (void)
12 union
14 sem_t s;
15 struct new_sem ns;
16 } u;
18 if (sem_init (&u.s, 0, 0) != 0)
20 puts ("sem_init failed");
21 return 1;
24 struct timespec ts = { 0, 1000000001 }; /* Invalid. */
25 errno = 0;
26 if (sem_timedwait (&u.s, &ts) >= 0)
28 puts ("sem_timedwait did not fail");
29 return 1;
31 if (errno != EINVAL)
33 perror ("sem_timedwait did not fail with EINVAL");
34 return 1;
36 if (u.ns.nwaiters != 0)
38 printf ("sem_timedwait modified nwaiters: %ld\n", u.ns.nwaiters);
39 return 1;
42 ts.tv_sec = /* Invalid. */ -2;
43 ts.tv_nsec = 0;
44 errno = 0;
45 if (sem_timedwait (&u.s, &ts) >= 0)
47 puts ("2nd sem_timedwait did not fail");
48 return 1;
50 if (errno != ETIMEDOUT)
52 perror ("2nd sem_timedwait did not fail with ETIMEDOUT");
53 return 1;
55 if (u.ns.nwaiters != 0)
57 printf ("2nd sem_timedwait modified nwaiters: %ld\n", u.ns.nwaiters);
58 return 1;
61 return 0;
64 #define TEST_FUNCTION do_test ()
65 #include "../test-skeleton.c"