aboutsummaryrefslogtreecommitdiffstats
path: root/lib/System/Unix/Path.inc
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2004-12-02 09:09:48 +0000
committerReid Spencer <rspencer@reidspencer.com>2004-12-02 09:09:48 +0000
commit86ac2dcda153cbf317fa6ea7c8ad97ec0f173c4c (patch)
tree8c4609ee0c655e2537158fb726cc8553766f96f2 /lib/System/Unix/Path.inc
parentfc757b5217623759c046239d4200a95013eb916b (diff)
downloadexternal_llvm-86ac2dcda153cbf317fa6ea7c8ad97ec0f173c4c.zip
external_llvm-86ac2dcda153cbf317fa6ea7c8ad97ec0f173c4c.tar.gz
external_llvm-86ac2dcda153cbf317fa6ea7c8ad97ec0f173c4c.tar.bz2
Fix seriously broken implementation of GetMagicNumber.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18422 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/System/Unix/Path.inc')
-rw-r--r--lib/System/Unix/Path.inc10
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/System/Unix/Path.inc b/lib/System/Unix/Path.inc
index 70cc4f0..5d2a4b6 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;
}