OSDN Git Service

(split) LDP: Change Makefile to stamp-based compilation
[linuxjm/LDP_man-pages.git] / original / man3 / mbsinit.3
1 .\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
2 .\"
3 .\" %%%LICENSE_START(GPLv2+_DOC_ONEPARA)
4 .\" This is free documentation; 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 of
7 .\" the License, or (at your option) any later version.
8 .\" %%%LICENSE_END
9 .\"
10 .\" References consulted:
11 .\"   GNU glibc-2 source code and manual
12 .\"   Dinkumware C library reference http://www.dinkumware.com/
13 .\"   OpenGroup's Single UNIX specification http://www.UNIX-systems.org/online.html
14 .\"   ISO/IEC 9899:1999
15 .\"
16 .TH MBSINIT 3  2000-11-20 "GNU" "Linux Programmer's Manual"
17 .SH NAME
18 mbsinit \- test for initial shift state
19 .SH SYNOPSIS
20 .nf
21 .B #include <wchar.h>
22 .sp
23 .BI "int mbsinit(const mbstate_t *" ps );
24 .fi
25 .SH DESCRIPTION
26 Character conversion between the multibyte representation and the wide
27 character representation uses conversion state, of type \fImbstate_t\fP.
28 Conversion of a string uses a finite-state machine; when it is interrupted
29 after the complete conversion of a number of characters, it may need to
30 save a state for processing the remaining characters.
31 Such a conversion
32 state is needed for the sake of encodings such as ISO-2022 and UTF-7.
33 .PP
34 The initial state is the state at the beginning of conversion of a string.
35 There are two kinds of state: The one used by multibyte to wide character
36 conversion functions, such as
37 .BR mbsrtowcs (3),
38 and the one used by wide
39 character to multibyte conversion functions, such as
40 .BR wcsrtombs (3),
41 but they both fit in a \fImbstate_t\fP, and they both have the same
42 representation for an initial state.
43 .PP
44 For 8-bit encodings, all states are equivalent to the initial state.
45 For multibyte encodings like UTF-8, EUC-*, BIG5 or SJIS, the wide character
46 to multibyte conversion functions never produce non-initial states, but the
47 multibyte to wide-character conversion functions like
48 .BR mbrtowc (3)
49 do
50 produce non-initial states when interrupted in the middle of a character.
51 .PP
52 One possible way to create an
53 .I mbstate_t
54 in initial state is to set it to zero:
55 .nf
56
57     mbstate_t state;
58     memset(&state,0,sizeof(mbstate_t));
59 .fi
60 .PP
61 On Linux, the following works as well, but might generate compiler warnings:
62 .nf
63
64     mbstate_t state = { 0 };
65 .fi
66 .PP
67 The function
68 .BR mbsinit ()
69 tests whether \fI*ps\fP corresponds to an
70 initial state.
71 .SH RETURN VALUE
72 .BR mbsinit ()
73 returns nonzero if \fI*ps\fP is an initial state, or if
74 \fIps\fP is a NULL pointer.
75 Otherwise it returns 0.
76 .SH CONFORMING TO
77 C99.
78 .SH NOTES
79 The behavior of
80 .BR mbsinit ()
81 depends on the
82 .B LC_CTYPE
83 category of the
84 current locale.
85 .SH SEE ALSO
86 .BR mbsrtowcs (3),
87 .BR wcsrtombs (3)