diff --git a/src/FileUtil.cpp b/src/FileUtil.cpp index 5e8ed7c..9a1740b 100644 --- a/src/FileUtil.cpp +++ b/src/FileUtil.cpp @@ -1,6 +1,6 @@ //------------------------------------------------------------------------------ // -// Copyright 2019 BBC Research and Development +// Copyright 2022 BBC Research and Development // // Author: Chris Needham // @@ -28,6 +28,8 @@ #include #include +#include + //------------------------------------------------------------------------------ namespace FileUtil { @@ -43,6 +45,22 @@ bool isStdioFilename(const char* filename) //------------------------------------------------------------------------------ +bool isStdinFifo() { + struct stat stat_buf; + + int result = fstat(fileno(stdin), &stat_buf); + + if (result >= 0) { + if (S_ISFIFO(stat_buf.st_mode)) { + return true; + } + } + + return false; +} + +//------------------------------------------------------------------------------ + const char* getInputFilename(const char* filename) { return FileUtil::isStdioFilename(filename) ? "(stdin)" : filename; diff --git a/src/FileUtil.h b/src/FileUtil.h index 44ea532..7c00a2c 100644 --- a/src/FileUtil.h +++ b/src/FileUtil.h @@ -1,6 +1,6 @@ //------------------------------------------------------------------------------ // -// Copyright 2016 BBC Research and Development +// Copyright 2022 BBC Research and Development // // Author: Chris Needham // @@ -28,6 +28,7 @@ namespace FileUtil { bool isStdioFilename(const char* filename); + bool isStdinFifo(); const char* getInputFilename(const char* filename); const char* getOutputFilename(const char* filename); } diff --git a/src/ProgressReporter.cpp b/src/ProgressReporter.cpp index 0f8755e..6f3c70d 100644 --- a/src/ProgressReporter.cpp +++ b/src/ProgressReporter.cpp @@ -1,6 +1,6 @@ //------------------------------------------------------------------------------ // -// Copyright 2013-2021 BBC Research and Development +// Copyright 2013-2022 BBC Research and Development // // Author: Chris Needham // @@ -22,31 +22,21 @@ //------------------------------------------------------------------------------ #include "ProgressReporter.h" +#include "FileUtil.h" #include "Log.h" -#include - #include #include //------------------------------------------------------------------------------ +// If we're reading from a pipe, we may not know what the total duration is, +// so don't report progress in this case. + ProgressReporter::ProgressReporter() : - show_progress_(true), + show_progress_(!FileUtil::isStdinFifo()), percent_(-1) // Force first update to display 0% { - // If we're reading from a pipe, we may not know what the total duration is, - // so don't report progress in this case. - - struct stat stat_buf; - - int result = fstat(fileno(stdin), &stat_buf); - - if (result >= 0) { - if (S_ISFIFO(stat_buf.st_mode)) { - show_progress_ = false; - } - } } //------------------------------------------------------------------------------