ithewei 6 years ago
parent
commit
7bb0de2e99
1 changed files with 19 additions and 5 deletions
  1. 19 5
      base/htime.h

+ 19 - 5
base/htime.h

@@ -36,13 +36,21 @@ static inline void usleep(unsigned int us) {
 
 
 #include <sys/timeb.h>
 #include <sys/timeb.h>
 static inline int gettimeofday(struct timeval *tv, struct timeval *tz) {
 static inline int gettimeofday(struct timeval *tv, struct timeval *tz) {
-  struct _timeb timebuffer;
+    struct _timeb tb;
 
 
-  _ftime( &timebuffer );
+    _ftime(&tb);
 
 
-  tv->tv_sec = (long) timebuffer.time;
-  tv->tv_usec = timebuffer.millitm * 1000;
-  return 0;
+    if (tv) {
+        tv->tv_sec =  tb.time;
+        tv->tv_usec = tb.millitm * 1000;
+    }
+
+    if (tz) {
+        tz->tz_minuteswest = tb.timezone;
+        tz->tz_dsttime = tb.dstflag;
+    }
+
+    return 0;
 }
 }
 #endif
 #endif
 
 
@@ -72,6 +80,12 @@ static inline unsigned int gettick() {
 // us
 // us
 unsigned long long gethrtime();
 unsigned long long gethrtime();
 
 
+static inline unsigned long long timestamp_ms() {
+    struct timeval tv;
+    gettimeofday(&tv, NULL);
+    return tv_sec * (unsigned long long)1000 + tv_usec/1000;
+}
+
 datetime_t datetime_now();
 datetime_t datetime_now();
 time_t     datetime_mktime(datetime_t* dt);
 time_t     datetime_mktime(datetime_t* dt);