[llvm-commits] CVS: llvm/lib/System/Win32/Path.cpp
Reid Spencer
reid at x10sys.com
Tue Dec 14 10:42:23 PST 2004
Changes in directory llvm/lib/System/Win32:
Path.cpp updated: 1.14 -> 1.15
---
Log message:
Add the getMagicNumber method.
Patch contributed by Henrik Bach. Thanks Henrik!
---
Diffs of the changes: (+19 -0)
Index: llvm/lib/System/Win32/Path.cpp
diff -u llvm/lib/System/Win32/Path.cpp:1.14 llvm/lib/System/Win32/Path.cpp:1.15
--- llvm/lib/System/Win32/Path.cpp:1.14 Mon Dec 13 23:26:43 2004
+++ llvm/lib/System/Win32/Path.cpp Tue Dec 14 12:42:13 2004
@@ -565,6 +565,25 @@
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;
+}
+
}
}
More information about the llvm-commits
mailing list