timelocal.c revision 74412
1135446Strhodes/*-
2193149Sdougb * Copyright (c) 2001 Alexey Zelkin
3135446Strhodes * Copyright (c) 1997 FreeBSD Inc.
4135446Strhodes * All rights reserved.
5193149Sdougb *
6135446Strhodes * Redistribution and use in source and binary forms, with or without
7135446Strhodes * modification, are permitted provided that the following conditions
8135446Strhodes * are met:
9135446Strhodes * 1. Redistributions of source code must retain the above copyright
10135446Strhodes *    notice, this list of conditions and the following disclaimer.
11135446Strhodes * 2. Redistributions in binary form must reproduce the above copyright
12135446Strhodes *    notice, this list of conditions and the following disclaimer in the
13135446Strhodes *    documentation and/or other materials provided with the distribution.
14135446Strhodes *
15135446Strhodes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16135446Strhodes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17135446Strhodes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18135446Strhodes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19135446Strhodes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20135446Strhodes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21234010Sdougb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22135446Strhodes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23170222Sdougb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24170222Sdougb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25135446Strhodes * SUCH DAMAGE.
26135446Strhodes *
27135446Strhodes * $FreeBSD: head/lib/libc/stdtime/timelocal.c 74412 2001-03-18 11:58:15Z ache $
28135446Strhodes */
29135446Strhodes
30135446Strhodes#include <stddef.h>
31135446Strhodes
32135446Strhodes#include "ldpart.h"
33135446Strhodes#include "timelocal.h"
34135446Strhodes
35static struct lc_time_T _time_locale;
36static int _time_using_locale;
37static char * time_locale_buf;
38
39#define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *))
40
41static const struct lc_time_T	_C_time_locale = {
42	{
43		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
44		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
45	}, {
46		"January", "February", "March", "April", "May", "June",
47		"July", "August", "September", "October", "November", "December"
48	}, {
49		"Sun", "Mon", "Tue", "Wed",
50		"Thu", "Fri", "Sat"
51	}, {
52		"Sunday", "Monday", "Tuesday", "Wednesday",
53		"Thursday", "Friday", "Saturday"
54	},
55
56	/* X_fmt */
57	"%H:%M:%S",
58
59	/*
60	** x_fmt
61	** Since the C language standard calls for
62	** "date, using locale's date format," anything goes.
63	** Using just numbers (as here) makes Quakers happier;
64	** it's also compatible with SVR4.
65	*/
66	"%m/%d/%y",
67
68	/*
69	** c_fmt (ctime-compatible)
70	*/
71	"%a %b %e %T %Y",
72
73	/* am */
74	"AM",
75
76	/* pm */
77	"PM",
78
79	/* date_fmt */
80	"%a %b %e %X %Z %Y",
81
82	/* alt_month
83	** Standalone motnhs forms for %OB
84	*/
85	{
86		"January", "February", "March", "April", "May", "June",
87		"July", "August", "September", "October", "November", "December"
88	},
89
90	/* md_order
91	** Month / day order in dates
92	*/
93	"md",
94
95	/* ampm_fmt
96	** To determine 12-hour clock format time (empty, if N/A)
97	*/
98	"%I:%M:%S %p"
99};
100
101struct lc_time_T *
102__get_current_time_locale(void) {
103	return (_time_using_locale
104		? &_time_locale
105		: (struct lc_time_T *)&_C_time_locale);
106}
107
108int
109__time_load_locale(const char *name) {
110
111	int	ret;
112
113	ret = __part_load_locale(name, &_time_using_locale,
114			time_locale_buf, "LC_TIME",
115			LCTIME_SIZE, LCTIME_SIZE,
116			(const char **)&_time_locale);
117
118	return (ret);
119}
120