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>
367#ifdef BSLS_PLATFORM_OS_WINDOWS
371 typedef void *HANDLE;
375 typedef HANDLE FileDescriptor;
379 typedef __int64 Offset;
382 static const Offset k_OFFSET_MAX = _I64_MAX;
385 static const Offset k_OFFSET_MIN = _I64_MIN;
387#elif defined(BSLS_PLATFORM_OS_UNIX)
390 typedef int FileDescriptor;
392#if defined(BDLS_FILESYSTEMUTIL_UNIXPLATFORM_64_BIT_OFF64)
395 typedef off64_t Offset;
399 typedef off_t Offset;
403 static const Offset k_OFFSET_MAX = (0x7FFFFFFFFFFFFFFFLL);
406 static const Offset k_OFFSET_MIN = (-0x7FFFFFFFFFFFFFFFLL-1);
408# error "'bdls_filesystemutil' does not support this platform."
540 static FileDescriptor
open(
const char *path,
544 template <
class STRING_TYPE>
545 static FileDescriptor
open(
const STRING_TYPE& path,
554 static int close(FileDescriptor descriptor);
560#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
570 template <
class STRING_TYPE>
581 template <
class STRING_TYPE>
582 static bool exists(
const STRING_TYPE& path);
597 template <
class STRING_TYPE>
599 bool followLinksFlag =
false);
609 static bool isDirectory(
const char *path,
bool followLinksFlag =
false);
610 template <
class STRING_TYPE>
612 bool followLinksFlag =
false);
621 template <
class STRING_TYPE>
631 template <
class STRING_TYPE>
633 const STRING_TYPE& path);
640 FileDescriptor descriptor);
656 bool isLeafDirectoryFlag =
false);
657 template <
class STRING_TYPE>
659 const STRING_TYPE& path,
660 bool isLeafDirectoryFlag =
false);
676 template <
class STRING_TYPE>
686#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
708#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
726#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
746 std::string *outPath,
749#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
751 std::pmr::string *outPath,
773#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
799 template <
class STRING_TYPE>
801 const STRING_TYPE& pattern,
837 bool sortFlag =
false);
869 const char *pattern);
870 template <
class STRING_TYPE>
872 const STRING_TYPE& pattern);
874 const char *pattern);
875 template <
class STRING_TYPE>
877 const STRING_TYPE& pattern);
878#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
880 const char *pattern);
881 template <
class STRING_TYPE>
883 const STRING_TYPE& pattern);
893 template <
class STRING_TYPE>
909 template <
class STRING_TYPE>
910 static Offset
getFileSize(
const STRING_TYPE& path);
940 template <
class STRING_TYPE>
942 const STRING_TYPE& path);
943 template <
class STRING_TYPE>
945 const STRING_TYPE& path);
946#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
949 template <
class STRING_TYPE>
951 const STRING_TYPE& path);
964 static int lock(FileDescriptor descriptor,
bool lockWriteFlag);
989 static int tryLock(FileDescriptor descriptor,
bool lockWriteFlag);
993 static int unlock(FileDescriptor descriptor);
1011 static int map(FileDescriptor descriptor,
1047 static int unmap(
void *address, bsl::size_t size);
1058 static int sync(
char *address, bsl::size_t numBytes,
bool syncFlag);
1078 static Offset
seek(FileDescriptor descriptor, Offset offset,
int whence);
1085 static int read(FileDescriptor descriptor,
void *buffer,
int numBytes);
1114 static int remove(
const char *path,
bool recursiveFlag =
false);
1115 template <
class STRING_TYPE>
1116 static int remove(
const STRING_TYPE& path,
bool recursiveFlag =
false);
1147 static int move(
const char *oldPath,
const char *newPath);
1148 template <
class OLD_STRING_TYPE,
class NEW_STRING_TYPE>
1149 static int move(
const OLD_STRING_TYPE& oldPath,
1150 const NEW_STRING_TYPE& newPath);
1156 static int write(FileDescriptor descriptor,
1174 FileDescriptor descriptor,
1176 bool reserveFlag =
false,
1218 static const char *
flatten(
char *cString);
1219 static const char *
flatten(
const char *cString);
1223 static const char *
flatten(
const std::string&
string);
1224#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
1225 static const char *
flatten(
const std::pmr::string&
string);
1238 template <
class TYPE>
1239 static const char *
flatten(
const TYPE&);
1251template <
class STRING_TYPE>
1254 const STRING_TYPE& path,
1265template <
class STRING_TYPE>
1273template <
class STRING_TYPE>
1280template <
class STRING_TYPE>
1283 bool followLinksFlag)
1289template <
class STRING_TYPE>
1292 bool followLinksFlag)
1298template <
class STRING_TYPE>
1306template <
class STRING_TYPE>
1309 const STRING_TYPE& path)
1315template <
class STRING_TYPE>
1318 const STRING_TYPE& path,
1319 bool isLeafDirectoryFlag)
1325template <
class STRING_TYPE>
1333template <
class STRING_TYPE>
1336 const STRING_TYPE& pattern,
1343template <
class STRING_TYPE>
1346 const STRING_TYPE& pattern)
1352template <
class STRING_TYPE>
1355 const STRING_TYPE& pattern)
1361#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
1362template <
class STRING_TYPE>
1365 std::pmr::vector<std::pmr::string> *result,
1366 const STRING_TYPE& pattern)
1373template <
class STRING_TYPE>
1376 const STRING_TYPE& path)
1382template <
class STRING_TYPE>
1390template <
class STRING_TYPE>
1393 const STRING_TYPE& path)
1399template <
class STRING_TYPE>
1402 const STRING_TYPE& path)
1408#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
1409template <
class STRING_TYPE>
1412 const STRING_TYPE& path)
1419template <
class STRING_TYPE>
1427template <
class OLD_STRING_TYPE,
class NEW_STRING_TYPE>
1430 const NEW_STRING_TYPE& newPath)
1459 return string.c_str();
1465 return string.c_str();
1468#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_PMR_STRING
1472 return string.c_str();
1491template <
class TYPE>
1495 BSLMF_ASSERT((
"Unsupported parameter type." && !
sizeof(TYPE)));
Definition bdlt_datetime.h:330
Definition bslstl_stringview.h:471
Definition bslstl_string.h:1252
Forward declaration.
Definition bslstl_function.h:946
Definition bslstl_vector.h:1120
Definition bslstl_stringref.h:374
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:231
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdls_fdstreambuf.h:412
bsl::ostream & operator<<(bsl::ostream &stream, FilePermissions::Enum value)
Definition bdls_filesystemutil.h:1213
static const char * flatten(char *cString)
Return the specified cString.
Definition bdls_filesystemutil.h:1445
Definition bdls_filesystemutil.h:364
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:413
@ e_SEEK_FROM_END
Definition bdls_filesystemutil.h:416
@ e_SEEK_FROM_CURRENT
Definition bdls_filesystemutil.h:415
@ e_SEEK_FROM_BEGINNING
Definition bdls_filesystemutil.h:414
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:478
@ e_TRUNCATE
Definition bdls_filesystemutil.h:479
@ e_KEEP
Definition bdls_filesystemutil.h:480
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:424
@ k_BAD_FILE_DESCRIPTOR
Definition bdls_filesystemutil.h:445
@ k_ERROR_PATH_NOT_FOUND
Definition bdls_filesystemutil.h:436
@ k_ERROR_ALREADY_EXISTS
Definition bdls_filesystemutil.h:432
@ k_ERROR_PAST_EOF
Definition bdls_filesystemutil.h:442
@ k_ERROR_LOCKING_CONFLICT
Definition bdls_filesystemutil.h:425
@ k_ERROR_LOCKING_INTERRUPTED
Definition bdls_filesystemutil.h:428
FileOpenPolicy
Definition bdls_filesystemutil.h:451
@ e_CREATE_PRIVATE
Definition bdls_filesystemutil.h:457
@ e_CREATE
Definition bdls_filesystemutil.h:454
@ e_OPEN
Definition bdls_filesystemutil.h:452
@ e_OPEN_OR_CREATE
Definition bdls_filesystemutil.h:461
static Offset seek(FileDescriptor descriptor, Offset offset, int whence)
static Offset getFileSize(FileDescriptor descriptor)
FileIOPolicy
Definition bdls_filesystemutil.h:467
@ e_READ_ONLY
Definition bdls_filesystemutil.h:468
@ e_READ_WRITE
Definition bdls_filesystemutil.h:471
@ e_APPEND_ONLY
Definition bdls_filesystemutil.h:470
@ e_WRITE_ONLY
Definition bdls_filesystemutil.h:469
@ e_READ_APPEND
Definition bdls_filesystemutil.h:472
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)
@ k_DEFAULT_FILE_GROWTH_INCREMENT
Definition bdls_filesystemutil.h:420
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:484
static int getSymbolicLinkTarget(std::string *result, const char *path)
static int remove(const char *path, bool recursiveFlag=false)