FSF GCC merge 02/23/03
[official-gcc.git] / libstdc++-v3 / config / io / c_io_libio_codecvt.c
blob38d8b55e0c2aed0fc534f1f6bd4a8528f554a1fa
1 /* Copyright (C) 2000 Free Software Foundation, Inc.
2 This file is part of the GNU IO Library.
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2, or (at
7 your option) any later version.
9 This library is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this library; see the file COPYING. If not, write to
16 the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
17 MA 02111-1307, USA.
19 As a special exception, if you link this library with files
20 compiled with a GNU compiler to produce an executable, this does
21 not cause the resulting executable to be covered by the GNU General
22 Public License. This exception does not however invalidate any
23 other reasons why the executable file might be covered by the GNU
24 General Public License. */
26 /* Slightly modified from glibc/libio/iofwide.c */
28 #include <libio.h>
30 #ifdef _GLIBCPP_USE_WCHAR_T
32 /* Prototypes of libio's codecvt functions. */
33 static enum __codecvt_result
34 do_out(struct _IO_codecvt *codecvt, __c_mbstate_t *statep,
35 const wchar_t *from_start, const wchar_t *from_end,
36 const wchar_t **from_stop, char *to_start, char *to_end,
37 char **to_stop);
39 static enum __codecvt_result
40 do_unshift(struct _IO_codecvt *codecvt, __c_mbstate_t *statep, char *to_start,
41 char *to_end, char **to_stop);
43 static enum __codecvt_result
44 do_in(struct _IO_codecvt *codecvt, __c_mbstate_t *statep,
45 const char *from_start, const char *from_end, const char **from_stop,
46 wchar_t *to_start, wchar_t *to_end, wchar_t **to_stop);
48 static int
49 do_encoding(struct _IO_codecvt *codecvt);
51 static int
52 do_length(struct _IO_codecvt *codecvt, __c_mbstate_t *statep,
53 const char *from_start, const char *from_end, _IO_size_t max);
55 static int
56 do_max_length(struct _IO_codecvt *codecvt);
58 static int
59 do_always_noconv(struct _IO_codecvt *codecvt);
62 /* The functions used in `codecvt' for libio are always the same. */
63 struct _IO_codecvt __c_libio_codecvt =
65 .__codecvt_destr = NULL, /* Destructor, never used. */
66 .__codecvt_do_out = do_out,
67 .__codecvt_do_unshift = do_unshift,
68 .__codecvt_do_in = do_in,
69 .__codecvt_do_encoding = do_encoding,
70 .__codecvt_do_always_noconv = do_always_noconv,
71 .__codecvt_do_length = do_length,
72 .__codecvt_do_max_length = do_max_length
75 static enum __codecvt_result
76 do_out(struct _IO_codecvt *codecvt, __c_mbstate_t *statep,
77 const wchar_t *from_start, const wchar_t *from_end,
78 const wchar_t **from_stop, char *to_start, char *to_end,
79 char **to_stop)
81 enum __codecvt_result res = __codecvt_ok;
83 while (from_start < from_end)
85 if (to_start >= to_end)
87 res = __codecvt_partial;
88 break;
90 *to_start++ = (char) *from_start++;
93 *from_stop = from_start;
94 *to_stop = to_start;
96 return res;
100 static enum __codecvt_result
101 do_unshift(struct _IO_codecvt *codecvt, __c_mbstate_t *statep,
102 char *to_start, char *to_end, char **to_stop)
104 *to_stop = to_start;
105 return __codecvt_ok;
109 static enum __codecvt_result
110 do_in(struct _IO_codecvt *codecvt, __c_mbstate_t *statep,
111 const char *from_start, const char *from_end, const char **from_stop,
112 wchar_t *to_start, wchar_t *to_end, wchar_t **to_stop)
114 enum __codecvt_result res = __codecvt_ok;
116 while (from_start < from_end)
118 if (to_start >= to_end)
120 res = __codecvt_partial;
121 break;
123 *to_start++ = (wchar_t) *from_start++;
126 *from_stop = from_start;
127 *to_stop = to_start;
129 return res;
133 static int
134 do_encoding(struct _IO_codecvt *codecvt)
135 { return 1; }
138 static int
139 do_always_noconv(struct _IO_codecvt *codecvt)
140 { return 0; }
143 static int
144 do_length(struct _IO_codecvt *codecvt, __c_mbstate_t *statep,
145 const char *from_start, const char *from_end, _IO_size_t max)
146 { return from_end - from_start; }
149 static int
150 do_max_length(struct _IO_codecvt *codecvt)
151 { return 1; }
153 #endif /* _GLIBCPP_USE_WCHAR_T */