1 /*
2 Copyright (c) 1990 Regents of the University of California.
3 All rights reserved.
4  */
5 #include <errno.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <wchar.h>
9 #include <locale.h>
10 #include <stdint.h>
11 #include "mbctype.h"
12 #include "local.h"
13 
14 int
__ascii_wctomb(char * s,wchar_t _wchar,mbstate_t * state)15 __ascii_wctomb (
16         char          *s,
17         wchar_t        _wchar,
18         mbstate_t     *state)
19 {
20   /* Avoids compiler warnings about comparisons that are always false
21      due to limited range when sizeof(wchar_t) is 2 but sizeof(wint_t)
22      is 4, as is the case on cygwin.  */
23   wint_t wchar = _wchar;
24 
25   (void) state;
26   if (s == NULL)
27     return 0;
28 
29   if ((size_t)wchar >= 0x100)
30     {
31       _REENT_ERRNO(r) = EILSEQ;
32       return -1;
33     }
34 
35   *s = (char) wchar;
36   return 1;
37 }
38 
39 #ifdef _MB_CAPABLE
40 /* for some conversions, we use the __count field as a place to store a state value */
41 #define __state __count
42 
43 int
__utf8_wctomb(char * s,wchar_t _wchar,mbstate_t * state)44 __utf8_wctomb (
45         char          *s,
46         wchar_t        _wchar,
47         mbstate_t     *state)
48 {
49   uint32_t wchar = _wchar;
50   int ret = 0;
51 
52   if (s == NULL)
53     return 0; /* UTF-8 encoding is not state-dependent */
54 
55   if (sizeof (wchar_t) == 2 && state->__count == -4
56       && (wchar < 0xdc00 || wchar > 0xdfff))
57     {
58       /* There's a leftover lone high surrogate.  Write out the CESU-8 value
59 	 of the surrogate and proceed to convert the given character.  Note
60 	 to return extra 3 bytes. */
61       wchar_t tmp;
62       tmp = ((uint32_t) state->__value.__wchb[0] << 16 | (uint32_t) state->__value.__wchb[1] << 8)
63           - ((uint32_t) 0x10000 >> 10 | (uint32_t) 0xd80d);
64       *s++ = 0xe0 | ((tmp & 0xf000) >> 12);
65       *s++ = 0x80 | ((tmp &  0xfc0) >> 6);
66       *s++ = 0x80 |  (tmp &   0x3f);
67       state->__count = 0;
68       ret = 3;
69     }
70   if (wchar <= 0x7f)
71     {
72       *s = wchar;
73       return ret + 1;
74     }
75   if (wchar >= 0x80 && wchar <= 0x7ff)
76     {
77       *s++ = 0xc0 | ((wchar & 0x7c0) >> 6);
78       *s   = 0x80 |  (wchar &  0x3f);
79       return ret + 2;
80     }
81   if (wchar >= 0x800 && wchar <= 0xffff)
82     {
83       /* No UTF-16 surrogate handling in UCS-4 */
84       if (sizeof (wchar_t) == 2 && wchar >= 0xd800 && wchar <= 0xdfff)
85 	{
86 	  uint32_t tmp;
87 	  if (wchar <= 0xdbff)
88 	    {
89 	      /* First half of a surrogate pair.  Store the state and
90 	         return ret + 0. */
91 	      tmp = ((wchar & 0x3ff) << 10) + 0x10000;
92 	      state->__value.__wchb[0] = (tmp >> 16) & 0xff;
93 	      state->__value.__wchb[1] = (tmp >> 8) & 0xff;
94 	      state->__count = -4;
95 	      *s = (0xf0 | ((tmp & 0x1c0000) >> 18));
96 	      return ret;
97 	    }
98 	  if (state->__count == -4)
99 	    {
100 	      /* Second half of a surrogate pair.  Reconstruct the full
101 		 Unicode value and return the trailing three bytes of the
102 		 UTF-8 character. */
103               tmp = ((uint32_t) state->__value.__wchb[0] << 16)
104 		    | (state->__value.__wchb[1] << 8)
105 		    | (wchar & 0x3ff);
106 	      state->__count = 0;
107 	      *s++ = 0xf0 | ((tmp & 0x1c0000) >> 18);
108 	      *s++ = 0x80 | ((tmp &  0x3f000) >> 12);
109 	      *s++ = 0x80 | ((tmp &    0xfc0) >> 6);
110 	      *s   = 0x80 |  (tmp &     0x3f);
111 	      return 4;
112 	    }
113 	  /* Otherwise translate into CESU-8 value. */
114 	}
115       *s++ = 0xe0 | ((wchar & 0xf000) >> 12);
116       *s++ = 0x80 | ((wchar &  0xfc0) >> 6);
117       *s   = 0x80 |  (wchar &   0x3f);
118       return ret + 3;
119     }
120   if (wchar >= (uint32_t) 0x10000 && wchar <= (uint32_t) 0x10ffff)
121     {
122       *s++ = 0xf0 | ((wchar & 0x1c0000) >> 18);
123       *s++ = 0x80 | ((wchar &  0x3f000) >> 12);
124       *s++ = 0x80 | ((wchar &    0xfc0) >> 6);
125       *s   = 0x80 |  (wchar &     0x3f);
126       return 4;
127     }
128 
129   _REENT_ERRNO(r) = EILSEQ;
130   return -1;
131 }
132 
133 /* Cygwin defines its own doublebyte charset conversion functions
134    because the underlying OS requires wchar_t == UTF-16. */
135 int
__sjis_wctomb(char * s,wchar_t _wchar,mbstate_t * state)136 __sjis_wctomb (
137         char          *s,
138         wchar_t        _wchar,
139         mbstate_t     *state)
140 {
141   wint_t wchar = _wchar;
142 
143   unsigned char char2 = (unsigned char)wchar;
144   unsigned char char1 = (unsigned char)(wchar >> 8);
145 
146   (void) state;
147   if (s == NULL)
148     return 0;  /* not state-dependent */
149 
150   if (char1 != 0x00)
151     {
152     /* first byte is non-zero..validate multi-byte char */
153       if (_issjis1(char1) && _issjis2(char2))
154 	{
155 	  *s++ = (char)char1;
156 	  *s = (char)char2;
157 	  return 2;
158 	}
159       else
160 	{
161 	  _REENT_ERRNO(r) = EILSEQ;
162 	  return -1;
163 	}
164     }
165   *s = (char) wchar;
166   return 1;
167 }
168 
169 int
__eucjp_wctomb(char * s,wchar_t _wchar,mbstate_t * state)170 __eucjp_wctomb (
171         char          *s,
172         wchar_t        _wchar,
173         mbstate_t     *state)
174 {
175   wint_t wchar = _wchar;
176   unsigned char char2 = (unsigned char)wchar;
177   unsigned char char1 = (unsigned char)(wchar >> 8);
178 
179   (void) state;
180   if (s == NULL)
181     return 0;  /* not state-dependent */
182 
183   if (char1 != 0x00)
184     {
185     /* first byte is non-zero..validate multi-byte char */
186       if (_iseucjp1 (char1) && _iseucjp2 (char2))
187 	{
188 	  *s++ = (char)char1;
189 	  *s = (char)char2;
190 	  return 2;
191 	}
192       else if (_iseucjp2 (char1) && _iseucjp2 (char2 | 0x80))
193 	{
194 	  *s++ = (char)0x8f;
195 	  *s++ = (char)char1;
196 	  *s = (char)(char2 | 0x80);
197 	  return 3;
198 	}
199       else
200 	{
201 	  _REENT_ERRNO(r) = EILSEQ;
202 	  return -1;
203 	}
204     }
205   *s = (char) wchar;
206   return 1;
207 }
208 
209 int
__jis_wctomb(char * s,wchar_t _wchar,mbstate_t * state)210 __jis_wctomb (
211         char          *s,
212         wchar_t        _wchar,
213         mbstate_t     *state)
214 {
215   wint_t wchar = _wchar;
216   int cnt = 0;
217   unsigned char char2 = (unsigned char)wchar;
218   unsigned char char1 = (unsigned char)(wchar >> 8);
219 
220   if (s == NULL)
221     return 1;  /* state-dependent */
222 
223   if (char1 != 0x00)
224     {
225     /* first byte is non-zero..validate multi-byte char */
226       if (_isjis (char1) && _isjis (char2))
227 	{
228 	  if (state->__state == 0)
229 	    {
230 	      /* must switch from ASCII to JIS state */
231 	      state->__state = 1;
232 	      *s++ = ESC_CHAR;
233 	      *s++ = '$';
234 	      *s++ = 'B';
235 	      cnt = 3;
236 	    }
237 	  *s++ = (char)char1;
238 	  *s = (char)char2;
239 	  return cnt + 2;
240 	}
241       _REENT_ERRNO(r) = EILSEQ;
242       return -1;
243     }
244   if (state->__state != 0)
245     {
246       /* must switch from JIS to ASCII state */
247       state->__state = 0;
248       *s++ = ESC_CHAR;
249       *s++ = '(';
250       *s++ = 'B';
251       cnt = 3;
252     }
253   *s = (char)char2;
254   return cnt + 1;
255 }
256 
257 #ifdef _MB_EXTENDED_CHARSETS_ISO
258 static int
___iso_wctomb(char * s,wchar_t _wchar,int iso_idx,mbstate_t * state)259 ___iso_wctomb (char *s, wchar_t _wchar, int iso_idx,
260 	       mbstate_t *state)
261 {
262   wint_t wchar = _wchar;
263 
264   if (s == NULL)
265     return 0;
266 
267   /* wchars <= 0x9f translate to all ISO charsets directly. */
268   if (wchar >= 0xa0)
269     {
270       if (iso_idx >= 0)
271 	{
272 	  unsigned char mb;
273 
274 	  for (mb = 0; mb < 0x60; ++mb)
275 	    if (__iso_8859_conv[iso_idx][mb] == wchar)
276 	      {
277 		*s = (char) (mb + 0xa0);
278 		return 1;
279 	      }
280 	  _REENT_ERRNO(r) = EILSEQ;
281 	  return -1;
282 	}
283     }
284 
285   if ((size_t)wchar >= 0x100)
286     {
287       _REENT_ERRNO(r) = EILSEQ;
288       return -1;
289     }
290 
291   *s = (char) wchar;
292   return 1;
293 }
294 
__iso_8859_1_wctomb(char * s,wchar_t _wchar,mbstate_t * state)295 int __iso_8859_1_wctomb (char *s, wchar_t _wchar,
296 			 mbstate_t *state)
297 {
298   return ___iso_wctomb (s, _wchar, -1, state);
299 }
300 
__iso_8859_2_wctomb(char * s,wchar_t _wchar,mbstate_t * state)301 int __iso_8859_2_wctomb (char *s, wchar_t _wchar,
302 			 mbstate_t *state)
303 {
304   return ___iso_wctomb (s, _wchar, 0, state);
305 }
306 
__iso_8859_3_wctomb(char * s,wchar_t _wchar,mbstate_t * state)307 int __iso_8859_3_wctomb (char *s, wchar_t _wchar,
308 			 mbstate_t *state)
309 {
310   return ___iso_wctomb (s, _wchar, 1, state);
311 }
312 
__iso_8859_4_wctomb(char * s,wchar_t _wchar,mbstate_t * state)313 int __iso_8859_4_wctomb (char *s, wchar_t _wchar,
314 			 mbstate_t *state)
315 {
316   return ___iso_wctomb (s, _wchar, 2, state);
317 }
318 
__iso_8859_5_wctomb(char * s,wchar_t _wchar,mbstate_t * state)319 int __iso_8859_5_wctomb (char *s, wchar_t _wchar,
320 			 mbstate_t *state)
321 {
322   return ___iso_wctomb (s, _wchar, 3, state);
323 }
324 
__iso_8859_6_wctomb(char * s,wchar_t _wchar,mbstate_t * state)325 int __iso_8859_6_wctomb (char *s, wchar_t _wchar,
326 			 mbstate_t *state)
327 {
328   return ___iso_wctomb (s, _wchar, 4, state);
329 }
330 
__iso_8859_7_wctomb(char * s,wchar_t _wchar,mbstate_t * state)331 int __iso_8859_7_wctomb (char *s, wchar_t _wchar,
332 			 mbstate_t *state)
333 {
334   return ___iso_wctomb (s, _wchar, 5, state);
335 }
336 
__iso_8859_8_wctomb(char * s,wchar_t _wchar,mbstate_t * state)337 int __iso_8859_8_wctomb (char *s, wchar_t _wchar,
338 			 mbstate_t *state)
339 {
340   return ___iso_wctomb (s, _wchar, 6, state);
341 }
342 
__iso_8859_9_wctomb(char * s,wchar_t _wchar,mbstate_t * state)343 int __iso_8859_9_wctomb (char *s, wchar_t _wchar,
344 			 mbstate_t *state)
345 {
346   return ___iso_wctomb (s, _wchar, 7, state);
347 }
348 
__iso_8859_10_wctomb(char * s,wchar_t _wchar,mbstate_t * state)349 int __iso_8859_10_wctomb (char *s, wchar_t _wchar,
350 			  mbstate_t *state)
351 {
352   return ___iso_wctomb (s, _wchar, 8, state);
353 }
354 
__iso_8859_11_wctomb(char * s,wchar_t _wchar,mbstate_t * state)355 int __iso_8859_11_wctomb (char *s, wchar_t _wchar,
356 			  mbstate_t *state)
357 {
358   return ___iso_wctomb (s, _wchar, 9, state);
359 }
360 
__iso_8859_13_wctomb(char * s,wchar_t _wchar,mbstate_t * state)361 int __iso_8859_13_wctomb (char *s, wchar_t _wchar,
362 			  mbstate_t *state)
363 {
364   return ___iso_wctomb (s, _wchar, 10, state);
365 }
366 
__iso_8859_14_wctomb(char * s,wchar_t _wchar,mbstate_t * state)367 int __iso_8859_14_wctomb (char *s, wchar_t _wchar,
368 			  mbstate_t *state)
369 {
370   return ___iso_wctomb (s, _wchar, 11, state);
371 }
372 
__iso_8859_15_wctomb(char * s,wchar_t _wchar,mbstate_t * state)373 int __iso_8859_15_wctomb (char *s, wchar_t _wchar,
374 			  mbstate_t *state)
375 {
376   return ___iso_wctomb (s, _wchar, 12, state);
377 }
378 
__iso_8859_16_wctomb(char * s,wchar_t _wchar,mbstate_t * state)379 int __iso_8859_16_wctomb (char *s, wchar_t _wchar,
380 			  mbstate_t *state)
381 {
382   return ___iso_wctomb (s, _wchar, 13, state);
383 }
384 
385 static wctomb_p __iso_8859_wctomb[17] = {
386   NULL,
387   __iso_8859_1_wctomb,
388   __iso_8859_2_wctomb,
389   __iso_8859_3_wctomb,
390   __iso_8859_4_wctomb,
391   __iso_8859_5_wctomb,
392   __iso_8859_6_wctomb,
393   __iso_8859_7_wctomb,
394   __iso_8859_8_wctomb,
395   __iso_8859_9_wctomb,
396   __iso_8859_10_wctomb,
397   __iso_8859_11_wctomb,
398   NULL,			/* No ISO 8859-12 */
399   __iso_8859_13_wctomb,
400   __iso_8859_14_wctomb,
401   __iso_8859_15_wctomb,
402   __iso_8859_16_wctomb
403 };
404 
405 /* val *MUST* be valid!  All checks for validity are supposed to be
406    performed before calling this function. */
407 wctomb_p
__iso_wctomb(int val)408 __iso_wctomb (int val)
409 {
410   return __iso_8859_wctomb[val];
411 }
412 #endif /* _MB_EXTENDED_CHARSETS_ISO */
413 
414 #ifdef _MB_EXTENDED_CHARSETS_WINDOWS
415 static int
___cp_wctomb(char * s,wchar_t _wchar,int cp_idx,mbstate_t * state)416 ___cp_wctomb (char *s, wchar_t _wchar, int cp_idx,
417 	      mbstate_t *state)
418 {
419   wint_t wchar = _wchar;
420 
421   if (s == NULL)
422     return 0;
423 
424   if (wchar >= 0x80)
425     {
426       if (cp_idx >= 0)
427 	{
428 	  unsigned char mb;
429 
430 	  for (mb = 0; mb < 0x80; ++mb)
431 	    if (__cp_conv[cp_idx][mb] == wchar)
432 	      {
433 		*s = (char) (mb + 0x80);
434 		return 1;
435 	      }
436 	  _REENT_ERRNO(r) = EILSEQ;
437 	  return -1;
438 	}
439     }
440 
441   if ((size_t)wchar >= 0x100)
442     {
443       _REENT_ERRNO(r) = EILSEQ;
444       return -1;
445     }
446 
447   *s = (char) wchar;
448   return 1;
449 }
450 
451 static int
__cp_437_wctomb(char * s,wchar_t _wchar,mbstate_t * state)452 __cp_437_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
453 {
454   return ___cp_wctomb (s, _wchar, 0, state);
455 }
456 
457 static int
__cp_720_wctomb(char * s,wchar_t _wchar,mbstate_t * state)458 __cp_720_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
459 {
460   return ___cp_wctomb (s, _wchar, 1, state);
461 }
462 
463 static int
__cp_737_wctomb(char * s,wchar_t _wchar,mbstate_t * state)464 __cp_737_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
465 {
466   return ___cp_wctomb (s, _wchar, 2, state);
467 }
468 
469 static int
__cp_775_wctomb(char * s,wchar_t _wchar,mbstate_t * state)470 __cp_775_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
471 {
472   return ___cp_wctomb (s, _wchar, 3, state);
473 }
474 
475 static int
__cp_850_wctomb(char * s,wchar_t _wchar,mbstate_t * state)476 __cp_850_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
477 {
478   return ___cp_wctomb (s, _wchar, 4, state);
479 }
480 
481 static int
__cp_852_wctomb(char * s,wchar_t _wchar,mbstate_t * state)482 __cp_852_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
483 {
484   return ___cp_wctomb (s, _wchar, 5, state);
485 }
486 
487 static int
__cp_855_wctomb(char * s,wchar_t _wchar,mbstate_t * state)488 __cp_855_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
489 {
490   return ___cp_wctomb (s, _wchar, 6, state);
491 }
492 
493 static int
__cp_857_wctomb(char * s,wchar_t _wchar,mbstate_t * state)494 __cp_857_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
495 {
496   return ___cp_wctomb (s, _wchar, 7, state);
497 }
498 
499 static int
__cp_858_wctomb(char * s,wchar_t _wchar,mbstate_t * state)500 __cp_858_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
501 {
502   return ___cp_wctomb (s, _wchar, 8, state);
503 }
504 
505 static int
__cp_862_wctomb(char * s,wchar_t _wchar,mbstate_t * state)506 __cp_862_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
507 {
508   return ___cp_wctomb (s, _wchar, 9, state);
509 }
510 
511 static int
__cp_866_wctomb(char * s,wchar_t _wchar,mbstate_t * state)512 __cp_866_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
513 {
514   return ___cp_wctomb (s, _wchar, 10, state);
515 }
516 
517 static int
__cp_874_wctomb(char * s,wchar_t _wchar,mbstate_t * state)518 __cp_874_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
519 {
520   return ___cp_wctomb (s, _wchar, 11, state);
521 }
522 
523 static int
__cp_1125_wctomb(char * s,wchar_t _wchar,mbstate_t * state)524 __cp_1125_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
525 {
526   return ___cp_wctomb (s, _wchar, 12, state);
527 }
528 
529 static int
__cp_1250_wctomb(char * s,wchar_t _wchar,mbstate_t * state)530 __cp_1250_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
531 {
532   return ___cp_wctomb (s, _wchar, 13, state);
533 }
534 
535 static int
__cp_1251_wctomb(char * s,wchar_t _wchar,mbstate_t * state)536 __cp_1251_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
537 {
538   return ___cp_wctomb (s, _wchar, 14, state);
539 }
540 
541 static int
__cp_1252_wctomb(char * s,wchar_t _wchar,mbstate_t * state)542 __cp_1252_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
543 {
544   return ___cp_wctomb (s, _wchar, 15, state);
545 }
546 
547 static int
__cp_1253_wctomb(char * s,wchar_t _wchar,mbstate_t * state)548 __cp_1253_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
549 {
550   return ___cp_wctomb (s, _wchar, 16, state);
551 }
552 
553 static int
__cp_1254_wctomb(char * s,wchar_t _wchar,mbstate_t * state)554 __cp_1254_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
555 {
556   return ___cp_wctomb (s, _wchar, 17, state);
557 }
558 
559 static int
__cp_1255_wctomb(char * s,wchar_t _wchar,mbstate_t * state)560 __cp_1255_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
561 {
562   return ___cp_wctomb (s, _wchar, 18, state);
563 }
564 
565 static int
__cp_1256_wctomb(char * s,wchar_t _wchar,mbstate_t * state)566 __cp_1256_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
567 {
568   return ___cp_wctomb (s, _wchar, 19, state);
569 }
570 
571 static int
__cp_1257_wctomb(char * s,wchar_t _wchar,mbstate_t * state)572 __cp_1257_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
573 {
574   return ___cp_wctomb (s, _wchar, 20, state);
575 }
576 
577 static int
__cp_1258_wctomb(char * s,wchar_t _wchar,mbstate_t * state)578 __cp_1258_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
579 {
580   return ___cp_wctomb (s, _wchar, 21, state);
581 }
582 
583 static int
__cp_20866_wctomb(char * s,wchar_t _wchar,mbstate_t * state)584 __cp_20866_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
585 {
586   return ___cp_wctomb (s, _wchar, 22, state);
587 }
588 
589 static int
__cp_21866_wctomb(char * s,wchar_t _wchar,mbstate_t * state)590 __cp_21866_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
591 {
592   return ___cp_wctomb (s, _wchar, 23, state);
593 }
594 
595 static int
__cp_101_wctomb(char * s,wchar_t _wchar,mbstate_t * state)596 __cp_101_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
597 {
598   return ___cp_wctomb (s, _wchar, 24, state);
599 }
600 
601 static int
__cp_102_wctomb(char * s,wchar_t _wchar,mbstate_t * state)602 __cp_102_wctomb (char *s, wchar_t _wchar, mbstate_t *state)
603 {
604   return ___cp_wctomb (s, _wchar, 25, state);
605 }
606 
607 static int
__cp_103_wctomb(struct _reent * r,char * s,wchar_t _wchar,mbstate_t * state)608 __cp_103_wctomb (struct _reent *r, char *s, wchar_t _wchar, mbstate_t *state)
609 {
610   return ___cp_wctomb (r, s, _wchar, 26, state);
611 }
612 
613 static wctomb_p __cp_xxx_wctomb[27] = {
614   __cp_437_wctomb,
615   __cp_720_wctomb,
616   __cp_737_wctomb,
617   __cp_775_wctomb,
618   __cp_850_wctomb,
619   __cp_852_wctomb,
620   __cp_855_wctomb,
621   __cp_857_wctomb,
622   __cp_858_wctomb,
623   __cp_862_wctomb,
624   __cp_866_wctomb,
625   __cp_874_wctomb,
626   __cp_1125_wctomb,
627   __cp_1250_wctomb,
628   __cp_1251_wctomb,
629   __cp_1252_wctomb,
630   __cp_1253_wctomb,
631   __cp_1254_wctomb,
632   __cp_1255_wctomb,
633   __cp_1256_wctomb,
634   __cp_1257_wctomb,
635   __cp_1258_wctomb,
636   __cp_20866_wctomb,
637   __cp_21866_wctomb,
638   __cp_101_wctomb,
639   __cp_102_wctomb,
640   __cp_103_wctomb,
641 };
642 
643 /* val *MUST* be valid!  All checks for validity are supposed to be
644    performed before calling this function. */
645 wctomb_p
__cp_wctomb(int val)646 __cp_wctomb (int val)
647 {
648   return __cp_xxx_wctomb[__cp_val_index (val)];
649 }
650 #endif /* _MB_EXTENDED_CHARSETS_WINDOWS */
651 #endif /* _MB_CAPABLE */
652