1 /* Skeleton for a conversion module.
2 Copyright (C) 1998-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <http://www.gnu.org/licenses/>. */
20 /* This file can be included to provide definitions of several things
21 many modules have in common. It can be customized using the following
24 DEFINE_INIT define the default initializer. This requires the
25 following symbol to be defined.
27 CHARSET_NAME string with official name of the coded character
30 DEFINE_FINI define the default destructor function.
32 MIN_NEEDED_FROM minimal number of bytes needed for the from-charset.
33 MIN_NEEDED_TO likewise for the to-charset.
35 MAX_NEEDED_FROM maximal number of bytes needed for the from-charset.
36 This macro is optional, it defaults to MIN_NEEDED_FROM.
37 MAX_NEEDED_TO likewise for the to-charset.
39 FROM_LOOP_MIN_NEEDED_FROM
40 FROM_LOOP_MAX_NEEDED_FROM
41 minimal/maximal number of bytes needed on input
42 of one round through the FROM_LOOP. Defaults
43 to MIN_NEEDED_FROM and MAX_NEEDED_FROM, respectively.
44 FROM_LOOP_MIN_NEEDED_TO
45 FROM_LOOP_MAX_NEEDED_TO
46 minimal/maximal number of bytes needed on output
47 of one round through the FROM_LOOP. Defaults
48 to MIN_NEEDED_TO and MAX_NEEDED_TO, respectively.
49 TO_LOOP_MIN_NEEDED_FROM
50 TO_LOOP_MAX_NEEDED_FROM
51 minimal/maximal number of bytes needed on input
52 of one round through the TO_LOOP. Defaults
53 to MIN_NEEDED_TO and MAX_NEEDED_TO, respectively.
56 minimal/maximal number of bytes needed on output
57 of one round through the TO_LOOP. Defaults
58 to MIN_NEEDED_FROM and MAX_NEEDED_FROM, respectively.
60 FROM_DIRECTION this macro is supposed to return a value != 0
61 if we convert from the current character set,
62 otherwise it return 0.
64 EMIT_SHIFT_TO_INIT this symbol is optional. If it is defined it
65 defines some code which writes out a sequence
66 of bytes which bring the current state into
69 FROM_LOOP name of the function implementing the conversion
70 from the current character set.
71 TO_LOOP likewise for the other direction
73 ONE_DIRECTION optional. If defined to 1, only one conversion
74 direction is defined instead of two. In this
75 case, FROM_DIRECTION should be defined to 1, and
76 FROM_LOOP and TO_LOOP should have the same value.
78 SAVE_RESET_STATE in case of an error we must reset the state for
79 the rerun so this macro must be defined for
80 stateful encodings. It takes an argument which
81 is nonzero when saving.
83 RESET_INPUT_BUFFER If the input character sets allow this the macro
84 can be defined to reset the input buffer pointers
85 to cover only those characters up to the error.
87 FUNCTION_NAME if not set the conversion function is named `gconv'.
89 PREPARE_LOOP optional code preparing the conversion loop. Can
90 contain variable definitions.
91 END_LOOP also optional, may be used to store information
93 EXTRA_LOOP_ARGS optional macro specifying extra arguments passed
96 STORE_REST optional, needed only when MAX_NEEDED_FROM > 4.
97 This macro stores the seen but unconverted input bytes
100 FROM_ONEBYTE optional. If defined, should be the name of a
101 specialized conversion function for a single byte
102 from the current character set to INTERNAL. This
103 function has prototype
105 FROM_ONEBYTE (struct __gconv_step *, unsigned char);
106 and does a special conversion:
107 - The input is a single byte.
108 - The output is a single uint32_t.
109 - The state before the conversion is the initial state;
110 the state after the conversion is irrelevant.
111 - No transliteration.
112 - __invocation_counter = 0.
113 - __internal_use = 1.
116 Modules can use mbstate_t to store conversion state as follows:
118 * Bits 2..0 of '__count' contain the number of lookahead input bytes
119 stored in __value.__wchb. Always zero if the converter never
120 returns __GCONV_INCOMPLETE_INPUT.
122 * Bits 31..3 of '__count' are module dependent shift state.
124 * __value: When STORE_REST/UNPACK_BYTES aren't defined and when the
125 converter has returned __GCONV_INCOMPLETE_INPUT, this contains
126 at most 4 lookahead bytes. Converters with an mb_cur_max > 4
127 (currently only UTF-8) must find a way to store their state
128 in __value.__wch and define STORE_REST/UNPACK_BYTES appropriately.
130 When __value contains lookahead, __count must not be zero, because
131 the converter is not in the initial state then, and mbsinit() --
132 defined as a (__count == 0) test -- must reflect this.
138 #define __need_size_t
150 # define DL_CALL_FCT(fct, args) fct args
153 /* The direction objects. */
155 # ifndef FROM_DIRECTION
156 # define FROM_DIRECTION_VAL NULL
157 # define TO_DIRECTION_VAL ((void *) ~((uintptr_t) 0))
158 # define FROM_DIRECTION (step->__data == FROM_DIRECTION_VAL)
161 # ifndef FROM_DIRECTION
162 # error "FROM_DIRECTION must be provided if non-default init is used"
166 /* How many bytes are needed at most for the from-charset. */
167 #ifndef MAX_NEEDED_FROM
168 # define MAX_NEEDED_FROM MIN_NEEDED_FROM
171 /* Same for the to-charset. */
172 #ifndef MAX_NEEDED_TO
173 # define MAX_NEEDED_TO MIN_NEEDED_TO
176 /* Defaults for the per-direction min/max constants. */
177 #ifndef FROM_LOOP_MIN_NEEDED_FROM
178 # define FROM_LOOP_MIN_NEEDED_FROM MIN_NEEDED_FROM
180 #ifndef FROM_LOOP_MAX_NEEDED_FROM
181 # define FROM_LOOP_MAX_NEEDED_FROM MAX_NEEDED_FROM
183 #ifndef FROM_LOOP_MIN_NEEDED_TO
184 # define FROM_LOOP_MIN_NEEDED_TO MIN_NEEDED_TO
186 #ifndef FROM_LOOP_MAX_NEEDED_TO
187 # define FROM_LOOP_MAX_NEEDED_TO MAX_NEEDED_TO
189 #ifndef TO_LOOP_MIN_NEEDED_FROM
190 # define TO_LOOP_MIN_NEEDED_FROM MIN_NEEDED_TO
192 #ifndef TO_LOOP_MAX_NEEDED_FROM
193 # define TO_LOOP_MAX_NEEDED_FROM MAX_NEEDED_TO
195 #ifndef TO_LOOP_MIN_NEEDED_TO
196 # define TO_LOOP_MIN_NEEDED_TO MIN_NEEDED_FROM
198 #ifndef TO_LOOP_MAX_NEEDED_TO
199 # define TO_LOOP_MAX_NEEDED_TO MAX_NEEDED_FROM
203 /* Define macros which can access unaligned buffers. These macros are
204 supposed to be used only in code outside the inner loops. For the inner
205 loops we have other definitions which allow optimized access. */
206 #if _STRING_ARCH_unaligned
207 /* We can handle unaligned memory access. */
208 # define get16u(addr) *((const uint16_t *) (addr))
209 # define get32u(addr) *((const uint32_t *) (addr))
211 /* We need no special support for writing values either. */
212 # define put16u(addr, val) *((uint16_t *) (addr)) = (val)
213 # define put32u(addr, val) *((uint32_t *) (addr)) = (val)
215 /* Distinguish between big endian and little endian. */
216 # if __BYTE_ORDER == __LITTLE_ENDIAN
217 # define get16u(addr) \
218 (((const unsigned char *) (addr))[1] << 8 \
219 | ((const unsigned char *) (addr))[0])
220 # define get32u(addr) \
221 (((((const unsigned char *) (addr))[3] << 8 \
222 | ((const unsigned char *) (addr))[2]) << 8 \
223 | ((const unsigned char *) (addr))[1]) << 8 \
224 | ((const unsigned char *) (addr))[0])
226 # define put16u(addr, val) \
227 ({ uint16_t __val = (val); \
228 ((unsigned char *) (addr))[0] = __val; \
229 ((unsigned char *) (addr))[1] = __val >> 8; \
231 # define put32u(addr, val) \
232 ({ uint32_t __val = (val); \
233 ((unsigned char *) (addr))[0] = __val; \
235 ((unsigned char *) (addr))[1] = __val; \
237 ((unsigned char *) (addr))[2] = __val; \
239 ((unsigned char *) (addr))[3] = __val; \
242 # define get16u(addr) \
243 (((const unsigned char *) (addr))[0] << 8 \
244 | ((const unsigned char *) (addr))[1])
245 # define get32u(addr) \
246 (((((const unsigned char *) (addr))[0] << 8 \
247 | ((const unsigned char *) (addr))[1]) << 8 \
248 | ((const unsigned char *) (addr))[2]) << 8 \
249 | ((const unsigned char *) (addr))[3])
251 # define put16u(addr, val) \
252 ({ uint16_t __val = (val); \
253 ((unsigned char *) (addr))[1] = __val; \
254 ((unsigned char *) (addr))[0] = __val >> 8; \
256 # define put32u(addr, val) \
257 ({ uint32_t __val = (val); \
258 ((unsigned char *) (addr))[3] = __val; \
260 ((unsigned char *) (addr))[2] = __val; \
262 ((unsigned char *) (addr))[1] = __val; \
264 ((unsigned char *) (addr))[0] = __val; \
270 /* For conversions from a fixed width character set to another fixed width
271 character set we can define RESET_INPUT_BUFFER in a very fast way. */
272 #if !defined RESET_INPUT_BUFFER && !defined SAVE_RESET_STATE
273 # if FROM_LOOP_MIN_NEEDED_FROM == FROM_LOOP_MAX_NEEDED_FROM \
274 && FROM_LOOP_MIN_NEEDED_TO == FROM_LOOP_MAX_NEEDED_TO \
275 && TO_LOOP_MIN_NEEDED_FROM == TO_LOOP_MAX_NEEDED_FROM \
276 && TO_LOOP_MIN_NEEDED_TO == TO_LOOP_MAX_NEEDED_TO
277 /* We have to use these `if's here since the compiler cannot know that
278 (outbuf - outerr) is always divisible by FROM/TO_LOOP_MIN_NEEDED_TO.
279 The ?:1 avoids division by zero warnings that gcc 3.2 emits even for
280 obviously unreachable code. */
281 # define RESET_INPUT_BUFFER \
282 if (FROM_DIRECTION) \
284 if (FROM_LOOP_MIN_NEEDED_FROM % FROM_LOOP_MIN_NEEDED_TO == 0) \
285 *inptrp -= (outbuf - outerr) \
286 * (FROM_LOOP_MIN_NEEDED_FROM / FROM_LOOP_MIN_NEEDED_TO); \
287 else if (FROM_LOOP_MIN_NEEDED_TO % FROM_LOOP_MIN_NEEDED_FROM == 0) \
288 *inptrp -= (outbuf - outerr) \
289 / (FROM_LOOP_MIN_NEEDED_TO / FROM_LOOP_MIN_NEEDED_FROM \
292 *inptrp -= ((outbuf - outerr) / FROM_LOOP_MIN_NEEDED_TO) \
293 * FROM_LOOP_MIN_NEEDED_FROM; \
297 if (TO_LOOP_MIN_NEEDED_FROM % TO_LOOP_MIN_NEEDED_TO == 0) \
298 *inptrp -= (outbuf - outerr) \
299 * (TO_LOOP_MIN_NEEDED_FROM / TO_LOOP_MIN_NEEDED_TO); \
300 else if (TO_LOOP_MIN_NEEDED_TO % TO_LOOP_MIN_NEEDED_FROM == 0) \
301 *inptrp -= (outbuf - outerr) \
302 / (TO_LOOP_MIN_NEEDED_TO / TO_LOOP_MIN_NEEDED_FROM ? : 1); \
304 *inptrp -= ((outbuf - outerr) / TO_LOOP_MIN_NEEDED_TO) \
305 * TO_LOOP_MIN_NEEDED_FROM; \
311 /* The default init function. It simply matches the name and initializes
312 the step data to point to one of the objects above. */
314 # ifndef CHARSET_NAME
315 # error "CHARSET_NAME not defined"
318 extern int gconv_init (struct __gconv_step
*step
);
320 gconv_init (struct __gconv_step
*step
)
322 /* Determine which direction. */
323 if (strcmp (step
->__from_name
, CHARSET_NAME
) == 0)
325 step
->__data
= FROM_DIRECTION_VAL
;
327 step
->__min_needed_from
= FROM_LOOP_MIN_NEEDED_FROM
;
328 step
->__max_needed_from
= FROM_LOOP_MAX_NEEDED_FROM
;
329 step
->__min_needed_to
= FROM_LOOP_MIN_NEEDED_TO
;
330 step
->__max_needed_to
= FROM_LOOP_MAX_NEEDED_TO
;
333 step
->__btowc_fct
= FROM_ONEBYTE
;
336 else if (__builtin_expect (strcmp (step
->__to_name
, CHARSET_NAME
), 0) == 0)
338 step
->__data
= TO_DIRECTION_VAL
;
340 step
->__min_needed_from
= TO_LOOP_MIN_NEEDED_FROM
;
341 step
->__max_needed_from
= TO_LOOP_MAX_NEEDED_FROM
;
342 step
->__min_needed_to
= TO_LOOP_MIN_NEEDED_TO
;
343 step
->__max_needed_to
= TO_LOOP_MAX_NEEDED_TO
;
346 return __GCONV_NOCONV
;
348 #ifdef SAVE_RESET_STATE
349 step
->__stateful
= 1;
351 step
->__stateful
= 0;
359 /* The default destructor function does nothing in the moment and so
360 we don't define it at all. But we still provide the macro just in
361 case we need it some day. */
366 /* If no arguments have to passed to the loop function define the macro
368 #ifndef EXTRA_LOOP_ARGS
369 # define EXTRA_LOOP_ARGS
373 /* This is the actual conversion function. */
374 #ifndef FUNCTION_NAME
375 # define FUNCTION_NAME gconv
378 /* The macros are used to access the function to convert single characters. */
379 #define SINGLE(fct) SINGLE2 (fct)
380 #define SINGLE2(fct) fct##_single
383 extern int FUNCTION_NAME (struct __gconv_step
*step
,
384 struct __gconv_step_data
*data
,
385 const unsigned char **inptrp
,
386 const unsigned char *inend
,
387 unsigned char **outbufstart
, size_t *irreversible
,
388 int do_flush
, int consume_incomplete
);
390 FUNCTION_NAME (struct __gconv_step
*step
, struct __gconv_step_data
*data
,
391 const unsigned char **inptrp
, const unsigned char *inend
,
392 unsigned char **outbufstart
, size_t *irreversible
, int do_flush
,
393 int consume_incomplete
)
395 struct __gconv_step
*next_step
= step
+ 1;
396 struct __gconv_step_data
*next_data
= data
+ 1;
397 __gconv_fct fct
= NULL
;
400 if ((data
->__flags
& __GCONV_IS_LAST
) == 0)
402 fct
= next_step
->__fct
;
404 if (next_step
->__shlib_handle
!= NULL
)
409 /* If the function is called with no input this means we have to reset
410 to the initial state. The possibly partly converted input is
412 if (__glibc_unlikely (do_flush
))
414 /* This should never happen during error handling. */
415 assert (outbufstart
== NULL
);
419 #ifdef EMIT_SHIFT_TO_INIT
422 /* We preserve the initial values of the pointer variables. */
423 unsigned char *outbuf
= data
->__outbuf
;
424 unsigned char *outstart
= outbuf
;
425 unsigned char *outend
= data
->__outbufend
;
431 # ifdef SAVE_RESET_STATE
432 SAVE_RESET_STATE (1);
435 /* Emit the escape sequence to reset the state. */
438 /* Call the steps down the chain if there are any but only if we
439 successfully emitted the escape sequence. This should only
440 fail if the output buffer is full. If the input is invalid
441 it should be discarded since the user wants to start from a
443 if (status
== __GCONV_OK
)
445 if (data
->__flags
& __GCONV_IS_LAST
)
446 /* Store information about how many bytes are available. */
447 data
->__outbuf
= outbuf
;
450 /* Write out all output which was produced. */
451 if (outbuf
> outstart
)
453 const unsigned char *outerr
= outstart
;
456 result
= DL_CALL_FCT (fct
, (next_step
, next_data
,
457 &outerr
, outbuf
, NULL
,
459 consume_incomplete
));
461 if (result
!= __GCONV_EMPTY_INPUT
)
463 if (__glibc_unlikely (outerr
!= outbuf
))
465 /* We have a problem. Undo the conversion. */
468 /* Restore the state. */
469 # ifdef SAVE_RESET_STATE
470 SAVE_RESET_STATE (0);
474 /* Change the status. */
479 if (status
== __GCONV_OK
)
480 /* Now flush the remaining steps. */
481 status
= DL_CALL_FCT (fct
, (next_step
, next_data
, NULL
,
482 NULL
, NULL
, irreversible
, 1,
483 consume_incomplete
));
490 /* Clear the state object. There might be bytes in there from
491 previous calls with CONSUME_INCOMPLETE == 1. But don't emit
493 memset (data
->__statep
, '\0', sizeof (*data
->__statep
));
495 if (! (data
->__flags
& __GCONV_IS_LAST
))
496 /* Now flush the remaining steps. */
497 status
= DL_CALL_FCT (fct
, (next_step
, next_data
, NULL
, NULL
,
498 NULL
, irreversible
, do_flush
,
499 consume_incomplete
));
504 /* We preserve the initial values of the pointer variables,
505 but only some conversion modules need it. */
506 const unsigned char *inptr
__attribute__ ((__unused__
)) = *inptrp
;
507 unsigned char *outbuf
= (__builtin_expect (outbufstart
== NULL
, 1)
508 ? data
->__outbuf
: *outbufstart
);
509 unsigned char *outend
= data
->__outbufend
;
510 unsigned char *outstart
;
511 /* This variable is used to count the number of characters we
512 actually converted. */
513 size_t lirreversible
= 0;
514 size_t *lirreversiblep
= irreversible
? &lirreversible
: NULL
;
516 /* The following assumes that encodings, which have a variable length
517 what might unalign a buffer even though it is an aligned in the
518 beginning, either don't have the minimal number of bytes as a divisor
519 of the maximum length or have a minimum length of 1. This is true
520 for all known and supported encodings.
521 We use && instead of || to combine the subexpression for the FROM
522 encoding and for the TO encoding, because usually one of them is
523 INTERNAL, for which the subexpression evaluates to 1, but INTERNAL
524 buffers are always aligned correctly. */
525 #define POSSIBLY_UNALIGNED \
526 (!_STRING_ARCH_unaligned \
527 && (((FROM_LOOP_MIN_NEEDED_FROM != 1 \
528 && FROM_LOOP_MAX_NEEDED_FROM % FROM_LOOP_MIN_NEEDED_FROM == 0) \
529 && (FROM_LOOP_MIN_NEEDED_TO != 1 \
530 && FROM_LOOP_MAX_NEEDED_TO % FROM_LOOP_MIN_NEEDED_TO == 0)) \
531 || ((TO_LOOP_MIN_NEEDED_FROM != 1 \
532 && TO_LOOP_MAX_NEEDED_FROM % TO_LOOP_MIN_NEEDED_FROM == 0) \
533 && (TO_LOOP_MIN_NEEDED_TO != 1 \
534 && TO_LOOP_MAX_NEEDED_TO % TO_LOOP_MIN_NEEDED_TO == 0))))
535 #if POSSIBLY_UNALIGNED
537 # define GEN_unaligned(name) GEN_unaligned2 (name)
538 # define GEN_unaligned2(name) name##_unaligned
547 #if FROM_LOOP_MAX_NEEDED_FROM > 1 || TO_LOOP_MAX_NEEDED_FROM > 1
548 /* If the function is used to implement the mb*towc*() or wc*tomb*()
549 functions we must test whether any bytes from the last call are
550 stored in the `state' object. */
551 if (((FROM_LOOP_MAX_NEEDED_FROM
> 1 && TO_LOOP_MAX_NEEDED_FROM
> 1)
552 || (FROM_LOOP_MAX_NEEDED_FROM
> 1 && FROM_DIRECTION
)
553 || (TO_LOOP_MAX_NEEDED_FROM
> 1 && !FROM_DIRECTION
))
554 && consume_incomplete
&& (data
->__statep
->__count
& 7) != 0)
556 /* Yep, we have some bytes left over. Process them now.
557 But this must not happen while we are called from an
559 assert (outbufstart
== NULL
);
561 # if FROM_LOOP_MAX_NEEDED_FROM > 1
562 if (TO_LOOP_MAX_NEEDED_FROM
== 1 || FROM_DIRECTION
)
563 status
= SINGLE(FROM_LOOP
) (step
, data
, inptrp
, inend
, &outbuf
,
564 outend
, lirreversiblep
568 # if FROM_LOOP_MAX_NEEDED_FROM > 1 && TO_LOOP_MAX_NEEDED_FROM > 1
571 # if TO_LOOP_MAX_NEEDED_FROM > 1
572 status
= SINGLE(TO_LOOP
) (step
, data
, inptrp
, inend
, &outbuf
,
573 outend
, lirreversiblep EXTRA_LOOP_ARGS
);
577 if (__builtin_expect (status
, __GCONV_OK
) != __GCONV_OK
)
582 #if POSSIBLY_UNALIGNED
585 && ((uintptr_t) inptr
% FROM_LOOP_MIN_NEEDED_FROM
!= 0
586 || ((data
->__flags
& __GCONV_IS_LAST
)
587 && (uintptr_t) outbuf
% FROM_LOOP_MIN_NEEDED_TO
!= 0)))
589 && (((data
->__flags
& __GCONV_IS_LAST
)
590 && (uintptr_t) outbuf
% TO_LOOP_MIN_NEEDED_TO
!= 0)
591 || (uintptr_t) inptr
% TO_LOOP_MIN_NEEDED_FROM
!= 0)));
596 /* Remember the start value for this round. */
598 /* The outbuf buffer is empty. */
601 #ifdef SAVE_RESET_STATE
602 SAVE_RESET_STATE (1);
605 if (__glibc_likely (!unaligned
))
608 /* Run the conversion loop. */
609 status
= FROM_LOOP (step
, data
, inptrp
, inend
, &outbuf
, outend
,
610 lirreversiblep EXTRA_LOOP_ARGS
);
612 /* Run the conversion loop. */
613 status
= TO_LOOP (step
, data
, inptrp
, inend
, &outbuf
, outend
,
614 lirreversiblep EXTRA_LOOP_ARGS
);
616 #if POSSIBLY_UNALIGNED
620 /* Run the conversion loop. */
621 status
= GEN_unaligned (FROM_LOOP
) (step
, data
, inptrp
, inend
,
626 /* Run the conversion loop. */
627 status
= GEN_unaligned (TO_LOOP
) (step
, data
, inptrp
, inend
,
634 /* If we were called as part of an error handling module we
635 don't do anything else here. */
636 if (__glibc_unlikely (outbufstart
!= NULL
))
638 *outbufstart
= outbuf
;
642 /* We finished one use of the loops. */
643 ++data
->__invocation_counter
;
645 /* If this is the last step leave the loop, there is nothing
647 if (__glibc_unlikely (data
->__flags
& __GCONV_IS_LAST
))
649 /* Store information about how many bytes are available. */
650 data
->__outbuf
= outbuf
;
652 /* Remember how many non-identical characters we
653 converted in an irreversible way. */
654 *irreversible
+= lirreversible
;
659 /* Write out all output which was produced. */
660 if (__glibc_likely (outbuf
> outstart
))
662 const unsigned char *outerr
= data
->__outbuf
;
665 result
= DL_CALL_FCT (fct
, (next_step
, next_data
, &outerr
,
666 outbuf
, NULL
, irreversible
, 0,
667 consume_incomplete
));
669 if (result
!= __GCONV_EMPTY_INPUT
)
671 if (__glibc_unlikely (outerr
!= outbuf
))
673 #ifdef RESET_INPUT_BUFFER
676 /* We have a problem in one of the functions below.
677 Undo the conversion upto the error point. */
678 size_t nstatus
__attribute__ ((unused
));
680 /* Reload the pointers. */
684 /* Restore the state. */
685 # ifdef SAVE_RESET_STATE
686 SAVE_RESET_STATE (0);
689 if (__glibc_likely (!unaligned
))
692 /* Run the conversion loop. */
693 nstatus
= FROM_LOOP (step
, data
, inptrp
, inend
,
698 /* Run the conversion loop. */
699 nstatus
= TO_LOOP (step
, data
, inptrp
, inend
,
704 # if POSSIBLY_UNALIGNED
708 /* Run the conversion loop. */
709 nstatus
= GEN_unaligned (FROM_LOOP
) (step
, data
,
716 /* Run the conversion loop. */
717 nstatus
= GEN_unaligned (TO_LOOP
) (step
, data
,
725 /* We must run out of output buffer space in this
727 assert (outbuf
== outerr
);
728 assert (nstatus
== __GCONV_FULL_OUTPUT
);
730 /* If we haven't consumed a single byte decrement
731 the invocation counter. */
732 if (__glibc_unlikely (outbuf
== outstart
))
733 --data
->__invocation_counter
;
734 #endif /* reset input buffer */
737 /* Change the status. */
741 /* All the output is consumed, we can make another run
742 if everything was ok. */
743 if (status
== __GCONV_FULL_OUTPUT
)
746 outbuf
= data
->__outbuf
;
750 if (status
!= __GCONV_OK
)
753 /* Reset the output buffer pointer for the next round. */
754 outbuf
= data
->__outbuf
;
761 /* If we are supposed to consume all character store now all of the
762 remaining characters in the `state' object. */
763 #if FROM_LOOP_MAX_NEEDED_FROM > 1 || TO_LOOP_MAX_NEEDED_FROM > 1
764 if (((FROM_LOOP_MAX_NEEDED_FROM
> 1 && TO_LOOP_MAX_NEEDED_FROM
> 1)
765 || (FROM_LOOP_MAX_NEEDED_FROM
> 1 && FROM_DIRECTION
)
766 || (TO_LOOP_MAX_NEEDED_FROM
> 1 && !FROM_DIRECTION
))
767 && __builtin_expect (consume_incomplete
, 0)
768 && status
== __GCONV_INCOMPLETE_INPUT
)
771 mbstate_t *state
= data
->__statep
;
775 /* Make sure the remaining bytes fit into the state objects
777 assert (inend
- *inptrp
< 4);
780 for (cnt
= 0; *inptrp
< inend
; ++cnt
)
781 data
->__statep
->__value
.__wchb
[cnt
] = *(*inptrp
)++;
782 data
->__statep
->__count
&= ~7;
783 data
->__statep
->__count
|= cnt
;
788 #undef POSSIBLY_UNALIGNED
797 #undef MIN_NEEDED_FROM
799 #undef MAX_NEEDED_FROM
801 #undef FROM_LOOP_MIN_NEEDED_FROM
802 #undef FROM_LOOP_MAX_NEEDED_FROM
803 #undef FROM_LOOP_MIN_NEEDED_TO
804 #undef FROM_LOOP_MAX_NEEDED_TO
805 #undef TO_LOOP_MIN_NEEDED_FROM
806 #undef TO_LOOP_MAX_NEEDED_FROM
807 #undef TO_LOOP_MIN_NEEDED_TO
808 #undef TO_LOOP_MAX_NEEDED_TO
809 #undef FROM_DIRECTION
810 #undef EMIT_SHIFT_TO_INIT
814 #undef SAVE_RESET_STATE
815 #undef RESET_INPUT_BUFFER
819 #undef EXTRA_LOOP_ARGS