X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fnetradiant.git;a=blobdiff_plain;f=libs%2Fos%2Ffile.h;h=43381c63ab9ef9b14935e5e0c362c436345c8929;hp=b1290760c933a4daf65be96c3a95bd12f7f9da1d;hb=9d606a0b3be053550486b8f1a00255e340ccf8a8;hpb=231225d6f97d0b926b2e896e5783cccfbc7c5619;ds=sidebyside diff --git a/libs/os/file.h b/libs/os/file.h index b1290760..43381c63 100644 --- a/libs/os/file.h +++ b/libs/os/file.h @@ -1,37 +1,37 @@ /* -Copyright (C) 2001-2006, William Joseph. -All Rights Reserved. + Copyright (C) 2001-2006, William Joseph. + All Rights Reserved. -This file is part of GtkRadiant. + This file is part of GtkRadiant. -GtkRadiant is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + GtkRadiant is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -GtkRadiant is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GtkRadiant is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GtkRadiant; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + You should have received a copy of the GNU General Public License + along with GtkRadiant; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ -#if !defined(INCLUDED_OS_FILE_H) +#if !defined( INCLUDED_OS_FILE_H ) #define INCLUDED_OS_FILE_H /// \file /// \brief OS file-system querying and manipulation. #if defined( WIN32 ) -#define S_ISDIR(mode) (mode & _S_IFDIR) +#define S_ISDIR( mode ) ( mode & _S_IFDIR ) #include // _access() #define F_OK 0x00 #define W_OK 0x02 #define R_OK 0x04 -#define access(path, mode) _access(path, mode) +#define access( path, mode ) _access( path, mode ) #else #include // access() #endif @@ -51,10 +51,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA /// - The directory component of \p from identifies an existing directory which is accessible for writing. /// - The path \p to does not identify an existing file or directory. /// - 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; +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; } /// \brief Attempts to remove the file identified by \p path and returns true if the operation was successful. @@ -62,72 +61,63 @@ inline bool file_move(const char* from, const char* to) /// The operation will fail unless: /// - The \p path identifies an existing file. /// - 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; +inline bool file_remove( const char* path ){ + ASSERT_MESSAGE( path != 0, "file_remove: invalid path" ); + return remove( path ) == 0; } namespace FileAccess { - enum Mode - { - Read = R_OK, - Write = W_OK, - ReadWrite = Read | Write, - Exists = F_OK - }; +enum Mode +{ + Read = R_OK, + Write = W_OK, + ReadWrite = Read | Write, + Exists = F_OK +}; } /// \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; +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; } /// \brief Returns true if the file or directory identified by \p path exists and may be opened for reading. -inline bool file_readable(const char* path) -{ - return file_accessible(path, FileAccess::Read); +inline bool file_readable( const char* path ){ + return file_accessible( path, FileAccess::Read ); } /// \brief Returns true if the file or directory identified by \p path exists and may be opened for writing. -inline bool file_writeable(const char* path) -{ - return file_accessible(path, FileAccess::Write); +inline bool file_writeable( const char* path ){ + return file_accessible( path, FileAccess::Write ); } /// \brief Returns true if the file or directory identified by \p path exists. -inline bool file_exists(const char* path) -{ - return file_accessible(path, FileAccess::Exists); +inline bool file_exists( const char* path ){ + return file_accessible( path, FileAccess::Exists ); } /// \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) - { - return false; - } - return S_ISDIR (st.st_mode) != 0; +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 ) { + return false; + } + return S_ISDIR( st.st_mode ) != 0; } 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) - { - return 0; - } - return st.st_size; +inline FileSize file_size( const char* path ){ + ASSERT_MESSAGE( path != 0, "file_size: invalid path" ); + struct stat st; + if ( stat( path, &st ) == -1 ) { + return 0; + } + return st.st_size; } /// Seconds elapsed since Jan 1, 1970 @@ -136,15 +126,13 @@ typedef std::time_t FileTime; 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) - { - return c_invalidFileTime; - } - return st.st_mtime; +inline FileTime file_modified( const char* path ){ + ASSERT_MESSAGE( path != 0, "file_modified: invalid path" ); + struct stat st; + if ( stat( path, &st ) == -1 ) { + return c_invalidFileTime; + } + return st.st_mtime; }