[asterisk-dev] timeval.tv_sec is time_t. How to print/scan?

Richard Mudgett rmudgett at digium.com
Sat Feb 17 13:26:32 CST 2018


On Sat, Feb 17, 2018 at 5:58 AM, Alexander Traud <pabstraud at compuserve.com>
wrote:

> While compiling Asterisk on OpenBSD, I get a lot of warnings about the
> usage of data-type time_t, when used in combination with printf/scanf,
> for example in the file res_http_media_cache.c:
>
> struct timeval actual_expires = ast_tvnow(); // gettimeofday(&t, NULL);
> snprintf(time_buf, sizeof(time_buf), "%30lu", actual_expires.tv_sec);
>
> On the Internet, there are a lot of suggestions, like
> <http://stackoverflow.com/q/27057677>. Which approach does the Asterisk
> team prefer? Or should I create a new issue report with all findings so
> that somebody else can look into each of those?
>

As that link shows there is no good way to do it.  You just have to settle
for
a portable enough way.  Nor is there an "official" Asterisk way.  You
probably
could search the Asterisk code and find an example of all those
suggestions.
Usually, I have just cast the value to match an appropriate printf format
specifier
to head off nuisance compiler messages.  However, even with the casts I
just
saw on another related stackoverflow page some compilers are stupid enough
to
still complain.

Richard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-dev/attachments/20180217/06db40f1/attachment.html>


More information about the asterisk-dev mailing list