Commit eb690f1b authored by Guillaume Pasero's avatar Guillaume Pasero

ENH: wrap for isatty()

parent d47e53b8
......@@ -61,6 +61,9 @@ public:
/** Parse a filename with additional information */
static bool ParseFileNameForAdditionalInfo(const std::string& id, std::string& file, unsigned int& addNum);
/** Returns true if the file descriptor fd is interactive (i.e. like isatty on unix) */
static bool IsInteractive(int fd);
};
} // namespace otb
......
......@@ -28,6 +28,7 @@
/*=====================================================================
WIN32 / MSVC++ implementation
*====================================================================*/
#include <Windows.h>
#ifndef WIN32CE
# include <io.h>
#else
......@@ -37,6 +38,7 @@
/*=====================================================================
POSIX (Unix) implementation
*====================================================================*/
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#endif
......@@ -202,4 +204,37 @@ bool System::ParseFileNameForAdditionalInfo(const std::string& id, std::string&
return true;
}
bool System::IsInteractive(int fd)
{
#if (defined(WIN32) || defined(WIN32CE)) && !defined(__CYGWIN__) && !defined(__MINGW32__)
// Windows implementation
HANDLE hcon;
/* get OS handle of the file descriptor */
hcon = (HANDLE) _get_osfhandle(fd);
if (hcon == INVALID_HANDLE_VALUE)
return false;
/* check if its a device (i.e. console, printer, serial port) */
if (GetFileType(hcon) != FILE_TYPE_CHAR)
return false;
/* check if its a handle to a console output screen buffer */
CONSOLE_SCREEN_BUFFER_INFO screenBufferInfo;
DWORD mode;
if (!fd)
{
if (!GetConsoleMode(hcon, &mode))
return false;
}
else if (!GetConsoleScreenBufferInfo(hcon, &screenBufferInfo))
return false;
return true;
#else
// Unix implementation
return isatty(fd);
#endif
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment