Beispiel #1
0
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))
    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;
}
Beispiel #2
0
MemoryBuffer *MemoryBuffer::getSTDIN() {
  char Buffer[4096*4];

  std::vector<char> FileData;

  // Read in all of the data from stdin, we cannot mmap stdin.
  //
  // FIXME: That isn't necessarily true, we should try to mmap stdin and
  // fallback if it fails.
  sys::Program::ChangeStdinToBinary();
  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();
  MemoryBuffer *B = new STDINBufferFile();
  B->initCopyOf(&FileData[0], &FileData[Size-1]);
  return B;
}