2
2
3
3
#include < stdlib.h>
4
4
#include < stdio.h>
5
+ #include < chrono>
5
6
6
7
#if defined(_WIN32) && !defined(__CYGWIN__)
7
8
#undef UNICODE
@@ -17,7 +18,6 @@ extern char **environ;
17
18
18
19
#include < ctype.h>
19
20
#include < qglobal.h>
20
- #include < qdatetime.h>
21
21
#include < qglobal.h>
22
22
#include < qdir.h>
23
23
#include < map>
@@ -34,7 +34,7 @@ static std::map<std::string,std::string> proc_env = std::map<std::string,std::st
34
34
#endif
35
35
36
36
static double g_sysElapsedTime;
37
- static QTime g_time ;
37
+ static std::chrono::steady_clock::time_point g_startTime ;
38
38
39
39
40
40
int Portable::system (const char *command,const char *args,bool commandHasConsole)
@@ -69,7 +69,7 @@ int Portable::system(const char *command,const char *args,bool commandHasConsole
69
69
70
70
// on Solaris fork() duplicates the memory usage
71
71
// so we use vfork instead
72
-
72
+
73
73
// spawn shell
74
74
if ((pid=vfork ())<0 )
75
75
{
@@ -138,11 +138,11 @@ int Portable::system(const char *command,const char *args,bool commandHasConsole
138
138
}
139
139
else
140
140
{
141
- // Because ShellExecuteEx can delegate execution to Shell extensions
142
- // (data sources, context menu handlers, verb implementations) that
143
- // are activated using Component Object Model (COM), COM should be
144
- // initialized before ShellExecuteEx is called. Some Shell extensions
145
- // require the COM single-threaded apartment (STA) type.
141
+ // Because ShellExecuteEx can delegate execution to Shell extensions
142
+ // (data sources, context menu handlers, verb implementations) that
143
+ // are activated using Component Object Model (COM), COM should be
144
+ // initialized before ShellExecuteEx is called. Some Shell extensions
145
+ // require the COM single-threaded apartment (STA) type.
146
146
// For that case COM is initialized as follows
147
147
CoInitializeEx (NULL , COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
148
148
@@ -156,13 +156,13 @@ int Portable::system(const char *command,const char *args,bool commandHasConsole
156
156
SHELLEXECUTEINFOW sInfo = {
157
157
sizeof (SHELLEXECUTEINFOW), /* structure size */
158
158
SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI, /* tell us the process
159
- * handle so we can wait till it's done |
160
- * do not display msg box if error
159
+ * handle so we can wait till it's done |
160
+ * do not display msg box if error
161
161
*/
162
162
NULL , /* window handle */
163
163
NULL , /* action to perform: open */
164
164
(LPCWSTR)commandw.ucs2 (), /* file to execute */
165
- (LPCWSTR)argsw.ucs2 (), /* argument list */
165
+ (LPCWSTR)argsw.ucs2 (), /* argument list */
166
166
NULL , /* use current working dir */
167
167
SW_HIDE, /* minimize on start-up */
168
168
0 , /* application instance handle */
@@ -180,7 +180,7 @@ int Portable::system(const char *command,const char *args,bool commandHasConsole
180
180
}
181
181
else if (sInfo .hProcess ) /* executable was launched, wait for it to finish */
182
182
{
183
- WaitForSingleObject (sInfo .hProcess ,INFINITE);
183
+ WaitForSingleObject (sInfo .hProcess ,INFINITE);
184
184
/* get process exit code */
185
185
DWORD exitCode;
186
186
if (!GetExitCodeProcess (sInfo .hProcess ,&exitCode))
@@ -269,7 +269,7 @@ void Portable::unsetenv(const char *variable)
269
269
}
270
270
271
271
const char *Portable::getenv (const char *variable)
272
- {
272
+ {
273
273
#if defined(_WIN32) && !defined(__CYGWIN__)
274
274
return ::getenv (variable);
275
275
#else
@@ -303,7 +303,7 @@ portable_off_t Portable::fseek(FILE *f,portable_off_t offset, int whence)
303
303
portable_off_t Portable::ftell (FILE *f)
304
304
{
305
305
#if defined(__MINGW32__)
306
- return ftello64 (f);
306
+ return ftello64 (f);
307
307
#elif defined(_WIN32) && !defined(__CYGWIN__)
308
308
return _ftelli64 (f);
309
309
#else
@@ -448,12 +448,14 @@ int Portable::pclose(FILE *stream)
448
448
449
449
void Portable::sysTimerStart ()
450
450
{
451
- g_time. start ();
451
+ g_startTime = std::chrono::steady_clock::now ();
452
452
}
453
453
454
454
void Portable::sysTimerStop ()
455
455
{
456
- g_sysElapsedTime+=((double )g_time.elapsed ())/1000.0 ;
456
+ std::chrono::steady_clock::time_point endTime = std::chrono::steady_clock::now ();
457
+ g_sysElapsedTime+= std::chrono::duration_cast<
458
+ std::chrono::microseconds>(endTime - g_startTime).count ()/1000000.0 ;
457
459
}
458
460
459
461
double Portable::getSysElapsedTime ()
@@ -561,7 +563,7 @@ static const char * portable_memmem (const char *haystack, size_t haystack_len,
561
563
const char *Portable::strnstr (const char *haystack, const char *needle, size_t haystack_len)
562
564
{
563
565
size_t needle_len = strnlen (needle, haystack_len);
564
- if (needle_len < haystack_len || !needle[needle_len])
566
+ if (needle_len < haystack_len || !needle[needle_len])
565
567
{
566
568
const char *x = portable_memmem (haystack, haystack_len, needle, needle_len);
567
569
if (x && !memchr (haystack, 0 , x - haystack))
0 commit comments