From 0f4635e876560d00df58c809526435180d0b1912 Mon Sep 17 00:00:00 2001 From: David Gobbi Date: Sun, 18 Aug 2024 09:24:26 -0600 Subject: [PATCH] Prefer SystemTools::Stat over system stat/stat64 This keeps all of the stat() calls in VTK centralized (except the ones implemented in ThirdParty). Note that kwsys no longer defines any LSF support macros since 2019, so this might impact the ability to use large files on some 32-bit platforms, but hopefully any platforms where this is a concern will honor _FILE_OFFSET_BITS=64 like 32-bit glibc does. --- IO/EnSight/vtkEnSight6BinaryReader.cxx | 28 ++----------- IO/EnSight/vtkEnSightGoldBinaryReader.cxx | 25 +----------- IO/LSDyna/LSDynaFamily.cxx | 48 +---------------------- 3 files changed, 8 insertions(+), 93 deletions(-) diff --git a/IO/EnSight/vtkEnSight6BinaryReader.cxx b/IO/EnSight/vtkEnSight6BinaryReader.cxx index 167e63efd41..1f26a171c26 100644 --- a/IO/EnSight/vtkEnSight6BinaryReader.cxx +++ b/IO/EnSight/vtkEnSight6BinaryReader.cxx @@ -18,33 +18,13 @@ #include "vtkUnstructuredGrid.h" #include "vtksys/Encoding.hxx" #include "vtksys/FStream.hxx" +#include "vtksys/SystemTools.hxx" #include #include -#include - -#if defined(_WIN32) -#define VTK_STAT_STRUCT struct _stat64 -#define VTK_STAT_FUNC _stat64 -#elif defined _DARWIN_FEATURE_64_BIT_INODE || defined __FreeBSD__ || defined __NetBSD__ || \ - defined __OpenBSD__ -// The BSDs use stat(). -#define VTK_STAT_STRUCT struct stat -#define VTK_STAT_FUNC stat -#elif defined __EMSCRIPTEN__ -#if defined _LARGEFILE64_SOURCE -#define VTK_STAT_STRUCT struct stat64 -#define VTK_STAT_FUNC stat64 -#else -#define VTK_STAT_STRUCT struct stat -#define VTK_STAT_FUNC stat -#endif -#else -// here, we're relying on _FILE_OFFSET_BITS defined in vtkWin32Header.h to help -// us on POSIX without resorting to using stat64. -#define VTK_STAT_STRUCT struct stat64 -#define VTK_STAT_FUNC stat64 -#endif + +#define VTK_STAT_STRUCT vtksys::SystemTools::Stat_t +#define VTK_STAT_FUNC vtksys::SystemTools::Stat VTK_ABI_NAMESPACE_BEGIN vtkStandardNewMacro(vtkEnSight6BinaryReader); diff --git a/IO/EnSight/vtkEnSightGoldBinaryReader.cxx b/IO/EnSight/vtkEnSightGoldBinaryReader.cxx index ff8cad7bd46..75c126a2b0c 100644 --- a/IO/EnSight/vtkEnSightGoldBinaryReader.cxx +++ b/IO/EnSight/vtkEnSightGoldBinaryReader.cxx @@ -26,31 +26,10 @@ #include #include #include -#include #include -#if defined(_WIN32) -#define VTK_STAT_STRUCT struct _stat64 -#define VTK_STAT_FUNC _stat64 -#elif defined _DARWIN_FEATURE_64_BIT_INODE || defined __FreeBSD__ || defined __NetBSD__ || \ - defined __OpenBSD__ -// The BSDs use stat(). -#define VTK_STAT_STRUCT struct stat -#define VTK_STAT_FUNC stat -#elif defined __EMSCRIPTEN__ -#if defined _LARGEFILE64_SOURCE -#define VTK_STAT_STRUCT struct stat64 -#define VTK_STAT_FUNC stat64 -#else -#define VTK_STAT_STRUCT struct stat -#define VTK_STAT_FUNC stat -#endif -#else -// here, we're relying on _FILE_OFFSET_BITS defined in vtkWin32Header.h to help -// us on POSIX without resorting to using stat64. -#define VTK_STAT_STRUCT struct stat64 -#define VTK_STAT_FUNC stat64 -#endif +#define VTK_STAT_STRUCT vtksys::SystemTools::Stat_t +#define VTK_STAT_FUNC vtksys::SystemTools::Stat VTK_ABI_NAMESPACE_BEGIN class vtkEnSightGoldBinaryReader::vtkUtilities diff --git a/IO/LSDyna/LSDynaFamily.cxx b/IO/LSDyna/LSDynaFamily.cxx index fdb914ab6fa..1574d97b281 100644 --- a/IO/LSDyna/LSDynaFamily.cxx +++ b/IO/LSDyna/LSDynaFamily.cxx @@ -18,44 +18,6 @@ VTK_ABI_NAMESPACE_BEGIN namespace { -// Decide which of 3 stat varieties to use: stat, stat64, __stat64 -// Usually stat uses 32 bit fields, and stat64 (with underscores in Windows) uses 64 bit fields. -// But on the BSDs, stat uses 64 bit fields these days. -#if (VTK_SIZEOF_ID_TYPE == 8) && !defined(_DARWIN_FEATURE_64_BIT_INODE) && \ - !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) -#ifndef _WIN32 -#if defined __EMSCRIPTEN__ -#if defined _LARGEFILE64_SOURCE -#define USE_STAT_64 -#else -#define USE_STAT -#endif -#else -#define USE_STAT_64 -#endif -#else -#define USE_WIN_STAT_64 -#endif -#else -#define USE_STAT -#endif - -#if defined(USE_STAT_64) -int LS_DYNA_STAT(const char* fname, struct stat64& s) -{ - return stat64(fname, &s); -} -#elif defined(USE_WIN_STAT_64) -int LS_DYNA_STAT(const char* fname, struct __stat64& s) -{ - return __stat64(fname, &s); -} -#elif defined(USE_STAT) -int LS_DYNA_STAT(const char* fname, struct stat& s) -{ - return stat(fname, &s); -} -#endif vtkLSDynaFile_t VTK_LSDYNA_OPENFILE(const char* fname) { @@ -205,18 +167,12 @@ int LSDynaFamily::ScanDatabaseDirectory() int adaptLevel = 0; int tryAdapt = 0; // don't try an adaptive step unless we have one good file at the current level. bool adapted = true; // true when advancing over a mesh adaptation. -#if defined(USE_WIN_STAT_64) - struct __stat64 st; -#elif defined(USE_STAT_64) - struct stat64 st; -#elif defined(USE_STAT) - struct stat st; -#endif + vtksys::SystemTools::Stat_t st; while (tryAdapt >= 0) { tmpFile = vtkLSGetFamilyFileName( this->DatabaseDirectory.c_str(), this->DatabaseBaseName, adaptLevel, filenum); - if (LS_DYNA_STAT(tmpFile.c_str(), st) == 0) + if (vtksys::SystemTools::Stat(tmpFile.c_str(), &st) == 0) { if (adapted) { -- GitLab