Files
mars-tinyldap/mstorage.h
2024-02-02 14:38:25 +00:00

39 lines
1.1 KiB
C

#ifndef _MSTORAGE_H
#define _MSTORAGE_H
#include <stddef.h>
#include <sys/types.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 */
ssize_t mstorage_add(mstorage_t* p,const char* s,size_t n);
/* same as mstorage_add but does not do the byte_copy */
ssize_t mstorage_reserve(mstorage_t* p,size_t n);
/* undo mapping. return 0 on success, -1 on failure */
int 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] */
// the name is slightly confusing. It stores a bstr (bstr.h)
// return offset (>=0) relative to p->root on success, -1 on fail
ssize_t mstorage_add_bin(mstorage_t* p,const char* s,size_t n);
#endif