mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-12 03:32:10 +00:00
* Use low-level unix I/O interface since we're on Unix.
* Don't use variable length arrays (replaced with alloca) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17901 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
0033baf94e
commit
be31d2ad78
@ -17,6 +17,7 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include <llvm/Config/config.h>
|
#include <llvm/Config/config.h>
|
||||||
|
#include <llvm/Config/alloca.h>
|
||||||
#include "Unix.h"
|
#include "Unix.h"
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -157,20 +158,29 @@ Path::getBasename() const {
|
|||||||
|
|
||||||
bool Path::hasMagicNumber(const std::string &Magic) const {
|
bool Path::hasMagicNumber(const std::string &Magic) const {
|
||||||
size_t len = Magic.size();
|
size_t len = Magic.size();
|
||||||
char buf[ 1 + len];
|
assert(len < 1024 && "Request for magic string too long");
|
||||||
std::ifstream f(path.c_str());
|
char* buf = (char*) alloca(1 + len);
|
||||||
f.read(buf, 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';
|
buf[len] = '\0';
|
||||||
f.close();
|
|
||||||
return Magic == buf;
|
return Magic == buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
|
bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
|
||||||
if (!isFile())
|
if (!isFile())
|
||||||
return false;
|
return false;
|
||||||
char buf[1 + len];
|
assert(len < 1024 && "Request for magic string too long");
|
||||||
std::ifstream f(path.c_str());
|
char* buf = (char*) alloca(1 + len);
|
||||||
f.read(buf,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';
|
buf[len] = '\0';
|
||||||
Magic = buf;
|
Magic = buf;
|
||||||
return true;
|
return true;
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include <llvm/Config/config.h>
|
#include <llvm/Config/config.h>
|
||||||
|
#include <llvm/Config/alloca.h>
|
||||||
#include "Unix.h"
|
#include "Unix.h"
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -157,20 +158,29 @@ Path::getBasename() const {
|
|||||||
|
|
||||||
bool Path::hasMagicNumber(const std::string &Magic) const {
|
bool Path::hasMagicNumber(const std::string &Magic) const {
|
||||||
size_t len = Magic.size();
|
size_t len = Magic.size();
|
||||||
char buf[ 1 + len];
|
assert(len < 1024 && "Request for magic string too long");
|
||||||
std::ifstream f(path.c_str());
|
char* buf = (char*) alloca(1 + len);
|
||||||
f.read(buf, 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';
|
buf[len] = '\0';
|
||||||
f.close();
|
|
||||||
return Magic == buf;
|
return Magic == buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
|
bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
|
||||||
if (!isFile())
|
if (!isFile())
|
||||||
return false;
|
return false;
|
||||||
char buf[1 + len];
|
assert(len < 1024 && "Request for magic string too long");
|
||||||
std::ifstream f(path.c_str());
|
char* buf = (char*) alloca(1 + len);
|
||||||
f.read(buf,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';
|
buf[len] = '\0';
|
||||||
Magic = buf;
|
Magic = buf;
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user