14297a3b0SGarrett D'Amore /*
2*62c3776aSGarrett D'Amore * Copyright 2014 Garrett D'Amore <garrett@damore.org>
36b5e5868SGarrett D'Amore * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
44297a3b0SGarrett D'Amore * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
54297a3b0SGarrett D'Amore * Copyright (c) 1997 FreeBSD Inc.
64297a3b0SGarrett D'Amore * All rights reserved.
74297a3b0SGarrett D'Amore *
84297a3b0SGarrett D'Amore * Redistribution and use in source and binary forms, with or without
94297a3b0SGarrett D'Amore * modification, are permitted provided that the following conditions
104297a3b0SGarrett D'Amore * are met:
114297a3b0SGarrett D'Amore * 1. Redistributions of source code must retain the above copyright
124297a3b0SGarrett D'Amore * notice, this list of conditions and the following disclaimer.
134297a3b0SGarrett D'Amore * 2. Redistributions in binary form must reproduce the above copyright
144297a3b0SGarrett D'Amore * notice, this list of conditions and the following disclaimer in the
154297a3b0SGarrett D'Amore * documentation and/or other materials provided with the distribution.
164297a3b0SGarrett D'Amore *
174297a3b0SGarrett D'Amore * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
184297a3b0SGarrett D'Amore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
194297a3b0SGarrett D'Amore * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
204297a3b0SGarrett D'Amore * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
214297a3b0SGarrett D'Amore * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
224297a3b0SGarrett D'Amore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
234297a3b0SGarrett D'Amore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
244297a3b0SGarrett D'Amore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
254297a3b0SGarrett D'Amore * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
264297a3b0SGarrett D'Amore * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
274297a3b0SGarrett D'Amore * SUCH DAMAGE.
284297a3b0SGarrett D'Amore */
294297a3b0SGarrett D'Amore
304297a3b0SGarrett D'Amore #include "lint.h"
314297a3b0SGarrett D'Amore #include <stddef.h>
32*62c3776aSGarrett D'Amore #include <errno.h>
334297a3b0SGarrett D'Amore #include "ldpart.h"
344297a3b0SGarrett D'Amore #include "timelocal.h"
35*62c3776aSGarrett D'Amore #include "localeimpl.h"
364297a3b0SGarrett D'Amore
37*62c3776aSGarrett D'Amore #define LCTIME_SIZE (sizeof (struct lc_time) / sizeof (char *))
384297a3b0SGarrett D'Amore
39*62c3776aSGarrett D'Amore struct lc_time lc_time_posix = {
404297a3b0SGarrett D'Amore {
414297a3b0SGarrett D'Amore "Jan", "Feb", "Mar", "Apr", "May", "Jun",
424297a3b0SGarrett D'Amore "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
434297a3b0SGarrett D'Amore }, {
444297a3b0SGarrett D'Amore "January", "February", "March", "April", "May", "June",
454297a3b0SGarrett D'Amore "July", "August", "September", "October", "November", "December"
464297a3b0SGarrett D'Amore }, {
474297a3b0SGarrett D'Amore "Sun", "Mon", "Tue", "Wed",
484297a3b0SGarrett D'Amore "Thu", "Fri", "Sat"
494297a3b0SGarrett D'Amore }, {
504297a3b0SGarrett D'Amore "Sunday", "Monday", "Tuesday", "Wednesday",
514297a3b0SGarrett D'Amore "Thursday", "Friday", "Saturday"
524297a3b0SGarrett D'Amore },
534297a3b0SGarrett D'Amore
544297a3b0SGarrett D'Amore /* X_fmt */
554297a3b0SGarrett D'Amore "%H:%M:%S",
564297a3b0SGarrett D'Amore
574297a3b0SGarrett D'Amore /*
584297a3b0SGarrett D'Amore * x_fmt
594297a3b0SGarrett D'Amore * Since the C language standard calls for
604297a3b0SGarrett D'Amore * "date, using locale's date format," anything goes.
614297a3b0SGarrett D'Amore * Using just numbers (as here) makes Quakers happier;
624297a3b0SGarrett D'Amore * it's also compatible with SVR4.
634297a3b0SGarrett D'Amore */
644297a3b0SGarrett D'Amore "%m/%d/%y",
654297a3b0SGarrett D'Amore
664297a3b0SGarrett D'Amore /*
674297a3b0SGarrett D'Amore * c_fmt
684297a3b0SGarrett D'Amore */
694297a3b0SGarrett D'Amore "%a %b %e %H:%M:%S %Y",
704297a3b0SGarrett D'Amore
714297a3b0SGarrett D'Amore /* am */
724297a3b0SGarrett D'Amore "AM",
734297a3b0SGarrett D'Amore
744297a3b0SGarrett D'Amore /* pm */
754297a3b0SGarrett D'Amore "PM",
764297a3b0SGarrett D'Amore
774297a3b0SGarrett D'Amore /* date_fmt */
784297a3b0SGarrett D'Amore "%a %b %e %H:%M:%S %Z %Y",
794297a3b0SGarrett D'Amore
804297a3b0SGarrett D'Amore /*
814297a3b0SGarrett D'Amore * ampm_fmt - To determine 12-hour clock format time (empty, if N/A)
824297a3b0SGarrett D'Amore */
834297a3b0SGarrett D'Amore "%I:%M:%S %p"
844297a3b0SGarrett D'Amore };
854297a3b0SGarrett D'Amore
86*62c3776aSGarrett D'Amore struct locdata __posix_time_locdata = {
87*62c3776aSGarrett D'Amore .l_lname = "C",
88*62c3776aSGarrett D'Amore .l_data = { &lc_time_posix }
89*62c3776aSGarrett D'Amore };
90*62c3776aSGarrett D'Amore
91*62c3776aSGarrett D'Amore struct locdata *
__lc_time_load(const char * name)92*62c3776aSGarrett D'Amore __lc_time_load(const char *name)
934297a3b0SGarrett D'Amore {
94*62c3776aSGarrett D'Amore struct locdata *ldata;
95*62c3776aSGarrett D'Amore struct lc_time *ltime;
96*62c3776aSGarrett D'Amore int ret;
97*62c3776aSGarrett D'Amore
98*62c3776aSGarrett D'Amore if ((ldata = __locdata_alloc(name, sizeof (*ltime))) == NULL) {
99*62c3776aSGarrett D'Amore errno = EINVAL;
100*62c3776aSGarrett D'Amore return (NULL);
101*62c3776aSGarrett D'Amore }
102*62c3776aSGarrett D'Amore ltime = ldata->l_data[0];
103*62c3776aSGarrett D'Amore
104*62c3776aSGarrett D'Amore ret = __part_load_locale(name, (char **)&ldata->l_data[1],
105*62c3776aSGarrett D'Amore "LC_TIME", LCTIME_SIZE, LCTIME_SIZE, (const char **)ltime);
106*62c3776aSGarrett D'Amore
107*62c3776aSGarrett D'Amore if (ret != _LDP_LOADED) {
108*62c3776aSGarrett D'Amore __locdata_free(ldata);
109*62c3776aSGarrett D'Amore errno = EINVAL;
110*62c3776aSGarrett D'Amore return (NULL);
1114297a3b0SGarrett D'Amore }
1124297a3b0SGarrett D'Amore
113*62c3776aSGarrett D'Amore return (ldata);
1144297a3b0SGarrett D'Amore }
115