xref: /minix3/lib/libintl/sysdep.c (revision 36dcc4a4a93f782ada76dce3d52fbeab0e063cf1)
1*36dcc4a4SLionel Sambuc /*	$NetBSD: sysdep.c,v 1.2 2005/04/27 09:50:26 yamt Exp $	*/
2*36dcc4a4SLionel Sambuc 
3*36dcc4a4SLionel Sambuc /*-
4*36dcc4a4SLionel Sambuc  * Copyright (c)2004 Citrus Project,
5*36dcc4a4SLionel Sambuc  * All rights reserved.
6*36dcc4a4SLionel Sambuc  *
7*36dcc4a4SLionel Sambuc  * Redistribution and use in source and binary forms, with or without
8*36dcc4a4SLionel Sambuc  * modification, are permitted provided that the following conditions
9*36dcc4a4SLionel Sambuc  * are met:
10*36dcc4a4SLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
11*36dcc4a4SLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
12*36dcc4a4SLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
13*36dcc4a4SLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
14*36dcc4a4SLionel Sambuc  *    documentation and/or other materials provided with the distribution.
15*36dcc4a4SLionel Sambuc  *
16*36dcc4a4SLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17*36dcc4a4SLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*36dcc4a4SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*36dcc4a4SLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*36dcc4a4SLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*36dcc4a4SLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*36dcc4a4SLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*36dcc4a4SLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*36dcc4a4SLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*36dcc4a4SLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*36dcc4a4SLionel Sambuc  * SUCH DAMAGE.
27*36dcc4a4SLionel Sambuc  */
28*36dcc4a4SLionel Sambuc 
29*36dcc4a4SLionel Sambuc #include <sys/cdefs.h>
30*36dcc4a4SLionel Sambuc #if defined(LIBC_SCCS) && !defined(lint)
31*36dcc4a4SLionel Sambuc __RCSID("$NetBSD: sysdep.c,v 1.2 2005/04/27 09:50:26 yamt Exp $");
32*36dcc4a4SLionel Sambuc #endif /* LIBC_SCCS and not lint */
33*36dcc4a4SLionel Sambuc 
34*36dcc4a4SLionel Sambuc #include <sys/param.h>
35*36dcc4a4SLionel Sambuc #include <sys/types.h>
36*36dcc4a4SLionel Sambuc 
37*36dcc4a4SLionel Sambuc #include <inttypes.h>
38*36dcc4a4SLionel Sambuc #include <stdlib.h>
39*36dcc4a4SLionel Sambuc #include <string.h>
40*36dcc4a4SLionel Sambuc 
41*36dcc4a4SLionel Sambuc #include "libintl_local.h"
42*36dcc4a4SLionel Sambuc 
43*36dcc4a4SLionel Sambuc struct sysdep_pair
44*36dcc4a4SLionel Sambuc {
45*36dcc4a4SLionel Sambuc 	const char *tag;
46*36dcc4a4SLionel Sambuc 	const char *string;
47*36dcc4a4SLionel Sambuc 	size_t len;
48*36dcc4a4SLionel Sambuc };
49*36dcc4a4SLionel Sambuc 
50*36dcc4a4SLionel Sambuc #define T_(tag)		{ #tag, tag, sizeof (tag)-1 }
51*36dcc4a4SLionel Sambuc #define numof(a)	(sizeof (a) / sizeof ((a)[0]))
52*36dcc4a4SLionel Sambuc 
53*36dcc4a4SLionel Sambuc const struct sysdep_pair sysdep_pair_table[] = {
54*36dcc4a4SLionel Sambuc 	/* this table must be sorted in the dictionary order. */
55*36dcc4a4SLionel Sambuc 	T_(PRIX16),
56*36dcc4a4SLionel Sambuc 	T_(PRIX32),
57*36dcc4a4SLionel Sambuc 	T_(PRIX64),
58*36dcc4a4SLionel Sambuc 	T_(PRIX8),
59*36dcc4a4SLionel Sambuc 	T_(PRIXFAST16),
60*36dcc4a4SLionel Sambuc 	T_(PRIXFAST32),
61*36dcc4a4SLionel Sambuc 	T_(PRIXFAST64),
62*36dcc4a4SLionel Sambuc 	T_(PRIXFAST8),
63*36dcc4a4SLionel Sambuc 	T_(PRIXLEAST16),
64*36dcc4a4SLionel Sambuc 	T_(PRIXLEAST32),
65*36dcc4a4SLionel Sambuc 	T_(PRIXLEAST64),
66*36dcc4a4SLionel Sambuc 	T_(PRIXLEAST8),
67*36dcc4a4SLionel Sambuc 	T_(PRIXMAX),
68*36dcc4a4SLionel Sambuc 	T_(PRIXPTR),
69*36dcc4a4SLionel Sambuc 	T_(PRId16),
70*36dcc4a4SLionel Sambuc 	T_(PRId32),
71*36dcc4a4SLionel Sambuc 	T_(PRId64),
72*36dcc4a4SLionel Sambuc 	T_(PRId8),
73*36dcc4a4SLionel Sambuc 	T_(PRIdFAST16),
74*36dcc4a4SLionel Sambuc 	T_(PRIdFAST32),
75*36dcc4a4SLionel Sambuc 	T_(PRIdFAST64),
76*36dcc4a4SLionel Sambuc 	T_(PRIdFAST8),
77*36dcc4a4SLionel Sambuc 	T_(PRIdLEAST16),
78*36dcc4a4SLionel Sambuc 	T_(PRIdLEAST32),
79*36dcc4a4SLionel Sambuc 	T_(PRIdLEAST64),
80*36dcc4a4SLionel Sambuc 	T_(PRIdLEAST8),
81*36dcc4a4SLionel Sambuc 	T_(PRIdMAX),
82*36dcc4a4SLionel Sambuc 	T_(PRIdPTR),
83*36dcc4a4SLionel Sambuc 	T_(PRIi16),
84*36dcc4a4SLionel Sambuc 	T_(PRIi32),
85*36dcc4a4SLionel Sambuc 	T_(PRIi64),
86*36dcc4a4SLionel Sambuc 	T_(PRIi8),
87*36dcc4a4SLionel Sambuc 	T_(PRIiFAST16),
88*36dcc4a4SLionel Sambuc 	T_(PRIiFAST32),
89*36dcc4a4SLionel Sambuc 	T_(PRIiFAST64),
90*36dcc4a4SLionel Sambuc 	T_(PRIiFAST8),
91*36dcc4a4SLionel Sambuc 	T_(PRIiLEAST16),
92*36dcc4a4SLionel Sambuc 	T_(PRIiLEAST32),
93*36dcc4a4SLionel Sambuc 	T_(PRIiLEAST64),
94*36dcc4a4SLionel Sambuc 	T_(PRIiLEAST8),
95*36dcc4a4SLionel Sambuc 	T_(PRIiMAX),
96*36dcc4a4SLionel Sambuc 	T_(PRIiPTR),
97*36dcc4a4SLionel Sambuc 	T_(PRIo16),
98*36dcc4a4SLionel Sambuc 	T_(PRIo32),
99*36dcc4a4SLionel Sambuc 	T_(PRIo64),
100*36dcc4a4SLionel Sambuc 	T_(PRIo8),
101*36dcc4a4SLionel Sambuc 	T_(PRIoFAST16),
102*36dcc4a4SLionel Sambuc 	T_(PRIoFAST32),
103*36dcc4a4SLionel Sambuc 	T_(PRIoFAST64),
104*36dcc4a4SLionel Sambuc 	T_(PRIoFAST8),
105*36dcc4a4SLionel Sambuc 	T_(PRIoLEAST16),
106*36dcc4a4SLionel Sambuc 	T_(PRIoLEAST32),
107*36dcc4a4SLionel Sambuc 	T_(PRIoLEAST64),
108*36dcc4a4SLionel Sambuc 	T_(PRIoLEAST8),
109*36dcc4a4SLionel Sambuc 	T_(PRIoMAX),
110*36dcc4a4SLionel Sambuc 	T_(PRIoPTR),
111*36dcc4a4SLionel Sambuc 	T_(PRIu16),
112*36dcc4a4SLionel Sambuc 	T_(PRIu32),
113*36dcc4a4SLionel Sambuc 	T_(PRIu64),
114*36dcc4a4SLionel Sambuc 	T_(PRIu8),
115*36dcc4a4SLionel Sambuc 	T_(PRIuFAST16),
116*36dcc4a4SLionel Sambuc 	T_(PRIuFAST32),
117*36dcc4a4SLionel Sambuc 	T_(PRIuFAST64),
118*36dcc4a4SLionel Sambuc 	T_(PRIuFAST8),
119*36dcc4a4SLionel Sambuc 	T_(PRIuLEAST16),
120*36dcc4a4SLionel Sambuc 	T_(PRIuLEAST32),
121*36dcc4a4SLionel Sambuc 	T_(PRIuLEAST64),
122*36dcc4a4SLionel Sambuc 	T_(PRIuLEAST8),
123*36dcc4a4SLionel Sambuc 	T_(PRIuMAX),
124*36dcc4a4SLionel Sambuc 	T_(PRIuPTR),
125*36dcc4a4SLionel Sambuc 	T_(PRIx16),
126*36dcc4a4SLionel Sambuc 	T_(PRIx32),
127*36dcc4a4SLionel Sambuc 	T_(PRIx64),
128*36dcc4a4SLionel Sambuc 	T_(PRIx8),
129*36dcc4a4SLionel Sambuc 	T_(PRIxFAST16),
130*36dcc4a4SLionel Sambuc 	T_(PRIxFAST32),
131*36dcc4a4SLionel Sambuc 	T_(PRIxFAST64),
132*36dcc4a4SLionel Sambuc 	T_(PRIxFAST8),
133*36dcc4a4SLionel Sambuc 	T_(PRIxLEAST16),
134*36dcc4a4SLionel Sambuc 	T_(PRIxLEAST32),
135*36dcc4a4SLionel Sambuc 	T_(PRIxLEAST64),
136*36dcc4a4SLionel Sambuc 	T_(PRIxLEAST8),
137*36dcc4a4SLionel Sambuc 	T_(PRIxMAX),
138*36dcc4a4SLionel Sambuc 	T_(PRIxPTR),
139*36dcc4a4SLionel Sambuc 	T_(SCNd16),
140*36dcc4a4SLionel Sambuc 	T_(SCNd32),
141*36dcc4a4SLionel Sambuc 	T_(SCNd64),
142*36dcc4a4SLionel Sambuc 	T_(SCNd8),
143*36dcc4a4SLionel Sambuc 	T_(SCNdFAST16),
144*36dcc4a4SLionel Sambuc 	T_(SCNdFAST32),
145*36dcc4a4SLionel Sambuc 	T_(SCNdFAST64),
146*36dcc4a4SLionel Sambuc 	T_(SCNdFAST8),
147*36dcc4a4SLionel Sambuc 	T_(SCNdLEAST16),
148*36dcc4a4SLionel Sambuc 	T_(SCNdLEAST32),
149*36dcc4a4SLionel Sambuc 	T_(SCNdLEAST64),
150*36dcc4a4SLionel Sambuc 	T_(SCNdLEAST8),
151*36dcc4a4SLionel Sambuc 	T_(SCNdMAX),
152*36dcc4a4SLionel Sambuc 	T_(SCNdPTR),
153*36dcc4a4SLionel Sambuc 	T_(SCNi16),
154*36dcc4a4SLionel Sambuc 	T_(SCNi32),
155*36dcc4a4SLionel Sambuc 	T_(SCNi64),
156*36dcc4a4SLionel Sambuc 	T_(SCNi8),
157*36dcc4a4SLionel Sambuc 	T_(SCNiFAST16),
158*36dcc4a4SLionel Sambuc 	T_(SCNiFAST32),
159*36dcc4a4SLionel Sambuc 	T_(SCNiFAST64),
160*36dcc4a4SLionel Sambuc 	T_(SCNiFAST8),
161*36dcc4a4SLionel Sambuc 	T_(SCNiLEAST16),
162*36dcc4a4SLionel Sambuc 	T_(SCNiLEAST32),
163*36dcc4a4SLionel Sambuc 	T_(SCNiLEAST64),
164*36dcc4a4SLionel Sambuc 	T_(SCNiLEAST8),
165*36dcc4a4SLionel Sambuc 	T_(SCNiMAX),
166*36dcc4a4SLionel Sambuc 	T_(SCNiPTR),
167*36dcc4a4SLionel Sambuc 	T_(SCNo16),
168*36dcc4a4SLionel Sambuc 	T_(SCNo32),
169*36dcc4a4SLionel Sambuc 	T_(SCNo64),
170*36dcc4a4SLionel Sambuc 	T_(SCNo8),
171*36dcc4a4SLionel Sambuc 	T_(SCNoFAST16),
172*36dcc4a4SLionel Sambuc 	T_(SCNoFAST32),
173*36dcc4a4SLionel Sambuc 	T_(SCNoFAST64),
174*36dcc4a4SLionel Sambuc 	T_(SCNoFAST8),
175*36dcc4a4SLionel Sambuc 	T_(SCNoLEAST16),
176*36dcc4a4SLionel Sambuc 	T_(SCNoLEAST32),
177*36dcc4a4SLionel Sambuc 	T_(SCNoLEAST64),
178*36dcc4a4SLionel Sambuc 	T_(SCNoLEAST8),
179*36dcc4a4SLionel Sambuc 	T_(SCNoMAX),
180*36dcc4a4SLionel Sambuc 	T_(SCNoPTR),
181*36dcc4a4SLionel Sambuc 	T_(SCNu16),
182*36dcc4a4SLionel Sambuc 	T_(SCNu32),
183*36dcc4a4SLionel Sambuc 	T_(SCNu64),
184*36dcc4a4SLionel Sambuc 	T_(SCNu8),
185*36dcc4a4SLionel Sambuc 	T_(SCNuFAST16),
186*36dcc4a4SLionel Sambuc 	T_(SCNuFAST32),
187*36dcc4a4SLionel Sambuc 	T_(SCNuFAST64),
188*36dcc4a4SLionel Sambuc 	T_(SCNuFAST8),
189*36dcc4a4SLionel Sambuc 	T_(SCNuLEAST16),
190*36dcc4a4SLionel Sambuc 	T_(SCNuLEAST32),
191*36dcc4a4SLionel Sambuc 	T_(SCNuLEAST64),
192*36dcc4a4SLionel Sambuc 	T_(SCNuLEAST8),
193*36dcc4a4SLionel Sambuc 	T_(SCNuMAX),
194*36dcc4a4SLionel Sambuc 	T_(SCNuPTR),
195*36dcc4a4SLionel Sambuc 	T_(SCNx16),
196*36dcc4a4SLionel Sambuc 	T_(SCNx32),
197*36dcc4a4SLionel Sambuc 	T_(SCNx64),
198*36dcc4a4SLionel Sambuc 	T_(SCNx8),
199*36dcc4a4SLionel Sambuc 	T_(SCNxFAST16),
200*36dcc4a4SLionel Sambuc 	T_(SCNxFAST32),
201*36dcc4a4SLionel Sambuc 	T_(SCNxFAST64),
202*36dcc4a4SLionel Sambuc 	T_(SCNxFAST8),
203*36dcc4a4SLionel Sambuc 	T_(SCNxLEAST16),
204*36dcc4a4SLionel Sambuc 	T_(SCNxLEAST32),
205*36dcc4a4SLionel Sambuc 	T_(SCNxLEAST64),
206*36dcc4a4SLionel Sambuc 	T_(SCNxLEAST8),
207*36dcc4a4SLionel Sambuc 	T_(SCNxMAX),
208*36dcc4a4SLionel Sambuc 	T_(SCNxPTR)
209*36dcc4a4SLionel Sambuc };
210*36dcc4a4SLionel Sambuc 
211*36dcc4a4SLionel Sambuc static int
cmp_sysdep_tag(const void * tag,const void * elem)212*36dcc4a4SLionel Sambuc cmp_sysdep_tag(const void *tag, const void *elem)
213*36dcc4a4SLionel Sambuc {
214*36dcc4a4SLionel Sambuc 	const struct sysdep_pair *pair = elem;
215*36dcc4a4SLionel Sambuc 
216*36dcc4a4SLionel Sambuc 	return strcmp(tag, pair->tag);
217*36dcc4a4SLionel Sambuc }
218*36dcc4a4SLionel Sambuc 
219*36dcc4a4SLionel Sambuc const char *
__intl_sysdep_get_string_by_tag(const char * tag,size_t * rlen)220*36dcc4a4SLionel Sambuc __intl_sysdep_get_string_by_tag(const char *tag, size_t *rlen)
221*36dcc4a4SLionel Sambuc {
222*36dcc4a4SLionel Sambuc 	const struct sysdep_pair *found;
223*36dcc4a4SLionel Sambuc 
224*36dcc4a4SLionel Sambuc 	found = bsearch(tag, sysdep_pair_table, numof(sysdep_pair_table),
225*36dcc4a4SLionel Sambuc 			sizeof(sysdep_pair_table[0]), &cmp_sysdep_tag);
226*36dcc4a4SLionel Sambuc 
227*36dcc4a4SLionel Sambuc 	if (found) {
228*36dcc4a4SLionel Sambuc 		if (rlen)
229*36dcc4a4SLionel Sambuc 			*rlen = found->len;
230*36dcc4a4SLionel Sambuc 		return found->string;
231*36dcc4a4SLionel Sambuc 	}
232*36dcc4a4SLionel Sambuc 
233*36dcc4a4SLionel Sambuc 	if (rlen)
234*36dcc4a4SLionel Sambuc 		*rlen = 0;
235*36dcc4a4SLionel Sambuc 	return "";
236*36dcc4a4SLionel Sambuc }
237