Make getSTDIN return null if the standard input is empty, as the header file

documentation implies and as its uses depend.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40939 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Spencer 2007-08-08 20:01:58 +00:00
parent 53424ad141
commit 2372ccc111

View File

@ -248,11 +248,13 @@ MemoryBuffer *MemoryBuffer::getSTDIN() {
// Read in all of the data from stdin, we cannot mmap stdin.
sys::Program::ChangeStdinToBinary();
while (size_t ReadBytes = fread(Buffer, 1, 4096*4, stdin))
while (size_t ReadBytes = fread(Buffer, sizeof(char), 4096*4, stdin))
FileData.insert(FileData.end(), Buffer, Buffer+ReadBytes);
FileData.push_back(0); // &FileData[Size] is invalid. So is &*FileData.end().
size_t Size = FileData.size();
if (Size <= 1)
return 0;
MemoryBuffer *B = new STDINBufferFile();
B->initCopyOf(&FileData[0], &FileData[Size-1]);
return B;