From 50cfec7a946dba4099733332626a7e64ee564d40 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Fri, 18 Jun 2010 21:03:52 +0200 Subject: [PATCH] src/utils_params.[ch]: Implement "time_to_rfc1123". --- src/utils_params.c | 15 +++++++++++++++ src/utils_params.h | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/src/utils_params.c b/src/utils_params.c index 2c7bcc2..bfde56b 100644 --- a/src/utils_params.c +++ b/src/utils_params.c @@ -267,4 +267,19 @@ const char *script_name (void) return (ret); } /* }}} char *script_name */ +int time_to_rfc1123 (time_t t, char *buffer, size_t buffer_size) /* {{{ */ +{ + struct tm tm_tmp; + size_t status; + + if (localtime_r (&t, &tm_tmp) == NULL) + return (errno); + + status = strftime (buffer, buffer_size, "%a, %d %b %Y %T %z", &tm_tmp); + if (status == 0) + return (errno); + + return (0); +} /* }}} int time_to_rfc1123 */ + /* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/src/utils_params.h b/src/utils_params.h index 5d0c845..0d3f0e5 100644 --- a/src/utils_params.h +++ b/src/utils_params.h @@ -1,6 +1,8 @@ #ifndef UTILS_PARAMS_H #define UTILS_PARAMS_H 1 +#include + int param_init (void); void param_finish (void); @@ -10,4 +12,6 @@ int uri_escape (char *dst, const char *src, size_t size); const char *script_name (void); +int time_to_rfc1123 (time_t t, char *buffer, size_t buffer_size); + #endif /* UTILS_PARAMS_H */ -- 2.30.2