8#ifndef PXR_ARCH_FILE_SYSTEM_H
9#define PXR_ARCH_FILE_SYSTEM_H
26#if defined(ARCH_OS_LINUX)
28#include <sys/statfs.h>
30#elif defined(ARCH_OS_DARWIN)
34#elif defined(ARCH_OS_WINDOWS)
37#include <stringapiset.h>
42#if !defined(ARCH_OS_WINDOWS)
46 #include <sys/param.h>
50 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
60#if defined(ARCH_OS_WINDOWS)
61 #define ARCH_GLOB_NOCHECK 1
62 #define ARCH_GLOB_MARK 2
63 #define ARCH_GLOB_NOSORT 4
65 #define ARCH_GLOB_NOCHECK GLOB_NOCHECK
66 #define ARCH_GLOB_MARK GLOB_MARK
67 #define ARCH_GLOB_NOSORT GLOB_NOSORT
69#define ARCH_GLOB_DEFAULT (ARCH_GLOB_NOCHECK | ARCH_GLOB_MARK)
73 #define ARCH_PATH_MAX PATH_MAX
76 #define ARCH_PATH_MAX MAXPATHLEN
79 #define ARCH_PATH_MAX _MAX_PATH
81 #define ARCH_PATH_MAX 1024
87#if defined(ARCH_OS_WINDOWS)
88 #define ARCH_PATH_SEP "\\"
89 #define ARCH_PATH_LIST_SEP ";"
90 #define ARCH_REL_PATH_IDENT ".\\"
92 #define ARCH_PATH_SEP "/"
93 #define ARCH_PATH_LIST_SEP ":"
94 #define ARCH_REL_PATH_IDENT "./"
97#if defined(ARCH_OS_WINDOWS)
167 bool stripDriveSpecifier =
false);
208 const std::string& suffix = std::string());
232 const std::string& prefix, std::string* pathname = 0);
244 const std::string& prefix);
267 return m.get_deleter().GetLength();
273 return m.get_deleter().GetLength();
333 void const *addr,
size_t len,
unsigned char *pageMap);
340int64_t
ArchPRead(FILE *file,
void *buffer,
size_t count, int64_t offset);
347int64_t
ArchPWrite(FILE *file,
void const *bytes,
size_t count, int64_t offset);
369#if defined(ARCH_OS_WINDOWS)
372inline std::string ArchWindowsUtf16ToUtf8(
const std::wstring &wstr)
374 if (wstr.empty())
return std::string();
376 int size = WideCharToMultiByte(
377 CP_UTF8, 0, wstr.data(), (
int)wstr.size(), NULL, 0, NULL, NULL);
378 if (size == 0)
return std::string();
379 std::string str(size, 0);
380 if (WideCharToMultiByte(CP_UTF8, 0, wstr.data(), (
int)wstr.size(),
381 &str[0], size, NULL, NULL) == 0) {
382 return std::string();
388inline std::wstring ArchWindowsUtf8ToUtf16(
const std::string &str)
390 if (str.empty())
return std::wstring();
392 int size = MultiByteToWideChar(
393 CP_UTF8, 0, str.data(), (
int)str.size(), NULL, 0);
394 if (size == 0)
return std::wstring();
395 std::wstring wstr(size, 0);
396 if(MultiByteToWideChar(
397 CP_UTF8, 0, str.data(), (
int)str.size(), &wstr[0], size) == 0) {
398 return std::wstring();
ARCH_API 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...
ARCH_API FILE * ArchOpenFile(char const *fileName, char const *mode)
Opens a file.
ARCH_API 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.
ARCH_API std::string ArchNormPath(const std::string &path, bool stripDriveSpecifier=false)
Normalizes the specified path, eliminating double slashes, etc.
size_t ArchGetFileMappingLength(ArchConstFileMapping const &m)
Return the length of an ArchConstFileMapping.
Definition fileSystem.h:266
ARCH_API std::string ArchMakeTmpSubdir(const std::string &tmpdir, const std::string &prefix)
Create a temporary sub-direcrory, in a given temporary directory.
ARCH_API int ArchMakeTmpFile(const std::string &prefix, std::string *pathname=0)
Create a temporary file, in a system-determined temporary directory.
ARCH_API bool ArchGetModificationTime(const char *pathname, double *time)
Returns the modification time (mtime) in seconds for a file.
ARCH_API 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.
ARCH_API std::string ArchReadLink(const char *path)
Returns the value of the symbolic link at path.
ArchMemAdvice
Definition fileSystem.h:304
@ ArchMemAdviceRandomAccess
Definition fileSystem.h:308
@ ArchMemAdviceDontNeed
Definition fileSystem.h:307
@ ArchMemAdviceWillNeed
Definition fileSystem.h:306
@ ArchMemAdviceNormal
Definition fileSystem.h:305
ARCH_API void ArchMemAdvise(void const *addr, size_t len, ArchMemAdvice adv)
Advise the OS regarding how the application intends to access a range of memory.
ARCH_API int64_t ArchPRead(FILE *file, void *buffer, size_t count, int64_t offset)
Read up to count bytes from offset in file into buffer.
ARCH_API int ArchUnlinkFile(const char *path)
ARCH_API 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 ...
ARCH_API int64_t ArchGetFileLength(const char *fileName)
Return the length of a file in bytes.
std::unique_ptr< char, Arch_Unmapper > ArchMutableFileMapping
Definition fileSystem.h:262
ARCH_API int ArchCloseFile(int fd)
struct stat ArchStatType
Definition fileSystem.h:100
std::unique_ptr< char const, Arch_Unmapper > ArchConstFileMapping
ArchConstFileMapping and ArchMutableFileMapping are std::unique_ptr<char const *, ....
Definition fileSystem.h:261
ARCH_API std::string ArchGetFileName(FILE *file)
Return a filename for this file, if one can be obtained.
ARCH_API int ArchRmDir(const char *path)
ARCH_API std::string ArchAbsPath(const std::string &path)
Returns the canonical absolute path of the specified filename.
ARCH_API int ArchFileIsaTTY(int fd)
ARCH_API int ArchChmod(const char *path, int mode)
ARCH_API bool ArchGetStatMode(const char *pathname, int *mode)
Returns the permissions mode (mode_t) for the given pathname.
ARCH_API FILE * ArchFdOpen(int fd, const char *mode)
ArchFileAdvice
Definition fileSystem.h:354
@ ArchFileAdviceWillNeed
Definition fileSystem.h:356
@ ArchFileAdviceDontNeed
Definition fileSystem.h:357
@ ArchFileAdviceRandomAccess
Definition fileSystem.h:358
@ ArchFileAdviceNormal
Definition fileSystem.h:355
ARCH_API int ArchFileAccess(const char *path, int mode)
ARCH_API 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.
ARCH_API bool ArchStatIsWritable(const ArchStatType *st)
Returns true if the data in stat struct st indicates that the target file or directory is writable.
ARCH_API const char * ArchGetTmpDir()
Return the path to a temporary directory for this platform.
ARCH_API int ArchFileNo(FILE *file)
ARCH_API std::string ArchMakeTmpFileName(const std::string &prefix, const std::string &suffix=std::string())
Make a temporary file name, in a system-determined temporary directory.
Definition fileSystem.h:247
size_t GetLength() const
Definition fileSystem.h:252
Arch_Unmapper()
Definition fileSystem.h:248
Arch_Unmapper(size_t length)
Definition fileSystem.h:249
ARCH_API void operator()(char *mapStart) const
ARCH_API void operator()(char const *mapStart) const