Check fstats instead of using isatty().

This commit is contained in:
King_DuckZ 2015-09-29 17:40:01 +02:00
parent c69252604c
commit db1311839d

View file

@ -11,6 +11,7 @@
#include <memory>
#include <functional>
#include <unistd.h>
#include <sys/stat.h>
#include <iterator>
#define STRINGIZE_IMPL(s) #s
@ -88,8 +89,19 @@ namespace {
std::string getCleanHtml (const std::string& parUrl, const po::variables_map& parVarMap) {
std::string tidyHtml;
struct stat stats;
if (isatty(fileno(stdin))) {
const int r = fstat(fileno(stdin), &stats);
bool interactive = true;
if (r < 0) {
//TODO: error
interactive = false;
}
else {
interactive = static_cast<bool>(S_ISCHR(stats.st_mode));
}
if (interactive) {
tidyHtml = duck::getCleanHtml(
parUrl,
false,