Go to the source code of this file.
Functions | |
ppCPP (extern"C"{) typedef struct ctl_mmap | |
A memory mapped file (Read Only) Basically get a const pointer to a file. | |
const void * | ctl_mmap_open (ctl_mmap *map, const char *szPath) |
Open a memory map. | |
void | ctl_mmap_close (ctl_mmap *map) |
Close a memory map. |
Definition in file mmap.h.
void ctl_mmap_close | ( | ctl_mmap * | map | ) |
Close a memory map.
map | Map instance to open |
Definition at line 116 of file mmap.c.
References assertobjptr.
Referenced by ppCPP().
00117 { 00118 assertobjptr(map); 00119 if( map->base ) 00120 munmap( (void*)map->base, map->size ); 00121 if( map->fd != -1 ) 00122 close( map->fd ); 00123 map->fd = -1; 00124 map->base = NULL; 00125 map->size = 0; 00126 }
const void* ctl_mmap_open | ( | ctl_mmap * | map, | |
const char * | szPath | |||
) |
Open a memory map.
map | Map instance to open | |
szPath | Path to file to map into memory |
Definition at line 85 of file mmap.c.
References assertconst, and assertobjptr.
Referenced by BMI_Load(), and ppCPP().
00086 { 00087 assertobjptr(map); 00088 assertconst(szPath,1); 00089 map->base = NULL; 00090 map->size = 0; 00091 map->fd = open(szPath, O_RDONLY); 00092 if(map->fd != -1) 00093 { 00094 struct stat buf; 00095 if ( !fstat(map->fd, &buf) ) 00096 { 00097 map->size = buf.st_size; 00098 map->base = mmap(0, map->size, PROT_READ, MAP_SHARED, map->fd, 0); 00099 if( map->base == MAP_FAILED ) 00100 { 00101 map->base = NULL; 00102 map->size = 0; 00103 close(map->fd); 00104 map->fd = -1; 00105 } 00106 return map->base; 00107 } 00108 } 00109 return NULL; 00110 }
ppCPP | ( | ) |
A memory mapped file (Read Only) Basically get a const pointer to a file.
TODO: Make tchar templates of these
< Where the memory is
< Length of it
< File descriptor to close when finished
Definition at line 9 of file mmap.h.
References ctl_mmap_close(), ctl_mmap_open(), and ppCPP().
00009 {) 00010 00015 typedef struct ctl_mmap 00016 { 00017 void* base; 00018 size_t size; 00019 #ifdef WIN32 00020 void* hFile; 00021 void* hMap; 00022 #else /* LINUX */ 00023 int fd; 00024 #endif 00025 } ctl_mmap;