Define __intmax_t, __uintmax_t in bits/types.h.
[glibc.git] / nptl / tst-sem15.c
blobca7d4915c1c042cc90fc1545dd4f688ec21b36b4
1 /* Test for SEM_VALUE_MAX overflow detection: BZ #18434.
2 Copyright (C) 2015-2016 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 <http://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <limits.h>
21 #include <semaphore.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <unistd.h>
27 static int
28 do_test (void)
30 sem_t s;
32 if (sem_init (&s, 0, SEM_VALUE_MAX))
34 printf ("sem_init: %m\n");
35 return 1;
38 int result = 0;
40 int value = 0xdeadbeef;
41 if (sem_getvalue (&s, &value))
43 printf ("sem_getvalue: %m\n");
44 result = 1;
46 else
48 printf ("sem_getvalue after init: %d\n", value);
49 if (value != SEM_VALUE_MAX)
51 printf ("\tshould be %d\n", SEM_VALUE_MAX);
52 result = 1;
56 errno = 0;
57 if (sem_post(&s) == 0)
59 puts ("sem_post at SEM_VALUE_MAX succeeded!");
60 result = 1;
62 else
64 printf ("sem_post at SEM_VALUE_MAX: %m (%d)\n", errno);
65 if (errno != EOVERFLOW)
67 printf ("\tshould be %s (EOVERFLOW = %d)\n",
68 strerror (EOVERFLOW), EOVERFLOW);
69 result = 1;
73 value = 0xbad1d00d;
74 if (sem_getvalue (&s, &value))
76 printf ("sem_getvalue: %m\n");
77 result = 1;
79 else
81 printf ("sem_getvalue after post: %d\n", value);
82 if (value != SEM_VALUE_MAX)
84 printf ("\tshould be %d\n", SEM_VALUE_MAX);
85 result = 1;
89 if (sem_destroy (&s))
91 printf ("sem_destroy: %m\n");
92 result = 1;
95 return result;
98 #define TEST_FUNCTION do_test ()
99 #include "../test-skeleton.c"