[444] | 1 | /*- |
---|
| 2 | * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org> |
---|
| 3 | * Copyright (c) 1997 FreeBSD Inc. |
---|
| 4 | * All rights reserved. |
---|
| 5 | * |
---|
| 6 | * Redistribution and use in source and binary forms, with or without |
---|
| 7 | * modification, are permitted provided that the following conditions |
---|
| 8 | * are met: |
---|
| 9 | * 1. Redistributions of source code must retain the above copyright |
---|
| 10 | * notice, this list of conditions and the following disclaimer. |
---|
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
| 12 | * notice, this list of conditions and the following disclaimer in the |
---|
| 13 | * documentation and/or other materials provided with the distribution. |
---|
| 14 | * |
---|
| 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
---|
| 16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
---|
| 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
| 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
| 21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
| 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
| 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
| 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
| 25 | * SUCH DAMAGE. |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | #include <sys/cdefs.h> |
---|
| 29 | |
---|
| 30 | #include <stddef.h> |
---|
| 31 | #include "setlocale.h" |
---|
| 32 | |
---|
| 33 | #define LCTIME_SIZE (sizeof(struct lc_time_T) / sizeof(char *)) |
---|
| 34 | |
---|
| 35 | const struct lc_time_T _C_time_locale = { |
---|
| 36 | { |
---|
| 37 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
---|
| 38 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
---|
| 39 | }, { |
---|
| 40 | "January", "February", "March", "April", "May", "June", |
---|
| 41 | "July", "August", "September", "October", "November", "December" |
---|
| 42 | }, { |
---|
| 43 | "Sun", "Mon", "Tue", "Wed", |
---|
| 44 | "Thu", "Fri", "Sat" |
---|
| 45 | }, { |
---|
| 46 | "Sunday", "Monday", "Tuesday", "Wednesday", |
---|
| 47 | "Thursday", "Friday", "Saturday" |
---|
| 48 | }, |
---|
| 49 | |
---|
| 50 | /* X_fmt */ |
---|
| 51 | "%H:%M:%S", |
---|
| 52 | |
---|
| 53 | /* |
---|
| 54 | * x_fmt |
---|
| 55 | * Since the C language standard calls for |
---|
| 56 | * "date, using locale's date format," anything goes. |
---|
| 57 | * Using just numbers (as here) makes Quakers happier; |
---|
| 58 | * it's also compatible with SVR4. |
---|
| 59 | */ |
---|
| 60 | "%m/%d/%y", |
---|
| 61 | |
---|
| 62 | /* |
---|
| 63 | * c_fmt |
---|
| 64 | */ |
---|
| 65 | "%a %b %e %H:%M:%S %Y", |
---|
| 66 | |
---|
| 67 | /* am pm */ |
---|
| 68 | { "AM", "PM" }, |
---|
| 69 | |
---|
| 70 | /* date_fmt */ |
---|
| 71 | "%a %b %e %H:%M:%S %Z %Y", |
---|
| 72 | |
---|
| 73 | /* alt_month |
---|
| 74 | * Standalone months forms for %OB |
---|
| 75 | */ |
---|
| 76 | { |
---|
| 77 | "January", "February", "March", "April", "May", "June", |
---|
| 78 | "July", "August", "September", "October", "November", "December" |
---|
| 79 | }, |
---|
| 80 | |
---|
| 81 | /* md_order |
---|
| 82 | * Month / day order in dates |
---|
| 83 | */ |
---|
| 84 | "md", |
---|
| 85 | |
---|
| 86 | /* ampm_fmt |
---|
| 87 | * To determine 12-hour clock format time (empty, if N/A) |
---|
| 88 | */ |
---|
| 89 | "%I:%M:%S %p", |
---|
| 90 | |
---|
| 91 | /* era |
---|
| 92 | * Era. This and the following entries are used if the alternative |
---|
| 93 | * date format is specified in strftime |
---|
| 94 | */ |
---|
| 95 | "", |
---|
| 96 | |
---|
| 97 | /* era_d_fmt |
---|
| 98 | * Era date format used with the %Ex |
---|
| 99 | */ |
---|
| 100 | "", |
---|
| 101 | |
---|
| 102 | /* era_d_t_fmt |
---|
| 103 | * Era date/time format (%Ec) |
---|
| 104 | */ |
---|
| 105 | "", |
---|
| 106 | |
---|
| 107 | /* era_t_fmt |
---|
| 108 | * Era time format (%EX) |
---|
| 109 | */ |
---|
| 110 | "", |
---|
| 111 | |
---|
| 112 | /* alt_digits |
---|
| 113 | * Alternate digits used if %O format prefix is specified |
---|
| 114 | */ |
---|
| 115 | "" |
---|
| 116 | #ifdef __HAVE_LOCALE_INFO_EXTENDED__ |
---|
| 117 | , "ASCII", /* codeset */ |
---|
| 118 | { |
---|
| 119 | L"Jan", L"Feb", L"Mar", L"Apr", L"May", L"Jun", |
---|
| 120 | L"Jul", L"Aug", L"Sep", L"Oct", L"Nov", L"Dec" |
---|
| 121 | }, { |
---|
| 122 | L"January", L"February", L"March", L"April", L"May", L"June", |
---|
| 123 | L"July", L"August", L"September", L"October", L"November", |
---|
| 124 | L"December" |
---|
| 125 | }, { |
---|
| 126 | L"Sun", L"Mon", L"Tue", L"Wed", |
---|
| 127 | L"Thu", L"Fri", L"Sat" |
---|
| 128 | }, { |
---|
| 129 | L"Sunday", L"Monday", L"Tuesday", L"Wednesday", |
---|
| 130 | L"Thursday", L"Friday", L"Saturday" |
---|
| 131 | }, |
---|
| 132 | L"%H:%M:%S", |
---|
| 133 | L"%m/%d/%y", |
---|
| 134 | L"%a %b %e %H:%M:%S %Y", |
---|
| 135 | { L"AM", L"PM" }, |
---|
| 136 | L"%a %b %e %H:%M:%S %Z %Y", |
---|
| 137 | L"%I:%M:%S %p", |
---|
| 138 | L"", |
---|
| 139 | L"", |
---|
| 140 | L"", |
---|
| 141 | L"", |
---|
| 142 | L"" |
---|
| 143 | #endif |
---|
| 144 | }; |
---|
| 145 | |
---|
| 146 | int |
---|
| 147 | __time_load_locale (struct __locale_t *locale, const char *name, |
---|
| 148 | void *f_wctomb, const char *charset) |
---|
| 149 | { |
---|
| 150 | int ret; |
---|
| 151 | struct lc_time_T ti; |
---|
| 152 | char *bufp = NULL; |
---|
| 153 | |
---|
| 154 | #ifdef __CYGWIN__ |
---|
| 155 | extern int __set_lc_time_from_win (const char *, const struct lc_time_T *, |
---|
| 156 | struct lc_time_T *, char **, void *, |
---|
| 157 | const char *); |
---|
| 158 | ret = __set_lc_time_from_win (name, &_C_time_locale, &ti, &bufp, |
---|
| 159 | f_wctomb, charset); |
---|
| 160 | /* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */ |
---|
| 161 | if (ret >= 0) |
---|
| 162 | { |
---|
| 163 | struct lc_time_T *tip = NULL; |
---|
| 164 | |
---|
| 165 | if (ret > 0) |
---|
| 166 | { |
---|
| 167 | tip = (struct lc_time_T *) calloc (1, sizeof *tip); |
---|
| 168 | if (!tip) |
---|
| 169 | { |
---|
| 170 | free (bufp); |
---|
| 171 | return -1; |
---|
| 172 | } |
---|
| 173 | *tip = ti; |
---|
| 174 | } |
---|
| 175 | struct __lc_cats tmp = locale->lc_cat[LC_TIME]; |
---|
| 176 | locale->lc_cat[LC_TIME].ptr = ret == 0 ? &_C_time_locale : tip; |
---|
| 177 | locale->lc_cat[LC_TIME].buf = bufp; |
---|
| 178 | /* If buf is not NULL, both pointers have been alloc'ed */ |
---|
| 179 | if (tmp.buf) |
---|
| 180 | { |
---|
| 181 | free ((void *) tmp.ptr); |
---|
| 182 | free (tmp.buf); |
---|
| 183 | } |
---|
| 184 | ret = 0; |
---|
| 185 | } |
---|
| 186 | #else |
---|
| 187 | /* TODO */ |
---|
| 188 | #endif |
---|
| 189 | return (ret); |
---|
| 190 | } |
---|