summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRay Strode <rstrode@redhat.com>2007-05-21 10:06:58 -0400
committerRay Strode <rstrode@redhat.com>2007-05-21 10:06:58 -0400
commitce1debbfe5b82ead42ba1e11f50aa9709f84dd3f (patch)
tree10e452d7416869cc676ce3e6e3700c5213ed354b /src
parentaebc4650c6e9705638847d08c7ba2e28efcdbae4 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/ply-utils.c14
-rw-r--r--src/ply-utils.h1
2 files changed, 15 insertions, 0 deletions
diff --git a/src/ply-utils.c b/src/ply-utils.c
index 0e55dfb..b395504 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 1fa8d44..4da3f51 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 */