8#ifndef INCLUDED_BDLS_FILESYSTEMUTIL
9#define INCLUDED_BDLS_FILESYSTEMUTIL
324#include <bdlscm_version.h>
335#include <bsl_functional.h>
336#include <bsl_optional.h>
343#include <bsl_string.h>
344#include <bsl_string_view.h>
345#include <bsl_vector.h>
346#include <bsl_cstddef.h>
351#include <sys/types.h>
365#ifdef BSLS_PLATFORM_OS_WINDOWS
369 typedef void *HANDLE;
373 typedef HANDLE FileDescriptor;
377 typedef __int64 Offset;
380 static const Offset k_OFFSET_MAX = _I64_MAX;
383 static const Offset k_OFFSET_MIN = _I64_MIN;
385#elif defined(BSLS_PLATFORM_OS_UNIX)
388 typedef int FileDescriptor;
390#if defined(BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF64)
393 typedef off64_t Offset;
397 typedef off_t Offset;
401 static const Offset k_OFFSET_MAX = (0x7FFFFFFFFFFFFFFFLL);
404 static const Offset k_OFFSET_MIN = (-0x7FFFFFFFFFFFFFFFLL-1);
406# error "'bdls_filesystemutil' does not support this platform."
536 static FileDescriptor
open(
const char *path,
540 template <
class STRING_TYPE>
541 static FileDescriptor
open(
const STRING_TYPE& path,
550 static int close(FileDescriptor descriptor);
556#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
566 template <
class STRING_TYPE>
577 template <
class STRING_TYPE>
578 static bool exists(
const STRING_TYPE& path);
593 template <
class STRING_TYPE>
595 bool followLinksFlag =
false);
604 static bool isDirectory(
const char *path,
bool followLinksFlag =
false);
605 template <
class STRING_TYPE>
607 bool followLinksFlag =
false);
616 template <
class STRING_TYPE>
626 template <
class STRING_TYPE>
628 const STRING_TYPE& path);
635 FileDescriptor descriptor);
651 bool isLeafDirectoryFlag =
false);
652 template <
class STRING_TYPE>
654 const STRING_TYPE& path,
655 bool isLeafDirectoryFlag =
false);
670 template <
class STRING_TYPE>
680#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
700#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
718#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
738 std::string *outPath,
741#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
743 std::pmr::string *outPath,
763#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
788 template <
class STRING_TYPE>
790 const STRING_TYPE& pattern,
825 bool sortFlag =
false);
856 const char *pattern);
857 template <
class STRING_TYPE>
859 const STRING_TYPE& pattern);
861 const char *pattern);
862 template <
class STRING_TYPE>
864 const STRING_TYPE& pattern);
865#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
867 const char *pattern);
868 template <
class STRING_TYPE>
870 const STRING_TYPE& pattern);
879 template <
class STRING_TYPE>
894 template <
class STRING_TYPE>
895 static Offset
getFileSize(
const STRING_TYPE& path);
922 template <
class STRING_TYPE>
924 const STRING_TYPE& path);
925 template <
class STRING_TYPE>
927 const STRING_TYPE& path);
928#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
931 template <
class STRING_TYPE>
933 const STRING_TYPE& path);
945 static int lock(FileDescriptor descriptor,
bool lockWriteFlag);
968 static int tryLock(FileDescriptor descriptor,
bool lockWriteFlag);
972 static int unlock(FileDescriptor descriptor);
989 static int map(FileDescriptor descriptor,
1022 static int unmap(
void *address, bsl::size_t size);
1032 static int sync(
char *address, bsl::size_t numBytes,
bool syncFlag);
1051 static Offset
seek(FileDescriptor descriptor, Offset offset,
int whence);
1058 static int read(FileDescriptor descriptor,
void *buffer,
int numBytes);
1079 static int remove(
const char *path,
bool recursiveFlag =
false);
1080 template <
class STRING_TYPE>
1081 static int remove(
const STRING_TYPE& path,
bool recursiveFlag =
false);
1109 static int move(
const char *oldPath,
const char *newPath);
1110 template <
class OLD_STRING_TYPE,
class NEW_STRING_TYPE>
1111 static int move(
const OLD_STRING_TYPE& oldPath,
1112 const NEW_STRING_TYPE& newPath);
1118 static int write(FileDescriptor descriptor,
1135 FileDescriptor descriptor,
1137 bool reserveFlag =
false,
1176 static const char *
flatten(
char *cString);
1177 static const char *
flatten(
const char *cString);
1181 static const char *
flatten(
const std::string&
string);
1182#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
1183 static const char *
flatten(
const std::pmr::string&
string);
1196 template <
class TYPE>
1197 static const char *
flatten(
const TYPE&);
1209template <
class STRING_TYPE>
1212 const STRING_TYPE& path,
1223template <
class STRING_TYPE>
1231template <
class STRING_TYPE>
1238template <
class STRING_TYPE>
1241 bool followLinksFlag)
1247template <
class STRING_TYPE>
1250 bool followLinksFlag)
1256template <
class STRING_TYPE>
1264template <
class STRING_TYPE>
1267 const STRING_TYPE& path)
1273template <
class STRING_TYPE>
1276 const STRING_TYPE& path,
1277 bool isLeafDirectoryFlag)
1283template <
class STRING_TYPE>
1291template <
class STRING_TYPE>
1294 const STRING_TYPE& pattern,
1301template <
class STRING_TYPE>
1304 const STRING_TYPE& pattern)
1310template <
class STRING_TYPE>
1313 const STRING_TYPE& pattern)
1319#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
1320template <
class STRING_TYPE>
1323 std::pmr::vector<std::pmr::string> *result,
1324 const STRING_TYPE& pattern)
1331template <
class STRING_TYPE>
1334 const STRING_TYPE& path)
1340template <
class STRING_TYPE>
1348template <
class STRING_TYPE>
1351 const STRING_TYPE& path)
1357template <
class STRING_TYPE>
1360 const STRING_TYPE& path)
1366#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
1367template <
class STRING_TYPE>
1370 const STRING_TYPE& path)
1377template <
class STRING_TYPE>
1385template <
class OLD_STRING_TYPE,
class NEW_STRING_TYPE>
1388 const NEW_STRING_TYPE& newPath)
1417 return string.c_str();
1423 return string.c_str();
1426#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
1430 return string.c_str();
1449template <
class TYPE>
1453 BSLMF_ASSERT((
"Unsupported parameter type." && !
sizeof(TYPE)));
Definition bdlt_datetime.h:331
Definition bslstl_stringview.h:441
Definition bslstl_string.h:1281
Forward declaration.
Definition bslstl_function.h:934
Definition bslstl_vector.h:1025
Definition bslstl_stringref.h:372
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:229
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdls_fdstreambuf.h:412
bsl::ostream & operator<<(bsl::ostream &stream, FilesystemUtil::Whence value)
Definition bdls_filesystemutil.h:1171
static const char * flatten(char *cString)
Return the specified cString.
Definition bdls_filesystemutil.h:1403
Definition bdls_filesystemutil.h:362
static int createTemporarySubdirectory(std::string *outPath, const bsl::string_view &rootDirectory, const bsl::string_view &prefix)
static int createTemporarySubdirectory(bsl::string *outPath, const bsl::string_view &rootDirectory, const bsl::string_view &prefix)
static int setWorkingDirectory(const char *path)
static int createTemporaryDirectory(bsl::string *outPath, const bsl::string_view &prefix)
static int getSystemTemporaryDirectory(std::string *path)
static int read(FileDescriptor descriptor, void *buffer, int numBytes)
static int getSystemTemporaryDirectory(bsl::string *path)
static int mapChecked(FileDescriptor descriptor, void **address, Offset offset, bsl::size_t size, int mode)
static int createDirectories(const char *path, bool isLeafDirectoryFlag=false)
static bool isRegularFile(const char *path, bool followLinksFlag=false)
static int findMatchingPaths(std::vector< std::string > *result, const char *pattern)
static int getSymbolicLinkTarget(bsl::string *result, const char *path)
static int getWorkingDirectory(bsl::string *path)
static int map(FileDescriptor descriptor, void **address, Offset offset, bsl::size_t size, int mode)
static int createPrivateDirectory(const char *path)
Whence
Definition bdls_filesystemutil.h:411
@ e_SEEK_FROM_END
Definition bdls_filesystemutil.h:414
@ e_SEEK_FROM_CURRENT
Definition bdls_filesystemutil.h:413
@ e_SEEK_FROM_BEGINNING
Definition bdls_filesystemutil.h:412
static int lock(FileDescriptor descriptor, bool lockWriteFlag)
static int rollFileChain(const bsl::string_view &path, int maxSuffix)
static void makeUnsafeTemporaryFilename(std::string *outPath, const bsl::string_view &prefix)
static void makeUnsafeTemporaryFilename(bsl::string *outPath, const bsl::string_view &prefix)
static int visitPaths(const char *pattern, const bsl::function< void(const char *path)> &visitor)
FileTruncatePolicy
Definition bdls_filesystemutil.h:476
@ e_TRUNCATE
Definition bdls_filesystemutil.h:477
@ e_KEEP
Definition bdls_filesystemutil.h:478
static Offset getAvailableSpace(const char *path)
static Offset getAvailableSpace(FileDescriptor descriptor)
static bool isSymbolicLink(const char *path)
static int close(FileDescriptor descriptor)
static bool exists(const char *path)
static int truncateFileSize(FileDescriptor descriptor, Offset size)
static Offset getFileSizeLimit()
static int getWorkingDirectory(std::string *path)
static bool isDirectory(const char *path, bool followLinksFlag=false)
static int unmap(void *address, bsl::size_t size)
ErrorType
Definition bdls_filesystemutil.h:422
@ k_BAD_FILE_DESCRIPTOR
Definition bdls_filesystemutil.h:443
@ k_ERROR_PATH_NOT_FOUND
Definition bdls_filesystemutil.h:434
@ k_ERROR_ALREADY_EXISTS
Definition bdls_filesystemutil.h:430
@ k_ERROR_PAST_EOF
Definition bdls_filesystemutil.h:440
@ k_ERROR_LOCKING_CONFLICT
Definition bdls_filesystemutil.h:423
@ k_ERROR_LOCKING_INTERRUPTED
Definition bdls_filesystemutil.h:426
@ k_DEFAULT_FILE_GROWTH_INCREMENT
Definition bdls_filesystemutil.h:418
FileOpenPolicy
Definition bdls_filesystemutil.h:449
@ e_CREATE_PRIVATE
Definition bdls_filesystemutil.h:455
@ e_CREATE
Definition bdls_filesystemutil.h:452
@ e_OPEN
Definition bdls_filesystemutil.h:450
@ e_OPEN_OR_CREATE
Definition bdls_filesystemutil.h:459
static Offset seek(FileDescriptor descriptor, Offset offset, int whence)
static Offset getFileSize(FileDescriptor descriptor)
FileIOPolicy
Definition bdls_filesystemutil.h:465
@ e_READ_ONLY
Definition bdls_filesystemutil.h:466
@ e_READ_WRITE
Definition bdls_filesystemutil.h:469
@ e_APPEND_ONLY
Definition bdls_filesystemutil.h:468
@ e_WRITE_ONLY
Definition bdls_filesystemutil.h:467
@ e_READ_APPEND
Definition bdls_filesystemutil.h:470
static FileDescriptor createTemporaryFile(std::string *outPath, const bsl::string_view &prefix)
static int write(FileDescriptor descriptor, const void *buffer, int numBytes)
static int visitTree(const bsl::string_view &root, const bsl::string_view &pattern, const bsl::function< void(const char *path)> &visitor, bool sortFlag=false)
static Offset getFileSize(const char *path)
static int getLastModificationTime(bdlt::Datetime *time, const char *path)
static FileDescriptor open(const char *path, FileOpenPolicy openPolicy, FileIOPolicy ioPolicy, FileTruncatePolicy truncatePolicy=e_KEEP)
static FileDescriptor createTemporaryFile(bsl::string *outPath, const bsl::string_view &prefix)
static int tryLock(FileDescriptor descriptor, bool lockWriteFlag)
static int unlock(FileDescriptor descriptor)
static int move(const char *oldPath, const char *newPath)
static int getLastModificationTime(bdlt::Datetime *time, FileDescriptor descriptor)
static int sync(char *address, bsl::size_t numBytes, bool syncFlag)
static int findMatchingPaths(bsl::vector< bsl::string > *result, const char *pattern)
static int growFile(FileDescriptor descriptor, Offset size, bool reserveFlag=false, bsl::size_t increment=k_DEFAULT_FILE_GROWTH_INCREMENT)
static int createTemporaryDirectory(std::string *outPath, const bsl::string_view &prefix)
static const FileDescriptor k_INVALID_FD
Definition bdls_filesystemutil.h:482
static int getSymbolicLinkTarget(std::string *result, const char *path)
static int remove(const char *path, bool recursiveFlag=false)