simplify readFile, use std::array instead of c-style bufs
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <format>
|
||||
#include <log.hpp>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
@@ -41,23 +37,6 @@ std::string pBytes(double bytes, const bool isKbytes) {
|
||||
return "++++";
|
||||
}
|
||||
|
||||
/* reads maxlen of chars of the file in path into buffer */
|
||||
ssize_t readFile(const char* path, char* buffer, const size_t maxlen) {
|
||||
const int fd = open(path, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
applog(LOG::ERR, "Error reading {}", path);
|
||||
return 0;
|
||||
}
|
||||
const ssize_t len = read(fd, buffer, maxlen - 1);
|
||||
if (len >= 0) buffer[len] = '\0';
|
||||
close(fd);
|
||||
return len;
|
||||
}
|
||||
|
||||
/* overload so it takes std::string as path */
|
||||
ssize_t readFile(const std::string& path, char* buffer, const size_t maxlen) {
|
||||
return readFile(path.c_str(), buffer, maxlen);
|
||||
}
|
||||
|
||||
/* finds first dir in path and returns it. don't refactor, you don't understand it, its fast enough, and you only use it on init */
|
||||
std::string getFirstDir(const std::string_view& path) {
|
||||
|
||||
Reference in New Issue
Block a user