Add the getMagicNumber method.
authorReid Spencer <rspencer@reidspencer.com>
Tue, 14 Dec 2004 18:42:13 +0000 (18:42 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Tue, 14 Dec 2004 18:42:13 +0000 (18:42 +0000)
Patch contributed by Henrik Bach. Thanks Henrik!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18933 91177308-0d34-0410-b5e6-96231b3b80d8

lib/System/Win32/Path.cpp
lib/System/Win32/Path.inc

index 88e20cd354f417fcc97b7fbb8daec5223afa5de0..f6e4c3b4763733095b8d61ba1565fcef413bcf7f 100644 (file)
@@ -565,6 +565,25 @@ Path::destroyFile() {
   return true;
 }
 
+bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
+  if (!isFile())
+    return false;
+  assert(len < 1024 && "Request for magic string too long");
+  char* buf = (char*) alloca(1 + len);
+  std::ofstream ofs(path.c_str(),std::ofstream::in);
+  if (!ofs.is_open())
+    return false;
+  std::ifstream ifs(path.c_str());
+  if (!ifs.is_open())
+    return false;
+  ifs.read(buf, len);
+  ofs.close();
+  ifs.close();
+  buf[len] = '\0';
+  Magic = buf;
+  return true;
+}
+
 }
 }
 
index 88e20cd354f417fcc97b7fbb8daec5223afa5de0..f6e4c3b4763733095b8d61ba1565fcef413bcf7f 100644 (file)
@@ -565,6 +565,25 @@ Path::destroyFile() {
   return true;
 }
 
+bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
+  if (!isFile())
+    return false;
+  assert(len < 1024 && "Request for magic string too long");
+  char* buf = (char*) alloca(1 + len);
+  std::ofstream ofs(path.c_str(),std::ofstream::in);
+  if (!ofs.is_open())
+    return false;
+  std::ifstream ifs(path.c_str());
+  if (!ifs.is_open())
+    return false;
+  ifs.read(buf, len);
+  ofs.close();
+  ifs.close();
+  buf[len] = '\0';
+  Magic = buf;
+  return true;
+}
+
 }
 }