diff options
-rw-r--r-- | src/include/gnunet_time_lib.h | 9 | ||||
-rw-r--r-- | src/util/common_logging.c | 27 | ||||
-rw-r--r-- | src/util/time.c | 12 |
3 files changed, 48 insertions, 0 deletions
diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h index d131e4eef..660d15af9 100644 --- a/src/include/gnunet_time_lib.h +++ b/src/include/gnunet_time_lib.h | |||
@@ -465,6 +465,15 @@ void | |||
465 | GNUNET_TIME_set_offset (long long offset); | 465 | GNUNET_TIME_set_offset (long long offset); |
466 | 466 | ||
467 | 467 | ||
468 | /** | ||
469 | * Get the timestamp offset for this instance. | ||
470 | * | ||
471 | * @return the offset we currently skew the locale time by | ||
472 | */ | ||
473 | long long | ||
474 | GNUNET_TIME_get_offset (void); | ||
475 | |||
476 | |||
468 | #if 0 /* keep Emacsens' auto-indent happy */ | 477 | #if 0 /* keep Emacsens' auto-indent happy */ |
469 | { | 478 | { |
470 | #endif | 479 | #endif |
diff --git a/src/util/common_logging.c b/src/util/common_logging.c index 000c33880..cd845ccce 100644 --- a/src/util/common_logging.c +++ b/src/util/common_logging.c | |||
@@ -886,11 +886,14 @@ mylog (enum GNUNET_ErrorType kind, const char *comp, const char *message, | |||
886 | memset (date, 0, DATE_STR_SIZE); | 886 | memset (date, 0, DATE_STR_SIZE); |
887 | { | 887 | { |
888 | char buf[size]; | 888 | char buf[size]; |
889 | long long offset; | ||
889 | #ifdef WINDOWS | 890 | #ifdef WINDOWS |
890 | LARGE_INTEGER pc; | 891 | LARGE_INTEGER pc; |
891 | time_t timetmp; | 892 | time_t timetmp; |
892 | 893 | ||
894 | offset = GNUNET_TIME_get_offset (); | ||
893 | time (&timetmp); | 895 | time (&timetmp); |
896 | timetmp += offset / 1000; | ||
894 | tmptr = localtime (&timetmp); | 897 | tmptr = localtime (&timetmp); |
895 | pc.QuadPart = 0; | 898 | pc.QuadPart = 0; |
896 | QueryPerformanceCounter (&pc); | 899 | QueryPerformanceCounter (&pc); |
@@ -909,6 +912,30 @@ mylog (enum GNUNET_ErrorType kind, const char *comp, const char *message, | |||
909 | struct timeval timeofday; | 912 | struct timeval timeofday; |
910 | 913 | ||
911 | gettimeofday (&timeofday, NULL); | 914 | gettimeofday (&timeofday, NULL); |
915 | offset = GNUNET_TIME_get_offset (); | ||
916 | if (offset > 0) | ||
917 | { | ||
918 | timeofday.tv_sec += offset / 1000LL; | ||
919 | timeofday.tv_usec += (offset % 1000LL) * 1000LL; | ||
920 | if (timeofday.tv_usec > 1000000LL) | ||
921 | { | ||
922 | timeofday.tv_usec -= 1000000LL; | ||
923 | timeofday.tv_sec++; | ||
924 | } | ||
925 | } | ||
926 | else | ||
927 | { | ||
928 | timeofday.tv_sec += offset / 1000LL; | ||
929 | if (timeofday.tv_usec > - (offset % 1000LL) * 1000LL) | ||
930 | { | ||
931 | timeofday.tv_usec += (offset % 1000LL) * 1000LL; | ||
932 | } | ||
933 | else | ||
934 | { | ||
935 | timeofday.tv_usec += 1000000LL + (offset % 1000LL) * 1000LL; | ||
936 | timeofday.tv_sec--; | ||
937 | } | ||
938 | } | ||
912 | tmptr = localtime (&timeofday.tv_sec); | 939 | tmptr = localtime (&timeofday.tv_sec); |
913 | if (NULL == tmptr) | 940 | if (NULL == tmptr) |
914 | { | 941 | { |
diff --git a/src/util/time.c b/src/util/time.c index b82a1ba7c..825b7f8ca 100644 --- a/src/util/time.c +++ b/src/util/time.c | |||
@@ -46,6 +46,18 @@ GNUNET_TIME_set_offset (long long offset) | |||
46 | 46 | ||
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Get the timestamp offset for this instance. | ||
50 | * | ||
51 | * @return the offset we currently skew the locale time by | ||
52 | */ | ||
53 | long long | ||
54 | GNUNET_TIME_get_offset () | ||
55 | { | ||
56 | return timestamp_offset; | ||
57 | } | ||
58 | |||
59 | |||
60 | /** | ||
49 | * Get the current time (works just as "time", just that we use the | 61 | * Get the current time (works just as "time", just that we use the |
50 | * unit of time that the cron-jobs use (and is 64 bit)). | 62 | * unit of time that the cron-jobs use (and is 64 bit)). |
51 | * | 63 | * |