1#include <sys/sem.h> 2#include <stdarg.h> 3#include "syscall.h" 4#include "ipc.h" 5 6union semun { 7 int val; 8 struct semid_ds *buf; 9 unsigned short *array; 10}; 11 12int semctl(int id, int num, int cmd, ...) 13{ 14 union semun arg = {0}; 15 va_list ap; 16 switch (cmd) { 17 case SETVAL: case GETALL: case SETALL: case IPC_STAT: case IPC_SET: 18 case IPC_INFO: case SEM_INFO: case SEM_STAT: 19 va_start(ap, cmd); 20 arg = va_arg(ap, union semun); 21 va_end(ap); 22 } 23#ifdef SYS_semctl 24 return syscall(SYS_semctl, id, num, cmd | IPC_64, arg.buf); 25#else 26 return syscall(SYS_ipc, IPCOP_semctl, id, num, cmd | IPC_64, &arg.buf); 27#endif 28} 29