Replace non-threadsafe gmtime and setlocale
[novacoin.git] / src / util.cpp
index a15fa67..8b0afa9 100644 (file)
@@ -1157,13 +1157,19 @@ void createConf()
     srand(time(NULL));
 
     ofstream pConf;
+#if BOOST_FILESYSTEM_VERSION >= 3
     pConf.open(GetConfigFile().generic_string().c_str());
+#else
+    pConf.open(GetConfigFile().string().c_str());
+#endif
     pConf << "rpcuser=user\nrpcpassword="
             + randomStrGen(15)
             + "\nrpcport=8344"
             + "\nport=7777"
-            + "\ndaemon=0 #(0=off, 1=on) Run in the background as a daemon and accept commands"
-            + "\nserver=0 #(0=off, 1=on) Accept command line and JSON-RPC commands"
+            + "\n#(0=off, 1=on) daemon - run in the background as a daemon and accept commands"
+            + "\ndaemon=0"
+            + "\n#(0=off, 1=on) server - accept command line and JSON-RPC commands"
+            + "\nserver=0"
             + "\nrpcallowip=127.0.0.1"
             + "\ntestnet=0";
     pConf.close();
@@ -1458,3 +1464,13 @@ bool NewThread(void(*pfn)(void*), void* parg)
     }
     return true;
 }
+
+std::string DateTimeStrFormat(const char* pszFormat, int64_t nTime)
+{
+    // std::locale takes ownership of the pointer
+    std::locale loc(std::locale::classic(), new boost::posix_time::time_facet(pszFormat));
+    std::stringstream ss;
+    ss.imbue(loc);
+    ss << boost::posix_time::from_time_t(nTime);
+    return ss.str();
+}
\ No newline at end of file