Skip to content

Commit

Permalink
[skip ci] Add std:: to invoked C std lib functions
Browse files Browse the repository at this point in the history
  • Loading branch information
red0124 committed Feb 25, 2024
1 parent 0ebbee1 commit f8e14b1
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 35 deletions.
10 changes: 5 additions & 5 deletions include/ss/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
}
Expand Down Expand Up @@ -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;
Expand All @@ -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';

Expand Down
4 changes: 2 additions & 2 deletions include/ss/extract.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions include/ss/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ class parser {

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,
Expand Down Expand Up @@ -736,12 +736,12 @@ class parser {
}

~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_);
}
}

Expand Down Expand Up @@ -800,7 +800,7 @@ class parser {
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_,
Expand Down
2 changes: 1 addition & 1 deletion include/ss/splitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class splitter {
};

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) {
Expand Down
28 changes: 14 additions & 14 deletions ssp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{};
}
Expand Down Expand Up @@ -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;
Expand All @@ -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';

Expand Down Expand Up @@ -1183,7 +1183,7 @@ class splitter {
};

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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2805,7 +2805,7 @@ class parser {

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,
Expand Down Expand Up @@ -2866,12 +2866,12 @@ class parser {
}

~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_);
}
}

Expand Down Expand Up @@ -2930,7 +2930,7 @@ class parser {
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_,
Expand Down
8 changes: 4 additions & 4 deletions test/test_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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));
}

Expand Down
6 changes: 3 additions & 3 deletions test/test_parser1_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char>(fgetc(file));
auto file = std::fopen(f.name.c_str(), "r");
std::fseek(file, n, SEEK_SET);
return static_cast<char>(std::fgetc(file));
}
};

Expand Down

0 comments on commit f8e14b1

Please sign in to comment.