Misc changes (#1513)
Some checks are pending
CodeQL / Analyze (push) Waiting to run
mkdocs / deploy (push) Waiting to run

* Start moving to string_view where possible
* Rework readdir object to use atomic load/store
This commit is contained in:
trapexit 2025-08-21 23:42:58 -04:00 • committed by GitHub
parent 2101ef5bcc
commit 6ac7f389c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
61 changed files with 841 additions and 745 deletions

View file

@ -24,7 +24,7 @@
#include <time.h>
#include <cstdint>
#include <string>
#define KB (1024ULL)
#define MB (KB * 1024ULL)
@ -33,85 +33,6 @@
namespace num
{
int
to_uint64_t(const std::string &str,
uint64_t &value)
{
char *endptr;
uint64_t tmp;
tmp = strtoll(str.c_str(),&endptr,10);
switch(*endptr)
{
case 'k':
case 'K':
tmp *= 1024;
break;
case 'm':
case 'M':
tmp *= (1024 * 1024);
break;
case 'g':
case 'G':
tmp *= (1024 * 1024 * 1024);
break;
case 't':
case 'T':
tmp *= (1024ULL * 1024 * 1024 * 1024);
break;
case '\0':
break;
default:
return -1;
}
value = tmp;
return 0;
}
int
to_double(const std::string &str_,
double *d_)
{
double tmp;
char *endptr;
tmp = strtod(str_.c_str(),&endptr);
if(*endptr != '\0')
return -1;
*d_ = tmp;
return 0;
}
int
to_time_t(const std::string &str,
time_t &value)
{
time_t tmp;
char *endptr;
tmp = strtoll(str.c_str(),&endptr,10);
if(*endptr != '\0')
return -1;
if(tmp < 0)
return -1;
value = tmp;
return 0;
}
}
namespace num
{
std::string
humanize(const uint64_t bytes_)