38 const int saved_errno = errno;
51 const size_t size = strlen(
src) + 1;
67 if (strcmp(
value,
"max") == 0)
70 if (*value < '0' || *value >
'9')
72 "decimal integer"),
value);
108 && strcmp(
value,
"iB") != 0
109 && strcmp(
value,
"B") != 0)
112 if (multiplier == 0) {
116 "`MiB' (2^20), and `GiB' (2^30)."));
123 result *= multiplier;
126 if (result < min || result >
max)
141 return (
n >> 20) + ((
n & ((
UINT32_C(1) << 20) - 1)) != 0);
159 bufs[slot][0] =
'\0';
191 assert(unit_min <= unit_max);
199 size_t left =
sizeof(
bufs[slot]);
212 double d = (double)(
value);
216 }
while (unit < unit_min || (
d > 9999.9 && unit < unit_max));
224 static const char suffix[5][4] = {
"B",
"KiB",
"MiB",
"GiB",
"TiB" };
227 if (always_also_bytes &&
value >= 10000) {
252 if (
len < 0 || (
size_t)(
len) >= *left) {
unsigned char suffix[65536]
RZ_API void Ht_() free(HtName_(Ht) *ht)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * realloc(void *ptr, size_t size)
assert(limit<=UINT32_MAX/2)
void message_error(const char *fmt,...)
void message_fatal(const char *fmt,...)
@ V_ERROR
Only error messages.
Common includes, definitions, and prototypes.
uint64_t str_to_uint64(const char *name, const char *value, uint64_t min, uint64_t max)
Fancy version of strtoull()
const char * uint64_to_str(uint64_t value, uint32_t slot)
Convert uint64_t to a string.
bool is_tty_stdin(void)
Test if stdin is a terminal.
bool is_empty_filename(const char *filename)
Check if filename is empty and print an error message.
char * xstrdup(const char *src)
Safe strdup() that never returns NULL.
const char * uint64_to_nicestr(uint64_t value, enum nicestr_unit unit_min, enum nicestr_unit unit_max, bool always_also_bytes, uint32_t slot)
Convert uint64_t to a nice human readable string.
static enum @663 thousand
Thousand separator support in uint64_to_str() and uint64_to_nicestr()
void * xrealloc(void *ptr, size_t size)
Safe realloc() that never returns NULL.
bool is_tty_stdout(void)
Test if stdout is a terminal.
void my_snprintf(char **pos, size_t *left, const char *fmt,...)
uint64_t round_up_to_mib(uint64_t n)
Round an integer up to the next full MiB and convert to MiB.
static char bufs[4][128]
Buffers for uint64_to_str() and uint64_to_nicestr()
static void check_thousand_sep(uint32_t slot)
void error(const char *msg)