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

FreeTDS API

Loading...
Searching...
No Matches
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 _tdsguard_c6YssGkHHqKMDRUMOWVASl_
21#define _tdsguard_c6YssGkHHqKMDRUMOWVASl_
22
23#if HAVE_ICONV
24#include <iconv.h>
25/* avoid conflict with win-iconv library */
26#if defined(_LIBICONV_H) && defined(WINICONV_CONST)
27#undef libiconv_open
28#undef libiconv_close
29#undef libiconv
30#endif
31#else
32/* Define iconv_t for src/replacements/iconv.c. */
33#undef iconv_t
34typedef void *iconv_t;
35#endif /* HAVE_ICONV */
36
37#if HAVE_ERRNO_H
38#include <errno.h>
39#endif
40
41#if HAVE_WCHAR_H
42#include <wchar.h>
43#endif
44
45/* The following EILSEQ advice is borrowed verbatim from GNU iconv. */
46/* Some systems, like SunOS 4, don't have EILSEQ. Some systems, like BSD/OS,
47 have EILSEQ in a different header. On these systems, define EILSEQ
48 ourselves. */
49#ifndef EILSEQ
50# define EILSEQ ENOENT
51#endif
52
53#if HAVE_STDLIB_H
54#include <stdlib.h>
55#endif /* HAVE_STDLIB_H */
56
57#include <freetds/pushvis.h>
58
59#ifdef __cplusplus
60extern "C"
61{
62#endif
63
64#if ! HAVE_ICONV
65iconv_t tds_sys_iconv_open(const char *tocode, const char *fromcode);
66size_t tds_sys_iconv(iconv_t cd, const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft);
67int tds_sys_iconv_close(iconv_t cd);
68#else
69#define tds_sys_iconv_open iconv_open
70#define tds_sys_iconv iconv
71#define tds_sys_iconv_close iconv_close
72#endif /* !HAVE_ICONV */
73
74
75typedef enum
76{ to_server, to_client } TDS_ICONV_DIRECTION;
77
78 typedef struct _character_set_alias
79{
80 const char *alias;
81 int canonic;
82} CHARACTER_SET_ALIAS;
83
84 typedef struct tds_errno_message_flags {
85 unsigned int e2big:1;
86 unsigned int eilseq:1;
87 unsigned int einval:1;
88} TDS_ERRNO_MESSAGE_FLAGS;
89
90 typedef struct tdsiconvdir
91{
92 TDS_ENCODING charset;
93
94 iconv_t cd;
95} TDSICONVDIR;
96
97 struct tdsiconvinfo
98{
99 struct tdsiconvdir to, from;
100
101#define TDS_ENCODING_MEMCPY 1
102 unsigned int flags;
103
104 /*
105 * Suppress error messages that would otherwise be emitted by tds_iconv().
106 * Functions that process large buffers ask tds_iconv to convert it in "chunks".
107 * We don't want to emit spurious EILSEQ errors or multiple errors for one
108 * buffer. tds_iconv() checks this structure before emiting a message, and
109 * adds to it whenever it emits one. Callers that handle a particular situation themselves
110 * can prepopulate it.
111 */
112 TDS_ERRNO_MESSAGE_FLAGS suppress;
113
114};
115
116/* We use ICONV_CONST for tds_iconv(), even if we don't have iconv() */
117#ifndef ICONV_CONST
118# define ICONV_CONST const
119#endif
120
121size_t tds_iconv(TDSSOCKET * tds, TDSICONV * char_conv, TDS_ICONV_DIRECTION io,
122 const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft);
123int tds_canonical_charset(const char *charset_name);
124const char *tds_canonical_charset_name(const char *charset_name);
125TDSICONV *tds_iconv_get(TDSCONNECTION * conn, const char *client_charset, const char *server_charset);
126TDSICONV *tds_iconv_get_info(TDSCONNECTION * conn, int canonic_client, int canonic_server);
127
128#ifdef __cplusplus
129}
130#endif
131
132#include <freetds/popvis.h>
133
134#endif /* _tdsguard_c6YssGkHHqKMDRUMOWVASl_ */
TDS_ENCODING
struct tds_encoding TDS_ENCODING
Information relevant to libiconv.
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:762
tds_canonical_charset_name
const char * tds_canonical_charset_name(const char *charset_name)
Determine canonical iconv character set name.
Definition iconv.c:986
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:593
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:345
tds_canonical_charset
int tds_canonical_charset(const char *charset_name)
Determine canonical iconv character set.
Definition iconv.c:974
_character_set_alias
Definition iconv.h:79
tds_errno_message_flags
Definition iconv.h:84
tdsiconvdir
Definition iconv.h:91
tdsiconvinfo
Definition iconv.h:98