From 81bc1d7af5886089bcd065382476f202ad7cc9ea Mon Sep 17 00:00:00 2001 From: Tilghman Lesher Date: Wed, 18 Jul 2007 19:47:20 +0000 Subject: 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 --- main/utils.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'main/utils.c') diff --git a/main/utils.c b/main/utils.c index 65139356d..d719837af 100644 --- a/main/utils.c +++ b/main/utils.c @@ -973,6 +973,33 @@ int ast_atomic_fetchadd_int_slow(volatile int *p, int v) return ret; } +/*! \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. */ -- cgit v1.2.3