2 Copyright (c) 1998-1999 Matra Datavision
3 Copyright (c) 1999-2012 OPEN CASCADE SAS
5 The content of this file is subject to the Open CASCADE Technology Public
6 License Version 6.5 (the "License"). You may not use the content of this file
7 except in compliance with the License. Please obtain a copy of the License
8 at http://www.opencascade.org and read it completely before using this file.
10 The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 The Original Code and all software distributed under the License is
14 distributed on an "AS IS" basis, without warranty of any kind, and the
15 Initial Developer hereby disclaims all such warranties, including without
16 limitation, any warranties of merchantability, fitness for a particular
17 purpose or non-infringement. Please see the License for the specific terms
18 and conditions governing the rights and limitations under the License.
22 #if !defined( WNT ) && !defined(__hpux) && !defined( HPUX)
24 #include <sys/types.h>
28 #if defined(HAVE_CONFIG_H)
31 #if defined(HAVE_STDLIB_H)
34 #if defined(HAVE_MALLOC_H)
38 /* Modified by Stephan GARNAUD (ARM) 1992 for Matra Datavision */
44 int osd_getkey(char *) ;
45 int create_sharedmemory (int **,char *,int);
46 int open_sharedmemory (int **,char *,int);
47 int remove_sharedmemory (int * ,char * );
51 int create_sharedmemory(int **section, char *section_name, int section_size)
52 /*===============================
54 CREATE a mapping memory section
57 otherwise successfull : the shared memory id
59 ===============================================================*/
63 key = (key_t) osd_getkey (section_name);
66 status = shmget( key,section_size,0750 + IPC_CREAT) ;
68 if( status < 0 ) return 0 ; /* shmget failed */
70 *section = (int*)shmat(status,NULL,0) ; /* shmat failed */
72 if( *section == (int*)-1 ) {
73 *section = (int*)malloc(section_size) ;
81 int open_sharedmemory(int **section, char *section_name, int section_size)
82 /*=============================
84 OPEN a mapping memory section
85 We suppose that the shared memory segment is already
90 ================================================================*/
94 key = (key_t) osd_getkey (section_name);
97 /* Test if shared memory identified by "k" exists ? */
98 status = shmget( key,0,0) ;
100 if( status < 0 ) return 0; /* shmget failed */
102 /* Try to attach the shared memory to the current process */
103 *section = (int*)shmat(status,NULL,0) ;
105 if( *section == (int*)-1 ) return 0; /* shmat failed */
111 int remove_sharedmemory(int *shmid, char *section_name)
112 /*===========================================
114 CLOSE a mapping memory section
116 ========================================================*/
118 status = shmctl(*shmid ,IPC_RMID,NULL) ;
119 if (status < 0) return 0;