WPILibC++ 2023.4.3
fs Namespace Reference

Typedefs

using ifstream = ghc::filesystem::ifstream
 
using ofstream = ghc::filesystem::ofstream
 
using fstream = ghc::filesystem::fstream
 
using file_t = int
 

Enumerations

enum  CreationDisposition : unsigned { CD_CreateAlways = 0 , CD_CreateNew = 1 , CD_OpenExisting = 2 , CD_OpenAlways = 3 }
 
enum  FileAccess : unsigned { FA_Read = 1 , FA_Write = 2 }
 
enum  OpenFlags : unsigned {
  OF_None = 0 , F_None = 0 , OF_Text = 1 , F_Text = 1 ,
  OF_Append = 2 , F_Append = 2 , OF_Delete = 4 , OF_ChildInherit = 8 ,
  OF_UpdateAtime = 16
}
 

Functions

OpenFlags operator| (OpenFlags A, OpenFlags B)
 
OpenFlagsoperator|= (OpenFlags &A, OpenFlags B)
 
FileAccess operator| (FileAccess A, FileAccess B)
 
FileAccessoperator|= (FileAccess &A, FileAccess B)
 
file_t OpenFile (const path &Path, std::error_code &EC, CreationDisposition Disp, FileAccess Access, OpenFlags Flags, unsigned Mode=0666)
 Opens a file with the specified creation disposition, access mode, and flags and returns a platform-specific file object. More...
 
file_t OpenFileForWrite (const path &Path, std::error_code &EC, CreationDisposition Disp, OpenFlags Flags, unsigned Mode=0666)
 Opens the file with the given name in a write-only or read-write mode, returning its open file descriptor. More...
 
file_t OpenFileForReadWrite (const path &Path, std::error_code &EC, CreationDisposition Disp, OpenFlags Flags, unsigned Mode=0666)
 Opens the file with the given name in a write-only or read-write mode, returning its open file descriptor. More...
 
file_t OpenFileForRead (const path &Path, std::error_code &EC, OpenFlags Flags=OF_None)
 Opens the file with the given name in a read-only mode, returning its open file descriptor. More...
 
int FileToFd (file_t &F, std::error_code &EC, OpenFlags Flags)
 Converts a file object to a file descriptor. More...
 
void CloseFile (file_t &F)
 Closes the file object. More...
 

Variables

const file_t kInvalidFile
 

Typedef Documentation

◆ file_t

typedef int fs::file_t

◆ fstream

◆ ifstream

◆ ofstream

Enumeration Type Documentation

◆ CreationDisposition

enum fs::CreationDisposition : unsigned
Enumerator
CD_CreateAlways 

CD_CreateAlways - When opening a file:

  • If it already exists, truncate it.
  • If it does not already exist, create a new file.
CD_CreateNew 

CD_CreateNew - When opening a file:

  • If it already exists, fail.
  • If it does not already exist, create a new file.
CD_OpenExisting 

CD_OpenExisting - When opening a file:

  • If it already exists, open the file with the offset set to 0.
  • If it does not already exist, fail.
CD_OpenAlways 

CD_OpenAlways - When opening a file:

  • If it already exists, open the file with the offset set to 0.
  • If it does not already exist, create a new file.

◆ FileAccess

enum fs::FileAccess : unsigned
Enumerator
FA_Read 
FA_Write 

◆ OpenFlags

enum fs::OpenFlags : unsigned
Enumerator
OF_None 
F_None 
OF_Text 

The file should be opened in text mode on platforms that make this distinction.

F_Text 
OF_Append 

The file should be opened in append mode.

F_Append 
OF_Delete 

Delete the file on close. Only makes a difference on windows.

OF_ChildInherit 

When a child process is launched, this file should remain open in the child process.

OF_UpdateAtime 

Force files Atime to be updated on access.

Only makes a difference on windows.

Function Documentation

◆ CloseFile()

void fs::CloseFile ( file_t F)

Closes the file object.

Parameters
FOn input, this is the file to close. On output, the file is set to kInvalidFile.

◆ FileToFd()

int fs::FileToFd ( file_t F,
std::error_code &  EC,
OpenFlags  Flags 
)

Converts a file object to a file descriptor.

The returned file descriptor must be closed with ::close() instead of CloseFile().

Parameters
FOn input, this is the file to convert to a file descriptor. On output, the file is set to kInvalidFile.
ECError code output, set to non-zero on error
FlagsFlags passed to the OpenFile function that created file_t
Returns
file descriptor, or -1 on error

◆ OpenFile()

file_t fs::OpenFile ( const path Path,
std::error_code &  EC,
CreationDisposition  Disp,
FileAccess  Access,
OpenFlags  Flags,
unsigned  Mode = 0666 
)

Opens a file with the specified creation disposition, access mode, and flags and returns a platform-specific file object.

The caller is responsible for closing the file object once they are finished with it.

Parameters
PathThe path of the file to open, relative or absolute.
ECError code output, set to non-zero on error
DispValue specifying the existing-file behavior
AccessValue specifying whether to open the file in read, write, or read-write mode.
FlagsAdditional flags.
ModeThe access permissions of the file, represented in octal.
Returns
errc::success if Name has been opened, otherwise a platform-specific error_code.

◆ OpenFileForRead()

file_t fs::OpenFileForRead ( const path Path,
std::error_code &  EC,
OpenFlags  Flags = OF_None 
)

Opens the file with the given name in a read-only mode, returning its open file descriptor.

The caller is responsible for closing the freeing the file once they are finished with it.

Parameters
PathThe path of the file to open, relative or absolute.
ECError code output, set to non-zero on error
FlagsAdditional flags
Returns
a platform-specific file descriptor if Name has been opened, otherwise kInvalidFile.

◆ OpenFileForReadWrite()

file_t fs::OpenFileForReadWrite ( const path Path,
std::error_code &  EC,
CreationDisposition  Disp,
OpenFlags  Flags,
unsigned  Mode = 0666 
)
inline

Opens the file with the given name in a write-only or read-write mode, returning its open file descriptor.

If the file does not exist, it is created.

The caller is responsible for closing the freeing the file once they are finished with it.

Parameters
PathThe path of the file to open, relative or absolute.
ECError code output, set to non-zero on error
DispValue specifying the existing-file behavior
FlagsAdditional flags used to determine whether the file should be opened in, for example, read-write or in write-only mode.
ModeThe access permissions of the file, represented in octal.
Returns
a platform-specific file descriptor if Name has been opened, otherwise kInvalidFile.

◆ OpenFileForWrite()

file_t fs::OpenFileForWrite ( const path Path,
std::error_code &  EC,
CreationDisposition  Disp,
OpenFlags  Flags,
unsigned  Mode = 0666 
)
inline

Opens the file with the given name in a write-only or read-write mode, returning its open file descriptor.

If the file does not exist, it is created.

The caller is responsible for closing the freeing the file once they are finished with it.

Parameters
PathThe path of the file to open, relative or absolute.
ECError code output, set to non-zero on error
DispValue specifying the existing-file behavior
FlagsAdditional flags used to determine whether the file should be opened in, for example, read-write or in write-only mode.
ModeThe access permissions of the file, represented in octal.
Returns
a platform-specific file descriptor if Name has been opened, otherwise kInvalidFile.

◆ operator|() [1/2]

FileAccess fs::operator| ( FileAccess  A,
FileAccess  B 
)
inline

◆ operator|() [2/2]

OpenFlags fs::operator| ( OpenFlags  A,
OpenFlags  B 
)
inline

◆ operator|=() [1/2]

FileAccess & fs::operator|= ( FileAccess A,
FileAccess  B 
)
inline

◆ operator|=() [2/2]

OpenFlags & fs::operator|= ( OpenFlags A,
OpenFlags  B 
)
inline

Variable Documentation

◆ kInvalidFile

const file_t fs::kInvalidFile
extern