From: Ray Strode Date: Mon, 21 May 2007 14:06:58 +0000 (-0400) Subject: add new ply_get_timestamp() function X-Git-Tag: 0.1.0~281 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce1debbfe5b82ead42ba1e11f50aa9709f84dd3f;p=thirdparty%2Fplymouth.git add new ply_get_timestamp() function This commit adds a function, ply_get_timestamp(), that returns the current time in seconds since the epoch as a double. --- diff --git a/src/ply-utils.c b/src/ply-utils.c index 0e55dfb1..b395504b 100644 --- a/src/ply-utils.c +++ b/src/ply-utils.c @@ -228,4 +228,18 @@ ply_close_all_fds (void) close (fd); } +double +ply_get_timestamp (void) +{ + const double microseconds_per_second = 1000000.0; + double timestamp; + struct timeval now = { 0L, /* zero-filled */ }; + + gettimeofday (&now, NULL); + timestamp = ((microseconds_per_second * now.tv_sec) + now.tv_usec) / + microseconds_per_second; + + return timestamp; +} + /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/ply-utils.h b/src/ply-utils.h index 1fa8d44b..4da3f51b 100644 --- a/src/ply-utils.h +++ b/src/ply-utils.h @@ -49,6 +49,7 @@ bool ply_fd_can_take_data (int fd); char **ply_copy_string_array (const char * const *array); void ply_free_string_array (char **array); void ply_close_all_fds (void); +double ply_get_timestamp (void); #endif #endif /* PLY_UTILS_H */