forked from Mickyconca/TP1SO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shm_lib.h
36 lines (34 loc) · 1007 Bytes
/
shm_lib.h
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
#ifndef SHM_LIB
#define SHM_LIB
#include <sys/mman.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/shm.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <string.h>
#define SHM_NAME "/shm_TP"
#define HANDLE_ERROR(msg) \
do \
{ \
perror(msg); \
exit(EXIT_FAILURE); \
} while (0)
#endif
typedef struct
{
char name[FILENAME_MAX];
int fd; // used to read and write from the memory
int rIndex; // where should I read next
int wIndex; // where should I write
int size; // the size of the memory assigned
char *address; // use to map from a new process
} t_shm;
t_shm createShm(char *name, int size); // shm_open -> ftruncate -> mmap
t_shm joinShm(char *name, int size);
char *readShm(t_shm *shareMem);
void writeShm(t_shm *shareMem, char *fromWrite, int size, int offSet);
void closeShm(t_shm *shareMem);
void eraseShm(t_shm *shareMem);