xref: /haiku/src/system/libroot/posix/sys/xsi_sem.cpp (revision 0d452c8f34013b611a54c746a71c05e28796eae2)
1 /*
2  * Copyright 2008, Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Salvatore Benedetto <salvatore.benedetto@gmail.com>
7  */
8 
9 #include <sys/sem.h>
10 
11 #include <errno.h>
12 #include <fcntl.h>
13 #include <stdarg.h>
14 #include <stdlib.h>
15 
16 #include <OS.h>
17 
18 #include <posix/xsi_semaphore_defs.h>
19 #include <syscall_utils.h>
20 #include <syscalls.h>
21 
22 
23 int
24 semget(key_t key, int numSems, int semFlags)
25 {
26 	RETURN_AND_SET_ERRNO(_kern_xsi_semget(key, numSems, semFlags));
27 }
28 
29 
30 int
31 semctl(int semID, int semNum, int command, ...)
32 {
33 	union semun arg;
34 	va_list args;
35 
36 	switch (command) {
37 		case GETVAL:
38 		case GETPID:
39 		case GETNCNT:
40 		case GETZCNT:
41 		case IPC_RMID:
42 			RETURN_AND_SET_ERRNO(_kern_xsi_semctl(semID, semNum, command, 0));
43 
44 		case SETVAL:
45 		case GETALL:
46 		case SETALL:
47 		case IPC_STAT:
48 		case IPC_SET:
49 			va_start(args, command);
50 			arg = va_arg(args, union semun);
51 			va_end(args);
52 			RETURN_AND_SET_ERRNO(_kern_xsi_semctl(semID, semNum, command,
53 				&arg));
54 
55 		default:
56 			return EINVAL;
57 	}
58 }
59 
60 
61 int
62 semop(int semID, struct sembuf *semOps, size_t numSemOps)
63 {
64 	RETURN_AND_SET_ERRNO(_kern_xsi_semop(semID, semOps, numSemOps));
65 }
66