diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2004-11-16 17:14:08 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2004-11-16 17:14:08 +0000 |
commit | 1b13a7cdb8d5e299da8ec62c2dd4d14e65e3509c (patch) | |
tree | fe3ad35e4b1bc9e79067e7d8230ea9d1341a8633 /llvm/lib/System/Unix/Path.cpp | |
parent | 7391dde138fdbbfbcb1767aeb3621b0a3d9c694f (diff) | |
download | bcm5719-llvm-1b13a7cdb8d5e299da8ec62c2dd4d14e65e3509c.tar.gz bcm5719-llvm-1b13a7cdb8d5e299da8ec62c2dd4d14e65e3509c.zip |
* Use low-level unix I/O interface since we're on Unix.
* Don't use variable length arrays (replaced with alloca)
llvm-svn: 17901
Diffstat (limited to 'llvm/lib/System/Unix/Path.cpp')
-rw-r--r-- | llvm/lib/System/Unix/Path.cpp | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/llvm/lib/System/Unix/Path.cpp b/llvm/lib/System/Unix/Path.cpp index 55ef6669ee3..70cc4f01032 100644 --- a/llvm/lib/System/Unix/Path.cpp +++ b/llvm/lib/System/Unix/Path.cpp @@ -17,6 +17,7 @@ //===----------------------------------------------------------------------===// #include <llvm/Config/config.h> +#include <llvm/Config/alloca.h> #include "Unix.h" #include <sys/stat.h> #include <fcntl.h> @@ -157,20 +158,29 @@ Path::getBasename() const { bool Path::hasMagicNumber(const std::string &Magic) const { size_t len = Magic.size(); - char buf[ 1 + len]; - std::ifstream f(path.c_str()); - f.read(buf, len); + assert(len < 1024 && "Request for magic string too long"); + char* buf = (char*) alloca(1 + len); + int fd = ::open(path.c_str(),O_RDONLY); + if (fd < 0) + return false; + if (0 != ::read(fd, buf, len)) + return false; + close(fd); buf[len] = '\0'; - f.close(); return Magic == buf; } bool Path::getMagicNumber(std::string& Magic, unsigned len) const { if (!isFile()) return false; - char buf[1 + len]; - std::ifstream f(path.c_str()); - f.read(buf,len); + assert(len < 1024 && "Request for magic string too long"); + char* buf = (char*) alloca(1 + len); + int fd = ::open(path.c_str(),O_RDONLY); + if (fd < 0) + return false; + if (0 != ::read(fd, buf, len)) + return false; + close(fd); buf[len] = '\0'; Magic = buf; return true; |