summaryrefslogtreecommitdiffstats
path: root/mstorage.h
blob: 258e78655978757009f3b5317118dc4eb02dc73f (plain) (blame)
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
#ifndef _MSTORAGE_H
#define _MSTORAGE_H

#include <stddef.h>

/* (optionally persistent) mmapped storage. */

typedef struct mstorage {
  char* root;
  size_t mapped,used;
  int fd;
} mstorage_t;

void mstorage_init(mstorage_t* p);

int mstorage_init_persistent(mstorage_t* p,int fd);

/* Works like strstorage_add, but will return an
 * offset to mstorage_root, which is mmapped and may thus change. */
/* offset -1 ==> error */
long mstorage_add(mstorage_t* p,const char* s,size_t n);

/* undo mapping */
void mstorage_unmap(mstorage_t* p);

/* this is tinyldap specific.  If the data contains at least one 0-byte,
 * it is stored in a tinyldap specific encoding:
 *   char 0;
 *   uint32 len;
 *   char data[len] */
long mstorage_add_bin(mstorage_t* p,const char* s,size_t n);

#endif