blocxx
|
00001 /******************************************************************************* 00002 * Copyright (C) 2005, Quest Software, Inc. All rights reserved. 00003 * Copyright (C) 2006, Novell, Inc. All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * 00008 * * Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Neither the name of 00014 * Quest Software, Inc., 00015 * nor Novell, Inc., 00016 * nor the names of its contributors or employees may be used to 00017 * endorse or promote products derived from this software without 00018 * specific prior written permission. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00021 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00022 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00023 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00024 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00025 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00026 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00027 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00028 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00029 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00030 * POSSIBILITY OF SUCH DAMAGE. 00031 *******************************************************************************/ 00032 00033 00040 #ifndef BLOCXX_FILESYSTEM_HPP_INCLUDE_GUARD_ 00041 #define BLOCXX_FILESYSTEM_HPP_INCLUDE_GUARD_ 00042 #include "blocxx/BLOCXX_config.h" 00043 #include "blocxx/Types.hpp" 00044 #include "blocxx/ArrayFwd.hpp" 00045 #include "blocxx/Exception.hpp" 00046 #include "blocxx/CommonFwd.hpp" 00047 #include "blocxx/String.hpp" 00048 #ifdef BLOCXX_ENABLE_TEST_HOOKS 00049 #include "blocxx/GlobalPtr.hpp" 00050 #endif 00051 00052 #include <utility> 00053 00054 #ifdef BLOCXX_HAVE_SYS_PARAM_H 00055 #include <sys/param.h> 00056 #endif 00057 #ifndef MAXPATHLEN 00058 #ifdef PATH_MAX 00059 #define MAXPATHLEN PATH_MAX 00060 #else 00061 #define MAXPATHLEN 1024 00062 #endif 00063 #endif 00064 00065 namespace BLOCXX_NAMESPACE 00066 { 00067 00068 BLOCXX_DECLARE_APIEXCEPTION(FileSystem, BLOCXX_COMMON_API) 00069 00070 00074 namespace FileSystem 00075 { 00080 BLOCXX_COMMON_API File openFile(const String& path); 00088 BLOCXX_COMMON_API File createFile(const String& path); 00095 BLOCXX_COMMON_API File openOrCreateFile(const String& path); 00102 BLOCXX_COMMON_API File openForAppendOrCreateFile(const String& path); 00111 BLOCXX_COMMON_API File createAutoDeleteTempFile(const String& dir=String()); 00123 BLOCXX_COMMON_API File createTempFile(String& filePath, 00124 const String& dir=String()); 00131 BLOCXX_COMMON_API int changeFileOwner(const String& filename, 00132 const UserId& userId); 00136 BLOCXX_COMMON_API bool exists(const String& path); 00137 #ifndef BLOCXX_WIN32 00138 00146 BLOCXX_COMMON_API bool isExecutable(const String& path); 00147 #endif 00148 00151 BLOCXX_COMMON_API bool canRead(const String& path); 00155 BLOCXX_COMMON_API bool canWrite(const String& path); 00156 #ifndef BLOCXX_WIN32 00157 00165 BLOCXX_COMMON_API bool isLink(const String& path); 00166 #endif 00167 00170 BLOCXX_COMMON_API bool isDirectory(const String& path); 00176 BLOCXX_COMMON_API bool changeDirectory(const String& path); 00183 #ifndef BLOCXX_WIN32 00184 BLOCXX_COMMON_API bool makeDirectory(const String& path, int mode=0777); 00185 #else 00186 BLOCXX_COMMON_API bool makeDirectory(const String& path, int mode=-1); 00187 #endif 00188 00194 BLOCXX_COMMON_API bool getFileSize(const String& path, Int64& size); 00200 BLOCXX_COMMON_API UInt64 fileSize(FileHandle fh); 00206 BLOCXX_COMMON_API bool removeDirectory(const String& path); 00212 BLOCXX_COMMON_API bool removeFile(const String& path); 00219 BLOCXX_COMMON_API bool getDirectoryContents(const String& path, 00220 StringArray& dirEntries); 00227 BLOCXX_COMMON_API bool renameFile(const String& oldFileName, 00228 const String& newFileName); 00240 BLOCXX_COMMON_API size_t read(const FileHandle& hdl, void* bfr, size_t numberOfBytes, 00241 Int64 offset=-1L); 00252 BLOCXX_COMMON_API size_t write(FileHandle hdl, const void* bfr, 00253 size_t numberOfBytes, Int64 offset=-1L); 00265 BLOCXX_COMMON_API Int64 seek(const FileHandle& hdl, Int64 offset, int whence); 00271 BLOCXX_COMMON_API Int64 tell(const FileHandle& hdl); 00277 BLOCXX_COMMON_API void rewind(const FileHandle& hdl); 00283 BLOCXX_COMMON_API int close(const FileHandle& hdl); 00288 BLOCXX_COMMON_API int flush(FileHandle& hdl); 00296 BLOCXX_COMMON_API String getFileContents(const String& filename); 00297 00305 BLOCXX_COMMON_API StringArray getFileLines(const String& filename); 00306 00314 BLOCXX_COMMON_API String readSymbolicLink(const String& path); 00315 00316 namespace Path 00317 { 00339 BLOCXX_COMMON_API String realPath(const String& path); 00340 00341 enum ESecurity 00342 { 00343 E_INSECURE, E_SECURE_DIR, E_SECURE_FILE 00344 }; 00345 00367 BLOCXX_COMMON_API std::pair<ESecurity, String> 00368 security(String const & path, UserId uid); 00369 00374 BLOCXX_COMMON_API std::pair<ESecurity, String> security(String const & path); 00375 00388 BLOCXX_COMMON_API std::pair<ESecurity, String> 00389 security(String const & base_dir, String const & rel_path, UserId uid); 00390 00395 BLOCXX_COMMON_API std::pair<ESecurity, String> 00396 security(String const & base_dir, String const & rel_path); 00397 00408 BLOCXX_COMMON_API String dirname(const String& filename); 00409 00416 BLOCXX_COMMON_API String basename(const String& filename); 00417 00426 BLOCXX_COMMON_API String getCurrentWorkingDirectory(); 00427 00428 00429 } // end namespace Path 00430 00431 struct NullFactory 00432 { 00433 static void* create() 00434 { 00435 return 0; 00436 } 00437 }; 00438 #ifdef BLOCXX_ENABLE_TEST_HOOKS 00439 typedef GlobalPtr<FileSystemMockObject, NullFactory> FileSystemMockObject_t; 00449 extern FileSystemMockObject_t g_fileSystemMockObject; 00450 #endif 00451 00452 } // end namespace FileSystem 00453 00454 } // end namespace BLOCXX_NAMESPACE 00455 00456 #endif