shm.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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/shm.h>
  18. #include "ipc.h"
  19. #ifdef L_shmat
  20. /* Attach the shared memory segment associated with SHMID to the data
  21. segment of the calling process. SHMADDR and SHMFLG determine how
  22. and where the segment is attached. */
  23. void *
  24. shmat (shmid, shmaddr, shmflg)
  25. int shmid;
  26. const void *shmaddr;
  27. int shmflg;
  28. {
  29. int retval;
  30. unsigned long raddr;
  31. retval = __ipc(IPCOP_shmat, shmid, shmflg, (int) &raddr, (void *) shmaddr);
  32. return ((unsigned long int) retval > -(unsigned long int) SHMLBA
  33. ? (void *) retval : (void *) raddr);
  34. }
  35. #endif
  36. #ifdef L_shmctl
  37. /* Provide operations to control over shared memory segments. */
  38. int
  39. shmctl (shmid, cmd, buf)
  40. int shmid;
  41. int cmd;
  42. struct shmid_ds *buf;
  43. {
  44. return __ipc(IPCOP_shmctl, shmid, cmd, 0, buf);
  45. }
  46. #endif
  47. #ifdef L_shmdt
  48. /* Detach shared memory segment starting at address specified by SHMADDR
  49. from the caller's data segment. */
  50. int
  51. shmdt (shmaddr)
  52. const void *shmaddr;
  53. {
  54. return __ipc(IPCOP_shmdt, 0, 0, 0, (void *) shmaddr);
  55. }
  56. #endif
  57. #ifdef L_shmget
  58. /* Return an identifier for an shared memory segment of at least size SIZE
  59. which is associated with KEY. */
  60. int
  61. shmget (key, size, shmflg)
  62. key_t key;
  63. size_t size;
  64. int shmflg;
  65. {
  66. return __ipc(IPCOP_shmget, key, size, shmflg, NULL);
  67. }
  68. #endif