shm.c 2.3 KB

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