make time conversion thread safe

Non reentrant function 'localtime' called. For threadsafe applications it
is recommended to use the reentrant replacement function 'localtime_r'.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
remove use of obsolete usleep() function

The usleep function was marked obsolete in POSIX.1-2001 and was removed
in POSIX.1-2008.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
add input limits to fscanf() format strings

Huge values can cause crashes if width limits are not used.  This was
case until glibc 2.15 (released 2012-03-21).

Reference: https://sourceware.org/bugzilla/show_bug.cgi?id=13138
Signed-off-by: Sami Kerola <kerolasa@iki.fi>