1998-12-02 15:55:27 +01:00
|
|
|
/* GLIB - Library of useful routines for C programming
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
*
|
|
|
|
* giochannel.c: IO Channel abstraction
|
|
|
|
* Copyright 1998 Owen Taylor
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2000-07-26 13:02:02 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1998-12-02 15:55:27 +01:00
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2000-07-26 13:02:02 +02:00
|
|
|
* Lesser General Public License for more details.
|
1998-12-02 15:55:27 +01:00
|
|
|
*
|
2000-07-26 13:02:02 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
1998-12-02 15:55:27 +01:00
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
1999-02-24 07:14:27 +01:00
|
|
|
/*
|
2000-07-26 13:02:02 +02:00
|
|
|
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
1999-02-24 07:14:27 +01:00
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
1998-12-15 06:28:02 +01:00
|
|
|
/*
|
|
|
|
* MT safe
|
|
|
|
*/
|
|
|
|
|
Merge in current Win32 version. Almost no Unix code touched.
* README.win32: More text.
* config.h.win32 glibconfig.h.win32: Update to match the
corresponding generated files on Unix.
* makefile.msc: Update with new source files, and gthread
library. Use the compiler flag -MD instead of using -D_DLL and
"/nodefaultlib:libc msvcrt.lib" in the link phase.
* glib.def: Include new functions, drop removed ones.
* glib.h: Add comments about main loop and polling on Win32. (In
general, it's only for the GIMP's use.) Add Win32 IO Channel
functions. Remove the obsoleted old IO Channel stuff (which was
in #if 0 already).
* giowin32.c: New file.
* gmain.c: Include config.h, conditionalize <sys/time.h>
inclusion. Add g_poll implementation for Win32 (only for the
GIMP's needs for now, it's hard or even impossible to be as clean
and generic as on Unix). Implement g_get_current_time on Win32. If
threads aren't supported, don't try to wake up main thread's
loop. On Win32, use a semaphore and not a pipe to wake up the main
loop.
* gmessages.c: On Win32, allocate a console window if the standard
output handle is invalid before writing to stdout, and reopen stdout
to that console window.
* giochannel.c: Conditionalize unistd.h inclusion. Some indentation
cleanup.
* gstrfuncs.c: Include <signal.h>.
* gutils.c: On Win32, also check the HOMEDRIVE and HOMEPATH
environment variables.
* gmodule-dl.c gmodule-dld.c: In
_g_module_build_path, don't add the "lib" prefix and
".so" or ".sl" suffix if already there.
* gmodule-win32.c: Likewise for the ".dll" suffix.
* gthread-posix.c: Conditionalize <sys/time.h> inclusion.
1999-01-17 00:46:42 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
1998-12-02 15:55:27 +01:00
|
|
|
#include "glib.h"
|
Merge in current Win32 version. Almost no Unix code touched.
* README.win32: More text.
* config.h.win32 glibconfig.h.win32: Update to match the
corresponding generated files on Unix.
* makefile.msc: Update with new source files, and gthread
library. Use the compiler flag -MD instead of using -D_DLL and
"/nodefaultlib:libc msvcrt.lib" in the link phase.
* glib.def: Include new functions, drop removed ones.
* glib.h: Add comments about main loop and polling on Win32. (In
general, it's only for the GIMP's use.) Add Win32 IO Channel
functions. Remove the obsoleted old IO Channel stuff (which was
in #if 0 already).
* giowin32.c: New file.
* gmain.c: Include config.h, conditionalize <sys/time.h>
inclusion. Add g_poll implementation for Win32 (only for the
GIMP's needs for now, it's hard or even impossible to be as clean
and generic as on Unix). Implement g_get_current_time on Win32. If
threads aren't supported, don't try to wake up main thread's
loop. On Win32, use a semaphore and not a pipe to wake up the main
loop.
* gmessages.c: On Win32, allocate a console window if the standard
output handle is invalid before writing to stdout, and reopen stdout
to that console window.
* giochannel.c: Conditionalize unistd.h inclusion. Some indentation
cleanup.
* gstrfuncs.c: Include <signal.h>.
* gutils.c: On Win32, also check the HOMEDRIVE and HOMEPATH
environment variables.
* gmodule-dl.c gmodule-dld.c: In
_g_module_build_path, don't add the "lib" prefix and
".so" or ".sl" suffix if already there.
* gmodule-win32.c: Likewise for the ".dll" suffix.
* gthread-posix.c: Conditionalize <sys/time.h> inclusion.
1999-01-17 00:46:42 +01:00
|
|
|
#ifdef HAVE_UNISTD_H
|
1998-12-02 15:55:27 +01:00
|
|
|
#include <unistd.h>
|
Merge in current Win32 version. Almost no Unix code touched.
* README.win32: More text.
* config.h.win32 glibconfig.h.win32: Update to match the
corresponding generated files on Unix.
* makefile.msc: Update with new source files, and gthread
library. Use the compiler flag -MD instead of using -D_DLL and
"/nodefaultlib:libc msvcrt.lib" in the link phase.
* glib.def: Include new functions, drop removed ones.
* glib.h: Add comments about main loop and polling on Win32. (In
general, it's only for the GIMP's use.) Add Win32 IO Channel
functions. Remove the obsoleted old IO Channel stuff (which was
in #if 0 already).
* giowin32.c: New file.
* gmain.c: Include config.h, conditionalize <sys/time.h>
inclusion. Add g_poll implementation for Win32 (only for the
GIMP's needs for now, it's hard or even impossible to be as clean
and generic as on Unix). Implement g_get_current_time on Win32. If
threads aren't supported, don't try to wake up main thread's
loop. On Win32, use a semaphore and not a pipe to wake up the main
loop.
* gmessages.c: On Win32, allocate a console window if the standard
output handle is invalid before writing to stdout, and reopen stdout
to that console window.
* giochannel.c: Conditionalize unistd.h inclusion. Some indentation
cleanup.
* gstrfuncs.c: Include <signal.h>.
* gutils.c: On Win32, also check the HOMEDRIVE and HOMEPATH
environment variables.
* gmodule-dl.c gmodule-dld.c: In
_g_module_build_path, don't add the "lib" prefix and
".so" or ".sl" suffix if already there.
* gmodule-win32.c: Likewise for the ".dll" suffix.
* gthread-posix.c: Conditionalize <sys/time.h> inclusion.
1999-01-17 00:46:42 +01:00
|
|
|
#endif
|
1998-12-02 15:55:27 +01:00
|
|
|
|
1998-12-15 23:30:15 +01:00
|
|
|
void
|
|
|
|
g_io_channel_init (GIOChannel *channel)
|
1998-12-02 15:55:27 +01:00
|
|
|
{
|
1998-12-15 23:30:15 +01:00
|
|
|
channel->channel_flags = 0;
|
|
|
|
channel->ref_count = 1;
|
1998-12-02 15:55:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
g_io_channel_ref (GIOChannel *channel)
|
|
|
|
{
|
|
|
|
g_return_if_fail (channel != NULL);
|
|
|
|
|
1998-12-15 23:30:15 +01:00
|
|
|
channel->ref_count++;
|
1998-12-02 15:55:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
g_io_channel_unref (GIOChannel *channel)
|
|
|
|
{
|
|
|
|
g_return_if_fail (channel != NULL);
|
|
|
|
|
1998-12-15 23:30:15 +01:00
|
|
|
channel->ref_count--;
|
|
|
|
if (channel->ref_count == 0)
|
|
|
|
channel->funcs->io_free (channel);
|
1998-12-02 15:55:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GIOError
|
|
|
|
g_io_channel_read (GIOChannel *channel,
|
|
|
|
gchar *buf,
|
|
|
|
guint count,
|
|
|
|
guint *bytes_read)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (channel != NULL, G_IO_ERROR_UNKNOWN);
|
|
|
|
|
1998-12-15 23:30:15 +01:00
|
|
|
return channel->funcs->io_read (channel, buf, count, bytes_read);
|
1998-12-02 15:55:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GIOError
|
|
|
|
g_io_channel_write (GIOChannel *channel,
|
|
|
|
gchar *buf,
|
|
|
|
guint count,
|
|
|
|
guint *bytes_written)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (channel != NULL, G_IO_ERROR_UNKNOWN);
|
|
|
|
|
1998-12-15 23:30:15 +01:00
|
|
|
return channel->funcs->io_write (channel, buf, count, bytes_written);
|
1998-12-02 15:55:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GIOError
|
|
|
|
g_io_channel_seek (GIOChannel *channel,
|
|
|
|
gint offset,
|
|
|
|
GSeekType type)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (channel != NULL, G_IO_ERROR_UNKNOWN);
|
|
|
|
|
1998-12-15 23:30:15 +01:00
|
|
|
return channel->funcs->io_seek (channel, offset, type);
|
1998-12-02 15:55:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
g_io_channel_close (GIOChannel *channel)
|
|
|
|
{
|
|
|
|
g_return_if_fail (channel != NULL);
|
|
|
|
|
1998-12-15 23:30:15 +01:00
|
|
|
channel->funcs->io_close (channel);
|
1998-12-02 15:55:27 +01:00
|
|
|
}
|
|
|
|
|
2000-12-05 21:45:33 +01:00
|
|
|
GSource *
|
|
|
|
g_io_create_watch (GIOChannel *channel,
|
|
|
|
GIOCondition condition)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (channel != NULL, NULL);
|
|
|
|
|
|
|
|
return channel->funcs->io_create_watch (channel, condition);
|
|
|
|
}
|
|
|
|
|
1998-12-02 15:55:27 +01:00
|
|
|
guint
|
Merge in current Win32 version. Almost no Unix code touched.
* README.win32: More text.
* config.h.win32 glibconfig.h.win32: Update to match the
corresponding generated files on Unix.
* makefile.msc: Update with new source files, and gthread
library. Use the compiler flag -MD instead of using -D_DLL and
"/nodefaultlib:libc msvcrt.lib" in the link phase.
* glib.def: Include new functions, drop removed ones.
* glib.h: Add comments about main loop and polling on Win32. (In
general, it's only for the GIMP's use.) Add Win32 IO Channel
functions. Remove the obsoleted old IO Channel stuff (which was
in #if 0 already).
* giowin32.c: New file.
* gmain.c: Include config.h, conditionalize <sys/time.h>
inclusion. Add g_poll implementation for Win32 (only for the
GIMP's needs for now, it's hard or even impossible to be as clean
and generic as on Unix). Implement g_get_current_time on Win32. If
threads aren't supported, don't try to wake up main thread's
loop. On Win32, use a semaphore and not a pipe to wake up the main
loop.
* gmessages.c: On Win32, allocate a console window if the standard
output handle is invalid before writing to stdout, and reopen stdout
to that console window.
* giochannel.c: Conditionalize unistd.h inclusion. Some indentation
cleanup.
* gstrfuncs.c: Include <signal.h>.
* gutils.c: On Win32, also check the HOMEDRIVE and HOMEPATH
environment variables.
* gmodule-dl.c gmodule-dld.c: In
_g_module_build_path, don't add the "lib" prefix and
".so" or ".sl" suffix if already there.
* gmodule-win32.c: Likewise for the ".dll" suffix.
* gthread-posix.c: Conditionalize <sys/time.h> inclusion.
1999-01-17 00:46:42 +01:00
|
|
|
g_io_add_watch_full (GIOChannel *channel,
|
1998-12-02 15:55:27 +01:00
|
|
|
gint priority,
|
|
|
|
GIOCondition condition,
|
|
|
|
GIOFunc func,
|
|
|
|
gpointer user_data,
|
|
|
|
GDestroyNotify notify)
|
|
|
|
{
|
2000-12-05 21:45:33 +01:00
|
|
|
GSource *source;
|
|
|
|
|
1998-12-02 15:55:27 +01:00
|
|
|
g_return_val_if_fail (channel != NULL, 0);
|
|
|
|
|
2000-12-05 21:45:33 +01:00
|
|
|
source = g_io_create_watch (channel, condition);
|
|
|
|
|
|
|
|
if (priority != G_PRIORITY_DEFAULT)
|
|
|
|
g_source_set_priority (source, priority);
|
|
|
|
g_source_set_callback (source, (GSourceFunc)func, user_data, notify);
|
|
|
|
|
|
|
|
return g_source_attach (source, NULL);
|
1998-12-02 15:55:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
guint
|
Merge in current Win32 version. Almost no Unix code touched.
* README.win32: More text.
* config.h.win32 glibconfig.h.win32: Update to match the
corresponding generated files on Unix.
* makefile.msc: Update with new source files, and gthread
library. Use the compiler flag -MD instead of using -D_DLL and
"/nodefaultlib:libc msvcrt.lib" in the link phase.
* glib.def: Include new functions, drop removed ones.
* glib.h: Add comments about main loop and polling on Win32. (In
general, it's only for the GIMP's use.) Add Win32 IO Channel
functions. Remove the obsoleted old IO Channel stuff (which was
in #if 0 already).
* giowin32.c: New file.
* gmain.c: Include config.h, conditionalize <sys/time.h>
inclusion. Add g_poll implementation for Win32 (only for the
GIMP's needs for now, it's hard or even impossible to be as clean
and generic as on Unix). Implement g_get_current_time on Win32. If
threads aren't supported, don't try to wake up main thread's
loop. On Win32, use a semaphore and not a pipe to wake up the main
loop.
* gmessages.c: On Win32, allocate a console window if the standard
output handle is invalid before writing to stdout, and reopen stdout
to that console window.
* giochannel.c: Conditionalize unistd.h inclusion. Some indentation
cleanup.
* gstrfuncs.c: Include <signal.h>.
* gutils.c: On Win32, also check the HOMEDRIVE and HOMEPATH
environment variables.
* gmodule-dl.c gmodule-dld.c: In
_g_module_build_path, don't add the "lib" prefix and
".so" or ".sl" suffix if already there.
* gmodule-win32.c: Likewise for the ".dll" suffix.
* gthread-posix.c: Conditionalize <sys/time.h> inclusion.
1999-01-17 00:46:42 +01:00
|
|
|
g_io_add_watch (GIOChannel *channel,
|
1998-12-02 15:55:27 +01:00
|
|
|
GIOCondition condition,
|
|
|
|
GIOFunc func,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2000-12-05 21:45:33 +01:00
|
|
|
return g_io_add_watch_full (channel, G_PRIORITY_DEFAULT, condition, func, user_data, NULL);
|
1998-12-02 15:55:27 +01:00
|
|
|
}
|