MCPcopy Create free account
hub / github.com/apache/httpd / ap_recent_ctime_ex

Function ap_recent_ctime_ex

server/util_time.c:169–293  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

167}
168
169AP_DECLARE(apr_status_t) ap_recent_ctime_ex(char *date_str, apr_time_t t,
170 int option, int *len)
171{
172 /* ### This code is a clone of apr_ctime(), except that it
173 * uses ap_explode_recent_localtime() instead of apr_time_exp_lt().
174 */
175 apr_time_exp_t xt;
176 const char *s;
177 int real_year;
178 int needed;
179
180
181 /* Calculate the needed buffer length */
182 if (option & AP_CTIME_OPTION_COMPACT)
183 needed = AP_CTIME_COMPACT_LEN;
184 else
185 needed = APR_CTIME_LEN;
186
187 if (option & AP_CTIME_OPTION_USEC) {
188 needed += AP_CTIME_USEC_LENGTH;
189 }
190 else if (option & AP_CTIME_OPTION_MSEC) {
191 needed += AP_CTIME_MSEC_LENGTH;
192 }
193
194 if (option & AP_CTIME_OPTION_GMTOFF) {
195 needed += AP_CTIME_GMTOFF_LEN;
196 }
197
198 /* Check the provided buffer length (note: above AP_CTIME_COMPACT_LEN
199 * and APR_CTIME_LEN include the trailing '\0'; so does 'needed' then).
200 */
201 if (len && *len >= needed) {
202 *len = needed;
203 }
204 else {
205 if (len != NULL) {
206 *len = 0;
207 }
208 return APR_ENOMEM;
209 }
210
211 /* example without options: "Wed Jun 30 21:49:08 1993" */
212 /* example for compact format: "1993-06-30 21:49:08" */
213 /* example for compact+usec+gmtoff format:
214 * "1993-06-30 22:49:08.123456 +0100"
215 */
216
217 ap_explode_recent_localtime(&xt, t);
218 real_year = 1900 + xt.tm_year;
219 if (option & AP_CTIME_OPTION_COMPACT) {
220 int real_month = xt.tm_mon + 1;
221 *date_str++ = real_year / 1000 + '0';
222 *date_str++ = real_year % 1000 / 100 + '0';
223 *date_str++ = real_year % 100 / 10 + '0';
224 *date_str++ = real_year % 10 + '0';
225 *date_str++ = '-';
226 *date_str++ = real_month / 10 + '0';

Callers 2

log_ctimeFunction · 0.85
ap_recent_ctimeFunction · 0.85

Calls 1

Tested by

no test coverage detected