Fix problems on 64-bit Windows. Avoid warnings, some of which indicated
[platform/upstream/glib.git] / glib / giochannel.h
index 8f2d341..2a40aa2 100644 (file)
  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
  * file for a list of people on the GLib Team.  See the ChangeLog
  * files for a list of changes.  These files are distributed with
- * GLib at ftp://ftp.gtk.org/pub/gtk/. 
+ * GLib at ftp://ftp.gtk.org/pub/gtk/.
  */
 
+#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
+#error "Only <glib.h> can be included directly."
+#endif
+
 #ifndef __G_IOCHANNEL_H__
 #define __G_IOCHANNEL_H__
 
+#include <glib/gconvert.h>
 #include <glib/gmain.h>
-#include <glib/gtypes.h>
 #include <glib/gstring.h>
 
 G_BEGIN_DECLS
@@ -47,26 +51,20 @@ typedef enum
   G_IO_ERROR_UNKNOWN
 } GIOError;
 
-#define G_IO_CHANNEL_ERROR g_channel_error_quark()
+#define G_IO_CHANNEL_ERROR g_io_channel_error_quark()
 
 typedef enum
 {
   /* Derived from errno */
-  G_IO_CHANNEL_ERROR_ACCES,
-  G_IO_CHANNEL_ERROR_BADF,
-  G_IO_CHANNEL_ERROR_DEADLK,
-  G_IO_CHANNEL_ERROR_FAULT,
+  G_IO_CHANNEL_ERROR_FBIG,
   G_IO_CHANNEL_ERROR_INVAL,
   G_IO_CHANNEL_ERROR_IO,
   G_IO_CHANNEL_ERROR_ISDIR,
-  G_IO_CHANNEL_ERROR_MFILE,
-  G_IO_CHANNEL_ERROR_NOLCK,
   G_IO_CHANNEL_ERROR_NOSPC,
-  G_IO_CHANNEL_ERROR_PERM,
+  G_IO_CHANNEL_ERROR_NXIO,
+  G_IO_CHANNEL_ERROR_OVERFLOW,
   G_IO_CHANNEL_ERROR_PIPE,
-  G_IO_CHANNEL_ERROR_SPIPE,
   /* Other */
-  G_IO_CHANNEL_ERROR_ENCODE_RW,
   G_IO_CHANNEL_ERROR_FAILED
 } GIOChannelError;
 
@@ -75,7 +73,6 @@ typedef enum
   G_IO_STATUS_ERROR,
   G_IO_STATUS_NORMAL,
   G_IO_STATUS_EOF,
-  G_IO_STATUS_PARTIAL_CHARS, /* like EOF, but with unconverted data left */
   G_IO_STATUS_AGAIN
 } GIOStatus;
 
@@ -96,11 +93,6 @@ typedef enum
   G_IO_NVAL    GLIB_SYSDEF_POLLNVAL
 } GIOCondition;
 
-#define G_IO_CHANNEL_UNIX_LINE_TERM "\n"
-#define G_IO_CHANNEL_DOS_LINE_TERM "\r\n"
-#define G_IO_CHANNEL_MACINTOSH_LINE_TERM "\r"
-#define G_IO_CHANNEL_ENCODE_RAW "GIOChannelEncodeRaw"
-
 typedef enum
 {
   G_IO_FLAG_APPEND = 1 << 0,
@@ -110,44 +102,38 @@ typedef enum
   G_IO_FLAG_IS_SEEKABLE = 1 << 4,      /* Read only flag */
   G_IO_FLAG_MASK = (1 << 5) - 1,
   G_IO_FLAG_GET_MASK = G_IO_FLAG_MASK,
-  G_IO_FLAG_SET_MASK = G_IO_FLAG_APPEND | G_IO_FLAG_NONBLOCK,
+  G_IO_FLAG_SET_MASK = G_IO_FLAG_APPEND | G_IO_FLAG_NONBLOCK
 } GIOFlags;
 
-typedef enum
-{
-  G_IO_FILE_MODE_READ,
-  G_IO_FILE_MODE_WRITE,
-  G_IO_FILE_MODE_APPEND,
-  G_IO_FILE_MODE_READ_WRITE,
-  G_IO_FILE_MODE_READ_WRITE_TRUNCATE,
-  G_IO_FILE_MODE_READ_WRITE_APPEND,
-} GIOFileMode;
-
 struct _GIOChannel
 {
-  guint channel_flags;
-  guint ref_count;
+  /*< private >*/
+  gint ref_count;
   GIOFuncs *funcs;
 
   gchar *encoding;
   GIConv read_cd;
   GIConv write_cd;
-  gchar *line_term;
+  gchar *line_term;            /* String which indicates the end of a line of text */
+  guint line_term_len;         /* So we can have null in the line term */
 
   gsize buf_size;
-  GString *read_buf;
-  GString *encoded_read_buf;
-  GString *write_buf;
-
-  /* Group the flags together to save memory */
-
-  gboolean use_buffer : 1;
-  gboolean do_encode : 1;
-  gboolean ready_to_read : 1;
-  gboolean ready_to_write : 1;
-  gboolean close_on_unref : 1;
-  gboolean seekable_cached : 1;
-  gboolean is_seekable : 1;
+  GString *read_buf;           /* Raw data from the channel */
+  GString *encoded_read_buf;    /* Channel data converted to UTF-8 */
+  GString *write_buf;          /* Data ready to be written to the file */
+  gchar partial_write_buf[6];  /* UTF-8 partial characters, null terminated */
+
+  /* Group the flags together, immediately after partial_write_buf, to save memory */
+
+  guint use_buffer     : 1;    /* The encoding uses the buffers */
+  guint do_encode      : 1;    /* The encoding uses the GIConv coverters */
+  guint close_on_unref : 1;    /* Close the channel on final unref */
+  guint is_readable    : 1;    /* Cached GIOFlag */
+  guint is_writeable   : 1;    /* ditto */
+  guint is_seekable    : 1;    /* ditto */
+
+  gpointer reserved1;  
+  gpointer reserved2;  
 };
 
 typedef gboolean (*GIOFunc) (GIOChannel   *source,
@@ -166,7 +152,7 @@ struct _GIOFuncs
                                  gsize        *bytes_written,
                                  GError      **err);
   GIOStatus (*io_seek)           (GIOChannel   *channel, 
-                                 glong         offset, 
+                                 gint64        offset, 
                                  GSeekType     type,
                                  GError      **err);
   GIOStatus  (*io_close)         (GIOChannel   *channel,
@@ -181,7 +167,7 @@ struct _GIOFuncs
 };
 
 void        g_io_channel_init   (GIOChannel    *channel);
-void        g_io_channel_ref    (GIOChannel    *channel);
+GIOChannel *g_io_channel_ref    (GIOChannel    *channel);
 void        g_io_channel_unref  (GIOChannel    *channel);
 
 #ifndef G_DISABLE_DEPRECATED
@@ -194,7 +180,7 @@ GIOError  g_io_channel_write    (GIOChannel    *channel,
                                 gsize          count,
                                 gsize         *bytes_written);
 GIOError  g_io_channel_seek     (GIOChannel    *channel,
-                                glong          offset, 
+                                gint64         offset, 
                                 GSeekType      type);
 void      g_io_channel_close    (GIOChannel    *channel);
 #endif /* G_DISABLE_DEPRECATED */
@@ -227,12 +213,20 @@ GIOStatus             g_io_channel_set_flags            (GIOChannel   *channel,
                                                         GError      **error);
 GIOFlags              g_io_channel_get_flags            (GIOChannel   *channel);
 void                  g_io_channel_set_line_term        (GIOChannel   *channel,
-                                                        const gchar  *line_term);
-G_CONST_RETURN gchar* g_io_channel_get_line_term        (GIOChannel   *channel);
+                                                        const gchar  *line_term,
+                                                        gint          length);
+G_CONST_RETURN gchar* g_io_channel_get_line_term        (GIOChannel   *channel,
+                                                        gint         *length);
+void                 g_io_channel_set_buffered         (GIOChannel   *channel,
+                                                        gboolean      buffered);
+gboolean             g_io_channel_get_buffered         (GIOChannel   *channel);
 GIOStatus             g_io_channel_set_encoding         (GIOChannel   *channel,
                                                         const gchar  *encoding,
                                                         GError      **error);
 G_CONST_RETURN gchar* g_io_channel_get_encoding         (GIOChannel   *channel);
+void                  g_io_channel_set_close_on_unref  (GIOChannel   *channel,
+                                                        gboolean      do_close);
+gboolean              g_io_channel_get_close_on_unref  (GIOChannel   *channel);
 
 
 GIOStatus   g_io_channel_flush            (GIOChannel   *channel,
@@ -255,23 +249,33 @@ GIOStatus   g_io_channel_read_chars       (GIOChannel   *channel,
                                           gsize         count,
                                           gsize        *bytes_read,
                                           GError      **error);
+GIOStatus   g_io_channel_read_unichar     (GIOChannel   *channel,
+                                          gunichar     *thechar,
+                                          GError      **error);
 GIOStatus   g_io_channel_write_chars      (GIOChannel   *channel,
                                           const gchar  *buf,
                                           gssize        count,
                                           gsize        *bytes_written,
                                           GError      **error);
+GIOStatus   g_io_channel_write_unichar    (GIOChannel   *channel,
+                                          gunichar      thechar,
+                                          GError      **error);
 GIOStatus   g_io_channel_seek_position    (GIOChannel   *channel,
-                                          glong         offset,
+                                          gint64        offset,
                                           GSeekType     type,
                                           GError      **error);
+#ifdef G_OS_WIN32
+#define g_io_channel_new_file g_io_channel_new_file_utf8
+#endif
+
 GIOChannel* g_io_channel_new_file         (const gchar  *filename,
-                                          GIOFileMode   mode,
+                                          const gchar  *mode,
                                           GError      **error);
 
 /* Error handling */
 
-GQuark          g_channel_error_quark      (void);
-GIOChannelError g_channel_error_from_errno (gint en);
+GQuark          g_io_channel_error_quark      (void);
+GIOChannelError g_io_channel_error_from_errno (gint en);
 
 /* On Unix, IO channels created with this function for any file
  * descriptor or socket.
@@ -294,8 +298,16 @@ GIOChannelError g_channel_error_from_errno (gint en);
 GIOChannel* g_io_channel_unix_new    (int         fd);
 gint        g_io_channel_unix_get_fd (GIOChannel *channel);
 
+
+/* Hook for GClosure / GSource integration. Don't touch */
+GLIB_VAR GSourceFuncs g_io_watch_funcs;
+
 #ifdef G_OS_WIN32
 
+/* You can use this "pseudo file descriptor" in a GPollFD to add
+ * polling for Windows messages. GTK applications should not do that.
+ */
+
 #define G_WIN32_MSG_HANDLE 19981206
 
 /* Use this to get a GPollFD from a GIOChannel, so that you can call
@@ -313,17 +325,18 @@ void        g_io_channel_win32_make_pollfd (GIOChannel   *channel,
  */
 gint        g_io_channel_win32_poll   (GPollFD    *fds,
                                       gint        n_fds,
-                                      gint        timeout);
-
-/* This is used to add polling for Windows messages. GDK (GTk+) programs
- * should *not* use this.
- */
-void        g_main_poll_win32_msg_add (gint        priority,
-                                      GPollFD    *fd,
-                                      guint       hwnd);
+                                      gint        timeout_);
 
 /* Create an IO channel for Windows messages for window handle hwnd. */
+#if GLIB_SIZEOF_VOID_P == 8
+/* We use gsize here so that it is still an integer type and not a
+ * pointer, like the guint in the traditional prototype. We can't use
+ * intptr_t as that is not portable enough.
+ */
+GIOChannel *g_io_channel_win32_new_messages (gsize hwnd);
+#else
 GIOChannel *g_io_channel_win32_new_messages (guint hwnd);
+#endif
 
 /* Create an IO channel for C runtime (emulated Unix-like) file
  * descriptors. After calling g_io_add_watch() on a IO channel
@@ -332,7 +345,7 @@ GIOChannel *g_io_channel_win32_new_messages (guint hwnd);
  * implemented on Win32 by starting a thread that sits blocked in a
  * read() from the file descriptor most of the time. All reads from
  * the file descriptor should be done by this internal GLib
- * thread. Your code should call only g_io_channel_read().
+ * thread. Your code should call only g_io_channel_read_chars().
  */
 GIOChannel* g_io_channel_win32_new_fd (gint         fd);