Disk ARchive  2.5.5
Full featured and portable backup and archiving tool
Namespaces | Macros | Functions
tools.hpp File Reference

a set of general purpose routines More...

#include "../my_config.h"
#include <string>
#include <vector>
#include <map>
#include "path.hpp"
#include "infinint.hpp"
#include "generic_file.hpp"
#include "tuyau.hpp"
#include "integers.hpp"
#include "tlv_list.hpp"
#include "memory_pool.hpp"
#include "datetime.hpp"

Go to the source code of this file.

Namespaces

 libdar
 libdar namespace encapsulate all libdar symbols
 

Macros

#define TOOLS_SI_SUFFIX   1000
 
#define TOOLS_BIN_SUFFIX   1024
 

Functions

void libdar::tools_init ()
 libdar internal use only: it is launched from get_version() and initializes tools internal variables
 
void libdar::tools_end ()
 libdar internal use only: it is launched from close_and_clean() and releases tools internal variables
 
char * libdar::tools_str2charptr (const std::string &x)
 convert a string to a char * More...
 
void libdar::tools_write_string (generic_file &f, const std::string &s)
 write a string to a file with a '\0' at then end More...
 
void libdar::tools_read_string (generic_file &f, std::string &s)
 read a string from a file expecting it to terminate by '\0' More...
 
void libdar::tools_write_string_all (generic_file &f, const std::string &s)
 write a string to a file, '\0' has no special meaning nor is added at the end More...
 
void libdar::tools_read_string_size (generic_file &f, std::string &s, infinint taille)
 read a string if given size from a file '\0' has no special meaning More...
 
infinint libdar::tools_get_filesize (const path &p)
 retrieve the size in byte of a file More...
 
infinint libdar::tools_get_extended_size (std::string s, U_I base)
 convert the given string to infinint taking care of multiplication suffixes like k, M, T, etc. More...
 
std::string libdar::tools_display_integer_in_metric_system (infinint number, const std::string &unit, bool binary)
 
void libdar::tools_extract_basename (const char *command_name, std::string &basename)
 extracts the basename of a file (removing path part) More...
 
std::string::iterator libdar::tools_find_last_char_of (std::string &s, unsigned char v)
 give a pointer to the last character of the given value in the given string More...
 
std::string::iterator libdar::tools_find_first_char_of (std::string &s, unsigned char v)
 give a pointer to the last character of the given value in the given string More...
 
void libdar::tools_split_path_basename (const char *all, path *&chemin, std::string &base, memory_pool *pool=nullptr)
 split a given full path in path part and basename part More...
 
void libdar::tools_split_path_basename (const std::string &all, std::string &chemin, std::string &base, memory_pool *pool=nullptr)
 split a given full path in path part and basename part More...
 
void libdar::tools_open_pipes (user_interaction &dialog, const std::string &input, const std::string &output, tuyau *&in, tuyau *&out, memory_pool *pool=nullptr)
 open a pair of tuyau objects encapsulating two named pipes. More...
 
void libdar::tools_blocking_read (int fd, bool mode)
 set blocking/not blocking mode for reading on a file descriptor More...
 
std::string libdar::tools_name_of_uid (const infinint &uid)
 convert uid to name in regards to the current system's configuration More...
 
std::string libdar::tools_name_of_gid (const infinint &gid)
 convert gid to name in regards of the current system's configuration More...
 
std::string libdar::tools_uword2str (U_16 x)
 convert unsigned word to string More...
 
std::string libdar::tools_int2str (S_I x)
 convert integer to string More...
 
std::string libdar::tools_uint2str (U_I x)
 
U_I libdar::tools_str2int (const std::string &x)
 convert an integer written in decimal notation to the corresponding value More...
 
S_I libdar::tools_str2signed_int (const std::string &x)
 convert a signed integer written in decimal notation to the corresponding value More...
 
bool libdar::tools_my_atoi (const char *a, U_I &val)
 ascii to integer conversion More...
 
std::string libdar::tools_addspacebefore (std::string s, U_I expected_size)
 prepend spaces before the given string More...
 
std::string libdar::tools_display_date (const datetime &date)
 convert a date in second to its human readable representation More...
 
infinint libdar::tools_convert_date (const std::string &repres)
 convert a human readable date representation in number of second since the system reference date More...
 
void libdar::tools_system (user_interaction &dialog, const std::vector< std::string > &argvector)
 wrapper to the "system" system call. More...
 
void libdar::tools_system_with_pipe (user_interaction &dialog, const std::string &dar_cmd, const std::vector< std::string > &argvpipe, memory_pool *pool=nullptr)
 wrapper to the "system" system call using anonymous pipe to tranmit arguments to the child process More...
 
void libdar::tools_write_vector (generic_file &f, const std::vector< std::string > &x)
 write a list of string to file More...
 
void libdar::tools_read_vector (generic_file &f, std::vector< std::string > &x)
 read a list of string from a file More...
 
std::string libdar::tools_concat_vector (const std::string &separator, const std::vector< std::string > &x)
 concatenate a vectors of strings in a single string More...
 
std::vector< std::string > libdar::operator+ (std::vector< std::string > a, std::vector< std::string > b)
 concatenate two vectors More...
 
void libdar::tools_display_features (user_interaction &dialog)
 display the compilation time features of libdar More...
 
bool libdar::tools_is_equal_with_hourshift (const infinint &hourshift, const datetime &date1, const datetime &date2)
 test if two dates are equal taking care of a integer hour of difference More...
 
template<class T >
std::vector< T > libdar::operator+= (std::vector< T > &a, const std::vector< T > &b)
 template function to add two vectors
 
const char * libdar::tools_get_from_env (const char **env, const char *clef)
 isolate the value of a given variable from the environment vector More...
 
void libdar::tools_check_basename (user_interaction &dialog, const path &loc, std::string &base, const std::string &extension, memory_pool *pool=nullptr)
 does sanity checks on a slice name, check presence and detect whether the given basename is not rather a filename More...
 
std::string libdar::tools_getcwd ()
 get current working directory
 
std::string libdar::tools_readlink (const char *root)
 returns the file pointed to by a symbolic link (or transparent if the file is not a symlink). More...
 
bool libdar::tools_look_for (const char *argument, S_I argc, char *const argv[])
 test the presence of an argument More...
 
void libdar::tools_noexcept_make_date (const std::string &chem, bool symlink, const datetime &last_acc, const datetime &last_mod, const datetime &birth)
 set dates of a given file, no exception thrown More...
 
void libdar::tools_make_date (const std::string &chemin, bool symlink, const datetime &access, const datetime &modif, const datetime &birth)
 set dates of a given file, may throw exception More...
 
bool libdar::tools_is_case_insensitive_equal (const std::string &a, const std::string &b)
 compare two string in case insensitive manner More...
 
void libdar::tools_to_upper (const std::string &r, std::string &uppered)
 convert a string to upper case More...
 
void libdar::tools_remove_last_char_if_equal_to (char c, std::string &s)
 remove last character of a string is it equal to a given value More...
 
void libdar::tools_read_range (const std::string &s, S_I &min, U_I &max)
 from a string with a range notation (min-max) extract the range values More...
 
std::string libdar::tools_printf (const char *format,...)
 make printf-like formating to a std::string More...
 
std::string libdar::tools_vprintf (const char *format, va_list ap)
 make printf-like formating to a std::string More...
 
bool libdar::tools_do_some_files_match_mask_regex (user_interaction &ui, const std::string &c_chemin, const std::string &file_mask)
 test the presence of files corresponding to a given mask in a directory (regex mask) More...
 
void libdar::tools_unlink_file_mask_regex (user_interaction &dialog, const std::string &c_chemin, const std::string &file_mask, bool info_details)
 remove files from a given directory More...
 
void libdar::tools_avoid_slice_overwriting_regex (user_interaction &dialog, const path &chemin, const std::string &basename, const std::string &extension, bool info_details, bool allow_overwriting, bool warn_overwriting, bool dry_run)
 prevents slice overwriting: check the presence of slice and if necessary ask the user if they can be removed More...
 
void libdar::tools_add_elastic_buffer (generic_file &f, U_32 max_size, U_32 modulo, U_32 offset)
 
bool libdar::tools_are_on_same_filesystem (const std::string &file1, const std::string &file2)
 
path libdar::tools_relative2absolute_path (const path &src, const path &cwd)
 transform a relative path to an absolute one given the current directory value More...
 
void libdar::tools_block_all_signals (sigset_t &old_mask)
 block all signals (based on POSIX sigprocmask) More...
 
void libdar::tools_set_back_blocked_signals (sigset_t old_mask)
 unblock signals according to given mask More...
 
U_I libdar::tools_count_in_string (const std::string &s, const char a)
 counts the number of a given char in a given string More...
 
datetime libdar::tools_get_mtime (const std::string &s)
 returns the last modification date of the given file More...
 
infinint libdar::tools_get_size (const std::string &s)
 returns the size of the given plain file More...
 
datetime libdar::tools_get_ctime (const std::string &s)
 returns the last change date of the given file More...
 
std::vector< std::string > libdar::tools_split_in_words (generic_file &f)
 read a file and split its contents into words More...
 
std::vector< std::string > libdar::tools_split_in_words (const std::string &arg)
 read a std::string and split its contents into words More...
 
bool libdar::tools_find_next_char_out_of_parenthesis (const std::string &data, const char what, U_32 start, U_32 &found)
 look next char in string out of parenthesis More...
 
std::string libdar::tools_substitute (const std::string &hook, const std::map< char, std::string > &corres)
 produce the string resulting from the substition of % macro defined in the map More...
 
std::string libdar::tools_hook_substitute (const std::string &hook, const std::string &path, const std::string &basename, const std::string &num, const std::string &padded_num, const std::string &ext, const std::string &context)
 produces the string resulting from the substitution of %... macro More...
 
void libdar::tools_hook_execute (user_interaction &ui, const std::string &cmd_line)
 execute and retries at user will a given command line More...
 
void libdar::tools_hook_substitute_and_execute (user_interaction &ui, const std::string &hook, const std::string &path, const std::string &basename, const std::string &num, const std::string &padded_num, const std::string &ext, const std::string &context)
 subsititue and execute command line More...
 
std::string libdar::tools_build_regex_for_exclude_mask (const std::string &prefix, const std::string &relative_part)
 builds a regex from root directory and user provided regex to be applied to the relative path More...
 
std::string libdar::tools_output2xml (const std::string &src)
 convert string for xml output More...
 
U_I libdar::tools_octal2int (const std::string &perm)
 convert octal string to integer More...
 
std::string libdar::tools_int2octal (const U_I &perm)
 convert a number to a string corresponding to its octal representation More...
 
std::string libdar::tools_get_permission_string (char type, U_32 perm, bool hard)
 convert a permission number into its string representation (rwxrwxrwx)
 
void libdar::tools_set_permission (S_I fd, U_I perm)
 change the permission of the file which descriptor is given More...
 
U_I libdar::tools_get_permission (S_I fd)
 obtain the permission of the file which descriptor is given More...
 
uid_t libdar::tools_ownership2uid (const std::string &user)
 change ownership of the file which descriptor is given More...
 
uid_t libdar::tools_ownership2gid (const std::string &group)
 convert string group name or gid to numeric gid value More...
 
void libdar::tools_set_ownership (S_I filedesc, const std::string &slice_user, const std::string &slice_group)
 change ownership of the file which descriptor is given More...
 
void libdar::tools_memxor (void *dest, const void *src, U_I n)
 Produces in "dest" the XORed value of "dest" and "src". More...
 
tlv_list libdar::tools_string2tlv_list (user_interaction &dialog, const U_16 &type, const std::vector< std::string > &data)
 Produces a list of TLV from a constant type and a list of string. More...
 
void libdar::tools_read_from_pipe (user_interaction &dialog, S_I fd, tlv_list &result)
 Extract from anonymous pipe a tlv_list. More...
 
U_I libdar::tools_pseudo_random (U_I max)
 Produces a pseudo random number x, where 0 <= x < max. More...
 
template<class N , class B >
std::vector< B > libdar::tools_number_base_decomposition_in_big_endian (N number, const B &base)
 Template for the decomposition of any number in any base (decimal, octal, hexa, etc.) More...
 
std::string libdar::tools_unsigned_char_to_hexa (unsigned char x)
 convert a unsigned char into its hexa decima representation More...
 
std::string libdar::tools_string_to_hexa (const std::string &input)
 convert a string into its hexadecima representation More...
 
infinint libdar::tools_file_size_to_crc_size (const infinint &size)
 Defines the CRC size to use for a given filesize. More...
 
std::string libdar::tools_get_euid ()
 return a string containing the Effective UID
 
std::string libdar::tools_get_egid ()
 return a string containing the Effective UID
 
std::string libdar::tools_get_hostname ()
 return a string containing the hostname of the current host
 
std::string libdar::tools_get_date_utc ()
 return a string containing the current time (UTC)
 
std::string libdar::tools_get_compression_ratio (const infinint &storage_size, const infinint &file_size, bool compressed)
 return the string about compression ratio
 
std::string libdar::tools_strerror_r (int errnum)
 wrapper routine to strerror_r
 
void libdar::tools_merge_to_vector (std::vector< std::string > &a, const std::vector< std::string > &b)
 add in 'a', element of 'b' not already found in 'a'
 
std::vector< std::string > libdar::tools_substract_from_vector (const std::vector< std::string > &a, const std::vector< std::string > &b)
 remove from 'a' elements found in 'b' and return the resulting vector
 
struct dirent * libdar::tools_allocate_struct_dirent (const std::string &path_name, U_64 &max_name_length, memory_pool *pool=nullptr)
 
void libdar::tools_release_struct_dirent (struct dirent *ptr)
 
void libdar::tools_secu_string_show (user_interaction &dialog, const std::string &msg, const secu_string &key)
 display the content of a secu_string, this function is only for trouble shooting!
 
template<class T >
libdar::tools_max (T a, T b)
 
template<class T >
libdar::tools_min (T a, T b)
 
std::string libdar::tools_escape_chars_in_string (const std::string &val, const char *to_escape)
 escape with a anti-slash character a set of chars found in the given string
 
bool libdar::tools_infinint2U_64 (infinint val, U_64 &res)
 

Detailed Description

a set of general purpose routines

Definition in file tools.hpp.