aboutsummaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-10-24 15:45:42 +0000
committerNick Mathewson <nickm@torproject.org>2007-10-24 15:45:42 +0000
commit99d72f7295eca20d721482928712fc6d34983a5d (patch)
treebc3d8e9a86556b391227b8abe789dd722fc3c479 /src/common/util.c
parentab3fddd11e84b29ca503fabd4f230fb6708bc9b2 (diff)
downloadtor-99d72f7295eca20d721482928712fc6d34983a5d.tar
tor-99d72f7295eca20d721482928712fc6d34983a5d.tar.gz
r16100@catbus: nickm | 2007-10-24 11:33:52 -0400
Make tor_mmap_file() set and preserve errno in a useful way. svn:r12153
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 7a5740cc9..27ff0c2ce 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1782,16 +1782,20 @@ read_file_to_str(const char *filename, int flags, struct stat *stat_out)
fd = open(filename,O_RDONLY|(bin?O_BINARY:O_TEXT),0);
if (fd<0) {
int severity = LOG_WARN;
+ int save_errno = errno;
if (errno == ENOENT && (flags & RFTS_IGNORE_MISSING))
severity = LOG_INFO;
log_fn(severity, LD_FS,"Could not open \"%s\": %s ",filename,
strerror(errno));
+ errno = save_errno;
return NULL;
}
if (fstat(fd, &statbuf)<0) {
+ int save_errno = errno;
close(fd);
log_warn(LD_FS,"Could not fstat \"%s\".",filename);
+ errno = save_errno;
return NULL;
}
@@ -1802,10 +1806,12 @@ read_file_to_str(const char *filename, int flags, struct stat *stat_out)
r = read_all(fd,string,(size_t)statbuf.st_size,0);
if (r<0) {
+ int save_errno = errno;
log_warn(LD_FS,"Error reading from file \"%s\": %s", filename,
strerror(errno));
tor_free(string);
close(fd);
+ errno = save_errno;
return NULL;
}
string[r] = '\0'; /* NUL-terminate the result. */
@@ -1825,10 +1831,12 @@ read_file_to_str(const char *filename, int flags, struct stat *stat_out)
if (r != statbuf.st_size) {
/* Unless we're using text mode on win32, we'd better have an exact
* match for size. */
+ int save_errno = errno;
log_warn(LD_FS,"Could read only %d of %ld bytes of file \"%s\".",
r, (long)statbuf.st_size,filename);
tor_free(string);
close(fd);
+ errno = save_errno;
return NULL;
}
close(fd);