1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 /*  Fluent Bit
4  *  ==========
5  *  Copyright (C) 2019-2021 The Fluent Bit Authors
6  *  Copyright (C) 2015-2018 Treasure Data Inc.
7  *
8  *  Licensed under the Apache License, Version 2.0 (the "License");
9  *  you may not use this file except in compliance with the License.
10  *  You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  *  Unless required by applicable law or agreed to in writing, software
15  *  distributed under the License is distributed on an "AS IS" BASIS,
16  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *  See the License for the specific language governing permissions and
18  *  limitations under the License.
19  */
20 
21 /*
22  * This is a dumb implementation of langinfo.h that only supports LC_TIME
23  * and "C" locale. We use this implemenatation to support locale-dependent
24  * specifiers of strptime(3) on Windows.
25  */
26 
27 #ifndef FLB_LANGINFO_H
28 #define FLB_LANGINFO_H
29 
30 #ifndef _MSC_VER
31 #include <langinfo.h>
32 #else
33 
34 typedef int nl_item;
35 
36 #define D_T_FMT  0x00
37 #define D_FMT    0x01
38 #define T_FMT    0x02
39 
40 #define DAY_1    0x03
41 #define DAY_2    0x04
42 #define DAY_3    0x05
43 #define DAY_4    0x06
44 #define DAY_5    0x07
45 #define DAY_6    0x08
46 #define DAY_7    0x09
47 
48 #define ABDAY_1  0x0A
49 #define ABDAY_2  0x0B
50 #define ABDAY_3  0x0C
51 #define ABDAY_4  0x0D
52 #define ABDAY_5  0x0E
53 #define ABDAY_6  0x0F
54 #define ABDAY_7  0x10
55 
56 #define MON_1    0x11
57 #define MON_2    0x12
58 #define MON_3    0x13
59 #define MON_4    0x14
60 #define MON_5    0x15
61 #define MON_6    0x16
62 #define MON_7    0x17
63 #define MON_8    0x18
64 #define MON_9    0x19
65 #define MON_10   0x1A
66 #define MON_11   0x1B
67 #define MON_12   0x1C
68 
69 #define ABMON_1  0x1D
70 #define ABMON_2  0x1E
71 #define ABMON_3  0x1F
72 #define ABMON_4  0x20
73 #define ABMON_5  0x21
74 #define ABMON_6  0x22
75 #define ABMON_7  0x23
76 #define ABMON_8  0x24
77 #define ABMON_9  0x25
78 #define ABMON_10 0x26
79 #define ABMON_11 0x27
80 #define ABMON_12 0x28
81 
82 #define AM_STR     0x29
83 #define PM_STR     0x2A
84 #define T_FMT_AMPM 0x2B
85 
86 static const char *lc_time_c[] = {
87     "%a %b %e %H:%M:%S %Y", /* D_T_FMT */
88     "%m/%d/%y",    /* D_FMT */
89     "%H:%M:%S",    /* T_FMT */
90 
91     "Sunday",      /* DAY_1 */
92     "Monday",      /* DAY_2 */
93     "Tuesday",     /* DAY_3 */
94     "Wednesday",   /* DAY_4 */
95     "Thursday",    /* DAY_5 */
96     "Friday",      /* DAY_6 */
97     "Saturday",    /* DAY_7 */
98 
99     "Sun",         /* ABDAY_1 */
100     "Mon",         /* ABDAY_2 */
101     "Tue",         /* ABDAY_3 */
102     "Wed",         /* ABDAY_4 */
103     "Thu",         /* ABDAY_5 */
104     "Fri",         /* ABDAY_6 */
105     "Sat",         /* ABDAY_7 */
106 
107     "January",     /* MON_1 */
108     "February",    /* MON_2 */
109     "March",       /* MON_3 */
110     "April",       /* MON_4 */
111     "May",         /* MON_5 */
112     "June",        /* MON_6 */
113     "July",        /* MON_7 */
114     "August",      /* MON_8 */
115     "September",   /* MON_9 */
116     "October",     /* MON_10 */
117     "November",    /* MON_11 */
118     "December",    /* MON_12 */
119 
120     "Jan",         /* ABMON_1 */
121     "Feb",         /* ABMON_2 */
122     "Mar",         /* ABMON_3 */
123     "Apr",         /* ABMON_4 */
124     "May",         /* ABMON_5 */
125     "Jun",         /* ABMON_6 */
126     "Jul",         /* ABMON_7 */
127     "Aug",         /* ABMON_8 */
128     "Sep",         /* ABMON_9 */
129     "Oct",         /* ABMON_10 */
130     "Nov",         /* ABMON_11 */
131     "Dec",         /* ABMON_12 */
132 
133     "AM",          /* AM_STR */
134     "PM",          /* PM_STR */
135     "%I:%M:%S %p", /* T_FMT_AMPM */
136 };
137 
nl_langinfo(nl_item item)138 static inline const char *nl_langinfo(nl_item item)
139 {
140     if (item < 0 || 0x2B < item)
141         return "";
142     return lc_time_c[item];
143 }
144 #endif
145 #endif
146