Direct-BT v3.3.0-1-gc2d430c
Direct-BT - Direct Bluetooth Programming.
Classes | Macros | Typedefs | Functions | Variables
file_util.cpp File Reference
#include <jau/debug.hpp>
#include <jau/file_util.hpp>
#include <jau/base_codec.hpp>
#include <jau/os/os_support.hpp>
#include <cstdint>
#include <cstdlib>
#include <cinttypes>
#include <limits>
#include <cstring>
#include <cstdio>
#include <random>
#include <unistd.h>
#include <dirent.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/mount.h>
Include dependency graph for file_util.cpp:

Go to the source code of this file.

Classes

struct  copy_context_t
 

Macros

#define __posix_fstatat64   ::fstatat64
 
#define __posix_openat64   ::openat64
 
#define APPEND_BITSTR(U, V, M)   append_bitstr(out, M, U::V, #V, comma);
 
#define COPYOPTIONS_BIT_ENUM(X, M)
 
#define FILESTATS_FIELD_ENUM(X, M)
 
#define FMODEBITS_ENUM(X, M)
 
#define O_BINARY   0
 
#define O_NONBLOCK   0
 
#define TRAVERSEEVENT_ENUM(X, M)
 
#define TRAVERSEOPTIONS_ENUM(X, M)
 

Typedefs

typedef struct ::stat64 struct_stat64
 

Functions

static bool _dir_item_basename_compare (const dir_item &a, const dir_item &b)
 
static bool _visit (const file_stats &item_stats, const traverse_options topts, const path_visitor &visitor, std::vector< int > &dirfds) noexcept
 
static void append_bitstr (std::string &out, fmode_t mask, fmode_t bit, const std::string &bitstr)
 
template<typename T >
static void append_bitstr (std::string &out, T mask, T bit, const std::string &bitstr, bool &comma)
 
static const char c_backslash ('\\')
 
static const char c_slash ('/')
 
static bool copy_dir_preserve (const file_stats &src_stats, const int dst_dirfd, const std::string &dst_basename, const copy_options copts) noexcept
 
static bool copy_file (const int src_dirfd, const file_stats &src_stats, const int dst_dirfd, const std::string &dst_basename, const copy_options copts) noexcept
 
static bool copy_push_mkdir (const file_stats &dst_stats, copy_context_t &ctx) noexcept
 
static const std::string s_dot (".")
 
static const std::string s_dot_slash ("./")
 
static const std::string s_dotdot ("..")
 
static const std::string s_slash ("/")
 
static const std::string s_slash_dot ("/.")
 
static const std::string s_slash_dot_slash ("/./")
 
static const std::string s_slash_dotdot ("/..")
 
static const std::string s_slash_dotdot_slash ("/../")
 
static bool set_effective_uid (::uid_t user_id)
 

Variables

constexpr const int _open_dir_flags = O_RDONLY|O_BINARY|O_NOCTTY|O_DIRECTORY
 

Macro Definition Documentation

◆ O_BINARY

#define O_BINARY   0

Definition at line 53 of file file_util.cpp.

◆ O_NONBLOCK

#define O_NONBLOCK   0

Definition at line 56 of file file_util.cpp.

◆ __posix_fstatat64

#define __posix_fstatat64   ::fstatat64

Definition at line 78 of file file_util.cpp.

◆ __posix_openat64

#define __posix_openat64   ::openat64

Definition at line 79 of file file_util.cpp.

◆ APPEND_BITSTR

#define APPEND_BITSTR (   U,
  V,
 
)    append_bitstr(out, M, U::V, #V, comma);

Definition at line 347 of file file_util.cpp.

◆ FMODEBITS_ENUM

#define FMODEBITS_ENUM (   X,
 
)
Value:
X(fmode_t,sock,M) \
X(fmode_t,blk,M) \
X(fmode_t,chr,M) \
X(fmode_t,fifo,M) \
X(fmode_t,dir,M) \
X(fmode_t,file,M) \
X(fmode_t,link,M) \
X(fmode_t,no_access,M) \
X(fmode_t,not_existing,M)
fmode_t
Generic file type and POSIX protection mode bits as used in file_stats, touch(), mkdir() etc.
Definition: file_util.hpp:236

Definition at line 349 of file file_util.cpp.

◆ FILESTATS_FIELD_ENUM

#define FILESTATS_FIELD_ENUM (   X,
 
)
Value:
X(file_stats::field_t,type,M) \
X(file_stats::field_t,mode,M) \
X(file_stats::field_t,nlink,M) \
X(file_stats::field_t,atime,M) \
X(file_stats::field_t,mtime,M) \
X(file_stats::field_t,ctime,M) \
X(file_stats::field_t,size,M) \
X(file_stats::field_t,blocks,M) \
field_t
Field identifier which bit-mask indicates field_t fields.
Definition: file_util.hpp:411

Definition at line 422 of file file_util.cpp.

◆ TRAVERSEEVENT_ENUM

#define TRAVERSEEVENT_ENUM (   X,
 
)
Value:
X(traverse_event,symlink,M) \
X(traverse_event,file,M) \
X(traverse_event,dir_check_entry,M) \
X(traverse_event,dir_entry,M) \
X(traverse_event,dir_exit,M) \
X(traverse_event,dir_symlink,M)
traverse_event
Filesystem traverse event used to call path_visitor for path elements from visit().
Definition: file_util.hpp:763

Definition at line 1006 of file file_util.cpp.

◆ TRAVERSEOPTIONS_ENUM

#define TRAVERSEOPTIONS_ENUM (   X,
 
)
Value:
X(traverse_options,recursive,M) \
X(traverse_options,follow_symlinks,M) \
X(traverse_options,lexicographical_order,M) \
X(traverse_options,dir_check_entry,M) \
X(traverse_options,dir_entry,M) \
X(traverse_options,dir_exit,M)
traverse_options
Filesystem traverse options used to visit() path elements.
Definition: file_util.hpp:879

Definition at line 1023 of file file_util.cpp.

◆ COPYOPTIONS_BIT_ENUM

#define COPYOPTIONS_BIT_ENUM (   X,
 
)
Value:
X(copy_options,recursive,M) \
X(copy_options,follow_symlinks,M) \
X(copy_options,into_existing_dir,M) \
X(copy_options,ignore_symlink_errors,M) \
X(copy_options,overwrite,M) \
X(copy_options,preserve_all,M) \
copy_options
Filesystem copy options used to copy() path elements.
Definition: file_util.hpp:1035
void sync() noexcept
Synchronizes filesystems, i.e.
Definition: file_util.cpp:1932

Definition at line 1366 of file file_util.cpp.

Typedef Documentation

◆ struct_stat64

typedef struct ::stat64 struct_stat64

Definition at line 77 of file file_util.cpp.

Function Documentation

◆ c_slash()

static const char c_slash ( '/'  )
static
Here is the caller graph for this function:

◆ c_backslash()

static const char c_backslash ( '\\'  )
static
Here is the caller graph for this function:

◆ s_slash()

static const std::string s_slash ( "/"  )
static
Here is the caller graph for this function:

◆ s_slash_dot_slash()

static const std::string s_slash_dot_slash ( "/./"  )
static

◆ s_slash_dot()

static const std::string s_slash_dot ( "/."  )
static

◆ s_dot_slash()

static const std::string s_dot_slash ( "./"  )
static

◆ s_dot()

static const std::string s_dot ( "."  )
static
Here is the caller graph for this function:

◆ s_slash_dotdot_slash()

static const std::string s_slash_dotdot_slash ( "/../"  )
static

◆ s_slash_dotdot()

static const std::string s_slash_dotdot ( "/.."  )
static

◆ s_dotdot()

static const std::string s_dotdot ( ".."  )
static
Here is the caller graph for this function:

◆ append_bitstr() [1/2]

template<typename T >
static void append_bitstr ( std::string &  out,
mask,
bit,
const std::string &  bitstr,
bool &  comma 
)
static

Definition at line 340 of file file_util.cpp.

Here is the caller graph for this function:

◆ append_bitstr() [2/2]

static void append_bitstr ( std::string &  out,
fmode_t  mask,
fmode_t  bit,
const std::string &  bitstr 
)
static

Definition at line 360 of file file_util.cpp.

◆ _dir_item_basename_compare()

static bool _dir_item_basename_compare ( const dir_item a,
const dir_item b 
)
static

Definition at line 1039 of file file_util.cpp.

Here is the caller graph for this function:

◆ _visit()

static bool _visit ( const file_stats item_stats,
const traverse_options  topts,
const path_visitor visitor,
std::vector< int > &  dirfds 
)
staticnoexcept

Definition at line 1043 of file file_util.cpp.

Here is the caller graph for this function:

◆ copy_file()

static bool copy_file ( const int  src_dirfd,
const file_stats src_stats,
const int  dst_dirfd,
const std::string &  dst_basename,
const copy_options  copts 
)
staticnoexcept

Definition at line 1390 of file file_util.cpp.

Here is the caller graph for this function:

◆ copy_push_mkdir()

static bool copy_push_mkdir ( const file_stats dst_stats,
copy_context_t ctx 
)
staticnoexcept

Definition at line 1596 of file file_util.cpp.

Here is the caller graph for this function:

◆ copy_dir_preserve()

static bool copy_dir_preserve ( const file_stats src_stats,
const int  dst_dirfd,
const std::string &  dst_basename,
const copy_options  copts 
)
staticnoexcept

Definition at line 1678 of file file_util.cpp.

◆ set_effective_uid()

static bool set_effective_uid ( ::uid_t  user_id)
static

Definition at line 1936 of file file_util.cpp.

Here is the caller graph for this function:

Variable Documentation

◆ _open_dir_flags

constexpr const int _open_dir_flags = O_RDONLY|O_BINARY|O_NOCTTY|O_DIRECTORY
inlineconstexpr

Definition at line 59 of file file_util.cpp.