aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/System/Unix/MappedFile.inc1
-rw-r--r--lib/System/Unix/Unix.h7
2 files changed, 6 insertions, 2 deletions
diff --git a/lib/System/Unix/MappedFile.inc b/lib/System/Unix/MappedFile.inc
index 07683c1439..409cea7e82 100644
--- a/lib/System/Unix/MappedFile.inc
+++ b/lib/System/Unix/MappedFile.inc
@@ -51,6 +51,7 @@ void MappedFile::initialize() {
else if (options_&WRITE_ACCESS)
mode = O_WRONLY;
info_->fd_ = ::open(path_.c_str(),mode);
+
if (info_->fd_ < 0) {
delete info_;
info_ = 0;
diff --git a/lib/System/Unix/Unix.h b/lib/System/Unix/Unix.h
index 6dc75545b6..75009d0746 100644
--- a/lib/System/Unix/Unix.h
+++ b/lib/System/Unix/Unix.h
@@ -68,14 +68,17 @@
inline void ThrowErrno(const std::string& prefix) {
char buffer[MAXPATHLEN];
+ buffer[0] = 0;
#ifdef HAVE_STRERROR_R
// strerror_r is thread-safe.
- strerror_r(errno,buffer,MAXPATHLEN-1);
+ if (errno)
+ strerror_r(errno,buffer,MAXPATHLEN-1);
#elif HAVE_STRERROR
// Copy the thread un-safe result of strerror into
// the buffer as fast as possible to minimize impact
// of collision of strerror in multiple threads.
- strncpy(buffer,strerror(errno),MAXPATHLEN-1);
+ if (Errno)
+ strncpy(buffer,strerror(errno),MAXPATHLEN-1);
buffer[MAXPATHLEN-1] = 0;
#else
// Strange that this system doesn't even have strerror