Skip to content

Commit

Permalink
Added isStdinFifo() function
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisn committed Oct 13, 2022
1 parent 138b1b6 commit 3566329
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
20 changes: 19 additions & 1 deletion src/FileUtil.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//------------------------------------------------------------------------------
//
// Copyright 2019 BBC Research and Development
// Copyright 2022 BBC Research and Development
//
// Author: Chris Needham
//
Expand Down Expand Up @@ -28,6 +28,8 @@
#include <fstream>
#include <iostream>

#include <sys/stat.h>

//------------------------------------------------------------------------------

namespace FileUtil {
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/FileUtil.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//------------------------------------------------------------------------------
//
// Copyright 2016 BBC Research and Development
// Copyright 2022 BBC Research and Development
//
// Author: Chris Needham
//
Expand Down Expand Up @@ -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);
}
Expand Down
22 changes: 6 additions & 16 deletions src/ProgressReporter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//------------------------------------------------------------------------------
//
// Copyright 2013-2021 BBC Research and Development
// Copyright 2013-2022 BBC Research and Development
//
// Author: Chris Needham
//
Expand All @@ -22,31 +22,21 @@
//------------------------------------------------------------------------------

#include "ProgressReporter.h"
#include "FileUtil.h"
#include "Log.h"

#include <sys/stat.h>

#include <iomanip>
#include <iostream>

//------------------------------------------------------------------------------

// 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;
}
}
}

//------------------------------------------------------------------------------
Expand Down

0 comments on commit 3566329

Please sign in to comment.