xref: /titanic_41/usr/src/lib/libc/port/locale/timelocal.c (revision dc86508e0cf00a9f553cad05c9168a9ff8072dc6)
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 
28 /*
29  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
30  * Use is subject to license terms.
31  */
32 
33 #include "lint.h"
34 #include <stddef.h>
35 #include "ldpart.h"
36 #include "timelocal.h"
37 
38 static struct lc_time_T _time_locale;
39 static int _time_using_locale;
40 static char *time_locale_buf;
41 
42 #define	LCTIME_SIZE (sizeof (struct lc_time_T) / sizeof (char *))
43 
44 static const struct lc_time_T	_C_time_locale = {
45 	{
46 		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
47 		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
48 	}, {
49 		"January", "February", "March", "April", "May", "June",
50 		"July", "August", "September", "October", "November", "December"
51 	}, {
52 		"Sun", "Mon", "Tue", "Wed",
53 		"Thu", "Fri", "Sat"
54 	}, {
55 		"Sunday", "Monday", "Tuesday", "Wednesday",
56 		"Thursday", "Friday", "Saturday"
57 	},
58 
59 	/* X_fmt */
60 	"%H:%M:%S",
61 
62 	/*
63 	 * x_fmt
64 	 * Since the C language standard calls for
65 	 * "date, using locale's date format," anything goes.
66 	 * Using just numbers (as here) makes Quakers happier;
67 	 * it's also compatible with SVR4.
68 	 */
69 	"%m/%d/%y",
70 
71 	/*
72 	 * c_fmt
73 	 */
74 	"%a %b %e %H:%M:%S %Y",
75 
76 	/* am */
77 	"AM",
78 
79 	/* pm */
80 	"PM",
81 
82 	/* date_fmt */
83 	"%a %b %e %H:%M:%S %Z %Y",
84 
85 	/*
86 	 * ampm_fmt - To determine 12-hour clock format time (empty, if N/A)
87 	 */
88 	"%I:%M:%S %p"
89 };
90 
91 struct lc_time_T *
92 __get_current_time_locale(void)
93 {
94 	return (_time_using_locale ? &_time_locale :
95 	    (struct lc_time_T *)&_C_time_locale);
96 }
97 
98 int
99 __time_load_locale(const char *name)
100 {
101 	return (__part_load_locale(name, &_time_using_locale,
102 	    &time_locale_buf, "LC_TIME", LCTIME_SIZE, LCTIME_SIZE,
103 	    (const char **)&_time_locale));
104 }
105