X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=fd.c;h=8759d5099200c4f6c1b6c31e84b66da3372b5540;hp=6d32e93eeca6d205725390ea59b8e97fdd09b376;hb=d40858b7fea7cf170e3b0f75618cd58a61f1cecf;hpb=683dcc711c249f1cb689a04ada046364067e6540 diff --git a/fd.c b/fd.c index 6d32e93e..8759d509 100644 --- a/fd.c +++ b/fd.c @@ -225,19 +225,26 @@ again: * \param flags Exactly one of MAP_SHARED and MAP_PRIVATE. * \param fd The file to mmap from. * \param offset Mmap start. + * \param map Result pointer. * - * \return This function either returns a valid pointer to the mapped area - * or calls exit() on errors. + * \return Standard. + * + * \sa mmap(2). */ -void *para_mmap(size_t length, int prot, int flags, int fd, off_t offset) +int para_mmap(size_t length, int prot, int flags, int fd, off_t offset, + void *map) { - void *ret = mmap(NULL, length, prot, flags, fd, offset); - if (ret != MAP_FAILED) - return ret; - PARA_EMERG_LOG("mmap failed: %s\n", strerror(errno)); - PARA_EMERG_LOG("length: %zu, flags: %d, fd: %d, offset: %zu\n", - length, flags, fd, (size_t)offset); - exit(EXIT_FAILURE); + void **m = map; + + errno = EINVAL; + if (!length) + goto err; + *m = mmap(NULL, length, prot, flags, fd, offset); + if (*m != MAP_FAILED) + return 1; +err: + *m = NULL; + return -ERRNO_TO_PARA_ERROR(errno); } /** @@ -398,17 +405,7 @@ int mmap_full_file(const char *path, int open_mode, void **map, goto out; } *size = file_status.st_size; - ret = -E_EMPTY; - PARA_DEBUG_LOG("%s: size %zu\n", path, *size); - if (!*size) - goto out; - *map = mmap(NULL, *size, mmap_prot, mmap_flags, fd, 0); - if (*map == MAP_FAILED) { - *map = NULL; - ret = -E_MMAP; - goto out; - } - ret = 1; + ret = para_mmap(*size, mmap_prot, mmap_flags, fd, 0, map); out: if (ret < 0 || !fd_ptr) close(fd);