mirror of https://github.com/stella-emu/stella.git
Use proper C++ code for localtime and related functions.
This commit is contained in:
parent
e425d8065f
commit
24cd6cb219
|
@ -15,8 +15,6 @@
|
|||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//============================================================================
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include "SDL_lib.hxx"
|
||||
#include "bspf.hxx"
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ using uInt64 = uint64_t;
|
|||
#include <cstring>
|
||||
#include <cctype>
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
|
@ -94,10 +95,6 @@ namespace BSPF
|
|||
#define ATTRIBUTE_FMT_PRINTF __attribute__((__format__ (__printf__, 2, 0)))
|
||||
#elif defined(BSPF_WINDOWS)
|
||||
static const string PATH_SEPARATOR = "\\";
|
||||
#pragma warning (disable : 4146) // unary minus operator applied to unsigned type
|
||||
#pragma warning(2:4264) // no override available for virtual member function from base 'class'; function is hidden
|
||||
#pragma warning(2:4265) // class has virtual functions, but destructor is not virtual
|
||||
#pragma warning(2:4266) // no override available for virtual member function from base 'type'; function is hidden
|
||||
#define ATTRIBUTE_FMT_PRINTF
|
||||
#else
|
||||
#error Update src/common/bspf.hxx for path separator
|
||||
|
@ -215,6 +212,21 @@ namespace BSPF
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// C++11 way to get local time
|
||||
// Equivalent to the C-style localtime() function, but is thread-safe
|
||||
inline std::tm localTime()
|
||||
{
|
||||
std::time_t currtime;
|
||||
std::time(&currtime);
|
||||
std::tm tm_snapshot;
|
||||
#if defined BSPF_WINDOWS && !defined __GNUG__
|
||||
localtime_s(&tm_snapshot, &currtime);
|
||||
#else
|
||||
localtime_r(&currtime, &tm_snapshot);
|
||||
#endif
|
||||
return tm_snapshot;
|
||||
}
|
||||
} // namespace BSPF
|
||||
|
||||
#endif
|
||||
|
|
|
@ -15,8 +15,6 @@
|
|||
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
||||
//============================================================================
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#include "bspf.hxx"
|
||||
#include "System.hxx"
|
||||
#include "M6502.hxx"
|
||||
|
@ -1101,11 +1099,9 @@ string CartDebug::saveDisassembly()
|
|||
}
|
||||
|
||||
// Some boilerplate, similar to what DiStella adds
|
||||
// FIXME - change 'time' to proper C++ way - unsafe function
|
||||
time_t currtime;
|
||||
time(&currtime);
|
||||
auto timeinfo = BSPF::localTime();
|
||||
out << "; Disassembly of " << myOSystem.romFile().getShortPath() << "\n"
|
||||
<< "; Disassembled " << ctime(&currtime)
|
||||
<< "; Disassembled " << std::put_time(&timeinfo, "%c\n")
|
||||
<< "; Using Stella " << STELLA_VERSION << "\n;\n"
|
||||
<< "; ROM properties name : " << myConsole.properties().get(Cartridge_Name) << "\n"
|
||||
<< "; ROM properties MD5 : " << myConsole.properties().get(Cartridge_MD5) << "\n"
|
||||
|
|
|
@ -1784,17 +1784,11 @@ void DebuggerParser::executeSaverom()
|
|||
// "saveses"
|
||||
void DebuggerParser::executeSaveses()
|
||||
{
|
||||
// Create a file named with the current date and time
|
||||
time_t currtime;
|
||||
struct tm* timeinfo;
|
||||
char buffer[80];
|
||||
|
||||
// FIXME - change 'time' to proper C++ way - unsafe function
|
||||
time(&currtime);
|
||||
timeinfo = localtime(&currtime);
|
||||
strftime(buffer, 80, "session_%F_%H-%M-%S.txt", timeinfo);
|
||||
|
||||
FilesystemNode file(debugger.myOSystem.defaultSaveDir() + buffer);
|
||||
ostringstream filename;
|
||||
auto timeinfo = BSPF::localTime();
|
||||
filename << debugger.myOSystem.defaultSaveDir()
|
||||
<< std::put_time(&timeinfo, "session_%F_%H-%M-%S.txt");
|
||||
FilesystemNode file(filename.str());
|
||||
if(debugger.prompt().saveBuffer(file))
|
||||
commandResult << "saved " + file.getShortPath() + " OK";
|
||||
else
|
||||
|
|
|
@ -122,7 +122,7 @@
|
|||
<EnableEnhancedInstructionSet>StreamingSIMDExtensions</EnableEnhancedInstructionSet>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<DisableSpecificWarnings>4100;4244;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings>4100;4146;4244;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
<CompileAs>CompileAsCpp</CompileAs>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
|
@ -156,7 +156,7 @@
|
|||
<ObjectFileName>$(IntDir)%(RelativeDir)</ObjectFileName>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<DisableSpecificWarnings>4100;4244;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings>4100;4146;4244;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
<CompileAs>CompileAsCpp</CompileAs>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
|
@ -188,7 +188,7 @@
|
|||
<EnableEnhancedInstructionSet>StreamingSIMDExtensions</EnableEnhancedInstructionSet>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<DisableSpecificWarnings>4100;4244;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings>4100;4146;4244;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
<CompileAs>CompileAsCpp</CompileAs>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
|
@ -224,7 +224,7 @@
|
|||
<ObjectFileName>$(IntDir)%(RelativeDir)</ObjectFileName>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<MultiProcessorCompilation>true</MultiProcessorCompilation>
|
||||
<DisableSpecificWarnings>4100;4244;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
<DisableSpecificWarnings>4100;4146;4244;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
<CompileAs>CompileAsCpp</CompileAs>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
|
|
Loading…
Reference in New Issue