Commit cf3c309cbb2a549a07e5140578a9cc17614de082
1 parent
eb41ee25
replace <time.h> by <ctime> and <stdarg.h> by <cstdarg> and prefix with std:: where possible
Showing
1 changed file
with
24 additions
and
26 deletions
src/app/GLog.cpp
| ... | ... | @@ -20,15 +20,13 @@ |
| 20 | 20 | #ifdef HAVE_CONFIG_H |
| 21 | 21 | #include <config.h> |
| 22 | 22 | #endif |
| 23 | -#include <time.h> | |
| 24 | -#include <stdarg.h> // for "va_list" type | |
| 25 | -//#include <stdio.h> // fopen, fgets, fclose, etc... | |
| 26 | -//#include <string.h> // memcpy | |
| 23 | +#include <ctime> | |
| 24 | +#include <cstdarg> // for std::va_list type | |
| 25 | +#include <cstdio> // std::fopen, std::fgets, std::fclose, etc... | |
| 26 | +#include <cstring> // std::memcpy | |
| 27 | 27 | #include <string> |
| 28 | 28 | #include <iostream> |
| 29 | 29 | #include <sstream> |
| 30 | -#include <cstdio> // fopen, fgets, fclose, etc... | |
| 31 | -#include <cstring> // memcpy | |
| 32 | 30 | #include "GLog.hpp" |
| 33 | 31 | #include "GTools.hpp" |
| 34 | 32 | |
| ... | ... | @@ -165,9 +163,9 @@ void GLog::operator()(const char *msgFormat, ...) |
| 165 | 163 | char buffer[8192]; |
| 166 | 164 | |
| 167 | 165 | // Put message into buffer |
| 168 | - va_list vl; | |
| 166 | + std::va_list vl; | |
| 169 | 167 | va_start(vl, msgFormat); |
| 170 | - vsprintf(buffer, msgFormat, vl); | |
| 168 | + std::vsprintf(buffer, msgFormat, vl); | |
| 171 | 169 | va_end(vl); |
| 172 | 170 | |
| 173 | 171 | // Append message to string buffer |
| ... | ... | @@ -447,9 +445,9 @@ void GLog::open(const std::string& filename, bool clobber) |
| 447 | 445 | |
| 448 | 446 | // Open file |
| 449 | 447 | if (clobber) |
| 450 | - m_file = fopen(filename.c_str(), "w"); | |
| 448 | + m_file = std::fopen(filename.c_str(), "w"); | |
| 451 | 449 | else |
| 452 | - m_file = fopen(filename.c_str(), "a"); | |
| 450 | + m_file = std::fopen(filename.c_str(), "a"); | |
| 453 | 451 | |
| 454 | 452 | // Return |
| 455 | 453 | return; |
| ... | ... | @@ -469,7 +467,7 @@ void GLog::close(void) |
| 469 | 467 | |
| 470 | 468 | // Close any open file |
| 471 | 469 | if (m_file != NULL) { |
| 472 | - fclose(m_file); | |
| 470 | + std::fclose(m_file); | |
| 473 | 471 | m_file = NULL; |
| 474 | 472 | } |
| 475 | 473 | |
| ... | ... | @@ -679,7 +677,7 @@ void GLog::flush(bool force) |
| 679 | 677 | |
| 680 | 678 | // Find next CR |
| 681 | 679 | std::string line; |
| 682 | - size_t pos = m_buffer.find_first_of("\n", 0); | |
| 680 | + std::size_t pos = m_buffer.find_first_of("\n", 0); | |
| 683 | 681 | if (pos == std::string::npos) { |
| 684 | 682 | line = m_buffer; |
| 685 | 683 | newline = false; |
| ... | ... | @@ -709,7 +707,7 @@ void GLog::flush(bool force) |
| 709 | 707 | if (m_stderr) |
| 710 | 708 | std::cerr << line; |
| 711 | 709 | if (m_file != NULL) |
| 712 | - fprintf(m_file, line.c_str()); | |
| 710 | + std::fprintf(m_file, line.c_str()); | |
| 713 | 711 | |
| 714 | 712 | // Set newline flag for next line |
| 715 | 713 | m_newline = newline; |
| ... | ... | @@ -778,26 +776,26 @@ void GLog::header(const std::string& arg, int level) |
| 778 | 776 | std::string GLog::strdate(void) |
| 779 | 777 | { |
| 780 | 778 | // Allocate variables |
| 781 | - struct tm timeStruct; | |
| 782 | - time_t now; | |
| 783 | - char buffer[100]; | |
| 779 | + struct std::tm timeStruct; | |
| 780 | + std::time_t now; | |
| 781 | + char buffer[100]; | |
| 784 | 782 | |
| 785 | 783 | // Get time |
| 786 | - now = time(NULL); | |
| 784 | + now = std::time(NULL); | |
| 787 | 785 | #ifdef HAVE_GMTIME_R |
| 788 | - gmtime_r(&now, &timeStruct); | |
| 786 | + std::gmtime_r(&now, &timeStruct); | |
| 789 | 787 | #else |
| 790 | - memcpy(&timeStruct, gmtime(&now), sizeof(struct tm)); | |
| 788 | + std::memcpy(&timeStruct, gmtime(&now), sizeof(struct tm)); | |
| 791 | 789 | #endif |
| 792 | 790 | |
| 793 | 791 | // Write message type, time and task name to buffer |
| 794 | - sprintf(buffer, "%04d-%02d-%02dT%02d:%02d:%02d", | |
| 795 | - timeStruct.tm_year + 1900, | |
| 796 | - timeStruct.tm_mon + 1, | |
| 797 | - timeStruct.tm_mday, | |
| 798 | - timeStruct.tm_hour, | |
| 799 | - timeStruct.tm_min, | |
| 800 | - timeStruct.tm_sec); | |
| 792 | + std::sprintf(buffer, "%04d-%02d-%02dT%02d:%02d:%02d", | |
| 793 | + timeStruct.tm_year + 1900, | |
| 794 | + timeStruct.tm_mon + 1, | |
| 795 | + timeStruct.tm_mday, | |
| 796 | + timeStruct.tm_hour, | |
| 797 | + timeStruct.tm_min, | |
| 798 | + timeStruct.tm_sec); | |
| 801 | 799 | |
| 802 | 800 | // Build string from buffer |
| 803 | 801 | std::string date = buffer; | ... | ... |