Commit cea58b52 authored by Mathieu Westphal's avatar Mathieu Westphal

Replace stat() usage with vtksys::SystemTools::Stat

This commit replace a bunch of stat() usage by Stat
which is more robust especially on windows.
parent e0af64ea
......@@ -18,14 +18,14 @@
// CMakeCache.txt file. This test will display the file.
#include "vtkDebugLeaks.h"
#include <sys/stat.h>
#include <vtksys/SystemTools.hxx>
#include <string>
void vtkSystemInformationPrintFile(const char* name, ostream& os)
{
os << "================================================================\n";
struct stat fs;
if(stat(name, &fs) != 0)
vtksys::SystemTools::Stat_t fs;
if(vtksys::SystemTools::Stat(name, &fs) != 0)
{
os << "The file \"" << name << "\" does not exist.\n";
return;
......
......@@ -18,7 +18,6 @@
#include "vtkDebugLeaks.h"
#include "vtkObjectFactory.h"
#include <sys/stat.h>
#include <vtksys/SystemTools.hxx>
vtkStandardNewMacro(vtkDirectory)
......@@ -285,8 +284,8 @@ int vtkDirectory::FileIsDirectory(const char *name)
strcpy(&fullPath[n], name);
int result = 0;
struct stat fs;
if(stat(fullPath, &fs) == 0)
vtksys::SystemTools::Stat_t fs;
if(vtksys::SystemTools::Stat(fullPath, &fs) == 0)
{
#if defined(_WIN32)
result = ((fs.st_mode & _S_IFDIR) != 0);
......
......@@ -22,4 +22,5 @@ vtk_module(vtkFiltersHybrid
vtkImagingCore
vtkImagingSources
vtkRenderingCore
)
\ No newline at end of file
vtksys
)
......@@ -14,24 +14,24 @@
=========================================================================*/
#include "vtkFacetReader.h"
#include "vtkPolyData.h"
#include "vtkAppendPolyData.h"
#include "vtkCellArray.h"
#include "vtkCellData.h"
#include "vtkCellType.h"
#include "vtkDoubleArray.h"
#include "vtkErrorCode.h"
#include "vtkGarbageCollector.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkObjectFactory.h"
#include "vtkErrorCode.h"
#include "vtkCellType.h"
#include "vtkCellArray.h"
#include "vtkGarbageCollector.h"
#include "vtkAppendPolyData.h"
#include "vtkPointData.h"
#include "vtkCellData.h"
#include "vtkUnsignedIntArray.h"
#include "vtkDoubleArray.h"
#include "vtkPolyData.h"
#include "vtkSmartPointer.h"
#include "vtkUnsignedIntArray.h"
#include <vtksys/SystemTools.hxx>
#include <sstream>
#include <sys/stat.h>
#include <string>
#include <vector>
......@@ -95,8 +95,8 @@ vtkFacetReader::~vtkFacetReader()
//-----------------------------------------------------------------------------
int vtkFacetReader::CanReadFile(const char *filename)
{
struct stat fs;
if (stat(filename, &fs))
vtksys::SystemTools::Stat_t fs;
if (vtksys::SystemTools::Stat(filename, &fs))
{
// Specified filename not found
return 0;
......@@ -140,8 +140,8 @@ int vtkFacetReader::RequestData(
return 1;
}
struct stat fs;
if ( stat(this->FileName, &fs) )
vtksys::SystemTools::Stat_t fs;
if (vtksys::SystemTools::Stat(this->FileName, &fs))
{
this->SetErrorCode(vtkErrorCode::FileNotFoundError);
vtkErrorMacro("Specified filename not found");
......
......@@ -21,7 +21,7 @@
#include "vtkPolyData.h"
#include "vtkStringArray.h"
#include <sys/stat.h>
#include <vtksys/SystemTools.hxx>
//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkXYZMolReader);
......@@ -178,8 +178,8 @@ int vtkXYZMolReader::CanReadFile(const char* name)
// First make sure the file exists. This prevents an empty file
// from being created on older compilers.
struct stat fs;
if(stat(name, &fs) != 0)
vtksys::SystemTools::Stat_t fs;
if (vtksys::SystemTools::Stat(name, &fs) != 0)
{
return 0;
}
......
......@@ -21,11 +21,11 @@
#include "vtkPointData.h"
#include "vtkErrorCode.h"
#include <vtksys/SystemTools.hxx>
#include <vector>
#include <string>
#include <sys/stat.h>
#include "DICOMAppHelper.h"
#include "DICOMParser.h"
......@@ -117,8 +117,8 @@ void vtkDICOMImageReader::ExecuteInformation()
if (this->FileName)
{
struct stat fs;
if ( stat(this->FileName, &fs) )
vtksys::SystemTools::Stat_t fs;
if (vtksys::SystemTools::Stat(this->FileName, &fs))
{
vtkErrorMacro("Unable to open file " << this->FileName );
return;
......
......@@ -25,7 +25,7 @@
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkStringArray.h"
#include <sys/stat.h>
#include "vtksys/SystemTools.hxx"
vtkStandardNewMacro(vtkImageReader2);
......@@ -577,8 +577,8 @@ int vtkImageReader2::OpenFile()
// Open the new file
vtkDebugMacro(<< "Initialize: opening file " << this->InternalFileName);
struct stat fs;
if ( !stat( this->InternalFileName, &fs) )
vtksys::SystemTools::Stat_t fs;
if ( !vtksys::SystemTools::Stat( this->InternalFileName, &fs) )
{
#ifdef _WIN32
this->File = new ifstream(this->InternalFileName, ios::in | ios::binary);
......@@ -630,8 +630,8 @@ unsigned long vtkImageReader2::GetHeaderSize(unsigned long idx)
// make sure we figure out a filename to open
this->ComputeInternalFileName(idx);
struct stat statbuf;
if (!stat(this->InternalFileName, &statbuf))
vtksys::SystemTools::Stat_t statbuf;
if (!vtksys::SystemTools::Stat(this->InternalFileName, &statbuf))
{
return (int)(statbuf.st_size -
(long)this->DataIncrements[this->GetFileDimensionality()]);
......
......@@ -22,7 +22,6 @@
#include "vtksys/SystemTools.hxx"
#include <sys/stat.h>
#include <string>
#include <algorithm>
......@@ -191,8 +190,8 @@ static void vtkTIFFReaderInternalErrorHandler(const char* vtkNotUsed(module),
bool vtkTIFFReader::vtkTIFFReaderInternal::Open(const char *filename)
{
this->Clean();
struct stat fs;
if (stat(filename, &fs))
vtksys::SystemTools::Stat_t fs;
if (vtksys::SystemTools::Stat(filename, &fs))
{
return false;
}
......
......@@ -686,8 +686,8 @@ int vtkLSDynaReader::CanReadFile( const char* fname )
}
else
{
struct stat st;
if ( stat( fname, &st ) == 0 )
vtksys::SystemTools::Stat_t st;
if ( vtksys::SystemTools::Stat( fname, &st ) == 0 )
{
dbName.insert( 0, "/" );
p->Fam.SetDatabaseBaseName( dbName.c_str() );
......@@ -792,8 +792,8 @@ void vtkLSDynaReader::SetFileName( const char* f )
}
else
{
struct stat st;
if ( stat( f, &st ) == 0 )
vtksys::SystemTools::Stat_t st;
if ( vtksys::SystemTools::Stat( f, &st ) == 0 )
{
dbName.insert( 0, "/" );
this->P->Fam.SetDatabaseBaseName( dbName.c_str() );
......
......@@ -48,18 +48,18 @@
#include "vtkStringArray.h"
#include "vtkTable.h"
#include "vtkTypeInt64Array.h"
#include "vtkTypeUInt64Array.h"
#include "vtkUnicodeStringArray.h"
#include "vtkUnsignedCharArray.h"
#include "vtkUnsignedIntArray.h"
#include "vtkUnsignedLongArray.h"
#include "vtkUnsignedShortArray.h"
#include "vtkVariantArray.h"
#include <sstream>
#include "vtkTypeUInt64Array.h"
#include <vtksys/SystemTools.hxx>
#include <sstream>
#include <cctype>
#include <sys/stat.h>
// I need a safe way to read a line of arbitrary length. It exists on
// some platforms but not others so I'm afraid I have to write it
......@@ -430,13 +430,14 @@ int vtkDataReader::OpenVTKFile()
// first make sure the file exists, this prevents an empty file from
// being created on older compilers
struct stat fs;
if (stat(this->FileName, &fs) != 0)
vtksys::SystemTools::Stat_t fs;
if (vtksys::SystemTools::Stat(this->FileName, &fs) != 0)
{
vtkErrorMacro(<< "Unable to open file: "<< this->FileName);
this->SetErrorCode( vtkErrorCode::CannotOpenFileError );
return 0;
}
this->IS = new ifstream(this->FileName, ios::in | ios::binary);
if (this->IS->fail())
{
......
......@@ -66,8 +66,6 @@ POSSIBILITY OF SUCH DAMAGES.
#include "vtkMath.h"
#include <cctype>
#include <sys/types.h>
#include <sys/stat.h>
#include <string>
#include <vector>
......@@ -133,8 +131,8 @@ int vtkMNIObjectReader::CanReadFile(const char* fname)
{
// First make sure the file exists. This prevents an empty file
// from being created on older compilers.
struct stat fs;
if(stat(fname, &fs) != 0)
vtksys::SystemTools::Stat_t fs;
if (vtksys::SystemTools::Stat(fname, &fs) != 0)
{
return 0;
}
......@@ -739,8 +737,8 @@ int vtkMNIObjectReader::ReadFile(vtkPolyData *output)
}
// Make sure that the file exists.
struct stat fs;
if(stat(this->FileName, &fs) != 0)
vtksys::SystemTools::Stat_t fs;
if (vtksys::SystemTools::Stat(this->FileName, &fs) != 0)
{
vtkErrorMacro("ReadFile: Can't open file " << this->FileName);
return 0;
......
......@@ -63,8 +63,6 @@ POSSIBILITY OF SUCH DAMAGES.
#include "vtkStringArray.h"
#include <cctype>
#include <sys/types.h>
#include <sys/stat.h>
#include <string>
#include <vector>
......@@ -110,8 +108,8 @@ int vtkMNITagPointReader::CanReadFile(const char* fname)
{
// First make sure the file exists. This prevents an empty file
// from being created on older compilers.
struct stat fs;
if(stat(fname, &fs) != 0)
vtksys::SystemTools::Stat_t fs;
if (vtksys::SystemTools::Stat(fname, &fs) != 0)
{
return 0;
}
......@@ -440,8 +438,8 @@ int vtkMNITagPointReader::ReadFile(
}
// Make sure that the file exists.
struct stat fs;
if(stat(this->FileName, &fs) != 0)
vtksys::SystemTools::Stat_t fs;
if (vtksys::SystemTools::Stat(this->FileName, &fs) != 0)
{
vtkErrorMacro("ReadFile: Can't open file " << this->FileName);
return 0;
......
......@@ -64,8 +64,6 @@ POSSIBILITY OF SUCH DAMAGES.
#include "vtkPoints.h"
#include <cctype>
#include <sys/types.h>
#include <sys/stat.h>
#include <string>
#include <vector>
......@@ -122,8 +120,8 @@ int vtkMNITransformReader::CanReadFile(const char* fname)
{
// First make sure the file exists. This prevents an empty file
// from being created on older compilers.
struct stat fs;
if(stat(fname, &fs) != 0)
vtksys::SystemTools::Stat_t fs;
if (vtksys::SystemTools::Stat(fname, &fs) != 0)
{
return 0;
}
......@@ -845,8 +843,8 @@ int vtkMNITransformReader::ReadFile()
}
// Make sure that the file exists.
struct stat fs;
if(stat(this->FileName, &fs) != 0)
vtksys::SystemTools::Stat_t fs;
if (vtksys::SystemTools::Stat(this->FileName, &fs) != 0)
{
vtkErrorMacro("ReadFile: Can't open file " << this->FileName);
return 0;
......
......@@ -46,7 +46,6 @@
#include <vtksys/RegularExpression.hxx>
#include <sys/stat.h>
#include <cctype>
#undef DBG_PEXOIIRDR
......@@ -889,15 +888,14 @@ int vtkPExodusIIReader::DeterminePattern( const char* file )
// Count up the files
char buffer[1024];
struct stat fs;
vtksys::SystemTools::Stat_t fs;
// First go up every 100
for ( cc = min + 100; true; cc += 100 )
{
sprintf( buffer, pattern, prefix.c_str(), cc );
// Stat returns -1 if file NOT found
if ( stat( buffer, &fs ) == -1 )
if (vtksys::SystemTools::Stat(buffer, &fs) == -1)
break;
}
......@@ -907,8 +905,7 @@ int vtkPExodusIIReader::DeterminePattern( const char* file )
{
sprintf( buffer, pattern, prefix.c_str(), cc );
// Stat returns -1 if file NOT found
if ( stat( buffer, &fs ) == -1 )
if (vtksys::SystemTools::Stat(buffer, &fs) == -1)
break;
}
// Okay if I'm here than stat has failed so -1 on my cc
......@@ -924,8 +921,7 @@ int vtkPExodusIIReader::DeterminePattern( const char* file )
sprintf( buffer, pattern, prefix.c_str(), cc );
// Stat returns -1 if file NOT found
if ( stat( buffer, &fs ) == -1 )
if (vtksys::SystemTools::Stat(buffer, &fs) == -1)
break;
}
......@@ -939,8 +935,7 @@ int vtkPExodusIIReader::DeterminePattern( const char* file )
sprintf( buffer, pattern, prefix.c_str(), cc );
// Stat returns -1 if file NOT found
if ( stat( buffer, &fs ) == -1 )
if (vtksys::SystemTools::Stat(buffer, &fs) == -1)
break;
}
min = cc + 1;
......
......@@ -27,7 +27,6 @@
#include "vtkSQLiteToTableReader.h"
#include "vtksys/SystemTools.hxx"
#include <sys/stat.h>
void PrintFile(const char* name, std::ostream& os);
bool CompareAsciiFiles(const char* file1, const char* file2);
......@@ -113,8 +112,8 @@ void PrintFile(const char* name, std::ostream& os)
// CMake/CTestCustom.cmake
os << "CTEST_FULL_OUTPUT\n";
os << "File \"" << name << "\"";
struct stat fs;
if(stat(name, &fs) != 0)
vtksys::SystemTools::Stat_t fs;
if(vtksys::SystemTools::Stat(name, &fs) != 0)
{
os << " does not exist.\n";
return;
......
......@@ -43,13 +43,14 @@
#include "vtkXMLReaderVersion.h"
#include "vtkZLibDataCompressor.h"
#include <vtksys/SystemTools.hxx>
#include <algorithm>
#include <cassert>
#include <functional>
#include <locale> // C++ locale
#include <sstream>
#include <vector>
#include <sys/stat.h>
vtkCxxSetObjectMacro(vtkXMLReader,ReaderErrorObserver,vtkCommand);
vtkCxxSetObjectMacro(vtkXMLReader,ParserErrorObserver,vtkCommand);
......@@ -255,8 +256,8 @@ int vtkXMLReader::OpenVTKFile()
// Need to open a file. First make sure it exists. This prevents
// an empty file from being created on older compilers.
struct stat fs;
if (stat(this->FileName, &fs) != 0)
vtksys::SystemTools::Stat_t fs;
if (vtksys::SystemTools::Stat(this->FileName, &fs) != 0)
{
vtkErrorMacro("Error opening file " << this->FileName);
return 0;
......@@ -1322,8 +1323,8 @@ int vtkXMLReader::CanReadFile(const char* name)
{
// First make sure the file exists. This prevents an empty file
// from being created on older compilers.
struct stat fs;
if (stat(name, &fs) != 0)
vtksys::SystemTools::Stat_t fs;
if (vtksys::SystemTools::Stat(name, &fs) != 0)
{
return 0;
}
......
......@@ -9,4 +9,5 @@ vtk_module(vtkIOXMLParser
PRIVATE_DEPENDS
vtkIOCore
vtkexpat
)
\ No newline at end of file
vtksys
)
......@@ -15,8 +15,10 @@
#include "vtkXMLParser.h"
#include "vtkObjectFactory.h"
#include "vtk_expat.h"
#include <vtksys/SystemTools.hxx>
#include <cctype>
#include <sys/stat.h>
vtkStandardNewMacro(vtkXMLParser);
......@@ -126,8 +128,8 @@ int vtkXMLParser::Parse()
if ( !this->InputString && !this->Stream && this->FileName )
{
// If it is file, open it and set the appropriate stream
struct stat fs;
if (stat(this->FileName, &fs) != 0)
vtksys::SystemTools::Stat_t fs;
if (vtksys::SystemTools::Stat(this->FileName, &fs) != 0)
{
vtkErrorMacro("Cannot open XML file: " << this->FileName);
return 0;
......
......@@ -18,8 +18,8 @@
#include "vtkObjectFactory.h"
#include "vtkPSystemTools.h"
#include "vtkStringArray.h"
#include <sys/stat.h>
#include <vtksys/Directory.hxx>
#include <vtksys/SystemTools.hxx>
#include <string>
vtkStandardNewMacro(vtkPDirectory);
......@@ -190,8 +190,8 @@ int vtkPDirectory::FileIsDirectory(const char *name)
strcpy(&fullPath[n], name);
struct stat fs;
if(stat(fullPath, &fs) == 0)
vtksys::SystemTools::Stat_t fs;
if(vtksys::SystemTools::Stat(fullPath, &fs) == 0)
{
#if defined(_WIN32)
result = ((fs.st_mode & _S_IFDIR) != 0);
......
......@@ -37,8 +37,6 @@
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkInformation.h"
#include <sys/stat.h>
#include <sstream>
#include <vtksys/SystemTools.hxx>
......@@ -324,8 +322,8 @@ int vtkTesting::LookForFile(const char* newFileName)
{
return 0;
}
struct stat fs;
if (stat(newFileName, &fs) != 0)
vtksys::SystemTools::Stat_t fs;
if (vtksys::SystemTools::Stat(newFileName, &fs) != 0)
{
return 0;
}
......
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