1 #ifndef _MSTORAGE_H
2 #define _MSTORAGE_H
3 
4 #include <stddef.h>
5 
6 /* (optionally persistent) mmapped storage. */
7 
8 typedef struct mstorage {
9   char* root;
10   size_t mapped,used;
11   int fd;
12 } mstorage_t;
13 
14 void mstorage_init(mstorage_t* p);
15 
16 int mstorage_init_persistent(mstorage_t* p,int fd);
17 
18 /* Works like strstorage_add, but will return an
19  * offset to mstorage_root, which is mmapped and may thus change. */
20 /* offset -1 ==> error */
21 long mstorage_add(mstorage_t* p,const char* s,size_t n);
22 
23 /* undo mapping */
24 void mstorage_unmap(mstorage_t* p);
25 
26 /* this is tinyldap specific.  If the data contains at least one 0-byte,
27  * it is stored in a tinyldap specific encoding:
28  *   char 0;
29  *   uint32 len;
30  *   char data[len] */
31 long mstorage_add_bin(mstorage_t* p,const char* s,size_t n);
32 
33 #endif
34