[skip ci] Add std:: to invoked C std lib functions

This commit is contained in:
ado 2024-02-25 13:02:34 +01:00
parent 0ebbee1174
commit f8e14b1fcf
7 changed files with 35 additions and 35 deletions

View File

@ -29,7 +29,7 @@ inline void assert_throw_on_error_not_defined() {
} }
inline void* strict_realloc(void* ptr, size_t size) { inline void* strict_realloc(void* ptr, size_t size) {
ptr = realloc(ptr, size); ptr = std::realloc(ptr, size);
if (!ptr) { if (!ptr) {
throw std::bad_alloc{}; throw std::bad_alloc{};
} }
@ -62,9 +62,9 @@ ssize_t get_line_file(char** lineptr, size_t* n, FILE* fp) {
(*lineptr)[0] = '\0'; (*lineptr)[0] = '\0';
size_t line_used = 0; size_t line_used = 0;
while (fgets(buff, sizeof(buff), fp) != nullptr) { while (std::fgets(buff, sizeof(buff), fp) != nullptr) {
line_used = strlen(*lineptr); line_used = std::strlen(*lineptr);
size_t buff_used = strlen(buff); size_t buff_used = std::strlen(buff);
if (*n <= buff_used + line_used) { if (*n <= buff_used + line_used) {
size_t new_n = *n * 2; size_t new_n = *n * 2;
@ -73,7 +73,7 @@ ssize_t get_line_file(char** lineptr, size_t* n, FILE* fp) {
*n = new_n; *n = new_n;
} }
memcpy(*lineptr + line_used, buff, buff_used); std::memcpy(*lineptr + line_used, buff, buff_used);
line_used += buff_used; line_used += buff_used;
(*lineptr)[line_used] = '\0'; (*lineptr)[line_used] = '\0';

View File

@ -169,9 +169,9 @@ inline bool extract(const char* begin, const char* end, bool& value) {
} }
} else { } else {
size_t size = end - begin; size_t size = end - begin;
if (size == 4 && strncmp(begin, "true", size) == 0) { if (size == 4 && std::strncmp(begin, "true", size) == 0) {
value = true; value = true;
} else if (size == 5 && strncmp(begin, "false", size) == 0) { } else if (size == 5 && std::strncmp(begin, "false", size) == 0) {
value = false; value = false;
} else { } else {
return false; return false;

View File

@ -675,7 +675,7 @@ private:
struct reader { struct reader {
reader(const std::string& file_name_, const std::string& delim) reader(const std::string& file_name_, const std::string& delim)
: delim_{delim}, file_{fopen(file_name_.c_str(), "rb")} { : delim_{delim}, file_{std::fopen(file_name_.c_str(), "rb")} {
} }
reader(const char* const buffer, size_t csv_data_size, reader(const char* const buffer, size_t csv_data_size,
@ -736,12 +736,12 @@ private:
} }
~reader() { ~reader() {
free(buffer_); std::free(buffer_);
free(next_line_buffer_); std::free(next_line_buffer_);
free(helper_buffer_); std::free(helper_buffer_);
if (file_) { if (file_) {
fclose(file_); std::fclose(file_);
} }
} }
@ -800,7 +800,7 @@ private:
if (file_) { if (file_) {
ssize = get_line_file(&next_line_buffer_, ssize = get_line_file(&next_line_buffer_,
&next_line_buffer_size_, file_); &next_line_buffer_size_, file_);
curr_char_ = ftell(file_); curr_char_ = std::ftell(file_);
} else { } else {
ssize = get_line_buffer(&next_line_buffer_, ssize = get_line_buffer(&next_line_buffer_,
&next_line_buffer_size_, &next_line_buffer_size_,

View File

@ -199,7 +199,7 @@ private:
}; };
bool match(const char* const curr, const std::string& delim) { bool match(const char* const curr, const std::string& delim) {
return strncmp(curr, delim.c_str(), delim.size()) == 0; return std::strncmp(curr, delim.c_str(), delim.size()) == 0;
}; };
size_t delimiter_size(char) { size_t delimiter_size(char) {

28
ssp.hpp
View File

@ -641,7 +641,7 @@ inline void assert_throw_on_error_not_defined() {
} }
inline void* strict_realloc(void* ptr, size_t size) { inline void* strict_realloc(void* ptr, size_t size) {
ptr = realloc(ptr, size); ptr = std::realloc(ptr, size);
if (!ptr) { if (!ptr) {
throw std::bad_alloc{}; throw std::bad_alloc{};
} }
@ -674,9 +674,9 @@ ssize_t get_line_file(char** lineptr, size_t* n, FILE* fp) {
(*lineptr)[0] = '\0'; (*lineptr)[0] = '\0';
size_t line_used = 0; size_t line_used = 0;
while (fgets(buff, sizeof(buff), fp) != nullptr) { while (std::fgets(buff, sizeof(buff), fp) != nullptr) {
line_used = strlen(*lineptr); line_used = std::strlen(*lineptr);
size_t buff_used = strlen(buff); size_t buff_used = std::strlen(buff);
if (*n <= buff_used + line_used) { if (*n <= buff_used + line_used) {
size_t new_n = *n * 2; size_t new_n = *n * 2;
@ -685,7 +685,7 @@ ssize_t get_line_file(char** lineptr, size_t* n, FILE* fp) {
*n = new_n; *n = new_n;
} }
memcpy(*lineptr + line_used, buff, buff_used); std::memcpy(*lineptr + line_used, buff, buff_used);
line_used += buff_used; line_used += buff_used;
(*lineptr)[line_used] = '\0'; (*lineptr)[line_used] = '\0';
@ -1183,7 +1183,7 @@ private:
}; };
bool match(const char* const curr, const std::string& delim) { bool match(const char* const curr, const std::string& delim) {
return strncmp(curr, delim.c_str(), delim.size()) == 0; return std::strncmp(curr, delim.c_str(), delim.size()) == 0;
}; };
size_t delimiter_size(char) { size_t delimiter_size(char) {
@ -1623,9 +1623,9 @@ inline bool extract(const char* begin, const char* end, bool& value) {
} }
} else { } else {
size_t size = end - begin; size_t size = end - begin;
if (size == 4 && strncmp(begin, "true", size) == 0) { if (size == 4 && std::strncmp(begin, "true", size) == 0) {
value = true; value = true;
} else if (size == 5 && strncmp(begin, "false", size) == 0) { } else if (size == 5 && std::strncmp(begin, "false", size) == 0) {
value = false; value = false;
} else { } else {
return false; return false;
@ -2805,7 +2805,7 @@ private:
struct reader { struct reader {
reader(const std::string& file_name_, const std::string& delim) reader(const std::string& file_name_, const std::string& delim)
: delim_{delim}, file_{fopen(file_name_.c_str(), "rb")} { : delim_{delim}, file_{std::fopen(file_name_.c_str(), "rb")} {
} }
reader(const char* const buffer, size_t csv_data_size, reader(const char* const buffer, size_t csv_data_size,
@ -2866,12 +2866,12 @@ private:
} }
~reader() { ~reader() {
free(buffer_); std::free(buffer_);
free(next_line_buffer_); std::free(next_line_buffer_);
free(helper_buffer_); std::free(helper_buffer_);
if (file_) { if (file_) {
fclose(file_); std::fclose(file_);
} }
} }
@ -2930,7 +2930,7 @@ private:
if (file_) { if (file_) {
ssize = get_line_file(&next_line_buffer_, ssize = get_line_file(&next_line_buffer_,
&next_line_buffer_size_, file_); &next_line_buffer_size_, file_);
curr_char_ = ftell(file_); curr_char_ = std::ftell(file_);
} else { } else {
ssize = get_line_buffer(&next_line_buffer_, ssize = get_line_buffer(&next_line_buffer_,
&next_line_buffer_size_, &next_line_buffer_size_,

View File

@ -62,12 +62,12 @@ struct buffer {
[[maybe_unused]] inline buffer buff; [[maybe_unused]] inline buffer buff;
[[maybe_unused]] std::string time_now_rand() { [[maybe_unused]] std::string time_now_rand() {
srand(time(nullptr)); std::srand(std::time(nullptr));
std::stringstream ss; std::stringstream ss;
auto t = std::time(nullptr); auto t = std::time(nullptr);
auto tm = *std::localtime(&t); auto tm = *std::localtime(&t);
ss << std::put_time(&tm, "%d%m%Y%H%M%S"); ss << std::put_time(&tm, "%d%m%Y%H%M%S");
srand(time(nullptr)); std::srand(std::time(nullptr));
return ss.str() + std::to_string(rand()); return ss.str() + std::to_string(rand());
} }
@ -78,8 +78,8 @@ struct unique_file_name {
unique_file_name(const std::string& test) { unique_file_name(const std::string& test) {
do { do {
name = "ssp_test_" + test + "_" + std::to_string(i++) + name = "ssp_test_" + test + "_" + std::to_string(i++) + "_" +
"_" + time_now_rand() + "_file.csv"; time_now_rand() + "_file.csv";
} while (std::filesystem::exists(name)); } while (std::filesystem::exists(name));
} }

View File

@ -77,9 +77,9 @@ TEST_CASE_TEMPLATE("test position method", T, ParserOptionCombinations) {
if (!buff.empty()) { if (!buff.empty()) {
return buff[n]; return buff[n];
} else { } else {
auto file = fopen(f.name.c_str(), "r"); auto file = std::fopen(f.name.c_str(), "r");
fseek(file, n, SEEK_SET); std::fseek(file, n, SEEK_SET);
return static_cast<char>(fgetc(file)); return static_cast<char>(std::fgetc(file));
} }
}; };