aboutsummaryrefslogtreecommitdiff
path: root/lib/System/Unix
diff options
context:
space:
mode:
Diffstat (limited to 'lib/System/Unix')
-rw-r--r--lib/System/Unix/Path.cpp10
-rw-r--r--lib/System/Unix/Path.inc10
2 files changed, 12 insertions, 8 deletions
diff --git a/lib/System/Unix/Path.cpp b/lib/System/Unix/Path.cpp
index 70cc4f0103..5d2a4b688c 100644
--- a/lib/System/Unix/Path.cpp
+++ b/lib/System/Unix/Path.cpp
@@ -178,11 +178,13 @@ bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
int fd = ::open(path.c_str(),O_RDONLY);
if (fd < 0)
return false;
- if (0 != ::read(fd, buf, len))
+ ssize_t bytes_read = ::read(fd, buf, len);
+ ::close(fd);
+ if (ssize_t(len) != bytes_read) {
+ Magic.clear();
return false;
- close(fd);
- buf[len] = '\0';
- Magic = buf;
+ }
+ Magic.assign(buf,len);
return true;
}
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc
index 70cc4f0103..5d2a4b688c 100644
--- a/lib/System/Unix/Path.inc
+++ b/lib/System/Unix/Path.inc
@@ -178,11 +178,13 @@ bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
int fd = ::open(path.c_str(),O_RDONLY);
if (fd < 0)
return false;
- if (0 != ::read(fd, buf, len))
+ ssize_t bytes_read = ::read(fd, buf, len);
+ ::close(fd);
+ if (ssize_t(len) != bytes_read) {
+ Magic.clear();
return false;
- close(fd);
- buf[len] = '\0';
- Magic = buf;
+ }
+ Magic.assign(buf,len);
return true;
}