xref: /dragonfly/lib/libc/stdtime/timelocal.c (revision 222a27c4)
1 /*-
2  * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
3  * Copyright (c) 1997 FreeBSD Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  * $FreeBSD: src/lib/libc/stdtime/timelocal.c,v 1.8.2.4 2002/08/12 11:20:24 ache Exp $
28  * $DragonFly: src/lib/libc/stdtime/timelocal.c,v 1.3 2005/01/31 22:29:44 dillon Exp $
29  */
30 
31 #include "namespace.h"
32 #include <stddef.h>
33 #include <unistd.h>
34 #include "un-namespace.h"
35 
36 #include "ldpart.h"
37 #include "timelocal.h"
38 
39 static struct lc_time_T _time_locale;
40 static int _time_using_locale;
41 static char *time_locale_buf;
42 
43 #define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *))
44 
45 static const struct lc_time_T	_C_time_locale = {
46 	{
47 		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
48 		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
49 	}, {
50 		"January", "February", "March", "April", "May", "June",
51 		"July", "August", "September", "October", "November", "December"
52 	}, {
53 		"Sun", "Mon", "Tue", "Wed",
54 		"Thu", "Fri", "Sat"
55 	}, {
56 		"Sunday", "Monday", "Tuesday", "Wednesday",
57 		"Thursday", "Friday", "Saturday"
58 	},
59 
60 	/* X_fmt */
61 	"%H:%M:%S",
62 
63 	/*
64 	 * x_fmt
65 	 * Since the C language standard calls for
66 	 * "date, using locale's date format," anything goes.
67 	 * Using just numbers (as here) makes Quakers happier;
68 	 * it's also compatible with SVR4.
69 	 */
70 	"%m/%d/%y",
71 
72 	/*
73 	 * c_fmt
74 	 */
75 	"%a %b %e %H:%M:%S %Y",
76 
77 	/* am */
78 	"AM",
79 
80 	/* pm */
81 	"PM",
82 
83 	/* date_fmt */
84 	"%a %b %e %H:%M:%S %Z %Y",
85 
86 	/* alt_month
87 	 * Standalone months forms for %OB
88 	 */
89 	{
90 		"January", "February", "March", "April", "May", "June",
91 		"July", "August", "September", "October", "November", "December"
92 	},
93 
94 	/* md_order
95 	 * Month / day order in dates
96 	 */
97 	"md",
98 
99 	/* ampm_fmt
100 	 * To determine 12-hour clock format time (empty, if N/A)
101 	 */
102 	"%I:%M:%S %p"
103 };
104 
105 struct lc_time_T *
106 __get_current_time_locale(void)
107 {
108 	return (_time_using_locale
109 		? &_time_locale
110 		: (struct lc_time_T *)&_C_time_locale);
111 }
112 
113 int
114 __time_load_locale(const char *name)
115 {
116 	return (__part_load_locale(name, &_time_using_locale,
117 			time_locale_buf, "LC_TIME",
118 			LCTIME_SIZE, LCTIME_SIZE,
119 			(const char **)&_time_locale));
120 }
121