summaryrefslogtreecommitdiff
path: root/source4/lib/replace.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-10-25 23:26:13 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:04:43 -0500
commit1915f1ca4313e35c0a196bbb07ebd7d7a0eadef8 (patch)
treefdf1965ec826bde595382b8ab8f18952df804fc0 /source4/lib/replace.c
parent101a407dd72491c05c72bc2825d09133676f242c (diff)
downloadsamba-1915f1ca4313e35c0a196bbb07ebd7d7a0eadef8.tar.gz
samba-1915f1ca4313e35c0a196bbb07ebd7d7a0eadef8.tar.bz2
samba-1915f1ca4313e35c0a196bbb07ebd7d7a0eadef8.zip
r3223: continue the effort on LIBREPLACE to try to get the ldb tools to
compile on platforms like solaris without having to link to the whole of the Samba4 lib directory. (This used to be commit f6862bfc1cbc9278914b4b73365f63d3da0a08dd)
Diffstat (limited to 'source4/lib/replace.c')
-rw-r--r--source4/lib/replace.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/source4/lib/replace.c b/source4/lib/replace.c
index f3a0df6ef6..4ed99c833c 100644
--- a/source4/lib/replace.c
+++ b/source4/lib/replace.c
@@ -427,6 +427,39 @@ char *rep_inet_ntoa(struct in_addr ip)
#endif /* HAVE_SYSLOG */
#endif /* HAVE_VSYSLOG */
+/*******************************************************************
+yield the difference between *A and *B, in seconds, ignoring leap seconds
+********************************************************************/
+static int tm_diff(struct tm *a, struct tm *b)
+{
+ int ay = a->tm_year + (1900 - 1);
+ int by = b->tm_year + (1900 - 1);
+ int intervening_leap_days =
+ (ay/4 - by/4) - (ay/100 - by/100) + (ay/400 - by/400);
+ int years = ay - by;
+ int days = 365*years + intervening_leap_days + (a->tm_yday - b->tm_yday);
+ int hours = 24*days + (a->tm_hour - b->tm_hour);
+ int minutes = 60*hours + (a->tm_min - b->tm_min);
+ int seconds = 60*minutes + (a->tm_sec - b->tm_sec);
+
+ return seconds;
+}
+
+/*******************************************************************
+ return the UTC offset in seconds west of UTC, or 0 if it cannot be determined
+ ******************************************************************/
+int get_time_zone(time_t t)
+{
+ struct tm *tm = gmtime(&t);
+ struct tm tm_utc;
+ if (!tm)
+ return 0;
+ tm_utc = *tm;
+ tm = localtime(&t);
+ if (!tm)
+ return 0;
+ return tm_diff(&tm_utc,tm);
+}
#ifndef HAVE_TIMEGM
/*