Files
mars-tinyldap/mstorage_unmap.c
2024-02-02 14:38:25 +00:00

30 lines
604 B
C

/* this is not actually used by tinyldap itself. */
/* 100% unit test coverage by unit tests in mstorage_add.c */
#include "mstorage.h"
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <sys/shm.h>
int mstorage_unmap(mstorage_t* p) {
int r=0;
#ifdef MREMAP_MAYMOVE
if (p->root && p->root!=MAP_FAILED)
if (munmap(p->root,p->mapped) == -1)
r=-1;
#else
free(p->root);
#endif
if (p->fd!=-1) {
r |= ftruncate(p->fd,p->used);
r |= close(p->fd);
}
p->mapped=p->used=0;
p->root=0;
return r;
}