|
|
1.1 ! root 1: /* ! 2: * (User) Shared Memory Control Functions ! 3: * ! 4: * Note: shmget() must be first function called. ! 5: * ! 6: * $Log: shmop.c,v $ ! 7: * Revision 1.1 92/06/30 10:32:03 bin ! 8: * Initial revision ! 9: * ! 10: * 87/04/26 Allan Cornish ! 11: * Support for 32 bit 'key' added to shmget. ! 12: */ ! 13: ! 14: #include <sys/shm.h> ! 15: ! 16: int shmfd = -1; ! 17: static char shmdev[] = "/dev/shm"; ! 18: ! 19: /* ! 20: * Shared Memory Control Operations. ! 21: */ ! 22: ! 23: shmctl( shmid, cmd, buf ) ! 24: ! 25: int shmid; ! 26: int cmd; ! 27: int buf; ! 28: ! 29: { ! 30: int parm[4]; ! 31: ! 32: if ( shmfd < 0 ) ! 33: return -1; ! 34: ! 35: parm[0] = -1; ! 36: parm[1] = shmid; ! 37: parm[2] = cmd; ! 38: parm[3] = buf; ! 39: ! 40: ioctl( shmfd, SHMCTL, parm ); ! 41: return parm[0]; ! 42: } ! 43: ! 44: /* ! 45: * Get Shared Memory Segment. ! 46: */ ! 47: ! 48: shmget( key, size, shmflg ) ! 49: ! 50: key_t key; ! 51: int size; ! 52: int shmflg; ! 53: ! 54: { ! 55: int parm[5]; ! 56: ! 57: if ( shmfd < 0 ) { ! 58: ! 59: if ( (shmfd = open(shmdev, 2)) < 0 ) { ! 60: ! 61: perror( shmdev ); ! 62: return -1; ! 63: } ! 64: } ! 65: ! 66: parm[0] = -1; ! 67: parm[1] = key; ! 68: parm[2] = key >> 16; ! 69: parm[3] = size; ! 70: parm[4] = shmflg; ! 71: ! 72: ioctl( shmfd, SHMGET, parm ); ! 73: return parm[0]; ! 74: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.