From a083be01aad5d6997347d51d109099c9fe745821 Mon Sep 17 00:00:00 2001 From: spog Date: Tue, 21 Feb 2006 19:43:44 +0000 Subject: [PATCH] fixed access() assert when using msvc 8.0 runtime git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/trunk@20 8a3a26a2-13c4-0310-b231-cf6edde360e5 --- libs/gtkutil/filechooser.cpp | 1 + libs/os/file.h | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/gtkutil/filechooser.cpp b/libs/gtkutil/filechooser.cpp index b19936b4..fca0c679 100644 --- a/libs/gtkutil/filechooser.cpp +++ b/libs/gtkutil/filechooser.cpp @@ -477,6 +477,7 @@ const char* file_dialog(GtkWidget* parent, bool open, const char* title, const c file_dialog_show(parent, open, title, path, pattern); if(open + || file == 0 || !file_exists(file) || gtk_MessageBox(parent, "The file specified already exists.\nDo you want to replace it?", title, eMB_NOYES, eMB_ICONQUESTION) == eIDYES) { diff --git a/libs/os/file.h b/libs/os/file.h index 644add04..b1290760 100644 --- a/libs/os/file.h +++ b/libs/os/file.h @@ -27,10 +27,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #if defined( WIN32 ) #define S_ISDIR(mode) (mode & _S_IFDIR) -#include // access() +#include // _access() #define F_OK 0x00 #define W_OK 0x02 #define R_OK 0x04 +#define access(path, mode) _access(path, mode) #else #include // access() #endif @@ -41,6 +42,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include +#include "debugging/debugging.h" + /// \brief Attempts to move the file identified by \p from to \p to and returns true if the operation was successful. /// /// The operation will fail unless: @@ -50,6 +53,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA /// - The directory component of \p to identifies an existing directory which is accessible for writing. inline bool file_move(const char* from, const char* to) { + ASSERT_MESSAGE(from != 0 && to != 0, "file_move: invalid path"); return rename(from, to) == 0; } @@ -60,6 +64,7 @@ inline bool file_move(const char* from, const char* to) /// - The parent-directory component of \p path identifies an existing directory which is accessible for writing. inline bool file_remove(const char* path) { + ASSERT_MESSAGE(path != 0, "file_remove: invalid path"); return remove(path) == 0; } @@ -77,6 +82,7 @@ namespace FileAccess /// \brief Returns true if the file or directory identified by \p path exists and/or may be accessed for reading, writing or both, depending on the value of \p mode. inline bool file_accessible(const char* path, FileAccess::Mode mode) { + ASSERT_MESSAGE(path != 0, "file_accessible: invalid path"); return access(path, static_cast(mode)) == 0; } @@ -101,6 +107,7 @@ inline bool file_exists(const char* path) /// \brief Returns true if the file or directory identified by \p path exists and is a directory. inline bool file_is_directory(const char* path) { + ASSERT_MESSAGE(path != 0, "file_is_directory: invalid path"); struct stat st; if(stat(path, &st) == -1) { @@ -114,6 +121,7 @@ typedef std::size_t FileSize; /// \brief Returns the size in bytes of the file identified by \p path, or 0 if the file was not found. inline FileSize file_size(const char* path) { + ASSERT_MESSAGE(path != 0, "file_size: invalid path"); struct stat st; if(stat(path, &st) == -1) { @@ -130,6 +138,7 @@ const FileTime c_invalidFileTime = -1; /// \brief Returns the time that the file identified by \p path was last modified, or c_invalidFileTime if the file was not found. inline FileTime file_modified(const char* path) { + ASSERT_MESSAGE(path != 0, "file_modified: invalid path"); struct stat st; if(stat(path, &st) == -1) { -- 2.39.2