00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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 }
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 }
00453
00454 }
00455
00456 #endif