Commit:    3af489683753ab31d7397812989e82f6a424d244
Author:    Pierre Joye <pierre....@gmail.com>         Sat, 23 Mar 2013 10:18:31 
+0100
Committer: Anatol Belski <a...@php.net>      Sat, 23 Mar 2013 22:42:03 +0100
Parents:   04b492a5fef25c70fb42b0734e04d44cbc5a9241
Branches:  PHP-5.4 PHP-5.5 master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=3af489683753ab31d7397812989e82f6a424d244

Log:
- fix x64 issues on windows with the various time types (overflow, signed and 
unsigned bits ops, etc.) causing crashes on start, error or log, must be done 
in win32/time.c for some of these functions too

Signed-off-by: Anatol Belski <a...@php.net>

Changed paths:
  M  sapi/cli/php_cli_server.c


Diff:
diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c
index ab7f4cf..e834e75 100644
--- a/sapi/cli/php_cli_server.c
+++ b/sapi/cli/php_cli_server.c
@@ -24,11 +24,12 @@
 #include <assert.h>
 
 #ifdef PHP_WIN32
-#include <process.h>
-#include <io.h>
-#include "win32/time.h"
-#include "win32/signal.h"
-#include "win32/php_registry.h"
+# include <process.h>
+# include <io.h>
+# include "win32/time.h"
+# include "win32/signal.h"
+# include "win32/php_registry.h"
+# include <sys/timeb.h>
 #else
 # include "php_config.h"
 #endif
@@ -292,6 +293,34 @@ static const char php_cli_server_css[] = "<style>\n" \
                                                                                
"</style>\n";
 /* }}} */
 
+#ifdef PHP_WIN32
+int php_cli_server_get_system_time(char *buf) {
+       struct _timeb system_time;
+       errno_t err;
+
+       if (buf == NULL) {
+               return -1;
+       }
+
+       _ftime(&system_time);
+       err = ctime_s(buf, 52, &(system_time.time) );
+       if (err) {
+               return -1;
+       }
+       return 0;
+}
+#else
+int php_cli_server_get_system_time(char *buf) {
+       struct timeval tv;
+       struct tm tm;
+
+       gettimeofday(&tv, NULL);
+       php_localtime_r(&tv.tv_sec, &tm);
+       php_asctime_r(&tm, buf);
+       return 0;
+}
+#endif
+
 static void char_ptr_dtor_p(char **p) /* {{{ */
 {
        pefree(*p, 1);
@@ -630,13 +659,11 @@ static void sapi_cli_server_register_variables(zval 
*track_vars_array TSRMLS_DC)
 
 static void sapi_cli_server_log_message(char *msg TSRMLS_DC) /* {{{ */
 {
-       struct timeval tv;
-       struct tm tm;
        char buf[52];
-       gettimeofday(&tv, NULL);
-       php_localtime_r(&tv.tv_sec, &tm);
-       php_asctime_r(&tm, buf);
-       {
+
+       if (php_cli_server_get_system_time(buf) != 0) {
+               memmove(buf, "unknown time, can't be fetched", sizeof("unknown 
time, can't be fetched"));
+       } else {
                size_t l = strlen(buf);
                if (l > 0) {
                        buf[l - 1] = '\0';
@@ -2394,12 +2421,12 @@ int do_cli_server(int argc, char **argv TSRMLS_DC) /* 
{{{ */
        sapi_module.phpinfo_as_text = 0;
 
        {
-               struct timeval tv;
-               struct tm tm;
                char buf[52];
-               gettimeofday(&tv, NULL);
-               php_localtime_r(&tv.tv_sec, &tm);
-               php_asctime_r(&tm, buf);
+
+               if (php_cli_server_get_system_time(buf) != 0) {
+                       memmove(buf, "unknown time, can't be fetched", 
sizeof("unknown time, can't be fetched"));
+               }
+
                printf("PHP %s Development Server started at %s"
                                "Listening on http://%s\n";
                                "Document root is %s\n"


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to