X-Git-Url: http://git.tuebingen.mpg.de/?p=osl.git;a=blobdiff_plain;f=util.c;h=32f3402aae7cc95a62c48f3b15965a3de75e48f9;hp=7500c08b2a6f085f4acc4fc77efc985a4351d977;hb=aad03a8d23774d258ab90dadde119db15f26ec38;hpb=22abcc2013d2f68ec55e5e0113c682899662c7d7 diff --git a/util.c b/util.c index 7500c08..32f3402 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. */ @@ -61,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; @@ -88,7 +90,7 @@ int osl_open(const char *path, int flags, mode_t mode) if (ret >= 0) return ret; - return -E_OSL_OPEN; + return errno == ENOENT? -E_OSL_NOENT : -E_OSL_OPEN; } /** @@ -108,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); @@ -152,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 = -E_OSL_FSTAT; + ret = errno == ENOENT? -E_OSL_NOENT : -E_OSL_STAT; goto out; } *size = file_status.st_size;