X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=fd.c;h=3a8406d9c9fd1454a0807c8584bae78aa1b2f543;hp=d2f93611de1e66ad9bbcd8dcd5aada40546f560f;hb=4744d937c4160898d1fe151257606430750e580c;hpb=c953ad4edff1bb64fb54124bfec7c3726cb2865a diff --git a/fd.c b/fd.c index d2f93611..3a8406d9 100644 --- a/fd.c +++ b/fd.c @@ -142,9 +142,11 @@ __printf_2_3 int write_va_buffer(int fd, const char *fmt, ...) { char *msg; int ret; + va_list ap; - PARA_VSPRINTF(fmt, msg); - ret = write_buffer(fd, msg); + va_start(ap, fmt); + ret = xvasprintf(&msg, fmt, ap); + ret = write_all(fd, msg, ret); free(msg); return ret; } @@ -615,6 +617,22 @@ int mmap_full_file(const char *path, int open_mode, void **map, goto out; } *size = file_status.st_size; + /* + * If the file is empty, *size is zero and mmap() would return EINVAL + * (Invalid argument). This error is common enough to spend an extra + * error code which explicitly states the problem. + */ + ret = -E_EMPTY; + if (*size == 0) + goto out; + /* + * If fd refers to a directory, mmap() returns ENODEV (No such device), + * at least on Linux. "Is a directory" seems to be more to the point. + */ + ret = -ERRNO_TO_PARA_ERROR(EISDIR); + if (S_ISDIR(file_status.st_mode)) + goto out; + ret = para_mmap(*size, mmap_prot, mmap_flags, fd, 0, map); out: if (ret < 0 || !fd_ptr)