2

I am using llvm::MemoryBuffer::getFileOrSTDIN("-") and, according to the specification, it should Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".

Now, in the following context:

auto Source = llvm::MemoryBuffer::getFileOrSTDIN(File);

if (std::error_code err = Source.getError()) {
    llvm::errs() << err.message();
} else{
    someFunction(std::move(*Source), File, makeOutputWriter(Format, llvm::outs()),
            IdentifiersOnly, DumpAST);
}

it blocks on the first line (when File == "-"); as expected as the STDIN never closes.

When a special *char appears in STDIN, let's say <END_CHAR>, I know that I am finished reading for a given task. How could I close the STDIN in this situations and move on to someFunction ?

Thanks,

Stanislav Pankevich
  • 11,044
  • 8
  • 69
  • 129
Mathieu Nls
  • 2,285
  • 2
  • 17
  • 32

1 Answers1

0

You can always close the stdin file descriptor using close, i.e. close(0). If you check llvm::MemoryBuffer's source, you'll see that getFileOrSTDIN() basically boils down to a call to llvm::MemoryBuffer::getMemoryBufferForStream() with the first argument (the file descriptor) set to 0.

Also, see this SO answer.

The special character to close the standard input is ctrl-d (in *nix at least) on the command line (have a look here).

compor
  • 2,239
  • 1
  • 19
  • 29