diff options
author | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-07-18 19:47:20 +0000 |
---|---|---|
committer | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-07-18 19:47:20 +0000 |
commit | 74c2948c2299773fd3816af43e06e3bdf714ba3a (patch) | |
tree | 540f82bac3e6105b6fc34cd4b4613c1756a7512b /main/utils.c | |
parent | fd471b4a0cbb2abd7b4c8f30fee850cedefedaa1 (diff) |
Merge in ast_strftime branch, which changes timestamps to be accurate to the microsecond, instead of only to the second
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@75706 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/utils.c')
-rw-r--r-- | main/utils.c | 27 |
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; |