Message ID | 20170608165120.GQ2820@ovn.org |
---|---|
State | RFC |
Headers | show |
> > > > Signed-off-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com> > > Thanks for finding and fixing the problem. > > This approach fixes a problem in one place only. I see that there are other > calls to isatty() in the tree, so I would prefer to fix them all in one place. How > about the following approach instead? I have not tested it. [Alin Serdean] Thanks for the incremental. It makes more sense to just have it one place. I think isatty might be already defined. I will work around you incremental and add you as co-author. Thanks for the quick review.
diff --git a/include/windows/unistd.h b/include/windows/unistd.h index 2e9f0aef1647..00ca69762102 100644 --- a/include/windows/unistd.h +++ b/include/windows/unistd.h @@ -85,4 +85,19 @@ __inline long sysconf(int type) return value; } +/* On Windows, a console is a specialized character device, and isatty() only + * reports whether a file description is a character device and thus reports + * that devices such as /dev/null are ttys. This replacement avoids that + * problem. */ +#define isatty(fd) rpl_isatty(fd) +static __inline int +rpl_isatty(int fd) +{ + HANDLE h = (HANDLE) _get_osfhandle(fd); + DWORD st; + return (_isatty(STDOUT_FILENO) + && h != INVALID_HANDLE_VALUE + && GetConsoleMode(h, &st)); +} + #endif /* unistd.h */