LibSWOC++ 1.5.14
Solid Wall of C++
Loading...
Searching...
No Matches
swoc_file.cc File Reference
#include <variant>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include "swoc/swoc_file.h"
#include "swoc/bwf_base.h"
Include dependency graph for swoc_file.cc:

Go to the source code of this file.

Namespaces

namespace  swoc
 For template deduction guides.
 

Functions

file_status swoc::file::status (path const &file, std::error_code &ec)
 
int swoc::file::file_type (const file_status &fs)
 Return the file type value.
 
uintmax_t swoc::file::file_size (const file_status &fs)
 Size of the file or block device.
 
bool swoc::file::exists (const path &p)
 Check if path exists.
 
path swoc::file::absolute (path const &src, std::error_code &ec)
 
file_time_type swoc::file::last_write_time (file_status const &fs)
 
file_time_type swoc::file::access_time (file_status const &fs)
 
file_time_type swoc::file::status_time (file_status const &fs)
 
file_time_type swoc::file::last_write_time (path const &p, std::error_code &ec)
 
bool swoc::file::is_readable (const path &s)
 Check if file is readable.
 
path swoc::file::temp_directory_path ()
 Directory location suitable for temporary files.
 
path swoc::file::current_path ()
 Current working directory.
 
path swoc::file::canonical (const path &p, std::error_code &ec)
 
bool swoc::file::create_directory (const path &path, std::error_code &ec, mode_t mode) noexcept
 
bool swoc::file::create_directories (const path &p, std::error_code &ec, mode_t mode) noexcept
 
bool swoc::file::copy (const path &from, const path &to, std::error_code &ec)
 
uintmax_t swoc::file::remove_all (const path &p, std::error_code &ec)
 
bool swoc::file::remove (path const &p, std::error_code &ec)
 
std::string swoc::file::load (const path &p, std::error_code &ec)
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, file::path const &p)
 

Detailed Description

Minimalist version of std::filesystem.

Definition in file swoc_file.cc.

Function Documentation

◆ absolute()

path swoc::file::absolute ( path const & src,
std::error_code & ec )

Convert to absolute path.

Parameters
srcOriginal path
ecError code.
Returns
Absolute path.

If path is already absolute, a copy of it is returned. Otherwise an absolute path is constructed that refers to the same item in the file system as src. If an error occurs then ec is set to indicate the type of error.

Definition at line 124 of file swoc_file.cc.

◆ access_time()

file_time_type swoc::file::access_time ( file_status const & fs)
Returns
The access time for fs.

Definition at line 200 of file swoc_file.cc.

◆ canonical()

path swoc::file::canonical ( const path & p,
std::error_code & ec )
Returns
Canonicalized absolute pathname

Definition at line 251 of file swoc_file.cc.

◆ copy()

bool swoc::file::copy ( const path & from,
const path & to,
std::error_code & ec )

Copy files.

Parameters
fromSource file
toDestination file.
ecError code return.
Returns
true if from was copied, false on error.
Note
Not fully implemented.

Definition at line 327 of file swoc_file.cc.

◆ create_directories()

bool swoc::file::create_directories ( const path & p,
std::error_code & ec,
mode_t mode = 0775 )
noexcept

Create directories.

Parameters
pPath to directory.
ecError code return.
modePermissions for created directories.
Returns
true if p was created, false otherwise.
Note
Not fully implemented.

Definition at line 294 of file swoc_file.cc.

◆ create_directory()

bool swoc::file::create_directory ( const path & p,
std::error_code & ec,
mode_t mode = 0775 )
noexcept

Create directory.

Parameters
pPath to directory.
ecError code return.
modePermissions for created directory.
Returns
true if p was created, false otherwise.
Note
Not fully implemented.

Definition at line 272 of file swoc_file.cc.

◆ current_path()

path swoc::file::current_path ( )

Current working directory.

Definition at line 237 of file swoc_file.cc.

◆ exists()

bool swoc::file::exists ( const path & p)

Check if path exists.

Definition at line 117 of file swoc_file.cc.

◆ file_size()

uintmax_t swoc::file::file_size ( const file_status & fs)

Size of the file or block device.

Definition at line 112 of file swoc_file.cc.

◆ file_type()

int swoc::file::file_type ( const file_status & fs)

Return the file type value.

Definition at line 107 of file swoc_file.cc.

◆ is_readable()

bool swoc::file::is_readable ( const path & p)

Check if file is readable.

Definition at line 219 of file swoc_file.cc.

◆ last_write_time() [1/2]

file_time_type swoc::file::last_write_time ( file_status const & fs)
Returns
The modified time for fs.

Definition at line 195 of file swoc_file.cc.

◆ last_write_time() [2/2]

file_time_type swoc::file::last_write_time ( path const & p,
std::error_code & ec )

Modification time.

Parameters
pPath to target.
Returns
Time of last modification, or file_time_type::min() on error.

Definition at line 210 of file swoc_file.cc.

◆ load()

std::string swoc::file::load ( const path & p,
std::error_code & ec )

Load the file at p into a std::string.

Parameters
pPath to file
ecError code result of the file operation.
Returns
The contents of the file.

Definition at line 454 of file swoc_file.cc.

◆ remove()

bool swoc::file::remove ( const path & path,
std::error_code & ec )

Remove a file or empty directory.

Parameters
pathTarget.
ecError return.
Returns
true if the operation succeeded, false if ec has an error code.

Definition at line 430 of file swoc_file.cc.

◆ remove_all()

uintmax_t swoc::file::remove_all ( const path & path,
std::error_code & ec )

Remove a file or a directory and all nested files.

Parameters
pathTarget.
ecError return.
Returns
Number of items removed.

Definition at line 375 of file swoc_file.cc.

◆ status()

file_status swoc::file::status ( path const & file,
std::error_code & ec )
noexcept

Get the status of the file at p.

Parameters
filePath to file.
ecError code return.
Returns
Status of the file.

Definition at line 92 of file swoc_file.cc.

◆ status_time()

file_time_type swoc::file::status_time ( file_status const & fs)
Returns
The status change time for fs.

Definition at line 205 of file swoc_file.cc.

◆ temp_directory_path()

path swoc::file::temp_directory_path ( )

Directory location suitable for temporary files.

Definition at line 224 of file swoc_file.cc.