summaryrefslogtreecommitdiff
path: root/mystdlib.h
blob: 2e9499f24c61db529324f9e3fc439d6ded38d1ba (plain)
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
#include <sys/types.h>
#include <stdio.h>

typedef struct { int fh; unsigned char *addr; size_t size; } *MAP;

/* Mapps a file into memory
   returns pointer to the mapping struct,
   containing the file's size, the mapped
   address and its file handle.

   If readonly is true, the file will be
   opened and mapped read only. File is
   opened and mapped writable, if false.

   Returns NULL if memory could not be
   allocated, file could not be opened or
   mapped. Gives out an diagnostic message
   on stderr
*/
MAP map_file( char *filename, int readonly );

/* Unmapps a file from memory. NULL pointer
   checks are being done, so this is safe
   to be called from cleanup without knowing
   whether there actually is a map.
*/
void unmap_file ( MAP *pMap );

/* Gets file size of open file
   returns != 0 in case of error */
inline int getfilesize( int fd, unsigned long *size );