X-Git-Url: http://git.tuebingen.mpg.de/?p=osl.git;a=blobdiff_plain;f=util.c;h=34667e3fc7a6ace461652ec90c285b60bdb47307;hp=7bf74b0b2dc099c066e8e0dd96d93a47cb01fbd5;hb=b33ea63fb2357f0da13a30d2d0df6ffe8f2c4fc1;hpb=c1a4bb030717f2d2d209ccd8ab898ab66fa16869 diff --git a/util.c b/util.c index 7bf74b0..34667e3 100644 --- a/util.c +++ b/util.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2008 Andre Noll + * Copyright (C) 2006-2009 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -14,7 +14,6 @@ #include "log.h" #include "osl.h" -#include "error.h" #include "util.h" /** @@ -40,7 +39,7 @@ static ssize_t __write(int fd, const void *buf, size_t size) ret = write(fd, buf, size); if ((ret < 0) && (errno == EAGAIN || errno == EINTR)) continue; - return ret >= 0? ret : -ERRNO_TO_ERROR(errno); + return ret >= 0? ret : -E_OSL_WRITE; } } @@ -62,8 +61,10 @@ int write_all(int fd, const char *buf, size_t *len) *len = 0; while (*len < total) { int ret = __write(fd, buf + *len, total - *len); - if (ret < 0) + if (ret < 0) { + ERROR_LOG("write error: %s\n", strerror(errno)); return ret; + } *len += ret; } return 1; @@ -89,7 +90,7 @@ int osl_open(const char *path, int flags, mode_t mode) if (ret >= 0) return ret; - return -ERRNO_TO_ERROR(errno); + return errno == ENOENT? -E_OSL_NOENT : -E_OSL_OPEN; } /** @@ -109,9 +110,11 @@ int write_file(const char *filename, const void *buf, size_t size) if (ret < 0) return ret; fd = ret; - ret = write_all(fd, buf, &size); - if (ret < 0) - goto out; + if (size != 0) { + ret = write_all(fd, buf, &size); + if (ret < 0) + goto out; + } ret = 1; out: close(fd); @@ -153,7 +156,7 @@ int mmap_full_file(const char *path, int open_mode, void **map, return ret; fd = ret; if (fstat(fd, &file_status) < 0) { - ret = -ERRNO_TO_ERROR(errno); + ret = errno == ENOENT? -E_OSL_NOENT : -E_OSL_STAT; goto out; } *size = file_status.st_size; @@ -194,7 +197,7 @@ int osl_munmap(void *start, size_t length) err = errno; ERROR_LOG("munmap (%p/%zu) failed: %s\n", start, length, strerror(err)); - return -ERRNO_TO_ERROR(err); + return -E_OSL_MUNMAP; } /** @@ -226,7 +229,7 @@ __must_check __printf_1_2 __malloc char *make_message(const char *fmt, ...) n = vsnprintf(p, size, fmt, ap); va_end(ap); /* If that worked, return the string. */ - if (n > -1 && n < size) + if (n > -1 && (unsigned)n < size) break; /* Else try again with more space. */ if (n > -1) /* glibc 2.1 */ @@ -267,6 +270,6 @@ int truncate_file(const char *path, off_t size) if (statbuf.st_size < size) return ret; if (truncate(path, statbuf.st_size - size) < 0) - return -ERRNO_TO_ERROR(errno); + return -E_OSL_TRUNCATE; return 1; }