aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-05-18 08:44:04 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-05-18 08:44:04 +0000
commit5b78a469c26d0db206bfbd821f9a4c9f95334759 (patch)
treebc1e342393705b836a60d0254c3c34281ed03fee /lib
parent24950d8182ddd0207aaf5964b931e68d89ed9120 (diff)
downloadexternal_llvm-5b78a469c26d0db206bfbd821f9a4c9f95334759.zip
external_llvm-5b78a469c26d0db206bfbd821f9a4c9f95334759.tar.gz
external_llvm-5b78a469c26d0db206bfbd821f9a4c9f95334759.tar.bz2
Tweak MemoryBuffer::getSTDIN so that it returns after the first EOF.
It doesn't matter for piped input, but it's annoying when typing at the console. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@71998 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Support/MemoryBuffer.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp
index a4963d9..e35c626 100644
--- a/lib/Support/MemoryBuffer.cpp
+++ b/lib/Support/MemoryBuffer.cpp
@@ -258,13 +258,16 @@ public:
MemoryBuffer *MemoryBuffer::getSTDIN() {
char Buffer[4096*4];
-
+
std::vector<char> FileData;
-
+
// Read in all of the data from stdin, we cannot mmap stdin.
sys::Program::ChangeStdinToBinary();
- while (size_t ReadBytes = fread(Buffer, sizeof(char), 4096*4, stdin))
+ size_t ReadBytes;
+ do {
+ ReadBytes = fread(Buffer, sizeof(char), sizeof(Buffer), stdin);
FileData.insert(FileData.end(), Buffer, Buffer+ReadBytes);
+ } while (ReadBytes == sizeof(Buffer));
FileData.push_back(0); // &FileData[Size] is invalid. So is &*FileData.end().
size_t Size = FileData.size();