1 #include <common.h>
2 
3 int
4 main(void) {
5 	sem_t id;
6 
7 	if (sem_init(&id, 0, 0) < 0) {
8 		perror("sem_init");
9 		return 1;
10 	}
11 
12 	/* This should fail with EAGAIN and leave the value at 0. */
13 	if (sem_trywait(&id) >= 0) {
14 		sem_destroy(&id);
15 		return 1;
16 	}
17 	if (errno != EAGAIN) {
18 		perror("wrong error from sem_trywait()");
19 		sem_destroy(&id);
20 		return 1;
21 	}
22 	if (checkvalue(&id, 0) < 0) {
23 		sem_destroy(&id);
24 		return 1;
25 	}
26 
27 	if (sem_destroy(&id) < 0) {
28 		perror("sem_destroy");
29 		return 1;
30 	}
31 	return 0;
32 }
33