[PATCH] D63858: [Support] Add sys::fs::is_tty() wrapper around isatty(3)
Alex Brachet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 26 19:37:10 PDT 2019
abrachet created this revision.
abrachet added reviewers: jhenderson, rupprecht.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
Adds a wrapper in Support/Filesystem.h for determining if a file descriptor refers to a terminal.
This patch is needed by an upcoming patch which needs to know if stdin has redirected input or not.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D63858
Files:
llvm/include/llvm/Support/FileSystem.h
llvm/lib/Support/Unix/Path.inc
llvm/lib/Support/Windows/Path.inc
Index: llvm/lib/Support/Windows/Path.inc
===================================================================
--- llvm/lib/Support/Windows/Path.inc
+++ llvm/lib/Support/Windows/Path.inc
@@ -734,6 +734,10 @@
return getStatus(FileHandle, Result);
}
+bool is_tty(int FD) {
+ return _isatty(FD);
+}
+
std::error_code setPermissions(const Twine &Path, perms Permissions) {
SmallVector<wchar_t, 128> PathUTF16;
if (std::error_code EC = widenPath(Path, PathUTF16))
Index: llvm/lib/Support/Unix/Path.inc
===================================================================
--- llvm/lib/Support/Unix/Path.inc
+++ llvm/lib/Support/Unix/Path.inc
@@ -694,6 +694,10 @@
return fillStatus(StatRet, Status, Result);
}
+bool is_tty(int FD) {
+ return isatty(FD);
+}
+
std::error_code setPermissions(const Twine &Path, perms Permissions) {
SmallString<128> PathStorage;
StringRef P = Path.toNullTerminatedStringRef(PathStorage);
Index: llvm/include/llvm/Support/FileSystem.h
===================================================================
--- llvm/include/llvm/Support/FileSystem.h
+++ llvm/include/llvm/Support/FileSystem.h
@@ -634,6 +634,12 @@
/// platform-specific error_code.
std::error_code is_other(const Twine &path, bool &result);
+/// Does FD refer to a terminal?
+///
+/// @param FD Input file descriptor.
+/// @returns true if the file descriptor refers to a terminal.
+bool is_tty(int FD);
+
/// Get file status as if by POSIX stat().
///
/// @param path Input path.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63858.206777.patch
Type: text/x-patch
Size: 1507 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190627/d11a5980/attachment.bin>
More information about the llvm-commits
mailing list