LibSWOC++ 1.5.14
Solid Wall of C++
Loading...
Searching...
No Matches
swoc_file.h File Reference
#include <unistd.h>
#include <sys/stat.h>
#include <string>
#include <string_view>
#include <system_error>
#include <chrono>
#include "swoc/swoc_version.h"
#include "swoc/TextView.h"
Include dependency graph for swoc_file.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  swoc::file::unique_fd
 Scoped container for a file descriptor. More...
 
class  swoc::file::path
 
class  swoc::file::file_status
 Information about a file. More...
 
struct  std::hash< swoc::file::path >
 Enable use of path as a key in STL hashed containers. More...
 

Namespaces

namespace  swoc
 For template deduction guides.
 
namespace  std
 STL namespace.
 

Typedefs

using swoc::file::file_time_type = std::chrono::system_clock::time_point
 

Enumerations

enum class  file_type : signed char {
  none = 0 , not_found = -1 , regular = 1 , directory = 2 ,
  symlink = 3 , block = 4 , character = 5 , fifo = 6 ,
  socket = 7 , unknown = 8
}
 

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.
 
bool swoc::file::is_regular_file (const file_status &fs)
 Check if the path is to a regular file.
 
bool swoc::file::is_dir (const file_status &p)
 Check if the path is to a directory.
 
bool swoc::file::is_char_device (const file_status &fs)
 Check if the path is to a character device.
 
bool swoc::file::is_block_device (const file_status &fs)
 Check if the path is to a block device.
 
uintmax_t swoc::file::file_size (const file_status &fs)
 Size of the file or block device.
 
bool swoc::file::is_readable (const path &s)
 Check if file is readable.
 
bool swoc::file::exists (const path &p)
 Check if path exists.
 
bool swoc::file::exists (const file_status &fs)
 Check if path exists.
 
path swoc::file::absolute (path const &src, std::error_code &ec)
 
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)
 
bool swoc::file::remove (path const &p, std::error_code &ec)
 
uintmax_t swoc::file::remove_all (const path &p, std::error_code &ec)
 
file_time_type swoc::file::modify_time (file_status const &fs)
 
file_time_type swoc::file::last_write_time (file_status const &fs)
 
file_time_type swoc::file::last_write_time (path const &p, std::error_code &ec)
 
file_time_type swoc::file::access_time (file_status const &fs)
 
file_time_type swoc::file::status_time (file_status const &fs)
 
std::string swoc::file::load (const path &p, std::error_code &ec)
 
bool swoc::file::operator== (path const &lhs, path const &rhs)
 
bool swoc::file::operator!= (path const &lhs, path const &rhs)
 
path swoc::file::operator/ (const path &lhs, const path &rhs)
 
path swoc::file::operator/ (path &&lhs, const path &rhs)
 
path swoc::file::operator/ (const path &lhs, std::string_view rhs)
 
path swoc::file::operator/ (path &&lhs, std::string_view rhs)
 
BufferWriterswoc::bwformat (BufferWriter &w, bwf::Spec const &spec, file::path const &p)
 

Detailed Description

Simple path and file utilities.

Definition in file swoc_file.h.

Typedef Documentation

◆ file_time_type

using swoc::file::file_time_type = std::chrono::system_clock::time_point

Definition at line 24 of file swoc_file.h.

Enumeration Type Documentation

◆ file_type

enum class swoc::file::file_type : signed char
strong

Definition at line 26 of file swoc_file.h.

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() [1/2]

bool swoc::file::exists ( const file_status & fs)
inline

Check if path exists.

Definition at line 525 of file swoc_file.h.

◆ exists() [2/2]

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_block_device()

bool swoc::file::is_block_device ( const file_status & fs)
inline

Check if the path is to a block device.

Definition at line 510 of file swoc_file.h.

◆ is_char_device()

bool swoc::file::is_char_device ( const file_status & fs)
inline

Check if the path is to a character device.

Definition at line 505 of file swoc_file.h.

◆ is_dir()

bool swoc::file::is_dir ( const file_status & p)
inline

Check if the path is to a directory.

Definition at line 520 of file swoc_file.h.

◆ is_readable()

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

Check if file is readable.

Definition at line 219 of file swoc_file.cc.

◆ is_regular_file()

bool swoc::file::is_regular_file ( const file_status & fs)
inline

Check if the path is to a regular file.

Definition at line 515 of file swoc_file.h.

◆ 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.

◆ modify_time()

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

Definition at line 530 of file swoc_file.h.

◆ operator!=()

bool swoc::file::operator!= ( path const & lhs,
path const & rhs )
inline

Compare two paths.

Returns
true if lhs is not identical to rhs.

Definition at line 447 of file swoc_file.h.

◆ operator/() [1/4]

path swoc::file::operator/ ( const path & lhs,
const path & rhs )
inline

Combine two strings as file paths.

Returns
A path with the combined path.

Definition at line 456 of file swoc_file.h.

◆ operator/() [2/4]

path swoc::file::operator/ ( const path & lhs,
std::string_view rhs )
inline

Combine two strings as file paths.

Returns
A path with the combined path.

Definition at line 474 of file swoc_file.h.

◆ operator/() [3/4]

path swoc::file::operator/ ( path && lhs,
const path & rhs )
inline

Combine two strings as file paths.

Returns
A path with the combined path.

Definition at line 465 of file swoc_file.h.

◆ operator/() [4/4]

path swoc::file::operator/ ( path && lhs,
std::string_view rhs )
inline

Combine two strings as file paths.

Returns
A path with the combined path.

Definition at line 489 of file swoc_file.h.

◆ operator==()

bool swoc::file::operator== ( path const & lhs,
path const & rhs )
inline

Compare two paths.

Returns
true if lhs is identical to rhs.

Definition at line 438 of file swoc_file.h.

◆ 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.