137486f03SJoerg Wunsch /*- 24e862380SAlexey Zelkin * Copyright (c) 2001 Alexey Zelkin 337486f03SJoerg Wunsch * Copyright (c) 1997 FreeBSD Inc. 437486f03SJoerg Wunsch * All rights reserved. 537486f03SJoerg Wunsch * 637486f03SJoerg Wunsch * Redistribution and use in source and binary forms, with or without 737486f03SJoerg Wunsch * modification, are permitted provided that the following conditions 837486f03SJoerg Wunsch * are met: 937486f03SJoerg Wunsch * 1. Redistributions of source code must retain the above copyright 1037486f03SJoerg Wunsch * notice, this list of conditions and the following disclaimer. 1137486f03SJoerg Wunsch * 2. Redistributions in binary form must reproduce the above copyright 1237486f03SJoerg Wunsch * notice, this list of conditions and the following disclaimer in the 1337486f03SJoerg Wunsch * documentation and/or other materials provided with the distribution. 1437486f03SJoerg Wunsch * 1537486f03SJoerg Wunsch * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1637486f03SJoerg Wunsch * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1737486f03SJoerg Wunsch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1837486f03SJoerg Wunsch * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1937486f03SJoerg Wunsch * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2037486f03SJoerg Wunsch * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2137486f03SJoerg Wunsch * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2237486f03SJoerg Wunsch * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2337486f03SJoerg Wunsch * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2437486f03SJoerg Wunsch * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2537486f03SJoerg Wunsch * SUCH DAMAGE. 2637486f03SJoerg Wunsch * 277f3dea24SPeter Wemm * $FreeBSD$ 2837486f03SJoerg Wunsch */ 2937486f03SJoerg Wunsch 3050bab1e6SAndrey A. Chernov #include <stddef.h> 3150bab1e6SAndrey A. Chernov 324e862380SAlexey Zelkin #include "ldpart.h" 3337486f03SJoerg Wunsch #include "timelocal.h" 3437486f03SJoerg Wunsch 354e862380SAlexey Zelkin static struct lc_time_T _time_locale; 3618f3e1e4SAlexey Zelkin static int _time_using_locale; 374e862380SAlexey Zelkin static char * time_locale_buf; 3837486f03SJoerg Wunsch 39faeb1b82SAndrey A. Chernov #define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *)) 40da3785efSDmitrij Tejblum 4118f3e1e4SAlexey Zelkin static const struct lc_time_T _C_time_locale = { 4237486f03SJoerg Wunsch { 4337486f03SJoerg Wunsch "Jan", "Feb", "Mar", "Apr", "May", "Jun", 4437486f03SJoerg Wunsch "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 4537486f03SJoerg Wunsch }, { 4637486f03SJoerg Wunsch "January", "February", "March", "April", "May", "June", 4737486f03SJoerg Wunsch "July", "August", "September", "October", "November", "December" 4837486f03SJoerg Wunsch }, { 4937486f03SJoerg Wunsch "Sun", "Mon", "Tue", "Wed", 5037486f03SJoerg Wunsch "Thu", "Fri", "Sat" 5137486f03SJoerg Wunsch }, { 5237486f03SJoerg Wunsch "Sunday", "Monday", "Tuesday", "Wednesday", 5337486f03SJoerg Wunsch "Thursday", "Friday", "Saturday" 5437486f03SJoerg Wunsch }, 5537486f03SJoerg Wunsch 5637486f03SJoerg Wunsch /* X_fmt */ 5737486f03SJoerg Wunsch "%H:%M:%S", 5837486f03SJoerg Wunsch 5937486f03SJoerg Wunsch /* 6037486f03SJoerg Wunsch ** x_fmt 6137486f03SJoerg Wunsch ** Since the C language standard calls for 6237486f03SJoerg Wunsch ** "date, using locale's date format," anything goes. 6337486f03SJoerg Wunsch ** Using just numbers (as here) makes Quakers happier; 6437486f03SJoerg Wunsch ** it's also compatible with SVR4. 6537486f03SJoerg Wunsch */ 6650b4c62cSAndrey A. Chernov "%m/%d/%y", 6737486f03SJoerg Wunsch 6837486f03SJoerg Wunsch /* 6950b4c62cSAndrey A. Chernov ** c_fmt 7037486f03SJoerg Wunsch */ 7150b4c62cSAndrey A. Chernov "%a %b %e %H:%M:%S %Y", 7237486f03SJoerg Wunsch 7337486f03SJoerg Wunsch /* am */ 7437486f03SJoerg Wunsch "AM", 7537486f03SJoerg Wunsch 7637486f03SJoerg Wunsch /* pm */ 7737486f03SJoerg Wunsch "PM", 7837486f03SJoerg Wunsch 7937486f03SJoerg Wunsch /* date_fmt */ 8050b4c62cSAndrey A. Chernov "%a %b %e %H:%M:%S %Z %Y", 81da3785efSDmitrij Tejblum 82faeb1b82SAndrey A. Chernov /* alt_month 8316a7ebb6SAndrey A. Chernov ** Standalone months forms for %OB 84faeb1b82SAndrey A. Chernov */ 85da3785efSDmitrij Tejblum { 86da3785efSDmitrij Tejblum "January", "February", "March", "April", "May", "June", 87da3785efSDmitrij Tejblum "July", "August", "September", "October", "November", "December" 8811cd0d32SAndrey A. Chernov }, 8911cd0d32SAndrey A. Chernov 90faeb1b82SAndrey A. Chernov /* md_order 91faeb1b82SAndrey A. Chernov ** Month / day order in dates 9211cd0d32SAndrey A. Chernov */ 93faeb1b82SAndrey A. Chernov "md", 9450bab1e6SAndrey A. Chernov 9550bab1e6SAndrey A. Chernov /* ampm_fmt 9650bab1e6SAndrey A. Chernov ** To determine 12-hour clock format time (empty, if N/A) 9750bab1e6SAndrey A. Chernov */ 9850bab1e6SAndrey A. Chernov "%I:%M:%S %p" 9937486f03SJoerg Wunsch }; 10037486f03SJoerg Wunsch 10118f3e1e4SAlexey Zelkin struct lc_time_T * 10218f3e1e4SAlexey Zelkin __get_current_time_locale(void) { 10318f3e1e4SAlexey Zelkin return (_time_using_locale 1044e862380SAlexey Zelkin ? &_time_locale 10518f3e1e4SAlexey Zelkin : (struct lc_time_T *)&_C_time_locale); 10618f3e1e4SAlexey Zelkin } 10737486f03SJoerg Wunsch 10837486f03SJoerg Wunsch int 1094e862380SAlexey Zelkin __time_load_locale(const char *name) { 11037486f03SJoerg Wunsch 1114e862380SAlexey Zelkin int ret; 11237486f03SJoerg Wunsch 1134e862380SAlexey Zelkin ret = __part_load_locale(name, &_time_using_locale, 11450bab1e6SAndrey A. Chernov time_locale_buf, "LC_TIME", 115faeb1b82SAndrey A. Chernov LCTIME_SIZE, LCTIME_SIZE, 1164e862380SAlexey Zelkin (const char **)&_time_locale); 11737486f03SJoerg Wunsch 1184e862380SAlexey Zelkin return (ret); 119da3785efSDmitrij Tejblum } 120