1 /*
2 * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
3 * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
4 * Copyright (c) 1997 FreeBSD Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 #include "lint.h"
30 #include <stddef.h>
31 #include "ldpart.h"
32 #include "timelocal.h"
33
34 static struct lc_time_T _time_locale;
35 static int _time_using_locale;
36 static char *time_locale_buf;
37
38 #define LCTIME_SIZE (sizeof (struct lc_time_T) / sizeof (char *))
39
40 static const struct lc_time_T _C_time_locale = {
41 {
42 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
43 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
44 }, {
45 "January", "February", "March", "April", "May", "June",
46 "July", "August", "September", "October", "November", "December"
47 }, {
48 "Sun", "Mon", "Tue", "Wed",
49 "Thu", "Fri", "Sat"
50 }, {
51 "Sunday", "Monday", "Tuesday", "Wednesday",
52 "Thursday", "Friday", "Saturday"
53 },
54
55 /* X_fmt */
56 "%H:%M:%S",
57
58 /*
59 * x_fmt
60 * Since the C language standard calls for
67 /*
68 * c_fmt
69 */
70 "%a %b %e %H:%M:%S %Y",
71
72 /* am */
73 "AM",
74
75 /* pm */
76 "PM",
77
78 /* date_fmt */
79 "%a %b %e %H:%M:%S %Z %Y",
80
81 /*
82 * ampm_fmt - To determine 12-hour clock format time (empty, if N/A)
83 */
84 "%I:%M:%S %p"
85 };
86
87 struct lc_time_T *
88 __get_current_time_locale(void)
89 {
90 return (_time_using_locale ? &_time_locale :
91 (struct lc_time_T *)&_C_time_locale);
92 }
93
94 int
95 __time_load_locale(const char *name)
96 {
97 return (__part_load_locale(name, &_time_using_locale,
98 &time_locale_buf, "LC_TIME", LCTIME_SIZE, LCTIME_SIZE,
99 (const char **)&_time_locale));
100 }
|
1 /*
2 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
3 * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
4 * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
5 * Copyright (c) 1997 FreeBSD Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30 #include "lint.h"
31 #include <stddef.h>
32 #include <errno.h>
33 #include "ldpart.h"
34 #include "timelocal.h"
35 #include "localeimpl.h"
36
37 #define LCTIME_SIZE (sizeof (struct lc_time) / sizeof (char *))
38
39 struct lc_time lc_time_posix = {
40 {
41 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
42 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
43 }, {
44 "January", "February", "March", "April", "May", "June",
45 "July", "August", "September", "October", "November", "December"
46 }, {
47 "Sun", "Mon", "Tue", "Wed",
48 "Thu", "Fri", "Sat"
49 }, {
50 "Sunday", "Monday", "Tuesday", "Wednesday",
51 "Thursday", "Friday", "Saturday"
52 },
53
54 /* X_fmt */
55 "%H:%M:%S",
56
57 /*
58 * x_fmt
59 * Since the C language standard calls for
66 /*
67 * c_fmt
68 */
69 "%a %b %e %H:%M:%S %Y",
70
71 /* am */
72 "AM",
73
74 /* pm */
75 "PM",
76
77 /* date_fmt */
78 "%a %b %e %H:%M:%S %Z %Y",
79
80 /*
81 * ampm_fmt - To determine 12-hour clock format time (empty, if N/A)
82 */
83 "%I:%M:%S %p"
84 };
85
86 struct locdata __posix_time_locdata = {
87 .l_lname = "C",
88 .l_data = { &lc_time_posix }
89 };
90
91 struct locdata *
92 __lc_time_load(const char *name)
93 {
94 struct locdata *ldata;
95 struct lc_time *ltime;
96 int ret;
97
98 if ((ldata = __locdata_alloc(name, sizeof (*ltime))) == NULL) {
99 errno = EINVAL;
100 return (NULL);
101 }
102 ltime = ldata->l_data[0];
103
104 ret = __part_load_locale(name, (char **)&ldata->l_data[1],
105 "LC_TIME", LCTIME_SIZE, LCTIME_SIZE, (const char **)ltime);
106
107 if (ret != _LDP_LOADED) {
108 __locdata_free(ldata);
109 errno = EINVAL;
110 return (NULL);
111 }
112
113 return (ldata);
114 }
|