diff --git a/include/ss/common.hpp b/include/ss/common.hpp index 00ae9fb..7ecdb33 100644 --- a/include/ss/common.hpp +++ b/include/ss/common.hpp @@ -29,7 +29,7 @@ inline void assert_throw_on_error_not_defined() { } inline void* strict_realloc(void* ptr, size_t size) { - ptr = realloc(ptr, size); + ptr = std::realloc(ptr, size); if (!ptr) { throw std::bad_alloc{}; } @@ -62,9 +62,9 @@ ssize_t get_line_file(char** lineptr, size_t* n, FILE* fp) { (*lineptr)[0] = '\0'; size_t line_used = 0; - while (fgets(buff, sizeof(buff), fp) != nullptr) { - line_used = strlen(*lineptr); - size_t buff_used = strlen(buff); + while (std::fgets(buff, sizeof(buff), fp) != nullptr) { + line_used = std::strlen(*lineptr); + size_t buff_used = std::strlen(buff); if (*n <= buff_used + line_used) { 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; } - memcpy(*lineptr + line_used, buff, buff_used); + std::memcpy(*lineptr + line_used, buff, buff_used); line_used += buff_used; (*lineptr)[line_used] = '\0'; diff --git a/include/ss/extract.hpp b/include/ss/extract.hpp index a26828d..b49a6d8 100644 --- a/include/ss/extract.hpp +++ b/include/ss/extract.hpp @@ -169,9 +169,9 @@ inline bool extract(const char* begin, const char* end, bool& value) { } } else { size_t size = end - begin; - if (size == 4 && strncmp(begin, "true", size) == 0) { + if (size == 4 && std::strncmp(begin, "true", size) == 0) { value = true; - } else if (size == 5 && strncmp(begin, "false", size) == 0) { + } else if (size == 5 && std::strncmp(begin, "false", size) == 0) { value = false; } else { return false; diff --git a/include/ss/parser.hpp b/include/ss/parser.hpp index 2629403..154a881 100644 --- a/include/ss/parser.hpp +++ b/include/ss/parser.hpp @@ -675,7 +675,7 @@ private: struct reader { 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, @@ -736,12 +736,12 @@ private: } ~reader() { - free(buffer_); - free(next_line_buffer_); - free(helper_buffer_); + std::free(buffer_); + std::free(next_line_buffer_); + std::free(helper_buffer_); if (file_) { - fclose(file_); + std::fclose(file_); } } @@ -800,7 +800,7 @@ private: if (file_) { ssize = get_line_file(&next_line_buffer_, &next_line_buffer_size_, file_); - curr_char_ = ftell(file_); + curr_char_ = std::ftell(file_); } else { ssize = get_line_buffer(&next_line_buffer_, &next_line_buffer_size_, diff --git a/include/ss/splitter.hpp b/include/ss/splitter.hpp index dd8f365..d974e83 100644 --- a/include/ss/splitter.hpp +++ b/include/ss/splitter.hpp @@ -199,7 +199,7 @@ private: }; 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) { diff --git a/ssp.hpp b/ssp.hpp index 5fa3db0..6f0ea8d 100644 --- a/ssp.hpp +++ b/ssp.hpp @@ -641,7 +641,7 @@ inline void assert_throw_on_error_not_defined() { } inline void* strict_realloc(void* ptr, size_t size) { - ptr = realloc(ptr, size); + ptr = std::realloc(ptr, size); if (!ptr) { throw std::bad_alloc{}; } @@ -674,9 +674,9 @@ ssize_t get_line_file(char** lineptr, size_t* n, FILE* fp) { (*lineptr)[0] = '\0'; size_t line_used = 0; - while (fgets(buff, sizeof(buff), fp) != nullptr) { - line_used = strlen(*lineptr); - size_t buff_used = strlen(buff); + while (std::fgets(buff, sizeof(buff), fp) != nullptr) { + line_used = std::strlen(*lineptr); + size_t buff_used = std::strlen(buff); if (*n <= buff_used + line_used) { 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; } - memcpy(*lineptr + line_used, buff, buff_used); + std::memcpy(*lineptr + line_used, buff, buff_used); line_used += buff_used; (*lineptr)[line_used] = '\0'; @@ -1183,7 +1183,7 @@ private: }; 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) { @@ -1623,9 +1623,9 @@ inline bool extract(const char* begin, const char* end, bool& value) { } } else { size_t size = end - begin; - if (size == 4 && strncmp(begin, "true", size) == 0) { + if (size == 4 && std::strncmp(begin, "true", size) == 0) { value = true; - } else if (size == 5 && strncmp(begin, "false", size) == 0) { + } else if (size == 5 && std::strncmp(begin, "false", size) == 0) { value = false; } else { return false; @@ -2805,7 +2805,7 @@ private: struct reader { 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, @@ -2866,12 +2866,12 @@ private: } ~reader() { - free(buffer_); - free(next_line_buffer_); - free(helper_buffer_); + std::free(buffer_); + std::free(next_line_buffer_); + std::free(helper_buffer_); if (file_) { - fclose(file_); + std::fclose(file_); } } @@ -2930,7 +2930,7 @@ private: if (file_) { ssize = get_line_file(&next_line_buffer_, &next_line_buffer_size_, file_); - curr_char_ = ftell(file_); + curr_char_ = std::ftell(file_); } else { ssize = get_line_buffer(&next_line_buffer_, &next_line_buffer_size_, diff --git a/test/test_helpers.hpp b/test/test_helpers.hpp index c345883..188e731 100644 --- a/test/test_helpers.hpp +++ b/test/test_helpers.hpp @@ -62,12 +62,12 @@ struct buffer { [[maybe_unused]] inline buffer buff; [[maybe_unused]] std::string time_now_rand() { - srand(time(nullptr)); + std::srand(std::time(nullptr)); std::stringstream ss; auto t = std::time(nullptr); auto tm = *std::localtime(&t); 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()); } @@ -78,8 +78,8 @@ struct unique_file_name { unique_file_name(const std::string& test) { do { - name = "ssp_test_" + test + "_" + std::to_string(i++) + - "_" + time_now_rand() + "_file.csv"; + name = "ssp_test_" + test + "_" + std::to_string(i++) + "_" + + time_now_rand() + "_file.csv"; } while (std::filesystem::exists(name)); } diff --git a/test/test_parser1_1.cpp b/test/test_parser1_1.cpp index 42642d1..650393b 100644 --- a/test/test_parser1_1.cpp +++ b/test/test_parser1_1.cpp @@ -77,9 +77,9 @@ TEST_CASE_TEMPLATE("test position method", T, ParserOptionCombinations) { if (!buff.empty()) { return buff[n]; } else { - auto file = fopen(f.name.c_str(), "r"); - fseek(file, n, SEEK_SET); - return static_cast(fgetc(file)); + auto file = std::fopen(f.name.c_str(), "r"); + std::fseek(file, n, SEEK_SET); + return static_cast(std::fgetc(file)); } };