**/
_PUBLIC_ char *file_load(const char *fname, size_t *size, size_t maxsize, TALLOC_CTX *mem_ctx);
-/**
-mmap (if possible) or read a file
-**/
-_PUBLIC_ void *map_file(const char *fname, size_t size);
-
/**
load a file into memory and return an array of pointers to lines in the file
must be freed with talloc_free().
bool (*pfunc)(const char *, const char *, void *),
void *userdata);
-bool unmap_file(void *start, size_t size);
-
void print_asc(int level, const uint8_t *buf,int len);
void print_asc_cb(const uint8_t *buf, int len,
void (*cb)(const char *buf, void *private_data),
return p;
}
-
-/**
-mmap (if possible) or read a file
-**/
-_PUBLIC_ void *map_file(const char *fname, size_t size)
-{
- size_t s2 = 0;
- void *p = NULL;
-#ifdef HAVE_MMAP
- int fd;
- fd = open(fname, O_RDONLY, 0);
- if (fd == -1) {
- DEBUG(2,("Failed to load %s - %s\n", fname, strerror(errno)));
- return NULL;
- }
- p = mmap(NULL, size, PROT_READ, MAP_SHARED|MAP_FILE, fd, 0);
- close(fd);
- if (p == MAP_FAILED) {
- DEBUG(1,("Failed to mmap %s - %s\n", fname, strerror(errno)));
- return NULL;
- }
-#endif
- if (!p) {
- p = file_load(fname, &s2, 0, NULL);
- if (!p) return NULL;
- if (s2 != size) {
- DEBUG(1,("incorrect size for %s - got %d expected %d\n",
- fname, (int)s2, (int)size));
- talloc_free(p);
- return NULL;
- }
- }
-
- return p;
-}
-
-/**
- unmap or free memory
-**/
-
-bool unmap_file(void *start, size_t size)
-{
-#ifdef HAVE_MMAP
- if (munmap( start, size ) != 0) {
- DEBUG( 1, ("map_file: Failed to unmap address %p "
- "of size %u - %s\n",
- start, (unsigned int)size, strerror(errno) ));
- return false;
- }
- return true;
-#else
- talloc_free(start);
- return true;
-#endif
-}
-
/**
parse a buffer into lines
'p' will be freed on error, and otherwise will be made a child of the returned array