Selaa lähdekoodia

user internal tm struct for date descriptions

Julius Pfrommer 6 vuotta sitten
vanhempi
commit
df01d8a514
3 muutettua tiedostoa jossa 23 lisäystä ja 13 poistoa
  1. 4 6
      deps/libc_time.c
  2. 15 3
      deps/libc_time.h
  3. 4 4
      src/ua_types.c

+ 4 - 6
deps/libc_time.c

@@ -1,8 +1,7 @@
-/*
- * Originally released by the musl project (http://www.musl-libc.org/) under the
- * MIT license. Taken from the file /src/time/__secs_to_tm.c
- */
+/* Originally released by the musl project (http://www.musl-libc.org/) under the
+ * MIT license. Taken from the file /src/time/__secs_to_tm.c */
 
+#include <limits.h>
 #include "libc_time.h"
 
 /* 2000-03-01 (mod 400 year, immediately after feb29 */
@@ -12,8 +11,7 @@
 #define DAYS_PER_100Y (365*100 + 24)
 #define DAYS_PER_4Y   (365*4   + 1)
 
-int __secs_to_tm(long long t, struct tm *tm)
-{
+int __secs_to_tm(long long t, struct mytm *tm) {
     long long days, secs, years;
     int remdays, remsecs, remyears;
     int qc_cycles, c_cycles, q_cycles;

+ 15 - 3
deps/libc_time.h

@@ -1,8 +1,20 @@
 #ifndef LIBC_TIME_H_
 #define LIBC_TIME_H_
 
-#include <limits.h>
-#include <time.h>
-int __secs_to_tm(long long t, struct tm *tm);
+struct mytm {
+    int tm_sec;
+    int tm_min;
+    int tm_hour;
+    int tm_mday;
+    int tm_mon;
+    int tm_year;
+    int tm_wday;
+    int tm_yday;
+    int tm_isdst;
+    /* long __tm_gmtoff; */
+    /* const char *__tm_zone; */
+};
+
+int __secs_to_tm(long long t, struct mytm *tm);
 
 #endif /* LIBC_TIME_H_ */

+ 4 - 4
src/ua_types.c

@@ -102,10 +102,10 @@ UA_DateTime_toStruct(UA_DateTime t) {
     dateTimeStruct.milliSec = (u16)((t % 10000000) / 10000);
 
     /* Calculating the unix time with #include <time.h> */
-    time_t secSinceUnixEpoch =
-        (time_t)((t - UA_DATETIME_UNIX_EPOCH) / UA_SEC_TO_DATETIME);
-    struct tm ts;
-    memset(&ts, 0, sizeof(struct tm));
+    long long secSinceUnixEpoch = (long long)
+        ((t - UA_DATETIME_UNIX_EPOCH) / UA_SEC_TO_DATETIME);
+    struct mytm ts;
+    memset(&ts, 0, sizeof(struct mytm));
     __secs_to_tm(secSinceUnixEpoch, &ts);
     dateTimeStruct.sec    = (u16)ts.tm_sec;
     dateTimeStruct.min    = (u16)ts.tm_min;