GMime 2.4 Reference Manual | ||||
---|---|---|---|---|
void g_mime_iconv_init (void); void g_mime_iconv_shutdown (void); iconv_t g_mime_iconv_open (const char *to, const char *from); #define g_mime_iconv (cd,inbuf,inleft,outbuf,outleft) int g_mime_iconv_close (iconv_t cd);
These functions are wrappers around the system iconv(3) routines. The purpose of these wrappers are two-fold:
1. Cache iconv_t descriptors for you in order to optimize opening/closing many descriptors frequently
and
2. To use the appropriate system charset alias for the MIME charset names given as arguments.
void g_mime_iconv_init (void);
Initialize GMime's iconv cache. This *MUST* be called before any gmime-iconv interfaces will work correctly.
Note: this function is called for you by g_mime_init()
.
void g_mime_iconv_shutdown (void);
Frees internal iconv caches created in g_mime_iconv_init()
.
Note: this function is called for you by g_mime_shutdown()
.
iconv_t g_mime_iconv_open (const char *to, const char *from);
Allocates a coversion descriptor suitable for converting byte
sequences from charset from
to charset to
. The resulting
descriptor can be used with iconv()
(or the g_mime_iconv()
wrapper) any
number of times until closed using g_mime_iconv_close()
.
See the manual page for iconv_open(3) for further details.
|
charset to convert to |
|
charset to convert from |
Returns : |
a new conversion descriptor for use with g_mime_iconv() on
success or (iconv_t) -1 on fail as well as setting an appropriate
errno value.
|
#define g_mime_iconv(cd,inbuf,inleft,outbuf,outleft)
The argument cd
must be a conversion descriptor created using the
function g_mime_iconv_open.
The main case is when inbuf
is not NULL
and *inbuf is not
NULL
. In this case, the g_mime_iconv function converts the
multibyte sequence starting at *inbuf to a multibyte sequence
starting at *outbuf. At most *inleft bytes, starting at *inbuf,
will be read. At most *outleft bytes, starting at *outbuf, will
be written.
The g_mime_iconv function converts one multibyte character at a
time, and for each character conversion it increments *inbuf and
decrements *inleft by the number of converted input bytes, it
increments *outbuf and decrements *outleft by the number of
converted output bytes, and it updates the conversion state
contained in cd
. The conversion can stop for four reasons:
1. An invalid multibyte sequence is encountered in the input. In
this case it sets errno to EILSEQ
and returns (size_t)(-1).
*inbuf is left pointing to the beginning of the invalid multibyte
sequence.
2. The input byte sequence has been entirely converted, i.e.
*inleft has gone down to 0
. In this case g_mime_iconv returns
the number of non-reversible conversions performed during this
call.
3. An incomplete multibyte sequence is encountered in the input,
and the input byte sequence terminates after it. In this case it
sets errno to EINVAL
and returns (size_t)(-1). *inbuf is left
pointing to the beginning of the incomplete multibyte sequence.
4. The output buffer has no more room for the next converted
character. In this case it sets errno to E2BIG
and returns
(size_t)(-1).
A different case is when inbuf
is NULL
or *inbuf is NULL
, but
outbuf
is not NULL
and *outbuf is not NULL
. In this case, the
g_mime_iconv function attempts to set cd
's conversion state to
the initial state and store a corresponding shift sequence at
*outbuf. At most *outleft bytes, starting at *outbuf, will be
written. If the output buffer has no more room for this reset
sequence, it sets errno to E2BIG
and returns (size_t)(-1).
Otherwise it increments *outbuf and decrements *outleft by the
number of bytes written.
A third case is when inbuf
is NULL
or *inbuf is NULL
, and
outbuf
is NULL
or *outbuf is NULL
. In this case, the
g_mime_iconv function sets cd
's conversion state to the initial
state.
|
iconv_t conversion descriptor |
|
input buffer |
|
number of bytes left in inbuf
|
|
output buffer |
|
number of bytes left in outbuf
|