diff options
author | Carlo Marcelo Arenas Belón <carenas@gmail.com> | 2021-07-24 11:54:30 -0700 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2021-07-26 00:55:17 +0200 |
commit | 4b79c4fb565ab521eb943034918d92dd7fa7db75 (patch) | |
tree | ebb64e7e6af86f44c59040b622f893eb5c69573f | |
parent | 4a7bf79fcc2c7d0414d7d0a2bdc8fe4f1265739b (diff) | |
download | curl-4b79c4fb565ab521eb943034918d92dd7fa7db75.tar.gz |
examples/cookie_interface: avoid printfing time_t directly
time_t representation is undefined and varies on bitsize and signedness,
and as of C11 could be even non integer.
instead of casting to unsigned long (which would truncate in systems
with a 32bit long after 2106) use difftime to get the elapsed time as a
double and print that (without decimals) instead.
alternatively a cast to curl_off_t and its corresponding print
formatting could have been used (at least in POSIX) but portability and
curl agnostic code was prioritized.
Closes #7490
-rw-r--r-- | docs/examples/cookie_interface.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/docs/examples/cookie_interface.c b/docs/examples/cookie_interface.c index 42cbe4649..fb2b9fb7c 100644 --- a/docs/examples/cookie_interface.c +++ b/docs/examples/cookie_interface.c @@ -93,9 +93,9 @@ main(void) #define snprintf _snprintf #endif /* Netscape format cookie */ - snprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%lu\t%s\t%s", + snprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%.0lf\t%s\t%s", ".example.com", "TRUE", "/", "FALSE", - (unsigned long)time(NULL) + 31337UL, + difftime(time(NULL) + 31337, (time_t)0), "PREF", "hello example, i like you very much!"); res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline); if(res != CURLE_OK) { |