16#define UTILITY_H_CVSID "$Id: utility.h 5297 2022-01-07 00:51:15Z dpgilbert $"
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)))
52 {
return !strncmp(str, prefix, strlen(prefix)); }
55 {
return !strncmp(str.c_str(), prefix, strlen(prefix)); }
63#define DATEANDEPOCHLEN 64
90void swap2(
char *location);
91void swap4(
char *location);
92void swap8(
char *location);
94inline void swapx(
unsigned short * p)
96inline void swapx(
unsigned int * p)
117const char *
format_char_array(
char * str,
int strsize,
const char * chr,
int chrsize);
120template<
size_t STRSIZE,
size_t CHRSIZE>
126 const char * thousands_sep = 0);
130 const char * decimal_point = 0);
137 :
m_data(new unsigned char[sz]),
149 const unsigned char *
data()
const
176 bool open(
const char * name,
const char * mode)
180 m_file = fopen(name, mode);
185 void open(FILE * f,
bool owner =
false)
197 bool ok = !ferror(
m_file);
224#ifdef WITH_CXX11_REGEX
241 bool compile(
const char * pattern);
258#ifdef WITH_CXX11_REGEX
271#ifdef WITH_CXX11_REGEX
286#if defined(HAVE_LONG_DOUBLE_WIDER) && \
287 (!defined(__MINGW32__) || defined(__USE_MINGW_ANSI_STDIO))
289#define HAVE_LONG_DOUBLE_WIDER_PRINTF 1
291#undef HAVE_LONG_DOUBLE_WIDER_PRINTF
297#if defined(HAVE___INT128)
299#elif defined(HAVE_LONG_DOUBLE_WIDER_PRINTF)
300 return LDBL_MANT_DIG;
307const char *
uint128_hilo_to_str(
char * str,
int strsize, uint64_t value_hi, uint64_t value_lo);
310template <
size_t SIZE>
328#define CONTROLLER_UNKNOWN 0x00
329#define CONTROLLER_ATA 0x01
330#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
bool nonempty(const void *data, int size)
#define __attribute_format_printf(x, y)
std::string format_version_info(const char *prog_name, bool full=false)
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)