This commit is contained in:
2025-12-14 15:02:34 +01:00
parent bc3f911f60
commit e6ec18eccf

View File

@@ -1,5 +1,4 @@
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <array>
@@ -12,14 +11,14 @@
#include <string_view>
#include <utils.hpp>
// pads given string to length
/* pads given string to length */
std::string pad(std::string s, uint8_t len, JUST j) {
if (len > s.size())
s.insert(j == JUST::LEFT ? s.end() : s.begin(), len - s.size(), FILL_CHAR);
return s;
}
// returns the string centered within given length
/* returns the string centered within given length */
std::string center(std::string str, uint8_t len) {
uint8_t padding = len - str.size();
str.insert(str.begin(), padding / 2, FILL_CHAR);
@@ -27,7 +26,7 @@ std::string center(std::string str, uint8_t len) {
return str;
}
// converts large number in (k)bytes to human readable numer with suffix and sane decimal
/* converts large number in (k)bytes to human readable numer with suffix and sane decimal */
std::string pBytes(double bytes, bool isKbytes) {
std::array suffix_list = {'K', 'M', 'G', 'T', 'P', 'E', 'Z'};
for (auto& suffix : suffix_list) {
@@ -42,7 +41,7 @@ std::string pBytes(double bytes, bool isKbytes) {
return "++++";
}
/* SENSOR GETTERS + UTILS*/
/* reads maxlen of chars of the file in path into buffer */
ssize_t readFile(const char* path, char* buffer, size_t maxlen) {
int fd = open(path, O_RDONLY | O_CLOEXEC);
if (fd < 0) {
@@ -55,7 +54,8 @@ ssize_t readFile(const char* path, char* buffer, size_t maxlen) {
return len;
}
ssize_t readFile(std::string path, char* buffer, size_t maxlen) {
/* overload so it takes std::string as path */
ssize_t readFile(const std::string path, char* buffer, size_t maxlen) {
return readFile(path.c_str(), buffer, maxlen);
}