]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/os/file.h
fixed access() assert when using msvc 8.0 runtime
[xonotic/netradiant.git] / libs / os / file.h
index 644add043da8527444f16039928a0514150210c5..b1290760c933a4daf65be96c3a95bd12f7f9da1d 100644 (file)
@@ -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 <io.h> // access()
+#include <io.h> // _access()
 #define F_OK 0x00
 #define W_OK 0x02
 #define R_OK 0x04
+#define access(path, mode) _access(path, mode)
 #else
 #include <unistd.h> // access()
 #endif
@@ -41,6 +42,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <cstddef>
 #include <ctime>
 
+#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<int>(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)
   {