summaryrefslogtreecommitdiff
path: root/regress/lib/libpthread/semaphore/sem_trywait/sem_trywait.c
blob: b4a4fe64ff632604e07e2655cf3ac15893e2b7cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*	$OpenBSD: sem_trywait.c,v 1.2 2012/03/03 09:36:26 guenther Exp $	*/
/*
 * Martin Pieuchot <mpi@openbsd.org>, 2011. Public Domain.
 */

#include <errno.h>
#include <unistd.h>
#include <semaphore.h>
#include "test.h"

sem_t sem;

int
main(int argc, char **argv)
{
	int val;

	CHECKn(sem_trywait(&sem));
	ASSERT(errno == EINVAL);

	CHECKr(sem_init(&sem, 0, 0));

	CHECKn(sem_trywait(&sem));
	ASSERT(errno == EAGAIN);

	CHECKr(sem_post(&sem));
	CHECKr(sem_trywait(&sem));

	CHECKe(sem_getvalue(&sem, &val));
	ASSERT(val == 0);

	CHECKe(sem_destroy(&sem));

	SUCCEED;
}