Coverage Report

Created: 2023-03-26 06:28

/src/httpd/srclib/apr/time/unix/timestr.c
Line
Count
Source (jump to first uncovered line)
1
/* Licensed to the Apache Software Foundation (ASF) under one or more
2
 * contributor license agreements.  See the NOTICE file distributed with
3
 * this work for additional information regarding copyright ownership.
4
 * The ASF licenses this file to You under the Apache License, Version 2.0
5
 * (the "License"); you may not use this file except in compliance with
6
 * the License.  You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#include "apr_portable.h"
18
#include "apr_time.h"
19
#include "apr_lib.h"
20
#include "apr_private.h"
21
/* System Headers required for time library */
22
#if APR_HAVE_SYS_TIME_H
23
#include <sys/time.h>
24
#endif
25
#ifdef HAVE_TIME_H
26
#include <time.h>
27
#endif
28
#if APR_HAVE_STRING_H
29
#include <string.h>
30
#endif
31
/* End System Headers */
32
33
APR_DECLARE_DATA const char apr_month_snames[12][4] =
34
{
35
    "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
36
};
37
APR_DECLARE_DATA const char apr_day_snames[7][4] =
38
{
39
    "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
40
};
41
42
apr_status_t apr_rfc822_date(char *date_str, apr_time_t t)
43
0
{
44
0
    apr_time_exp_t xt;
45
0
    const char *s;
46
0
    int real_year;
47
48
0
    apr_time_exp_gmt(&xt, t);
49
50
    /* example: "Sat, 08 Jan 2000 18:31:41 GMT" */
51
    /*           12345678901234567890123456789  */
52
53
0
    s = &apr_day_snames[xt.tm_wday][0];
54
0
    *date_str++ = *s++;
55
0
    *date_str++ = *s++;
56
0
    *date_str++ = *s++;
57
0
    *date_str++ = ',';
58
0
    *date_str++ = ' ';
59
0
    *date_str++ = xt.tm_mday / 10 + '0';
60
0
    *date_str++ = xt.tm_mday % 10 + '0';
61
0
    *date_str++ = ' ';
62
0
    s = &apr_month_snames[xt.tm_mon][0];
63
0
    *date_str++ = *s++;
64
0
    *date_str++ = *s++;
65
0
    *date_str++ = *s++;
66
0
    *date_str++ = ' ';
67
0
    real_year = 1900 + xt.tm_year;
68
    /* This routine isn't y10k ready. */
69
0
    *date_str++ = real_year / 1000 + '0';
70
0
    *date_str++ = real_year % 1000 / 100 + '0';
71
0
    *date_str++ = real_year % 100 / 10 + '0';
72
0
    *date_str++ = real_year % 10 + '0';
73
0
    *date_str++ = ' ';
74
0
    *date_str++ = xt.tm_hour / 10 + '0';
75
0
    *date_str++ = xt.tm_hour % 10 + '0';
76
0
    *date_str++ = ':';
77
0
    *date_str++ = xt.tm_min / 10 + '0';
78
0
    *date_str++ = xt.tm_min % 10 + '0';
79
0
    *date_str++ = ':';
80
0
    *date_str++ = xt.tm_sec / 10 + '0';
81
0
    *date_str++ = xt.tm_sec % 10 + '0';
82
0
    *date_str++ = ' ';
83
0
    *date_str++ = 'G';
84
0
    *date_str++ = 'M';
85
0
    *date_str++ = 'T';
86
0
    *date_str++ = 0;
87
0
    return APR_SUCCESS;
88
0
}
89
90
apr_status_t apr_ctime(char *date_str, apr_time_t t)
91
0
{
92
0
    apr_time_exp_t xt;
93
0
    const char *s;
94
0
    int real_year;
95
96
    /* example: "Wed Jun 30 21:49:08 1993" */
97
    /*           123456789012345678901234  */
98
99
0
    apr_time_exp_lt(&xt, t);
100
0
    s = &apr_day_snames[xt.tm_wday][0];
101
0
    *date_str++ = *s++;
102
0
    *date_str++ = *s++;
103
0
    *date_str++ = *s++;
104
0
    *date_str++ = ' ';
105
0
    s = &apr_month_snames[xt.tm_mon][0];
106
0
    *date_str++ = *s++;
107
0
    *date_str++ = *s++;
108
0
    *date_str++ = *s++;
109
0
    *date_str++ = ' ';
110
0
    *date_str++ = xt.tm_mday / 10 + '0';
111
0
    *date_str++ = xt.tm_mday % 10 + '0';
112
0
    *date_str++ = ' ';
113
0
    *date_str++ = xt.tm_hour / 10 + '0';
114
0
    *date_str++ = xt.tm_hour % 10 + '0';
115
0
    *date_str++ = ':';
116
0
    *date_str++ = xt.tm_min / 10 + '0';
117
0
    *date_str++ = xt.tm_min % 10 + '0';
118
0
    *date_str++ = ':';
119
0
    *date_str++ = xt.tm_sec / 10 + '0';
120
0
    *date_str++ = xt.tm_sec % 10 + '0';
121
0
    *date_str++ = ' ';
122
0
    real_year = 1900 + xt.tm_year;
123
0
    *date_str++ = real_year / 1000 + '0';
124
0
    *date_str++ = real_year % 1000 / 100 + '0';
125
0
    *date_str++ = real_year % 100 / 10 + '0';
126
0
    *date_str++ = real_year % 10 + '0';
127
0
    *date_str++ = 0;
128
129
0
    return APR_SUCCESS;
130
0
}
131
132
apr_status_t apr_strftime(char *s, apr_size_t *retsize, apr_size_t max,
133
                        const char *format, apr_time_exp_t *xt)
134
0
{
135
0
    struct tm tm;
136
0
    memset(&tm, 0, sizeof tm);
137
0
    tm.tm_sec  = xt->tm_sec;
138
0
    tm.tm_min  = xt->tm_min;
139
0
    tm.tm_hour = xt->tm_hour;
140
0
    tm.tm_mday = xt->tm_mday;
141
0
    tm.tm_mon  = xt->tm_mon;
142
0
    tm.tm_year = xt->tm_year;
143
0
    tm.tm_wday = xt->tm_wday;
144
0
    tm.tm_yday = xt->tm_yday;
145
0
    tm.tm_isdst = xt->tm_isdst;
146
0
#if defined(HAVE_STRUCT_TM_TM_GMTOFF)
147
0
    tm.tm_gmtoff = xt->tm_gmtoff;
148
#elif defined(HAVE_STRUCT_TM___TM_GMTOFF)
149
    tm.__tm_gmtoff = xt->tm_gmtoff;
150
#endif
151
0
    (*retsize) = strftime(s, max, format, &tm);
152
0
    return APR_SUCCESS;
153
0
}