timelocal.c revision 92986
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 */
2728021Sjoerg
2892986Sobrien#include <sys/cdefs.h>
2992986Sobrien__FBSDID("$FreeBSD: head/lib/libc/stdtime/timelocal.c 92986 2002-03-22 21:53:29Z obrien $");
3092986Sobrien
3173359Sache#include <stddef.h>
3273359Sache
3372406Sphantom#include "ldpart.h"
3428021Sjoerg#include "timelocal.h"
3528021Sjoerg
3672406Sphantomstatic struct lc_time_T _time_locale;
3772167Sphantomstatic int _time_using_locale;
3889736Sphantomstatic char *time_locale_buf;
3928021Sjoerg
4074412Sache#define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *))
4151186Sdt
4272167Sphantomstatic const struct lc_time_T	_C_time_locale = {
4328021Sjoerg	{
4428021Sjoerg		"Jan", "Feb", "Mar", "Apr", "May", "Jun",
4528021Sjoerg		"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
4628021Sjoerg	}, {
4728021Sjoerg		"January", "February", "March", "April", "May", "June",
4828021Sjoerg		"July", "August", "September", "October", "November", "December"
4928021Sjoerg	}, {
5028021Sjoerg		"Sun", "Mon", "Tue", "Wed",
5128021Sjoerg		"Thu", "Fri", "Sat"
5228021Sjoerg	}, {
5328021Sjoerg		"Sunday", "Monday", "Tuesday", "Wednesday",
5428021Sjoerg		"Thursday", "Friday", "Saturday"
5528021Sjoerg	},
5628021Sjoerg
5728021Sjoerg	/* X_fmt */
5828021Sjoerg	"%H:%M:%S",
5928021Sjoerg
6028021Sjoerg	/*
6189736Sphantom	 * x_fmt
6289736Sphantom	 * Since the C language standard calls for
6389736Sphantom	 * "date, using locale's date format," anything goes.
6489736Sphantom	 * Using just numbers (as here) makes Quakers happier;
6589736Sphantom	 * it's also compatible with SVR4.
6689736Sphantom	 */
6774572Sache	"%m/%d/%y",
6828021Sjoerg
6928021Sjoerg	/*
7089736Sphantom	 * c_fmt
7189736Sphantom	 */
7274572Sache	"%a %b %e %H:%M:%S %Y",
7328021Sjoerg
7428021Sjoerg	/* am */
7528021Sjoerg	"AM",
7628021Sjoerg
7728021Sjoerg	/* pm */
7828021Sjoerg	"PM",
7928021Sjoerg
8028021Sjoerg	/* date_fmt */
8174572Sache	"%a %b %e %H:%M:%S %Z %Y",
8251186Sdt
8374412Sache	/* alt_month
8489736Sphantom	 * Standalone months forms for %OB
8589736Sphantom	 */
8651186Sdt	{
8751186Sdt		"January", "February", "March", "April", "May", "June",
8851186Sdt		"July", "August", "September", "October", "November", "December"
8953940Sache	},
9053940Sache
9174412Sache	/* md_order
9289736Sphantom	 * Month / day order in dates
9389736Sphantom	 */
9474412Sache	"md",
9553960Sache
9673359Sache	/* ampm_fmt
9789736Sphantom	 * To determine 12-hour clock format time (empty, if N/A)
9889736Sphantom	 */
9973359Sache	"%I:%M:%S %p"
10028021Sjoerg};
10128021Sjoerg
10272167Sphantomstruct lc_time_T *
10372167Sphantom__get_current_time_locale(void) {
10472167Sphantom	return (_time_using_locale
10572406Sphantom		? &_time_locale
10672167Sphantom		: (struct lc_time_T *)&_C_time_locale);
10772167Sphantom}
10828021Sjoerg
10928021Sjoergint
11072406Sphantom__time_load_locale(const char *name) {
11128021Sjoerg
11272406Sphantom	int	ret;
11328021Sjoerg
11472406Sphantom	ret = __part_load_locale(name, &_time_using_locale,
11573359Sache			time_locale_buf, "LC_TIME",
11674412Sache			LCTIME_SIZE, LCTIME_SIZE,
11772406Sphantom			(const char **)&_time_locale);
11828021Sjoerg
11972406Sphantom	return (ret);
12051186Sdt}
121