#pragma once
#include <time.h>
#include <utility>
#include <wtf/Forward.h>
#include <wtf/OptionSet.h>
#include <wtf/Vector.h>
#include <wtf/WallTime.h>
#include <wtf/text/WTFString.h>
#if USE(CF)
#include <wtf/RetainPtr.h>
#endif
#if USE(CF)
typedef const struct __CFData* CFDataRef;
#endif
OBJC_CLASS NSString;
#if PLATFORM(WIN)
typedef void *HANDLE;
#endif
#if USE(GLIB)
typedef struct _GFileIOStream GFileIOStream;
#endif
namespace WebCore {
struct FileMetadata;
namespace FileSystem {
#if USE(GLIB) && !PLATFORM(WIN)
typedef GFileIOStream* PlatformFileHandle;
const PlatformFileHandle invalidPlatformFileHandle = 0;
#elif PLATFORM(WIN)
typedef HANDLE PlatformFileHandle;
const PlatformFileHandle invalidPlatformFileHandle = reinterpret_cast<HANDLE>(-1);
#else
typedef int PlatformFileHandle;
const PlatformFileHandle invalidPlatformFileHandle = -1;
#endif
enum class FileOpenMode {
Read,
Write,
#if OS(DARWIN)
EventsOnly,
#endif
};
enum class FileSeekOrigin {
Beginning,
Current,
End,
};
enum class FileLockMode {
Shared = 1 << 0,
Exclusive = 1 << 1,
Nonblocking = 1 << 2,
};
enum class ShouldFollowSymbolicLinks { No, Yes };
WEBCORE_EXPORT bool fileExists(const String&);
WEBCORE_EXPORT bool deleteFile(const String&);
WEBCORE_EXPORT bool deleteEmptyDirectory(const String&);
WEBCORE_EXPORT bool moveFile(const String& oldPath, const String& newPath);
WEBCORE_EXPORT bool getFileSize(const String&, long long& result);
WEBCORE_EXPORT bool getFileSize(PlatformFileHandle, long long& result);
WEBCORE_EXPORT Optional<WallTime> getFileModificationTime(const String&);
WEBCORE_EXPORT Optional<WallTime> getFileCreationTime(const String&); WEBCORE_EXPORT Optional<FileMetadata> fileMetadata(const String& path);
WEBCORE_EXPORT Optional<FileMetadata> fileMetadataFollowingSymlinks(const String& path);
WEBCORE_EXPORT bool fileIsDirectory(const String&, ShouldFollowSymbolicLinks);
WEBCORE_EXPORT String pathByAppendingComponent(const String& path, const String& component);
String pathByAppendingComponents(StringView path, const Vector<StringView>& components);
String lastComponentOfPathIgnoringTrailingSlash(const String& path);
WEBCORE_EXPORT bool makeAllDirectories(const String& path);
String homeDirectoryPath();
WEBCORE_EXPORT String pathGetFileName(const String&);
WEBCORE_EXPORT String directoryName(const String&);
WEBCORE_EXPORT bool getVolumeFreeSpace(const String&, uint64_t&);
WEBCORE_EXPORT Optional<int32_t> getFileDeviceId(const CString&);
WEBCORE_EXPORT bool createSymbolicLink(const String& targetPath, const String& symbolicLinkPath);
WEBCORE_EXPORT void setMetadataURL(const String& path, const String& urlString, const String& referrer = { });
bool canExcludeFromBackup(); bool excludeFromBackup(const String&);
WEBCORE_EXPORT Vector<String> listDirectory(const String& path, const String& filter = String());
WEBCORE_EXPORT CString fileSystemRepresentation(const String&);
String stringFromFileSystemRepresentation(const char*);
inline bool isHandleValid(const PlatformFileHandle& handle) { return handle != invalidPlatformFileHandle; }
WEBCORE_EXPORT String openTemporaryFile(const String& prefix, PlatformFileHandle&);
WEBCORE_EXPORT PlatformFileHandle openFile(const String& path, FileOpenMode);
WEBCORE_EXPORT void closeFile(PlatformFileHandle&);
WEBCORE_EXPORT long long seekFile(PlatformFileHandle, long long offset, FileSeekOrigin);
bool truncateFile(PlatformFileHandle, long long offset);
WEBCORE_EXPORT int writeToFile(PlatformFileHandle, const char* data, int length);
WEBCORE_EXPORT int readFromFile(PlatformFileHandle, char* data, int length);
WEBCORE_EXPORT PlatformFileHandle openAndLockFile(const String&, FileOpenMode, OptionSet<FileLockMode> = FileLockMode::Exclusive);
WEBCORE_EXPORT void unlockAndCloseFile(PlatformFileHandle);
bool appendFileContentsToFileHandle(const String& path, PlatformFileHandle&);
bool hardLinkOrCopyFile(const String& source, const String& destination);
#if USE(FILE_LOCK)
WEBCORE_EXPORT bool lockFile(PlatformFileHandle, OptionSet<FileLockMode>);
WEBCORE_EXPORT bool unlockFile(PlatformFileHandle);
#endif
WEBCORE_EXPORT String encodeForFileName(const String&);
WEBCORE_EXPORT String decodeFromFilename(const String&);
WEBCORE_EXPORT bool filesHaveSameVolume(const String&, const String&);
#if USE(CF)
RetainPtr<CFURLRef> pathAsURL(const String&);
#endif
#if PLATFORM(GTK) || PLATFORM(WPE)
String filenameForDisplay(const String&);
#endif
#if PLATFORM(WIN)
WEBCORE_EXPORT String localUserSpecificStorageDirectory();
String roamingUserSpecificStorageDirectory();
#endif
#if PLATFORM(COCOA)
WEBCORE_EXPORT NSString *createTemporaryDirectory(NSString *directoryPrefix);
WEBCORE_EXPORT bool deleteNonEmptyDirectory(const String&);
#endif
#if PLATFORM(WIN_CAIRO)
WEBCORE_EXPORT String createTemporaryDirectory();
WEBCORE_EXPORT bool deleteNonEmptyDirectory(const String&);
#endif
WEBCORE_EXPORT String realPath(const String&);
class MappedFileData {
public:
MappedFileData() { }
MappedFileData(MappedFileData&&);
WEBCORE_EXPORT MappedFileData(const String& filePath, bool& success);
WEBCORE_EXPORT ~MappedFileData();
MappedFileData& operator=(MappedFileData&&);
explicit operator bool() const { return !!m_fileData; }
const void* data() const { return m_fileData; }
unsigned size() const { return m_fileSize; }
private:
void* m_fileData { nullptr };
unsigned m_fileSize { 0 };
};
inline MappedFileData::MappedFileData(MappedFileData&& other)
: m_fileData(std::exchange(other.m_fileData, nullptr))
, m_fileSize(std::exchange(other.m_fileSize, 0))
{
}
inline MappedFileData& MappedFileData::operator=(MappedFileData&& other)
{
m_fileData = std::exchange(other.m_fileData, nullptr);
m_fileSize = std::exchange(other.m_fileSize, 0);
return *this;
}
} }