FreeTDS API
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
tdsiconv.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 /* $Id: tdsiconv.h,v 1.40 2010-07-25 08:40:19 freddy77 Exp $ */
24 
25 #if HAVE_ICONV
26 #include <iconv.h>
27 #else
28 /* Define iconv_t for src/replacements/iconv.c. */
29 #undef iconv_t
30 typedef void *iconv_t;
31 #endif /* HAVE_ICONV */
32 
33 #if HAVE_ERRNO_H
34 #include <errno.h>
35 #endif
36 
37 #if HAVE_WCHAR_H
38 #include <wchar.h>
39 #endif
40 
41 /* The following EILSEQ advice is borrowed verbatim from GNU iconv. */
42 /* Some systems, like SunOS 4, don't have EILSEQ. Some systems, like BSD/OS,
43  have EILSEQ in a different header. On these systems, define EILSEQ
44  ourselves. */
45 #ifndef EILSEQ
46 # define EILSEQ ENOENT
47 #endif
48 
49 #if HAVE_STDLIB_H
50 #include <stdlib.h>
51 #endif /* HAVE_STDLIB_H */
52 
53 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
54 #pragma GCC visibility push(hidden)
55 #endif
56 
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61 
62 #if ! HAVE_ICONV
63 iconv_t tds_sys_iconv_open(const char *tocode, const char *fromcode);
64 size_t tds_sys_iconv(iconv_t cd, const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft);
65 int tds_sys_iconv_close(iconv_t cd);
66 #else
67 #define tds_sys_iconv_open iconv_open
68 #define tds_sys_iconv iconv
69 #define tds_sys_iconv_close iconv_close
70 #endif /* !HAVE_ICONV */
71 
72 
73 typedef enum
74 { to_server, to_client } TDS_ICONV_DIRECTION;
75 
76 typedef struct _character_set_alias
77 {
78  const char *alias;
79  int canonic;
81 
82 typedef struct tds_errno_message_flags {
83  unsigned int e2big:1;
84  unsigned int eilseq:1;
85  unsigned int einval:1;
87 
88 typedef struct tdsiconvdir
89 {
90  TDS_ENCODING charset;
91 
92  iconv_t cd;
93  iconv_t cd2;
94 
95  unsigned char num_got;
96  unsigned char num_left;
97  char left[6];
98 } TDSICONVDIR;
99 
101 {
102  struct tdsiconvdir to, from;
103 
104 #define TDS_ENCODING_INDIRECT 1
105 #define TDS_ENCODING_SWAPBYTE 2
106 #define TDS_ENCODING_MEMCPY 4
107  unsigned int flags;
108 
109  /*
110  * Suppress error messages that would otherwise be emitted by tds_iconv().
111  * Functions that process large buffers ask tds_iconv to convert it in "chunks".
112  * We don't want to emit spurious EILSEQ errors or multiple errors for one
113  * buffer. tds_iconv() checks this structure before emiting a message, and
114  * adds to it whenever it emits one. Callers that handle a particular situation themselves
115  * can prepopulate it.
116  */
117  TDS_ERRNO_MESSAGE_FLAGS suppress;
118 
119 };
120 
121 /* We use ICONV_CONST for tds_iconv(), even if we don't have iconv() */
122 #ifndef ICONV_CONST
123 # define ICONV_CONST const
124 #endif
125 
126 size_t tds_iconv_fread(TDSSOCKET * tds, TDSICONV * conv, FILE * stream, size_t field_len, size_t term_len, char *outbuf, size_t * outbytesleft);
127 size_t tds_iconv(TDSSOCKET * tds, TDSICONV * char_conv, TDS_ICONV_DIRECTION io,
128  const char **inbuf, size_t * inbytesleft, char **outbuf, size_t * outbytesleft);
129 const char *tds_canonical_charset_name(const char *charset_name);
130 const char *tds_sybase_charset_name(const char *charset_name);
131 TDSICONV *tds_iconv_get(TDSSOCKET * tds, const char *client_charset, const char *server_charset);
132 
133 #ifdef __cplusplus
134 }
135 #endif
136 
137 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__MINGW32__)
138 #pragma GCC visibility pop
139 #endif
140 
141 #endif /* _tds_iconv_h_ */
Information for a server connection.
Definition: tds.h:1329
Definition: tdsiconv.h:76
Definition: tdsiconv.h:88
size_t tds_iconv_fread(TDSSOCKET *tds, TDSICONV *conv, FILE *stream, size_t field_len, size_t term_len, char *outbuf, size_t *outbytesleft)
Read a data file, passing the data through iconv().
Definition: iconv.c:919
const char * tds_sybase_charset_name(const char *charset_name)
Determine the name Sybase uses for a character set, given a canonical iconv name. ...
Definition: iconv.c:1271
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:747
const char * tds_canonical_charset_name(const char *charset_name)
Determine canonical iconv character set name.
Definition: iconv.c:1253
Definition: tdsiconv.h:100
Definition: tdsiconv.h:82
Information relevant to libiconv.
Definition: tds.h:974
iconv_t tds_sys_iconv_open(const char *tocode, const char *fromcode)
Inputs are FreeTDS canonical names, no other.
Definition: iconv.c:342