#include <SystemFile.h>
Public Types | |
enum | OpenMode { SF_OPEN_READ_ONLY = (1 << 0) , SF_OPEN_READ_WRITE = (1 << 1) , SF_OPEN_WRITE_ONLY = (1 << 2) , SF_OPEN_APPEND = (1 << 3) , SF_OPEN_CREATE_NEW = (1 << 4) , SF_OPEN_CREATE = (1 << 5) , SF_OPEN_TRUNCATE = (1 << 6) , SF_OPEN_CREATE_PATH = (1 << 7) , SF_SKIP_CLOSE_ON_DESTRUCTION = (1 << 8) } |
enum | SeekMode { SF_SEEK_BEGIN = 0 , SF_SEEK_CURRENT , SF_SEEK_END } |
using | SizeType = AZ::IO::Internal::SizeType |
using | SeekSizeType = AZ::IO::Internal::SeekSizeType |
using | FileHandleType = AZ::IO::Internal::FileHandleType |
using | FindFileCB = AZStd::function< bool(const char *, bool)> |
FindFiles. | |
Public Member Functions | |
SystemFile (const char *fileName, int mode, int platformFlags=0) | |
Constructor which invokes Open() using the file name and mode. | |
SystemFile (SystemFile &&) | |
SystemFile & | operator= (SystemFile &&) |
bool | Open (const char *fileName, int mode, int platformFlags=0) |
bool | ReOpen (int mode, int platformFlags=0) |
void | Close () |
Closes a file, if file already close it has no effect. | |
void | Seek (SeekSizeType offset, SeekMode mode) |
Seek in current file. | |
SizeType | Tell () const |
Get the cursor position in the current file. | |
bool | Eof () const |
Is the cursor at the end of the file? | |
AZ::u64 | ModificationTime () |
Get the time the file was last modified. | |
SizeType | Read (SizeType byteSize, void *buffer) |
Read data from a file synchronous. Return number of bytes actually read in the buffer. | |
SizeType | Write (const void *buffer, SizeType byteSize) |
Writes data to a file synchronous. Return number of bytes actually written to the file. | |
void | Flush () |
Flush the contents of the file buffers to disk. | |
SizeType | Length () const |
Return file length. | |
SizeType | DiskOffset () const |
Return disc offset if possible, otherwise 0. | |
const char * | Name () const |
Return file name or NULL if file is not open. | |
bool | IsOpen () const |
const FileHandleType & | NativeHandle () const |
Return native handle to the file. | |
Static Public Member Functions | |
static bool | Exists (const char *path) |
Check if a file or directory exists. | |
static bool | IsDirectory (const char *path) |
Check if path is a directory. | |
static void | FindFiles (const char *filter, FindFileCB cb) |
static AZ::u64 | ModificationTime (const char *fileName) |
Get the time the file was last modified. | |
static SizeType | Length (const char *fileName) |
Return a length of a file. 0 if files has 0 length or doesn't exits. | |
static SizeType | Read (const char *fileName, void *buffer, SizeType byteSize=0, SizeType byteOffset=0) |
Read content from a file. If byteSize is 0 it reads the entire file. | |
static bool | Delete (const char *fileName) |
Delete a file, returns true if file was actually deleted. | |
static bool | Rename (const char *sourceFileName, const char *targetFileName, bool overwrite=false) |
Rename a file, returns true if the file was successfully renamed. If overwrite is true, rename even if target exists. | |
static bool | IsWritable (const char *sourceFileName) |
Returns true if a file is writable, false if it doesn't exist or is read only. | |
static bool | SetWritable (const char *sourceFileName, bool writable) |
Returns true if able to modify readonly attribute. Can fail if file doesn't exist. | |
static bool | CreateDir (const char *dirName) |
Recursively creates a directory hierarchy. | |
static bool | DeleteDir (const char *dirName) |
Delete a directory. | |
static const char * | GetNullFilename () |
Retrieves platform specific Null device path (ex: "/dev/null") | |
static SystemFile | GetStdin () |
static SystemFile | GetStdout () |
static SystemFile | GetStderr () |
Platform independent wrapper for system file.
Enumerator | |
---|---|
SF_OPEN_APPEND | All the writes will occur in the end of the file. |
SF_OPEN_CREATE_NEW | Create a file only if new, otherwise an error is returned. |
SF_OPEN_CREATE | Create a file, if file exists it will overwrite it's content. |
SF_OPEN_TRUNCATE | Opens a file and truncate it's size to zero. If file doesn't exist an error is returned. |
SF_OPEN_CREATE_PATH | Also create any intermediate paths that are part of the file path. Must be used in conjunction with SF_OPEN_CREATE or SF_OPEN_CREATE_NEW. |
SF_SKIP_CLOSE_ON_DESTRUCTION | SystemFile destructor will not invoke Close() on an open handle. |
|
static |
Opens stderr for write The destructor of SystemFile will not close the handle This allows stderr to continue to remain open even if the instance scope ends NOTE: However the handle can be explicitly closed using the Close() function Invoking that function will close the stderr handle
|
static |
Opens stdin for read The destructor of SystemFile will not close the handle This allows stdin to continue to remain open even if the instance scope ends NOTE: However the handle can be explicitly closed using the Close() function Invoking that function will close the stdin handle
|
static |
Opens stdout for write The destructor of SystemFile will not close the handle This allows stdout to continue to remain open even if the instance scope ends NOTE: However the handle can be explicitly closed using the Close() function Invoking that function will close the stdout handle
bool AZ::IO::SystemFile::Open | ( | const char * | fileName, |
int | mode, | ||
int | platformFlags = 0 |
||
) |
Opens a file.
fileName | full file name including path |
mode | combination of OpenMode flags |
platformFlags | platform flags that will be | "or" with the mapping of the OpenMode flags. |