137486f03SJoerg Wunsch /*- 252d6b430SAlexey Zelkin * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org> 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 */ 2737486f03SJoerg Wunsch 28333fc21eSDavid E. O'Brien #include <sys/cdefs.h> 29333fc21eSDavid E. O'Brien __FBSDID("$FreeBSD$"); 30333fc21eSDavid E. O'Brien 3150bab1e6SAndrey A. Chernov #include <stddef.h> 3250bab1e6SAndrey A. Chernov 334e862380SAlexey Zelkin #include "ldpart.h" 3437486f03SJoerg Wunsch #include "timelocal.h" 3537486f03SJoerg Wunsch 364e862380SAlexey Zelkin static struct lc_time_T _time_locale; 3718f3e1e4SAlexey Zelkin static int _time_using_locale; 384e862380SAlexey Zelkin static char *time_locale_buf; 3937486f03SJoerg Wunsch 40faeb1b82SAndrey A. Chernov #define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *)) 41da3785efSDmitrij Tejblum 4218f3e1e4SAlexey Zelkin static const struct lc_time_T _C_time_locale = { 4337486f03SJoerg Wunsch { 4437486f03SJoerg Wunsch "Jan", "Feb", "Mar", "Apr", "May", "Jun", 4537486f03SJoerg Wunsch "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 4637486f03SJoerg Wunsch }, { 4737486f03SJoerg Wunsch "January", "February", "March", "April", "May", "June", 4837486f03SJoerg Wunsch "July", "August", "September", "October", "November", "December" 4937486f03SJoerg Wunsch }, { 5037486f03SJoerg Wunsch "Sun", "Mon", "Tue", "Wed", 5137486f03SJoerg Wunsch "Thu", "Fri", "Sat" 5237486f03SJoerg Wunsch }, { 5337486f03SJoerg Wunsch "Sunday", "Monday", "Tuesday", "Wednesday", 5437486f03SJoerg Wunsch "Thursday", "Friday", "Saturday" 5537486f03SJoerg Wunsch }, 5637486f03SJoerg Wunsch 5737486f03SJoerg Wunsch /* X_fmt */ 5837486f03SJoerg Wunsch "%H:%M:%S", 5937486f03SJoerg Wunsch 6037486f03SJoerg Wunsch /* 61bcbeac34SAlexey Zelkin * x_fmt 62bcbeac34SAlexey Zelkin * Since the C language standard calls for 63bcbeac34SAlexey Zelkin * "date, using locale's date format," anything goes. 64bcbeac34SAlexey Zelkin * Using just numbers (as here) makes Quakers happier; 65bcbeac34SAlexey Zelkin * it's also compatible with SVR4. 6637486f03SJoerg Wunsch */ 6750b4c62cSAndrey A. Chernov "%m/%d/%y", 6837486f03SJoerg Wunsch 6937486f03SJoerg Wunsch /* 70bcbeac34SAlexey Zelkin * c_fmt 7137486f03SJoerg Wunsch */ 7250b4c62cSAndrey A. Chernov "%a %b %e %H:%M:%S %Y", 7337486f03SJoerg Wunsch 7437486f03SJoerg Wunsch /* am */ 7537486f03SJoerg Wunsch "AM", 7637486f03SJoerg Wunsch 7737486f03SJoerg Wunsch /* pm */ 7837486f03SJoerg Wunsch "PM", 7937486f03SJoerg Wunsch 8037486f03SJoerg Wunsch /* date_fmt */ 8150b4c62cSAndrey A. Chernov "%a %b %e %H:%M:%S %Z %Y", 82da3785efSDmitrij Tejblum 83faeb1b82SAndrey A. Chernov /* alt_month 84bcbeac34SAlexey Zelkin * Standalone months forms for %OB 85faeb1b82SAndrey A. Chernov */ 86da3785efSDmitrij Tejblum { 87da3785efSDmitrij Tejblum "January", "February", "March", "April", "May", "June", 88da3785efSDmitrij Tejblum "July", "August", "September", "October", "November", "December" 8911cd0d32SAndrey A. Chernov }, 9011cd0d32SAndrey A. Chernov 91faeb1b82SAndrey A. Chernov /* md_order 92bcbeac34SAlexey Zelkin * Month / day order in dates 9311cd0d32SAndrey A. Chernov */ 94faeb1b82SAndrey A. Chernov "md", 9550bab1e6SAndrey A. Chernov 9650bab1e6SAndrey A. Chernov /* ampm_fmt 97bcbeac34SAlexey Zelkin * To determine 12-hour clock format time (empty, if N/A) 9850bab1e6SAndrey A. Chernov */ 9950bab1e6SAndrey A. Chernov "%I:%M:%S %p" 10037486f03SJoerg Wunsch }; 10137486f03SJoerg Wunsch 10218f3e1e4SAlexey Zelkin struct lc_time_T * 1031491b31eSAndrey A. Chernov __get_current_time_locale(void) 1041491b31eSAndrey A. Chernov { 10518f3e1e4SAlexey Zelkin return (_time_using_locale 1064e862380SAlexey Zelkin ? &_time_locale 10718f3e1e4SAlexey Zelkin : (struct lc_time_T *)&_C_time_locale); 10818f3e1e4SAlexey Zelkin } 10937486f03SJoerg Wunsch 11037486f03SJoerg Wunsch int 1111491b31eSAndrey A. Chernov __time_load_locale(const char *name) 1121491b31eSAndrey A. Chernov { 1131491b31eSAndrey A. Chernov return (__part_load_locale(name, &_time_using_locale, 11450bab1e6SAndrey A. Chernov time_locale_buf, "LC_TIME", 115faeb1b82SAndrey A. Chernov LCTIME_SIZE, LCTIME_SIZE, 1161491b31eSAndrey A. Chernov (const char **)&_time_locale)); 117da3785efSDmitrij Tejblum } 118