[PATCH] D63859: [Support] Add getFileOrSTDIN which calls a callback if stdin is a tty

James Henderson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 4 09:07:50 PDT 2019


jhenderson added a comment.

In D63859#1570505 <https://reviews.llvm.org/D63859#1570505>, @abrachet wrote:

> > I stumbled on StandardInIsUserInput which might make this whole function redundant
>
> Ah thanks James, can't believe I didn't find that before. Do you mean this function getFileOrSTDIN with the callback, or sys::fs::is_tty? For is_tty, yes, but I'm not sure for getFileOrSTDIN. I will ask on the list I originally started this discussion on if the tools calling `if (StandardInIsUserInput)` is better than doing this through getFileOrSTDIN, it might be, actually cause not all such tools will use this. Good suggestion.


It really depends on your exact use-case, and it's somewhat hard to say which is the right thing to do based on that. Personally, I think you could do `if (StandardInIsUserInput)` in the caller, and then call getFileorSTDIN as appropriate afterwards.

> Also, I found this function RedirectIO here for Windows <https://github.com/llvm/llvm-project/blob/master/llvm/lib/Support/Windows/Program.inc#L126> and Unix <https://github.com/llvm/llvm-project/blob/master/llvm/lib/Support/Unix/Program.inc#L96> they are both static and actually have different signatures, actually.  But I bring it up because the Windows version uses DuplicateHandle <https://docs.microsoft.com/en-us/windows/win32/api/handleapi/nf-handleapi-duplicatehandle>. I'm guessing this test worked on Windows though or you would have said something. But I could use this if it is preferable to dup2.

It's probably preferable to use existing things rather than try to use the low-level APIs like dup2 that are not particularly portable.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63859/new/

https://reviews.llvm.org/D63859





More information about the llvm-commits mailing list