semctl.c 605 B

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