summaryrefslogtreecommitdiff
path: root/main/utils.c
diff options
context:
space:
mode:
authorTilghman Lesher <tilghman@meg.abyt.es>2007-07-18 19:47:20 +0000
committerTilghman Lesher <tilghman@meg.abyt.es>2007-07-18 19:47:20 +0000
commit81bc1d7af5886089bcd065382476f202ad7cc9ea (patch)
tree540f82bac3e6105b6fc34cd4b4613c1756a7512b /main/utils.c
parentb96fde308cd75eb17e5fdb0ea6d54c0f1f593ff9 (diff)
Merge in ast_strftime branch, which changes timestamps to be accurate to the microsecond, instead of only to the second
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@75706 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/utils.c')
-rw-r--r--main/utils.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/main/utils.c b/main/utils.c
index 65139356d..d719837af 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -976,6 +976,33 @@ int ast_atomic_fetchadd_int_slow(volatile int *p, int v)
/*! \brief
* get values from config variables.
*/
+int ast_get_timeval(const char *src, struct timeval *dst, struct timeval _default, int *consumed)
+{
+ long double dtv = 0.0;
+ int scanned;
+
+ if (dst == NULL)
+ return -1;
+
+ *dst = _default;
+
+ if (ast_strlen_zero(src))
+ return -1;
+
+ /* only integer at the moment, but one day we could accept more formats */
+ if (sscanf(src, "%Lf%n", &dtv, &scanned) > 0) {
+ dst->tv_sec = dtv;
+ dst->tv_usec = (dtv - dst->tv_sec) * 1000000.0;
+ if (consumed)
+ *consumed = scanned;
+ return 0;
+ } else
+ return -1;
+}
+
+/*! \brief
+ * get values from config variables.
+ */
int ast_get_time_t(const char *src, time_t *dst, time_t _default, int *consumed)
{
long t;