From 768fdab67a7efac1a0c5c89691dd26db0cb379ed Mon Sep 17 00:00:00 2001 From: David Rose Date: Sat, 11 Nov 2000 04:34:04 +0000 Subject: [PATCH] *** empty log message *** --- dtool/src/dtoolutil/filename.cxx | 55 ++++++++++++++++++++++++++++++++ dtool/src/dtoolutil/filename.h | 2 ++ 2 files changed, 57 insertions(+) diff --git a/dtool/src/dtoolutil/filename.cxx b/dtool/src/dtoolutil/filename.cxx index bd4f7df2d4..bfca1bf66b 100644 --- a/dtool/src/dtoolutil/filename.cxx +++ b/dtool/src/dtoolutil/filename.cxx @@ -581,6 +581,61 @@ exists() const { return exists; } +//////////////////////////////////////////////////////////////////// +// Function: Filename::is_regular_file +// Access: Public +// Description: Returns true if the filename exists and is the +// name of a regular file (i.e. not a directory or +// device), false otherwise. +//////////////////////////////////////////////////////////////////// +bool Filename:: +is_regular_file() const { +#ifdef WIN32_VC + struct _stat this_buf; + bool isdir = false; + + if (_stat(to_os_specific().c_str(), &this_buf) == 0) { + isdir = S_ISREG(this_buf.st_mode); + } +#else // WIN32_VC + struct stat this_buf; + bool isdir = false; + + if (stat(to_os_specific().c_str(), &this_buf) == 0) { + isdir = S_ISREG(this_buf.st_mode); + } +#endif + + return isdir; +} + +//////////////////////////////////////////////////////////////////// +// Function: Filename::is_directory +// Access: Public +// Description: Returns true if the filename exists and is a +// directory name, false otherwise. +//////////////////////////////////////////////////////////////////// +bool Filename:: +is_directory() const { +#ifdef WIN32_VC + struct _stat this_buf; + bool isdir = false; + + if (_stat(to_os_specific().c_str(), &this_buf) == 0) { + isdir = S_ISDIR(this_buf.st_mode); + } +#else // WIN32_VC + struct stat this_buf; + bool isdir = false; + + if (stat(to_os_specific().c_str(), &this_buf) == 0) { + isdir = S_ISDIR(this_buf.st_mode); + } +#endif + + return isdir; +} + //////////////////////////////////////////////////////////////////// // Function: Filename::compare_timestamps // Access: Public diff --git a/dtool/src/dtoolutil/filename.h b/dtool/src/dtoolutil/filename.h index b24dd502e9..345ce5c69b 100644 --- a/dtool/src/dtoolutil/filename.h +++ b/dtool/src/dtoolutil/filename.h @@ -122,6 +122,8 @@ public: string to_os_specific() const; bool exists() const; + bool is_regular_file() const; + bool is_directory() const; int compare_timestamps(const Filename &other, bool this_missing_is_old = true, bool other_missing_is_old = true) const;