-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use of ctime needs to be phased out and updated to strftime #99
Labels
Comments
Here's a small snippet that outputs the same values for both Input: #include <iostream>
#include <ctime>
int main()
{
auto result = std::time(nullptr);
std::cout << std::ctime(&result) << std::endl;
char buffer [80];
auto t = std::time(nullptr);
auto lt = std::localtime(&t);
//TODO: check the return value to see if bytes are filled
std::strftime(buffer, 80, "%a %b %2d %T %Y%n", lt);
std::cout << buffer << std::endl;
return 0;
}
Output: > clang++-7 -pthread -std=c++17 -o main main.cpp
> ./main
Thu Oct 27 22:18:34 2022
Thu Oct 27 22:18:34 2022
>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With ctime not being thread safe the suggested replacement is strftime for safety. Doing so requires a refactor of all time_t as well, since they can't be used with strftime and are also not thread safe.
see:
ctime c++ ref
strftime c++ ref
The text was updated successfully, but these errors were encountered: