}
int
-evutil_date_rfc1123(char *date, const size_t datelen, struct tm *cur_p) {
+evutil_date_rfc1123(char *date, const size_t datelen, const struct tm *tm)
+{
static const char *DAYS[] =
{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
static const char *MONTHS[] =
time_t t = time(NULL);
- /* If `cur_p` is null, set system's current time. */
- if (cur_p == NULL) {
+#ifndef _WIN32
+ struct tm sys;
+#endif
+
+ /* If `tm` is null, set system's current time. */
+ if (tm == NULL) {
#ifdef _WIN32
- cur_p = gmtime(&t);
+ tm = gmtime(&t);
#else
- {
- struct tm cur;
- gmtime_r(&t, &cur);
- cur_p = &cur;
- }
+ gmtime_r(&t, &sys);
+ tm = &sys;
#endif
}
return evutil_snprintf(
date, datelen, "%s, %02d %s %4d %02d:%02d:%02d GMT",
- DAYS[cur_p->tm_wday], cur_p->tm_mday, MONTHS[cur_p->tm_mon],
- 1900+cur_p->tm_year, cur_p->tm_hour, cur_p->tm_min, cur_p->tm_sec);
+ DAYS[tm->tm_wday], tm->tm_mday, MONTHS[tm->tm_mon],
+ 1900 + tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec);
}
/*
#define EV_MONOT_FALLBACK 2
/** Format a date string using RFC 1123 format (used in HTTP).
- * If `cur_p` is NULL, current system's time will be used.
+ * If `tm` is NULL, current system's time will be used.
* The number of characters written will be returned.
* One should check if the return value is smaller than `datelen` to check if
* the result is truncated or not.
*/
-EVENT2_EXPORT_SYMBOL
-int evutil_date_rfc1123(char *date, const size_t datelen, struct tm *cur_p);
+EVENT2_EXPORT_SYMBOL int
+evutil_date_rfc1123(char *date, const size_t datelen, const struct tm *tm);
/** Allocate a new struct evutil_monotonic_timer for use with the
* evutil_configure_monotonic_time() and evutil_gettime_monotonic()
{
struct tm query;
char result[30];
+ size_t i = 0;
/* Checks if too small buffers are safely accepted. */
{
}
/* Checks for testcases. */
- for (size_t i=0; ; i++) {
+ for (i = 0; ; i++) {
struct date_rfc1123_case c = date_rfc1123_cases[i];
if (strlen(c.date) == 0)