FreeTDS API: include/freetds/iconv.h Source File

FreeTDS API

iconv.h
1 /* FreeTDS - Library of routines accessing Sybase and Microsoft databases
2 * Copyright (C) 2002, 2003, 2004 Brian Bruns
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 */
19
20 #ifndef _tds_iconv_h_
21 #define _tds_iconv_h_
22
23 #if HAVE_ICONV
24 #include <iconv.h>
25 #else
26 /* Define iconv_t for src/replacements/iconv.c. */
27 #undef iconv_t
28 typedef void *iconv_t;
29 #endif /* HAVE_ICONV */
30
31 #if HAVE_ERRNO_H
32 #include <errno.h>
33 #endif
34
35 #if HAVE_WCHAR_H
36 #include <wchar.h>
37 #endif
38
39 /* The following EILSEQ advice is borrowed verbatim from GNU iconv. */
40 /* Some systems, like SunOS 4, don't have EILSEQ. Some systems, like BSD/OS,
41 have EILSEQ in a different header. On these systems, define EILSEQ
42 ourselves. */
43 #ifndef EILSEQ
44 # define EILSEQ ENOENT
45 #endif
46
47 #if HAVE_STDLIB_H
48 #include <stdlib.h>
49 #endif /* HAVE_STDLIB_H */
50
51 #include <freetds/pushvis.h>
52
53 #ifdef __cplusplus
54 extern "C"
55 {
56 #endif
57
58 #if ! HAVE_ICONV
59 iconv_t tds_sys_iconv_open(const char *tocode, const char *fromcode);
60 size_t tds_sys_iconv(iconv_t cd, const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft);
61 int tds_sys_iconv_close(iconv_t cd);
62 #else
63 #define tds_sys_iconv_open iconv_open
64 #define tds_sys_iconv iconv
65 #define tds_sys_iconv_close iconv_close
66 #endif /* !HAVE_ICONV */
67
68
69 typedef enum
70 { to_server, to_client } TDS_ICONV_DIRECTION;
71
72 typedef struct _character_set_alias
73 {
74 const char *alias;
75 int canonic;
76 } CHARACTER_SET_ALIAS;
77
78 typedef struct tds_errno_message_flags {
79 unsigned int e2big:1;
80 unsigned int eilseq:1;
81 unsigned int einval:1;
82 } TDS_ERRNO_MESSAGE_FLAGS;
83
84 typedef struct tdsiconvdir
85 {
86 TDS_ENCODING charset;
87
88 iconv_t cd;
89 } TDSICONVDIR;
90
91 struct tdsiconvinfo
92 {
93 struct tdsiconvdir to, from;
94
95 #define TDS_ENCODING_MEMCPY 1
96 unsigned int flags;
97
98 /*
99 * Suppress error messages that would otherwise be emitted by tds_iconv().
100 * Functions that process large buffers ask tds_iconv to convert it in "chunks".
101 * We don't want to emit spurious EILSEQ errors or multiple errors for one
102 * buffer. tds_iconv() checks this structure before emiting a message, and
103 * adds to it whenever it emits one. Callers that handle a particular situation themselves
104 * can prepopulate it.
105 */
106 TDS_ERRNO_MESSAGE_FLAGS suppress;
107
108 };
109
110 /* We use ICONV_CONST for tds_iconv(), even if we don't have iconv() */
111 #ifndef ICONV_CONST
112 # define ICONV_CONST const
113 #endif
114
115 size_t tds_iconv(TDSSOCKET * tds, TDSICONV * char_conv, TDS_ICONV_DIRECTION io,
116 const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft);
117 int tds_canonical_charset(const char *charset_name);
118 const char *tds_canonical_charset_name(const char *charset_name);
119 TDSICONV *tds_iconv_get(TDSCONNECTION * conn, const char *client_charset, const char *server_charset);
120 TDSICONV *tds_iconv_get_info(TDSCONNECTION * conn, int canonic_client, int canonic_server);
121
122 #ifdef __cplusplus
123 }
124 #endif
125
126 #include <freetds/popvis.h>
127
128 #endif /* _tds_iconv_h_ */
tdsiconvdir
Definition: iconv.h:85
tds_canonical_charset
int tds_canonical_charset(const char *charset_name)
Determine canonical iconv character set.
Definition: iconv.c:970
tds_iconv_get_info
TDSICONV * tds_iconv_get_info(TDSCONNECTION *conn, int canonic_client, int canonic_server)
Get a iconv info structure, allocate and initialize if needed.
Definition: iconv.c:758
tds_errno_message_flags
Definition: iconv.h:78
tds_canonical_charset_name
const char * tds_canonical_charset_name(const char *charset_name)
Determine canonical iconv character set name.
Definition: iconv.c:982
tdsiconvinfo
Definition: iconv.h:92
tds_connection
Definition: tds.h:1091
tds_sys_iconv_open
iconv_t tds_sys_iconv_open(const char *tocode, const char *fromcode)
Inputs are FreeTDS canonical names, no other.
Definition: iconv.c:360
tds_iconv
size_t tds_iconv(TDSSOCKET *tds, TDSICONV *char_conv, TDS_ICONV_DIRECTION io, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
Wrapper around iconv(3).
Definition: iconv.c:592
tds_socket
Information for a server connection.
Definition: tds.h:1163
tds_encoding
Information relevant to libiconv.
Definition: tds.h:618
_character_set_alias
Definition: iconv.h:73