timelocal.c revision 87659
128021Sjoerg/*-
287659Sphantom * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
328021Sjoerg * Copyright (c) 1997 FreeBSD Inc.
428021Sjoerg * All rights reserved.
528021Sjoerg *
628021Sjoerg * Redistribution and use in source and binary forms, with or without
728021Sjoerg * modification, are permitted provided that the following conditions
828021Sjoerg * are met:
928021Sjoerg * 1. Redistributions of source code must retain the above copyright
1028021Sjoerg *    notice, this list of conditions and the following disclaimer.
1128021Sjoerg * 2. Redistributions in binary form must reproduce the above copyright
1228021Sjoerg *    notice, this list of conditions and the following disclaimer in the
1328021Sjoerg *    documentation and/or other materials provided with the distribution.
1428021Sjoerg *
1528021Sjoerg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1628021Sjoerg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1728021Sjoerg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1828021Sjoerg * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1928021Sjoerg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2028021Sjoerg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2128021Sjoerg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2228021Sjoerg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2328021Sjoerg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2428021Sjoerg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2528021Sjoerg * SUCH DAMAGE.
2628021Sjoerg *
2750476Speter * $FreeBSD: head/lib/libc/stdtime/timelocal.c 87659 2001-12-11 16:00:47Z phantom $
2828021Sjoerg */
2928021Sjoerg
3073359Sache#include <stddef.h>
3173359Sache
3272406Sphantom#include "ldpart.h"
3328021Sjoerg#include "timelocal.h"
3428021Sjoerg
3572406Sphantomstatic struct lc_time_T _time_locale;
3672167Sphantomstatic int _time_using_locale;
3772406Sphantomstatic char * time_locale_buf;
3828021Sjoerg
3974412Sache#define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *))
4051186Sdt
4172167Sphantomstatic const struct lc_time_T	_C_time_locale = {
4228021Sjoerg	{
4328021Sjoerg		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
4428021Sjoerg		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
4528021Sjoerg	}, {
4628021Sjoerg		"January", "February", "March", "April", "May", "June",
4728021Sjoerg		"July", "August", "September", "October", "November", "December"
4828021Sjoerg	}, {
4928021Sjoerg		"Sun", "Mon", "Tue", "Wed",
5028021Sjoerg		"Thu", "Fri", "Sat"
5128021Sjoerg	}, {
5228021Sjoerg		"Sunday", "Monday", "Tuesday", "Wednesday",
5328021Sjoerg		"Thursday", "Friday", "Saturday"
5428021Sjoerg	},
5528021Sjoerg
5628021Sjoerg	/* X_fmt */
5728021Sjoerg	"%H:%M:%S",
5828021Sjoerg
5928021Sjoerg	/*
6028021Sjoerg	** x_fmt
6128021Sjoerg	** Since the C language standard calls for
6228021Sjoerg	** "date, using locale's date format," anything goes.
6328021Sjoerg	** Using just numbers (as here) makes Quakers happier;
6428021Sjoerg	** it's also compatible with SVR4.
6528021Sjoerg	*/
6674572Sache	"%m/%d/%y",
6728021Sjoerg
6828021Sjoerg	/*
6974572Sache	** c_fmt
7028021Sjoerg	*/
7174572Sache	"%a %b %e %H:%M:%S %Y",
7228021Sjoerg
7328021Sjoerg	/* am */
7428021Sjoerg	"AM",
7528021Sjoerg
7628021Sjoerg	/* pm */
7728021Sjoerg	"PM",
7828021Sjoerg
7928021Sjoerg	/* date_fmt */
8074572Sache	"%a %b %e %H:%M:%S %Z %Y",
8151186Sdt
8274412Sache	/* alt_month
8374414Sache	** Standalone months forms for %OB
8474412Sache	*/
8551186Sdt	{
8651186Sdt		"January", "February", "March", "April", "May", "June",
8751186Sdt		"July", "August", "September", "October", "November", "December"
8853940Sache	},
8953940Sache
9074412Sache	/* md_order
9174412Sache	** Month / day order in dates
9253940Sache	*/
9374412Sache	"md",
9453960Sache
9573359Sache	/* ampm_fmt
9673359Sache	** To determine 12-hour clock format time (empty, if N/A)
9773359Sache	*/
9873359Sache	"%I:%M:%S %p"
9928021Sjoerg};
10028021Sjoerg
10172167Sphantomstruct lc_time_T *
10272167Sphantom__get_current_time_locale(void) {
10372167Sphantom	return (_time_using_locale
10472406Sphantom		? &_time_locale
10572167Sphantom		: (struct lc_time_T *)&_C_time_locale);
10672167Sphantom}
10728021Sjoerg
10828021Sjoergint
10972406Sphantom__time_load_locale(const char *name) {
11028021Sjoerg
11172406Sphantom	int	ret;
11228021Sjoerg
11372406Sphantom	ret = __part_load_locale(name, &_time_using_locale,
11473359Sache			time_locale_buf, "LC_TIME",
11574412Sache			LCTIME_SIZE, LCTIME_SIZE,
11672406Sphantom			(const char **)&_time_locale);
11728021Sjoerg
11872406Sphantom	return (ret);
11951186Sdt}
120