[kdbus] sync with kdbus (kdbus.h - commit: 5ae1ecac44cb)
[platform/upstream/glib.git] / glib / gconvert.h
1 /* GLIB - Library of useful routines for C programming
2  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser 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  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16  */
17
18 /*
19  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
20  * file for a list of people on the GLib Team.  See the ChangeLog
21  * files for a list of changes.  These files are distributed with
22  * GLib at ftp://ftp.gtk.org/pub/gtk/.
23  */
24
25 #ifndef __G_CONVERT_H__
26 #define __G_CONVERT_H__
27
28 #if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
29 #error "Only <glib.h> can be included directly."
30 #endif
31
32 #include <glib/gerror.h>
33
34 G_BEGIN_DECLS
35
36 /**
37  * GConvertError:
38  * @G_CONVERT_ERROR_NO_CONVERSION: Conversion between the requested character
39  *     sets is not supported.
40  * @G_CONVERT_ERROR_ILLEGAL_SEQUENCE: Invalid byte sequence in conversion input.
41  * @G_CONVERT_ERROR_FAILED: Conversion failed for some reason.
42  * @G_CONVERT_ERROR_PARTIAL_INPUT: Partial character sequence at end of input.
43  * @G_CONVERT_ERROR_BAD_URI: URI is invalid.
44  * @G_CONVERT_ERROR_NOT_ABSOLUTE_PATH: Pathname is not an absolute path.
45  * @G_CONVERT_ERROR_NO_MEMORY: No memory available. Since: 2.40
46  *
47  * Error codes returned by character set conversion routines.
48  */
49 typedef enum
50 {
51   G_CONVERT_ERROR_NO_CONVERSION,
52   G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
53   G_CONVERT_ERROR_FAILED,
54   G_CONVERT_ERROR_PARTIAL_INPUT,
55   G_CONVERT_ERROR_BAD_URI,
56   G_CONVERT_ERROR_NOT_ABSOLUTE_PATH,
57   G_CONVERT_ERROR_NO_MEMORY
58 } GConvertError;
59
60 /**
61  * G_CONVERT_ERROR:
62  *
63  * Error domain for character set conversions. Errors in this domain will
64  * be from the #GConvertError enumeration. See #GError for information on
65  * error domains.
66  */
67 #define G_CONVERT_ERROR g_convert_error_quark()
68 GLIB_AVAILABLE_IN_ALL
69 GQuark g_convert_error_quark (void);
70
71 /**
72  * GIConv:
73  *
74  * The GIConv struct wraps an iconv() conversion descriptor. It contains
75  * private data and should only be accessed using the following functions.
76  */
77 typedef struct _GIConv *GIConv;
78
79 GLIB_AVAILABLE_IN_ALL
80 GIConv g_iconv_open   (const gchar  *to_codeset,
81                        const gchar  *from_codeset);
82 GLIB_AVAILABLE_IN_ALL
83 gsize  g_iconv        (GIConv        converter,
84                        gchar       **inbuf,
85                        gsize        *inbytes_left,
86                        gchar       **outbuf,
87                        gsize        *outbytes_left);
88 GLIB_AVAILABLE_IN_ALL
89 gint   g_iconv_close  (GIConv        converter);
90
91
92 GLIB_AVAILABLE_IN_ALL
93 gchar* g_convert               (const gchar  *str,
94                                 gssize        len,            
95                                 const gchar  *to_codeset,
96                                 const gchar  *from_codeset,
97                                 gsize        *bytes_read,     
98                                 gsize        *bytes_written,  
99                                 GError      **error) G_GNUC_MALLOC;
100 GLIB_AVAILABLE_IN_ALL
101 gchar* g_convert_with_iconv    (const gchar  *str,
102                                 gssize        len,
103                                 GIConv        converter,
104                                 gsize        *bytes_read,     
105                                 gsize        *bytes_written,  
106                                 GError      **error) G_GNUC_MALLOC;
107 GLIB_AVAILABLE_IN_ALL
108 gchar* g_convert_with_fallback (const gchar  *str,
109                                 gssize        len,            
110                                 const gchar  *to_codeset,
111                                 const gchar  *from_codeset,
112                                 const gchar  *fallback,
113                                 gsize        *bytes_read,     
114                                 gsize        *bytes_written,  
115                                 GError      **error) G_GNUC_MALLOC;
116
117
118 /* Convert between libc's idea of strings and UTF-8.
119  */
120 GLIB_AVAILABLE_IN_ALL
121 gchar* g_locale_to_utf8   (const gchar  *opsysstring,
122                            gssize        len,            
123                            gsize        *bytes_read,     
124                            gsize        *bytes_written,  
125                            GError      **error) G_GNUC_MALLOC;
126 GLIB_AVAILABLE_IN_ALL
127 gchar* g_locale_from_utf8 (const gchar  *utf8string,
128                            gssize        len,            
129                            gsize        *bytes_read,     
130                            gsize        *bytes_written,  
131                            GError      **error) G_GNUC_MALLOC;
132
133 /* Convert between the operating system (or C runtime)
134  * representation of file names and UTF-8.
135  */
136 GLIB_AVAILABLE_IN_ALL
137 gchar* g_filename_to_utf8   (const gchar  *opsysstring,
138                              gssize        len,            
139                              gsize        *bytes_read,     
140                              gsize        *bytes_written,  
141                              GError      **error) G_GNUC_MALLOC;
142 GLIB_AVAILABLE_IN_ALL
143 gchar* g_filename_from_utf8 (const gchar  *utf8string,
144                              gssize        len,            
145                              gsize        *bytes_read,     
146                              gsize        *bytes_written,  
147                              GError      **error) G_GNUC_MALLOC;
148
149 GLIB_AVAILABLE_IN_ALL
150 gchar *g_filename_from_uri (const gchar *uri,
151                             gchar      **hostname,
152                             GError     **error) G_GNUC_MALLOC;
153   
154 GLIB_AVAILABLE_IN_ALL
155 gchar *g_filename_to_uri   (const gchar *filename,
156                             const gchar *hostname,
157                             GError     **error) G_GNUC_MALLOC;
158 GLIB_AVAILABLE_IN_ALL
159 gchar *g_filename_display_name (const gchar *filename) G_GNUC_MALLOC;
160 GLIB_AVAILABLE_IN_ALL
161 gboolean g_get_filename_charsets (const gchar ***charsets);
162
163 GLIB_AVAILABLE_IN_ALL
164 gchar *g_filename_display_basename (const gchar *filename) G_GNUC_MALLOC;
165
166 GLIB_AVAILABLE_IN_ALL
167 gchar **g_uri_list_extract_uris (const gchar *uri_list) G_GNUC_MALLOC;
168
169 #ifdef G_OS_WIN32
170 #define g_filename_to_utf8   g_filename_to_utf8_utf8
171 #define g_filename_from_utf8 g_filename_from_utf8_utf8
172 #define g_filename_from_uri  g_filename_from_uri_utf8
173 #define g_filename_to_uri    g_filename_to_uri_utf8
174
175 GLIB_AVAILABLE_IN_ALL
176 gchar* g_filename_to_utf8_utf8   (const gchar  *opsysstring,
177                                   gssize        len,
178                                   gsize        *bytes_read,
179                                   gsize        *bytes_written,
180                                   GError      **error) G_GNUC_MALLOC;
181 GLIB_AVAILABLE_IN_ALL
182 gchar* g_filename_from_utf8_utf8 (const gchar  *utf8string,
183                                   gssize        len,
184                                   gsize        *bytes_read,
185                                   gsize        *bytes_written,
186                                   GError      **error) G_GNUC_MALLOC;
187 GLIB_AVAILABLE_IN_ALL
188 gchar *g_filename_from_uri_utf8  (const gchar  *uri,
189                                   gchar       **hostname,
190                                   GError      **error) G_GNUC_MALLOC;
191 GLIB_AVAILABLE_IN_ALL
192 gchar *g_filename_to_uri_utf8    (const gchar  *filename,
193                                   const gchar  *hostname,
194                                   GError      **error) G_GNUC_MALLOC;
195 #endif
196
197 G_END_DECLS
198
199 #endif /* __G_CONVERT_H__ */