8#ifndef PXR_ARCH_FILE_SYSTEM_H
9#define PXR_ARCH_FILE_SYSTEM_H
14#include "pxr/arch/pxr.h"
15#include "pxr/arch/api.h"
27#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_WASM_VM)
29#include <sys/statfs.h>
31#elif defined(ARCH_OS_DARWIN)
35#elif defined(ARCH_OS_WINDOWS)
38#include <stringapiset.h>
41ARCH_NAMESPACE_OPEN_SCOPE
43#if !defined(ARCH_OS_WINDOWS)
47 #include <sys/param.h>
51 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
61#if defined(ARCH_OS_WINDOWS)
62 #define ARCH_GLOB_NOCHECK 1
63 #define ARCH_GLOB_MARK 2
64 #define ARCH_GLOB_NOSORT 4
66 #define ARCH_GLOB_NOCHECK GLOB_NOCHECK
67 #define ARCH_GLOB_MARK GLOB_MARK
68 #define ARCH_GLOB_NOSORT GLOB_NOSORT
70#define ARCH_GLOB_DEFAULT (ARCH_GLOB_NOCHECK | ARCH_GLOB_MARK)
74 #define ARCH_PATH_MAX PATH_MAX
77 #define ARCH_PATH_MAX MAXPATHLEN
80 #define ARCH_PATH_MAX _MAX_PATH
82 #define ARCH_PATH_MAX 1024
88#if defined(ARCH_OS_WINDOWS)
89 #define ARCH_PATH_SEP "\\"
90 #define ARCH_PATH_LIST_SEP ";"
91 #define ARCH_REL_PATH_IDENT ".\\"
93 #define ARCH_PATH_SEP "/"
94 #define ARCH_PATH_LIST_SEP ":"
95 #define ARCH_REL_PATH_IDENT "./"
98#if defined(ARCH_OS_WINDOWS)
99typedef struct __stat64 ArchStatType;
168 bool stripDriveSpecifier =
false);
209 const std::string& suffix = std::string());
233 const std::string& prefix, std::string* pathname = 0);
245 const std::string& prefix);
268 return m.get_deleter().GetLength();
274 return m.get_deleter().GetLength();
334 void const *addr,
size_t len,
unsigned char *pageMap);
341int64_t
ArchPRead(FILE *file,
void *buffer,
size_t count, int64_t offset);
348int64_t
ArchPWrite(FILE *file,
void const *bytes,
size_t count, int64_t offset);
370#if defined(ARCH_OS_WINDOWS)
373inline std::string ArchWindowsUtf16ToUtf8(
const std::wstring &wstr)
375 if (wstr.empty())
return std::string();
377 int size = WideCharToMultiByte(
378 CP_UTF8, 0, wstr.data(), (
int)wstr.size(), NULL, 0, NULL, NULL);
379 if (size == 0)
return std::string();
380 std::string str(size, 0);
381 if (WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (
int)wstr.size(),
382 &str[0], size, NULL, NULL) == 0) {
383 return std::string();
389inline std::wstring ArchWindowsUtf8ToUtf16(
const std::string &str)
391 if (str.empty())
return std::wstring();
393 int size = MultiByteToWideChar(
394 CP_UTF8, 0, str.data(), (
int)str.size(), NULL, 0);
395 if (size == 0)
return std::wstring();
396 std::wstring wstr(size, 0);
397 if(MultiByteToWideChar(
398 CP_UTF8, 0, str.data(), (
int)str.size(), &wstr[0], size) == 0) {
399 return std::wstring();
406ARCH_NAMESPACE_CLOSE_SCOPE
bool ArchStatIsWritable(const ArchStatType *st)
Returns true if the data in stat struct st indicates that the target file or directory is writable.
size_t ArchGetFileMappingLength(ArchConstFileMapping const &m)
Return the length of an ArchConstFileMapping.
Definition fileSystem.h:267
bool ArchGetStatMode(const char *pathname, int *mode)
Returns the permissions mode (mode_t) for the given pathname.
ArchMutableFileMapping ArchMapFileReadWrite(FILE *file, std::string *errMsg=nullptr)
Privately map the passed file into memory and return a unique_ptr to the copy-on-write mapped content...
int ArchRmDir(const char *path)
int ArchFileIsaTTY(int fd)
bool ArchQueryMappedMemoryResidency(void const *addr, size_t len, unsigned char *pageMap)
Report whether or not the mapped virtual memory pages starting at addr for len bytes are resident in ...
FILE * ArchOpenFile(char const *fileName, char const *mode)
Opens a file.
int64_t ArchPRead(FILE *file, void *buffer, size_t count, int64_t offset)
Read up to count bytes from offset in file into buffer.
std::string ArchMakeTmpFileName(const std::string &prefix, const std::string &suffix=std::string())
Make a temporary file name, in a system-determined temporary directory.
int ArchFileAccess(const char *path, int mode)
void ArchMemAdvise(void const *addr, size_t len, ArchMemAdvice adv)
Advise the OS regarding how the application intends to access a range of memory.
int ArchCloseFile(int fd)
FILE * ArchFdOpen(int fd, const char *mode)
ArchMemAdvice
Definition fileSystem.h:305
@ ArchMemAdviceRandomAccess
Definition fileSystem.h:309
@ ArchMemAdviceDontNeed
Definition fileSystem.h:308
@ ArchMemAdviceWillNeed
Definition fileSystem.h:307
@ ArchMemAdviceNormal
Definition fileSystem.h:306
int64_t ArchPWrite(FILE *file, void const *bytes, size_t count, int64_t offset)
Write up to count bytes from buffer to file at offset.
const char * ArchGetTmpDir()
Return the path to a temporary directory for this platform.
std::unique_ptr< char, Arch_Unmapper > ArchMutableFileMapping
Definition fileSystem.h:263
std::string ArchNormPath(const std::string &path, bool stripDriveSpecifier=false)
Normalizes the specified path, eliminating double slashes, etc.
struct stat ArchStatType
Definition fileSystem.h:101
std::unique_ptr< char const, Arch_Unmapper > ArchConstFileMapping
ArchConstFileMapping and ArchMutableFileMapping are std::unique_ptr<char const *, ....
Definition fileSystem.h:262
std::string ArchMakeTmpSubdir(const std::string &tmpdir, const std::string &prefix)
Create a temporary sub-direcrory, in a given temporary directory.
bool ArchGetModificationTime(const char *pathname, double *time)
Returns the modification time (mtime) in seconds for a file.
int ArchUnlinkFile(const char *path)
int ArchChmod(const char *path, int mode)
int ArchFileNo(FILE *file)
std::string ArchReadLink(const char *path)
Returns the value of the symbolic link at path.
void ArchFileAdvise(FILE *file, int64_t offset, size_t count, ArchFileAdvice adv)
Advise the OS regarding how the application intends to access a range of bytes in a file.
ArchFileAdvice
Definition fileSystem.h:355
@ ArchFileAdviceWillNeed
Definition fileSystem.h:357
@ ArchFileAdviceDontNeed
Definition fileSystem.h:358
@ ArchFileAdviceRandomAccess
Definition fileSystem.h:359
@ ArchFileAdviceNormal
Definition fileSystem.h:356
int64_t ArchGetFileLength(const char *fileName)
Return the length of a file in bytes.
ArchConstFileMapping ArchMapFileReadOnly(FILE *file, std::string *errMsg=nullptr)
Privately map the passed file into memory and return a unique_ptr to the read-only mapped contents.
std::string ArchAbsPath(const std::string &path)
Returns the canonical absolute path of the specified filename.
int ArchMakeTmpFile(const std::string &prefix, std::string *pathname=0)
Create a temporary file, in a system-determined temporary directory.
std::string ArchGetFileName(FILE *file)
Return a filename for this file, if one can be obtained.
size_t GetLength() const
Definition fileSystem.h:253
Arch_Unmapper()
Definition fileSystem.h:249
Arch_Unmapper(size_t length)
Definition fileSystem.h:250
void operator()(char const *mapStart) const
void operator()(char *mapStart) const