summaryrefslogtreecommitdiffstats
path: root/llvm/lib/System/Unix/Path.cpp
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
commitf473185cbce52393eebbbb0d59a6b07a1c58524d (patch)
tree02a13fb4fa2afe88ae7f85a6088fc9f8ba829660 /llvm/lib/System/Unix/Path.cpp
parent1c8a34ff77b31500d2ccbf38cbd57cbc0db6ce26 (diff)
downloadbcm5719-llvm-f473185cbce52393eebbbb0d59a6b07a1c58524d.tar.gz
bcm5719-llvm-f473185cbce52393eebbbb0d59a6b07a1c58524d.zip
Fix seriously broken implementation of GetMagicNumber.
llvm-svn: 18422
Diffstat (limited to 'llvm/lib/System/Unix/Path.cpp')
-rw-r--r--llvm/lib/System/Unix/Path.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/llvm/lib/System/Unix/Path.cpp b/llvm/lib/System/Unix/Path.cpp
index 70cc4f01032..5d2a4b688c4 100644
--- a/llvm/lib/System/Unix/Path.cpp
+++ b/llvm/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;
}
OpenPOWER on IntegriCloud