1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#if !defined( WNT ) && !defined(__hpux) && !defined( HPUX)
#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#if defined(HAVE_CONFIG_H)
#include <oce-config.h>
#endif
#if defined(HAVE_STDLIB_H)
#include <stdlib.h>
#endif
#if defined(HAVE_MALLOC_H)
#include <malloc.h>
#endif
/* Modified by Stephan GARNAUD (ARM) 1992 for Matra Datavision */
static int status ;
/* #ifdef ANSI */
int osd_getkey(char *) ;
int create_sharedmemory (int **,char *,int);
int open_sharedmemory (int **,char *,int);
int remove_sharedmemory (int * ,char * );
/* #endif */
int create_sharedmemory(int **section, char *section_name, int section_size)
/*===============================
CREATE a mapping memory section
returns 0 if failed
otherwise successfull : the shared memory id
===============================================================*/
{
key_t key;
key = (key_t) osd_getkey (section_name);
*section = NULL ;
status = shmget( key,section_size,0750 + IPC_CREAT) ;
if( status < 0 ) return 0 ; /* shmget failed */
else {
*section = (int*)shmat(status,NULL,0) ; /* shmat failed */
if( *section == (int*)-1 ) {
*section = (int*)malloc(section_size) ;
return 0 ;
}
}
return status;
}
int open_sharedmemory(int **section, char *section_name, int section_size)
/*=============================
OPEN a mapping memory section
We suppose that the shared memory segment is already
created(allocated)
Returns Value:
0 : If failed
otherwise successfull
================================================================*/
{
key_t key;
key = (key_t) osd_getkey (section_name);
*section = NULL ;
/* Test if shared memory identified by "k" exists ? */
status = shmget( key,0,0) ;
if( status < 0 ) return 0; /* shmget failed */
/* Try to attach the shared memory to the current process */
*section = (int*)shmat(status,NULL,0) ;
if( *section == (int*)-1 ) return 0; /* shmat failed */
return status ;
}
int remove_sharedmemory(int *shmid, char *section_name)
/*===========================================
CLOSE a mapping memory section
========================================================*/
{
status = shmctl(*shmid ,IPC_RMID,NULL) ;
if (status < 0) return 0;
else return 1;
}
#endif
|