sem.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Copyright (C) 1995, 1997, 1998 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with the GNU C Library; see the file COPYING.LIB. If not,
  14. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA. */
  16. #include <errno.h>
  17. #include <sys/sem.h>
  18. #include "ipc.h"
  19. #ifdef L_semctl
  20. /* Return identifier for array of NSEMS semaphores associated with
  21. KEY. */
  22. #include <stdarg.h>
  23. /* Define a `union semun' suitable for Linux here. */
  24. union semun
  25. {
  26. int val; /* value for SETVAL */
  27. struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
  28. unsigned short int *array; /* array for GETALL & SETALL */
  29. struct seminfo *__buf; /* buffer for IPC_INFO */
  30. };
  31. int
  32. semctl (int semid, int semnum, int cmd, ...)
  33. {
  34. union semun arg;
  35. va_list ap;
  36. va_start (ap, cmd);
  37. /* Get the argument. */
  38. arg = va_arg (ap, union semun);
  39. va_end (ap);
  40. return __ipc(IPCOP_semctl, semid, semnum, cmd, &arg);
  41. }
  42. #endif
  43. #ifdef L_semget
  44. #include <stdlib.h> /* for definition of NULL */
  45. /* Return identifier for array of NSEMS semaphores associated with
  46. KEY. */
  47. int
  48. semget (key, nsems, semflg)
  49. key_t key;
  50. int nsems;
  51. int semflg;
  52. {
  53. return __ipc(IPCOP_semget, key, nsems, semflg, NULL);
  54. }
  55. #endif
  56. #ifdef L_semop
  57. /* Perform user-defined atomical operation of array of semaphores. */
  58. int
  59. semop (semid, sops, nsops)
  60. int semid;
  61. struct sembuf *sops;
  62. unsigned int nsops;
  63. {
  64. return __ipc(IPCOP_semop, semid, (int) nsops, 0, sops);
  65. }
  66. #endif