7#ifndef PXR_BASE_ARCH_FILE_SYSTEM_H
8#define PXR_BASE_ARCH_FILE_SYSTEM_H
15#include "pxr/base/arch/api.h"
16#include "pxr/base/arch/defines.h"
28#if defined(ARCH_OS_LINUX) || defined(ARCH_OS_WASM_VM)
30#include <sys/statfs.h>
32#elif defined(ARCH_OS_DARWIN)
36#elif defined(ARCH_OS_WINDOWS)
40PXR_NAMESPACE_OPEN_SCOPE
44#if !defined(ARCH_OS_WINDOWS)
48 #include <sys/param.h>
52 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
62#if defined(ARCH_OS_WINDOWS)
63 #define ARCH_GLOB_NOCHECK 1
64 #define ARCH_GLOB_MARK 2
65 #define ARCH_GLOB_NOSORT 4
67 #define ARCH_GLOB_NOCHECK GLOB_NOCHECK
68 #define ARCH_GLOB_MARK GLOB_MARK
69 #define ARCH_GLOB_NOSORT GLOB_NOSORT
71#define ARCH_GLOB_DEFAULT (ARCH_GLOB_NOCHECK | ARCH_GLOB_MARK)
75 #define ARCH_PATH_MAX PATH_MAX
78 #define ARCH_PATH_MAX MAXPATHLEN
81 #define ARCH_PATH_MAX _MAX_PATH
83 #define ARCH_PATH_MAX 1024
89#if defined(ARCH_OS_WINDOWS)
90 #define ARCH_PATH_SEP "\\"
91 #define ARCH_PATH_LIST_SEP ";"
92 #define ARCH_REL_PATH_IDENT ".\\"
94 #define ARCH_PATH_SEP "/"
95 #define ARCH_PATH_LIST_SEP ":"
96 #define ARCH_REL_PATH_IDENT "./"
99#if defined(ARCH_OS_WINDOWS)
100typedef struct __stat64 ArchStatType;
102typedef struct stat ArchStatType;
118#if defined(ARCH_OS_WINDOWS)
119# define ArchChmod(path, mode) _chmod(path, mode)
121# define ArchChmod(path, mode) chmod(path, mode)
124#if defined(ARCH_OS_WINDOWS)
125# define ArchCloseFile(fd) _close(fd)
127# define ArchCloseFile(fd) close(fd)
144#if defined(ARCH_OS_WINDOWS)
145 ARCH_API
int ArchWindowsFileAccess(
const char* path, uint32_t dwAccessMask);
146 ARCH_API
int ArchFileAccess(
const char* path,
int mode);
148# define ArchFileAccess(path, mode) access(path, mode)
151#if defined(ARCH_OS_WINDOWS)
152# define ArchFdOpen(fd, mode) _fdopen(fd, mode)
154# define ArchFdOpen(fd, mode) fdopen(fd, mode)
157#if defined(ARCH_OS_WINDOWS)
158# define ArchFileNo(stream) _fileno(stream)
160# define ArchFileNo(stream) fileno(stream)
163#if defined(ARCH_OS_WINDOWS)
164# define ArchFileIsaTTY(stream) _isatty(stream)
166# define ArchFileIsaTTY(stream) isatty(stream)
172#if defined(ARCH_OS_WINDOWS)
173 ARCH_API
int ArchRmDir(
const char* path);
175# define ArchRmDir(path) rmdir(path)
221 bool stripDriveSpecifier =
false);
262 const std::string& suffix = std::string());
286 const std::string& prefix, std::string* pathname = 0);
298 const std::string& prefix);
301struct Arch_Unmapper {
302 Arch_Unmapper() : _length(~0) {}
303 explicit Arch_Unmapper(
size_t length) : _length(length) {}
304 ARCH_API
void operator()(
char *mapStart)
const;
305 ARCH_API
void operator()(
char const *mapStart)
const;
306 size_t GetLength()
const {
return _length; }
316using ArchMutableFileMapping = std::unique_ptr<char, Arch_Unmapper>;
321 return m.get_deleter().GetLength();
327 return m.get_deleter().GetLength();
350ArchMutableFileMapping
355ArchMutableFileMapping
360 ArchMemAdviceWillNeed,
361 ArchMemAdviceDontNeed,
362 ArchMemAdviceRandomAccess,
387 void const *addr,
size_t len,
unsigned char *pageMap);
394int64_t
ArchPRead(FILE *file,
void *buffer,
size_t count, int64_t offset);
401int64_t
ArchPWrite(FILE *file,
void const *bytes,
size_t count, int64_t offset);
409 ArchFileAdviceNormal,
410 ArchFileAdviceWillNeed,
411 ArchFileAdviceDontNeed,
412 ArchFileAdviceRandomAccess,
423#if defined(ARCH_OS_WINDOWS)
426ARCH_API std::string ArchWindowsUtf16ToUtf8(
const std::wstring &wstr);
429ARCH_API std::wstring ArchWindowsUtf8ToUtf16(
const std::string &str);
435PXR_NAMESPACE_CLOSE_SCOPE
ARCH_API const char * ArchGetTmpDir()
Return the path to a temporary directory for this platform.
std::unique_ptr< char const, Arch_Unmapper > ArchConstFileMapping
ArchConstFileMapping and ArchMutableFileMapping are std::unique_ptr<char const *, ....
ARCH_API bool ArchTouchFile(const std::string &fileName, bool create)
Touch fileName, updating access and modification time to 'now'.
ARCH_API std::string ArchReadLink(const char *path)
Returns the value of the symbolic link at path.
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 std::string ArchGetFileName(FILE *file)
Return a filename for this file, if one can be obtained.
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 FILE * ArchOpenFile(char const *fileName, char const *mode)
Opens a file.
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 int ArchUnlinkFile(const char *path)
Delete a file.
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 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 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 std::string ArchMakeTmpFileName(const std::string &prefix, const std::string &suffix=std::string())
Make a temporary file name, in a system-determined temporary directory.
#define ArchRmDir(path)
Delete an empty directory.
size_t ArchGetFileMappingLength(ArchConstFileMapping const &m)
Return the length of an ArchConstFileMapping.
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 std::string ArchAbsPath(const std::string &path)
Returns the canonical absolute path of the specified filename.
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 bool ArchGetModificationTime(const char *pathname, double *time)
Returns the modification time (mtime) in seconds for a file.
ARCH_API int ArchMakeTmpFile(const std::string &prefix, std::string *pathname=0)
Create a temporary file, in a system-determined temporary directory.
ARCH_API int64_t ArchGetFileLength(const char *fileName)
Return the length of a file in bytes.
ARCH_API std::string ArchNormPath(const std::string &path, bool stripDriveSpecifier=false)
Normalizes the specified path, eliminating double slashes, etc.
ARCH_API std::string ArchMakeTmpSubdir(const std::string &tmpdir, const std::string &prefix)
Create a temporary sub-directory, in a given temporary directory.
ARCH_API bool ArchGetStatMode(const char *pathname, int *mode)
Returns the permissions mode (mode_t) for the given pathname.
Defines useful mathematical limits.