diff options
| -rw-r--r-- | http.c | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -6,6 +6,7 @@ #include <unistd.h> #include <errno.h> #include <inttypes.h> +#include <locale.h> #include <stdbool.h> #include <stddef.h> #include <stdlib.h> @@ -2750,11 +2751,18 @@ failure: static int append_expire(struct dynstr *const d, const struct tm *const exp) { + int ret = -1; char s[sizeof "Thu, 01 Jan 1970 00:00:00 GMT"]; + const locale_t l = newlocale(LC_TIME_MASK, "POSIX", (locale_t)0); - if (!strftime(s, sizeof s, "%a, %d %b %Y %H:%M:%S GMT", exp)) + if (l == (locale_t)0) { - fprintf(stderr, "%s: strftime(3) failed\n", __func__); + fprintf(stderr, "%s: newlocale(3): %s\n", __func__, strerror(errno)); + goto end; + } + else if (!strftime_l(s, sizeof s, "%a, %d %b %Y %H:%M:%S GMT", exp, l)) + { + fprintf(stderr, "%s: strftime_l(3) failed\n", __func__); return -1; } else if (dynstr_append(d, "; Expires=%s", s)) @@ -2763,7 +2771,11 @@ static int append_expire(struct dynstr *const d, const struct tm *const exp) return -1; } - return 0; + ret = 0; + +end: + freelocale(l); + return ret; } char *http_cookie_create(const char *const key, const char *const value, |
