[llvm-commits] CVS: llvm/lib/Bytecode/Reader/ReaderWrappers.cpp

Reid Spencer reid at x10sys.com
Mon Dec 20 23:51:45 PST 2004



Changes in directory llvm/lib/Bytecode/Reader:

ReaderWrappers.cpp updated: 1.40 -> 1.41
---
Log message:

For PR351: http://llvm.cs.uiuc.edu/PR351 :
Remove unix specific code (use of errno and read) from the reader.
Thanks to Jeff Cohen for pointing this out.


---
Diffs of the changes:  (+7 -10)

Index: llvm/lib/Bytecode/Reader/ReaderWrappers.cpp
diff -u llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.40 llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.41
--- llvm/lib/Bytecode/Reader/ReaderWrappers.cpp:1.40	Sun Dec 19 22:52:04 2004
+++ llvm/lib/Bytecode/Reader/ReaderWrappers.cpp	Tue Dec 21 01:51:33 2004
@@ -20,6 +20,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/System/MappedFile.h"
 #include <cerrno>
+#include <iostream>
 using namespace llvm;
 
 //===----------------------------------------------------------------------===//
@@ -41,10 +42,6 @@
   };
 }
 
-static std::string ErrnoMessage (int savedErrNum, std::string descr) {
-   return ::strerror(savedErrNum) + std::string(", while trying to ") + descr;
-}
-
 BytecodeFileReader::BytecodeFileReader(const std::string &Filename,
                                        llvm::BytecodeHandler* H ) 
   : BytecodeReader(H)
@@ -133,14 +130,14 @@
 BytecodeStdinReader::BytecodeStdinReader( BytecodeHandler* H ) 
   : BytecodeReader(H)
 {
-  int BlockSize;
-  unsigned char Buffer[4096*4];
+  char Buffer[4096*4];
 
   // Read in all of the data from stdin, we cannot mmap stdin...
-  while ((BlockSize = ::read(0 /*stdin*/, Buffer, 4096*4))) {
-    if (BlockSize == -1)
-      throw ErrnoMessage(errno, "read from standard input");
-    
+  while (std::cin.good()) {
+    std::cin.read(Buffer, 4096*4);
+    int BlockSize = std::cin.gcount();
+    if (0 >= BlockSize)
+      break;
     FileData.insert(FileData.end(), Buffer, Buffer+BlockSize);
   }
 






More information about the llvm-commits mailing list