]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commit
util: new function virTimeLocalOffsetFromUTC
authorLaine Stump <laine@laine.org>
Sat, 24 May 2014 14:21:26 +0000 (08:21 -0600)
committerLaine Stump <laine@laine.org>
Mon, 26 May 2014 10:51:05 +0000 (13:51 +0300)
commit1cddaea7aeca441b733c31990a3f139dd2d346f6
tree929734a100cb5efd9cd5ce4f470921179662a6bc
parent81271a9261b634a7ea5e7a17ef6892c123ac407b
util: new function virTimeLocalOffsetFromUTC

Since there isn't a single libc API to get this value, this patch
supplies one which gets the value by grabbing current time, then
converting that into a struct tm with gmtime_r(), then back to a
time_t using mktime.

The returned value is the difference between UTC and localtime in
seconds. If localtime is ahead of UTC (east) the offset will be a
positive number, and if localtime is behind UTC (west) the offset will
be negative.

This function should be POSIX-compliant, and is threadsafe, but not
async signal safe. If it was ever necessary to know this value in a
child process, we could cache it with a one-time init function when
libvirtd starts, then just supply the cached value, but that
complexity isn't needed for current usage; that would also have the
problem that it might not be accurate after a local daylight savings
boundary.

(If it weren't for DST, we could simply replace this entire function
with "-timezone"; timezone contains the offset of the current timezone
(negated from what we want) but doesn't account for DST. And in spite
of being guaranteed by POSIX, it isn't available on older versions of
mingw.)

Signed-off-by: Eric Blake <eblake@redhat.com>
src/libvirt_private.syms
src/util/virtime.c
src/util/virtime.h
tests/virtimetest.c