timelocal.c revision 72406
128021Sjoerg/*- 272406Sphantom * Copyright (c) 2001 Alexey Zelkin 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 72406 2001-02-12 08:53:33Z phantom $ 2828021Sjoerg */ 2928021Sjoerg 3072406Sphantom#include "ldpart.h" 3128021Sjoerg#include "timelocal.h" 3228021Sjoerg 3372406Sphantomstatic struct lc_time_T _time_locale; 3472167Sphantomstatic int _time_using_locale; 3572406Sphantomstatic char * time_locale_buf; 3628021Sjoerg 3772406Sphantom#define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *)) 3851186Sdt 3972167Sphantomstatic const struct lc_time_T _C_time_locale = { 4028021Sjoerg { 4128021Sjoerg "Jan", "Feb", "Mar", "Apr", "May", "Jun", 4228021Sjoerg "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 4328021Sjoerg }, { 4428021Sjoerg "January", "February", "March", "April", "May", "June", 4528021Sjoerg "July", "August", "September", "October", "November", "December" 4628021Sjoerg }, { 4728021Sjoerg "Sun", "Mon", "Tue", "Wed", 4828021Sjoerg "Thu", "Fri", "Sat" 4928021Sjoerg }, { 5028021Sjoerg "Sunday", "Monday", "Tuesday", "Wednesday", 5128021Sjoerg "Thursday", "Friday", "Saturday" 5228021Sjoerg }, 5328021Sjoerg 5428021Sjoerg /* X_fmt */ 5528021Sjoerg "%H:%M:%S", 5628021Sjoerg 5728021Sjoerg /* 5828021Sjoerg ** x_fmt 5928021Sjoerg ** Since the C language standard calls for 6028021Sjoerg ** "date, using locale's date format," anything goes. 6128021Sjoerg ** Using just numbers (as here) makes Quakers happier; 6228021Sjoerg ** it's also compatible with SVR4. 6328021Sjoerg */ 6428021Sjoerg "%m/%d/%y", 6528021Sjoerg 6628021Sjoerg /* 6728021Sjoerg ** c_fmt (ctime-compatible) 6828021Sjoerg */ 6972183Sache "%a %Ef %T %Y", 7028021Sjoerg 7128021Sjoerg /* am */ 7228021Sjoerg "AM", 7328021Sjoerg 7428021Sjoerg /* pm */ 7528021Sjoerg "PM", 7628021Sjoerg 7728021Sjoerg /* date_fmt */ 7853960Sache "%a %Ef %X %Z %Y", 7951186Sdt 8051186Sdt { 8151186Sdt "January", "February", "March", "April", "May", "June", 8251186Sdt "July", "August", "September", "October", "November", "December" 8353940Sache }, 8453940Sache 8553960Sache /* Ef_fmt 8653960Sache ** To determine short months / day order 8753940Sache */ 8853960Sache "%b %e", 8953960Sache 9053960Sache /* EF_fmt 9153960Sache ** To determine long months / day order 9253960Sache */ 9353960Sache "%B %e" 9428021Sjoerg}; 9528021Sjoerg 9672167Sphantomstruct lc_time_T * 9772167Sphantom__get_current_time_locale(void) { 9872167Sphantom return (_time_using_locale 9972406Sphantom ? &_time_locale 10072167Sphantom : (struct lc_time_T *)&_C_time_locale); 10172167Sphantom} 10228021Sjoerg 10328021Sjoergint 10472406Sphantom__time_load_locale(const char *name) { 10528021Sjoerg 10672406Sphantom int ret; 10728021Sjoerg 10872406Sphantom ret = __part_load_locale(name, &_time_using_locale, 10972406Sphantom time_locale_buf, "LC_TIME", LCTIME_SIZE, 11072406Sphantom (const char **)&_time_locale); 11128021Sjoerg 11272183Sache /* XXX: always overwrite for ctime format parsing compatibility */ 11372406Sphantom if (ret == 0 && _time_using_locale) 11472406Sphantom _time_locale.c_fmt = _C_time_locale.c_fmt; 11572406Sphantom return (ret); 11651186Sdt} 117