]> git.tuebingen.mpg.de Git - paraslash.git/commit
Replace gettimeofday() by clock_gettime().
authorAndre Noll <maan@systemlinux.org>
Sun, 31 Mar 2013 02:03:04 +0000 (02:03 +0000)
committerAndre Noll <maan@systemlinux.org>
Tue, 30 Apr 2013 12:12:45 +0000 (14:12 +0200)
commit24758c5f17064273786e704b84ceff56c234e347
treea40072e46886e6a15b27dc0c58fffcea678ff0d4
parent01f8023b7fe59abc29072c7b84caec5961f8f14b
Replace gettimeofday() by clock_gettime().

POSIX.1-2008 marks gettimeofday() as obsolete, so let's switch to
clock_gettime().

clock_gettime() operates on timespecs rather than on timevals like
gettimeofday() does. Since timevals are extensively used in all
parts of paraslash, and select() takes a timeval pointer as the
timeout parameter, it seems to be easiest to add a new wrapper,
clock_get_realtime(). It calls clock_gettime(), performs error
checking (all errors are treated fatal and abort the program), and
converts the result to a timeval.

Another difference between gettimeofday() and clock_gettime()
is that sys/time.h needs to be included for gettimeofday(), while
clock_gettime() is declared in time.h which gets included from para.h.
Hence we can remove the include statement for sys/time.h everywhere.

Programs which call clock_gettime need to be linked against librt on
glibc versions before 2.17 while BSD and newer glibc-based systems
have no such requirement. To make matters more interesting,
MacOS lacks clock_gettime() completely although this function conforms
to SUSv2 and POSIX.1-2001.

We'd like to avoid the unnecessary dependence on librt on systems that
have clock_gettime() in -lc, and we must fall back to gettimeofday()
on MacOS. Hence this commit also introduces a check in configure.ac
which determines whether clock_gettime() is available and, if it is,
whether -lrt is needed. Executables are only linked with -lrt if
configure found that this is necessary.
17 files changed:
Makefile.in
afh.c
afh_common.c
alsa_write.c
command.c
configure.ac
daemon.c
file_write.c
para.h
play.c
sched.c
sched.h
server.c
string.c
time.c
udp_send.c
wmadec_filter.c