-//===----------------------------------------------------------------------===//
-// MemoryBuffer::getFile implementation.
-//===----------------------------------------------------------------------===//
-
-MemoryBuffer *MemoryBuffer::getFile(const char *FilenameStart, unsigned FnSize,
- std::string *ErrStr, int64_t FileSize){
- // FIXME: it would be nice if PathWithStatus didn't copy the filename into a
- // temporary string. :(
- sys::PathWithStatus P(FilenameStart, FnSize);
-#if 1
- MemoryBufferMMapFile *M = new MemoryBufferMMapFile();
- if (!M->open(P, ErrStr))
- return M;
- delete M;
- return 0;
-#else
- // FIXME: We need an efficient and portable method to open a file and then use
- // 'read' to copy the bits out. The unix implementation is below. This is
- // an important optimization for clients that want to open large numbers of
- // small files (using mmap on everything can easily exhaust address space!).
-
- // If the user didn't specify a filesize, do a stat to find it.
- if (FileSize == -1) {
- const sys::FileStatus *FS = P.getFileStatus();
- if (FS == 0) return 0; // Error stat'ing file.
-
- FileSize = FS->fileSize;
+MemoryBuffer *MemoryBuffer::getFile(const char *Filename, std::string *ErrStr,
+ int64_t FileSize, struct stat *FileInfo) {
+ int OpenFlags = O_RDONLY;
+#ifdef O_BINARY
+ OpenFlags |= O_BINARY; // Open input file in binary mode on win32.
+#endif
+ int FD = ::open(Filename, OpenFlags);
+ if (FD == -1) {
+ if (ErrStr) *ErrStr = sys::StrError();
+ return 0;