diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C index 67d41baf96..c37e911aee 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016-2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -59,7 +59,12 @@ Description #include #include #include -#include + +#ifdef darwin + #include +#else + #include +#endif #ifdef USE_RANDOM #include @@ -652,16 +657,7 @@ time_t Foam::lastModified(const fileName& name, const bool followLink) } // Ignore an empty name - if (!name.empty()) - { - fileStat fileStatus(name, followLink); - if (fileStatus.isValid()) - { - return fileStatus.status().st_mtime; - } - } - - return 0; + return name.empty() ? 0 : fileStat(name, followLink).modTime(); } @@ -677,18 +673,7 @@ double Foam::highResLastModified(const fileName& name, const bool followLink) } // Ignore an empty name - if (!name.empty()) - { - fileStat fileStatus(name, followLink); - if (fileStatus.isValid()) - { - return - fileStatus.status().st_mtime - + 1e-9*fileStatus.status().st_mtim.tv_nsec; - } - } - - return 0; + return name.empty() ? 0 : fileStat(name, followLink).dmodTime(); } diff --git a/src/OSspecific/POSIX/fileStat.C b/src/OSspecific/POSIX/fileStat.C index 75d1fa1359..0d50a72186 100644 --- a/src/OSspecific/POSIX/fileStat.C +++ b/src/OSspecific/POSIX/fileStat.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -29,7 +29,9 @@ License #include #include -#include +#ifndef darwin + #include +#endif // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -48,6 +50,11 @@ Foam::fileStat::fileStat : isValid_(false) { + if (fName.empty()) + { + return; + } + // Work on volatile volatile bool locIsValid = false; @@ -84,20 +91,42 @@ Foam::label Foam::fileStat::size() const } -bool Foam::fileStat::sameDevice(const fileStat& stat2) const +time_t Foam::fileStat::modTime() const +{ + return isValid_ ? status_.st_mtime : 0; +} + + +double Foam::fileStat::dmodTime() const +{ + return + ( + isValid_ + ? + #ifdef darwin + (status_.st_mtime + 1e-9*status_.st_mtimespec.tv_nsec) + #else + (status_.st_mtime + 1e-9*status_.st_mtim.tv_nsec) + #endif + : 0 + ); +} + + +bool Foam::fileStat::sameDevice(const fileStat& other) const { return isValid_ && ( - major(status_.st_dev) == major(stat2.status().st_dev) - && minor(status_.st_dev) == minor(stat2.status().st_dev) + major(status_.st_dev) == major(other.status_.st_dev) + && minor(status_.st_dev) == minor(other.status_.st_dev) ); } -bool Foam::fileStat::sameINode(const fileStat& stat2) const +bool Foam::fileStat::sameINode(const fileStat& other) const { - return isValid_ && (status_.st_ino == stat2.status().st_ino); + return isValid_ && (status_.st_ino == other.status_.st_ino); } diff --git a/src/OSspecific/POSIX/fileStat.H b/src/OSspecific/POSIX/fileStat.H index f67fb89600..62a61afbbf 100644 --- a/src/OSspecific/POSIX/fileStat.H +++ b/src/OSspecific/POSIX/fileStat.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -51,8 +51,7 @@ SourceFiles namespace Foam { -// Forward declaration of friend functions and operators - +// Forward declarations class fileStat; Istream& operator>>(Istream& is, fileStat& fStat); @@ -88,6 +87,8 @@ public: // // \param maxTime \n // The timeout value. + // + // \note an empty filename is a no-op. fileStat ( const fileName& fName, @@ -101,34 +102,42 @@ public: // Member Functions - // Access + // Access - //- Raw status - const struct stat& status() const - { - return status_; - } + //- Raw status + const struct stat& status() const + { + return status_; + } - //- Was file-stat successful? - bool isValid() const - { - return isValid_; - } + //- Was file-stat successful? + bool isValid() const + { + return isValid_; + } - //- Size in bytes. Zero for invalid file-stat. - label size() const; + //- Size in bytes. Zero for an invalid file-stat. + label size() const; + + //- Return the modification time in seconds. + // Zero for an invalid file-stat. + time_t modTime() const; + + //- Return the modification time in seconds (nanosecond resolution) + // Zero for an invalid file-stat. + double dmodTime() const; - // Check + // Check - //- Compare two fileStats for same device - bool sameDevice(const fileStat& stat2) const; + //- Compare two fileStats for same device + bool sameDevice(const fileStat& other) const; - //- Compare two fileStats for same Inode - bool sameINode(const fileStat& stat2) const; + //- Compare two fileStats for same Inode + bool sameINode(const fileStat& other) const; - //- Compare state against inode - bool sameINode(const label iNode) const; + //- Compare state against inode + bool sameINode(const label iNode) const; // IOstream Operators diff --git a/src/OSspecific/POSIX/printStack.C b/src/OSspecific/POSIX/printStack.C index 6fd0565f78..2dd36142f9 100644 --- a/src/OSspecific/POSIX/printStack.C +++ b/src/OSspecific/POSIX/printStack.C @@ -86,9 +86,9 @@ string pOpen(const string& cmd, label line=0) inline word addressToWord(const uintptr_t addr) { - OStringStream nStream; - nStream << "0x" << hex << addr; - return nStream.str(); + OStringStream os; + os << "0x" << hex << addr; + return os.str(); } @@ -122,7 +122,7 @@ void printSourceFileAndLine 1 ); - if (line == "") + if (line.empty()) { os << " addr2line failed"; } @@ -161,7 +161,6 @@ fileName absolutePath(const char* fn) word demangleSymbol(const char* sn) { - word res; int st; char* cxx_sname = abi::__cxa_demangle ( @@ -173,15 +172,13 @@ word demangleSymbol(const char* sn) if (st == 0 && cxx_sname) { - res = word(cxx_sname); + word demangled(cxx_sname); free(cxx_sname); - } - else - { - res = word(sn); + + return demangled; } - return res; + return sn; } @@ -189,8 +186,8 @@ word demangleSymbol(const char* sn) } // End namespace Foam -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // void Foam::error::safePrintStack(std::ostream& os) {