blocxx
FileSystem.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2005, Quest Software, Inc. All rights reserved.
3 * Copyright (C) 2006, Novell, Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of
14 * Quest Software, Inc.,
15 * nor Novell, Inc.,
16 * nor the names of its contributors or employees may be used to
17 * endorse or promote products derived from this software without
18 * specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 *******************************************************************************/
32 
33 
40 #ifndef BLOCXX_FILESYSTEM_HPP_INCLUDE_GUARD_
41 #define BLOCXX_FILESYSTEM_HPP_INCLUDE_GUARD_
42 #include "blocxx/BLOCXX_config.h"
43 #include "blocxx/Types.hpp"
44 #include "blocxx/ArrayFwd.hpp"
45 #include "blocxx/Exception.hpp"
46 #include "blocxx/CommonFwd.hpp"
47 #include "blocxx/String.hpp"
48 #ifdef BLOCXX_ENABLE_TEST_HOOKS
49 #include "blocxx/GlobalPtr.hpp"
50 #endif
51 
52 #include <utility>
53 
54 #ifdef BLOCXX_HAVE_SYS_PARAM_H
55 #include <sys/param.h>
56 #endif
57 #ifndef MAXPATHLEN
58 #ifdef PATH_MAX
59 #define MAXPATHLEN PATH_MAX
60 #else
61 #define MAXPATHLEN 1024
62 #endif
63 #endif
64 
65 namespace BLOCXX_NAMESPACE
66 {
67 
68 BLOCXX_DECLARE_APIEXCEPTION(FileSystem, BLOCXX_COMMON_API)
69 
70 
74 namespace FileSystem
75 {
80  BLOCXX_COMMON_API File openFile(const String& path);
88  BLOCXX_COMMON_API File createFile(const String& path);
95  BLOCXX_COMMON_API File openOrCreateFile(const String& path);
102  BLOCXX_COMMON_API File openForAppendOrCreateFile(const String& path);
111  BLOCXX_COMMON_API File createAutoDeleteTempFile(const String& dir=String());
123  BLOCXX_COMMON_API File createTempFile(String& filePath,
124  const String& dir=String());
131  BLOCXX_COMMON_API int changeFileOwner(const String& filename,
132  const UserId& userId);
136  BLOCXX_COMMON_API bool exists(const String& path);
137 #ifndef BLOCXX_WIN32
138 
146  BLOCXX_COMMON_API bool isExecutable(const String& path);
147 #endif
148 
151  BLOCXX_COMMON_API bool canRead(const String& path);
155  BLOCXX_COMMON_API bool canWrite(const String& path);
156 #ifndef BLOCXX_WIN32
157 
165  BLOCXX_COMMON_API bool isLink(const String& path);
166 #endif
167 
170  BLOCXX_COMMON_API bool isDirectory(const String& path);
176  BLOCXX_COMMON_API bool changeDirectory(const String& path);
183 #ifndef BLOCXX_WIN32
184  BLOCXX_COMMON_API bool makeDirectory(const String& path, int mode=0777);
185 #else
186  BLOCXX_COMMON_API bool makeDirectory(const String& path, int mode=-1);
187 #endif
188 
194  BLOCXX_COMMON_API bool getFileSize(const String& path, Int64& size);
200  BLOCXX_COMMON_API UInt64 fileSize(FileHandle fh);
206  BLOCXX_COMMON_API bool removeDirectory(const String& path);
212  BLOCXX_COMMON_API bool removeFile(const String& path);
219  BLOCXX_COMMON_API bool getDirectoryContents(const String& path,
220  StringArray& dirEntries);
227  BLOCXX_COMMON_API bool renameFile(const String& oldFileName,
228  const String& newFileName);
240  BLOCXX_COMMON_API size_t read(const FileHandle& hdl, void* bfr, size_t numberOfBytes,
241  Int64 offset=-1L);
252  BLOCXX_COMMON_API size_t write(FileHandle hdl, const void* bfr,
253  size_t numberOfBytes, Int64 offset=-1L);
265  BLOCXX_COMMON_API Int64 seek(const FileHandle& hdl, Int64 offset, int whence);
271  BLOCXX_COMMON_API Int64 tell(const FileHandle& hdl);
277  BLOCXX_COMMON_API void rewind(const FileHandle& hdl);
283  BLOCXX_COMMON_API int close(const FileHandle& hdl);
288  BLOCXX_COMMON_API int flush(FileHandle& hdl);
296  BLOCXX_COMMON_API String getFileContents(const String& filename);
297 
305  BLOCXX_COMMON_API StringArray getFileLines(const String& filename);
306 
314  BLOCXX_COMMON_API String readSymbolicLink(const String& path);
315 
316  namespace Path
317  {
339  BLOCXX_COMMON_API String realPath(const String& path);
340 
342  {
344  };
345 
367  BLOCXX_COMMON_API std::pair<ESecurity, String>
368  security(String const & path, UserId uid);
369 
374  BLOCXX_COMMON_API std::pair<ESecurity, String> security(String const & path);
375 
388  BLOCXX_COMMON_API std::pair<ESecurity, String>
389  security(String const & base_dir, String const & rel_path, UserId uid);
390 
395  BLOCXX_COMMON_API std::pair<ESecurity, String>
396  security(String const & base_dir, String const & rel_path);
397 
408  BLOCXX_COMMON_API String dirname(const String& filename);
409 
416  BLOCXX_COMMON_API String basename(const String& filename);
417 
426  BLOCXX_COMMON_API String getCurrentWorkingDirectory();
427 
428 
429  } // end namespace Path
430 
431  struct NullFactory
432  {
433  static void* create()
434  {
435  return 0;
436  }
437  };
438 #ifdef BLOCXX_ENABLE_TEST_HOOKS
449  extern FileSystemMockObject_t g_fileSystemMockObject;
450 #endif
451 
452 } // end namespace FileSystem
453 
454 } // end namespace BLOCXX_NAMESPACE
455 
456 #endif