11811bdf3SPeter Wemm /*-
2*8a16b7a1SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause
3*8a16b7a1SPedro F. Giffuni *
41811bdf3SPeter Wemm * Copyright (c) 1980, 1993
51811bdf3SPeter Wemm * The Regents of the University of California. All rights reserved.
61811bdf3SPeter Wemm *
71811bdf3SPeter Wemm * Redistribution and use in source and binary forms, with or without
81811bdf3SPeter Wemm * modification, are permitted provided that the following conditions
91811bdf3SPeter Wemm * are met:
101811bdf3SPeter Wemm * 1. Redistributions of source code must retain the above copyright
111811bdf3SPeter Wemm * notice, this list of conditions and the following disclaimer.
121811bdf3SPeter Wemm * 2. Redistributions in binary form must reproduce the above copyright
131811bdf3SPeter Wemm * notice, this list of conditions and the following disclaimer in the
141811bdf3SPeter Wemm * documentation and/or other materials provided with the distribution.
15fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors
161811bdf3SPeter Wemm * may be used to endorse or promote products derived from this software
171811bdf3SPeter Wemm * without specific prior written permission.
181811bdf3SPeter Wemm *
191811bdf3SPeter Wemm * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
201811bdf3SPeter Wemm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
211811bdf3SPeter Wemm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
221811bdf3SPeter Wemm * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
231811bdf3SPeter Wemm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
241811bdf3SPeter Wemm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
251811bdf3SPeter Wemm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
261811bdf3SPeter Wemm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
271811bdf3SPeter Wemm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
281811bdf3SPeter Wemm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
291811bdf3SPeter Wemm * SUCH DAMAGE.
301811bdf3SPeter Wemm */
311811bdf3SPeter Wemm
321811bdf3SPeter Wemm #include <time.h>
331811bdf3SPeter Wemm
341811bdf3SPeter Wemm /*
351811bdf3SPeter Wemm * Convert a ctime(3) format string into a system format date.
361811bdf3SPeter Wemm * Return the date thus calculated.
371811bdf3SPeter Wemm *
381811bdf3SPeter Wemm * Return -1 if the string is not in ctime format.
391811bdf3SPeter Wemm */
401811bdf3SPeter Wemm time_t
unctime(char * str)412db673abSWarner Losh unctime(char *str)
421811bdf3SPeter Wemm {
431811bdf3SPeter Wemm struct tm then;
441811bdf3SPeter Wemm
45d6669bbcSRuslan Ermilov str = strptime(str, "%a %b %e %T %Y", &then);
46d6669bbcSRuslan Ermilov if (str == NULL || (*str != '\n' && *str != '\0'))
47d6669bbcSRuslan Ermilov return ((time_t)-1);
481811bdf3SPeter Wemm then.tm_isdst = -1;
491811bdf3SPeter Wemm return (mktime(&then));
501811bdf3SPeter Wemm }
51