16#define UTILITY_H_CVSID "$Id: utility.h 5519 2023-07-24 15:57:54Z chrfranke $"
27#ifdef WITH_CXX11_REGEX
34#define __attribute_format_printf(x, y)
35#elif defined(__MINGW32__) && __USE_MINGW_ANSI_STDIO
37#define __attribute_format_printf(x, y) __attribute__((format (gnu_printf, x, y)))
39#define __attribute_format_printf(x, y) __attribute__((format (printf, x, y)))
53 {
return !strncmp(str, prefix, strlen(prefix)); }
56 {
return !strncmp(str.c_str(), prefix, strlen(prefix)); }
64#define DATEANDEPOCHLEN 64
91void swap2(
char *location);
92void swap4(
char *location);
93void swap8(
char *location);
95inline void swapx(
unsigned short * p)
97inline void swapx(
unsigned int * p)
118const char *
format_char_array(
char * str,
int strsize,
const char * chr,
int chrsize);
121template<
size_t STRSIZE,
size_t CHRSIZE>
127 const char * thousands_sep = 0);
131 const char * decimal_point = 0);
138 :
m_data(new unsigned char[sz]),
150 const unsigned char *
data()
const
177 bool open(
const char * name,
const char * mode)
181 m_file = fopen(name, mode);
186 void open(FILE * f,
bool owner =
false)
198 bool ok = !ferror(
m_file);
225#ifdef WITH_CXX11_REGEX
242 bool compile(
const char * pattern);
259#ifdef WITH_CXX11_REGEX
272#ifdef WITH_CXX11_REGEX
287#if defined(HAVE_LONG_DOUBLE_WIDER) && \
288 (!defined(__MINGW32__) || __USE_MINGW_ANSI_STDIO)
290#define HAVE_LONG_DOUBLE_WIDER_PRINTF 1
292#undef HAVE_LONG_DOUBLE_WIDER_PRINTF
298#if defined(HAVE___INT128)
300#elif defined(HAVE_LONG_DOUBLE_WIDER_PRINTF)
301 return LDBL_MANT_DIG;
308const char *
uint128_hilo_to_str(
char * str,
int strsize, uint64_t value_hi, uint64_t value_lo);
311template <
size_t SIZE>
329#define CONTROLLER_UNKNOWN 0x00
330#define CONTROLLER_ATA 0x01
331#define CONTROLLER_SCSI 0x02
raw_buffer(unsigned sz, unsigned char val=0)
raw_buffer(const raw_buffer &)
const unsigned char * data() const
void operator=(const raw_buffer &)
Wrapper class for POSIX regex(3) or std::regex Supports copy & assignment and is compatible with STL ...
bool full_match(const char *str) const
Return true if full string matches pattern.
regular_expression & operator=(const regular_expression &x)
const char * get_errmsg() const
Get error message from last compile().
const char * get_pattern() const
void copy_buf(const regular_expression &x)
bool execute(const char *str, unsigned nmatch, match_range *pmatch) const
Return true if substring matches pattern, fill match_range array.
Wrapper class for FILE *.
void open(FILE *f, bool owner=false)
stdio_file(const stdio_file &)
stdio_file(const char *name, const char *mode)
stdio_file(FILE *f=0, bool owner=false)
bool open(const char *name, const char *mode)
void operator=(const stdio_file &)
std::string get_exe_dir()
const char const char * fmt
const char const char va_list ap
const char * format_capacity(char *str, int strsize, uint64_t val, const char *decimal_point=0)
void swap8(char *location)
void FixGlibcTimeZoneBug()
const char * format_char_array(char *str, int strsize, const char *chr, int chrsize)
void pout(const char *fmt,...) __attribute_format_printf(1
void swap4(char *location)
std::string std::string vstrprintf(const char *fmt, va_list ap)
void dateandtimezoneepoch(char(&buffer)[DATEANDEPOCHLEN], time_t tval)
long long get_timer_usec()
Get microseconds since some unspecified starting point.
std::string strprintf(const char *fmt,...) __attribute_format_printf(1
std::string format_version_info(const char *prog_name, int lines=2)
bool nonempty(const void *data, int size)
#define __attribute_format_printf(x, y)
const char * format_with_thousands_sep(char *str, int strsize, uint64_t val, const char *thousands_sep=0)
void swapx(unsigned short *p)
int split_selective_arg(char *s, uint64_t *start, uint64_t *stop, int *mode)
const char * uint128_hilo_to_str(char *str, int strsize, uint64_t value_hi, uint64_t value_lo)
const char * packetdevicetype(int type)
int uint128_to_str_precision_bits()
void swap2(char *location)
void void syserror(const char *message)
struct tm * time_to_tm_local(struct tm *tp, time_t t)
bool str_starts_with(const char *str, const char *prefix)