* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
/*
#include <errno.h>
#include <sys/stat.h>
-#ifdef _MSC_VER
-#define fstat(a,b) _fstat(a,b)
-#endif
-
#include "gstdio.h"
#include "glibintl.h"
-#include "galias.h"
typedef struct _GIOWin32Channel GIOWin32Channel;
typedef struct _GIOWin32Watch GIOWin32Watch;
g_print ("%sNONBLOCK", bar), bar = "|";
if (flags & G_IO_FLAG_IS_READABLE)
g_print ("%sREADABLE", bar), bar = "|";
- if (flags & G_IO_FLAG_IS_WRITEABLE)
- g_print ("%sWRITEABLE", bar), bar = "|";
+ if (flags & G_IO_FLAG_IS_WRITABLE)
+ g_print ("%sWRITABLE", bar), bar = "|";
if (flags & G_IO_FLAG_IS_SEEKABLE)
g_print ("%sSEEKABLE", bar), bar = "|";
}
g_free (emsg);
}
- if (win32_channel->type == G_IO_WIN32_SOCKET)
+ if (win32_channel->type == G_IO_WIN32_SOCKET &&
+ win32_channel->fd != -1)
if (WSAEventSelect (win32_channel->fd, NULL, 0) == SOCKET_ERROR)
if (win32_channel->debug)
{
GSource *source;
source = g_source_new (&g_io_watch_funcs, sizeof (GIOWin32Watch));
+ g_source_set_name (source, "GIOChannel (Win32)");
watch = (GIOWin32Watch *)source;
watch->channel = channel;
MODE_W = 1 << 1,
MODE_A = 1 << 2,
MODE_PLUS = 1 << 3,
- } mode_num;
+ };
+ int mode_num;
g_return_val_if_fail (filename != NULL, NULL);
g_return_val_if_fail (mode != NULL, NULL);
}
static GIOFlags
-g_io_win32_fd_get_flags_internal (GIOChannel *channel,
- struct stat *st)
+g_io_win32_fd_get_flags_internal (GIOChannel *channel,
+ struct _stati64 *st)
{
GIOWin32Channel *win32_channel = (GIOWin32Channel *) channel;
gchar c;
static GIOFlags
g_io_win32_fd_get_flags (GIOChannel *channel)
{
- struct stat st;
+ struct _stati64 st;
GIOWin32Channel *win32_channel = (GIOWin32Channel *)channel;
g_return_val_if_fail (win32_channel != NULL, 0);
g_return_val_if_fail (win32_channel->type == G_IO_WIN32_FILE_DESC, 0);
- if (0 == fstat (win32_channel->fd, &st))
+ if (0 == _fstati64 (win32_channel->fd, &st))
return g_io_win32_fd_get_flags_internal (channel, &st);
else
return 0;
g_io_win32_sock_get_flags,
};
+/**
+ * g_io_channel_win32_new_messages:
+ * @hwnd: a window handle.
+ *
+ * Creates a new #GIOChannel given a window handle on Windows.
+ *
+ * This function creates a #GIOChannel that can be used to poll for
+ * Windows messages for the window in question.
+ *
+ * Returns: a new #GIOChannel.
+ **/
GIOChannel *
#if GLIB_SIZEOF_VOID_P == 8
g_io_channel_win32_new_messages (gsize hwnd)
}
static GIOChannel *
-g_io_channel_win32_new_fd_internal (gint fd,
- struct stat *st)
+g_io_channel_win32_new_fd_internal (gint fd,
+ struct _stati64 *st)
{
GIOWin32Channel *win32_channel;
GIOChannel *channel;
return channel;
}
+/**
+ * g_io_channel_win32_new_fd:
+ * @fd: a C library file descriptor.
+ *
+ * Creates a new #GIOChannel given a file descriptor on Windows. This
+ * works for file descriptors from the C runtime.
+ *
+ * This function works for file descriptors as returned by the open(),
+ * creat(), pipe() and fileno() calls in the Microsoft C runtime. In
+ * order to meaningfully use this function your code should use the
+ * same C runtime as GLib uses, which is msvcrt.dll. Note that in
+ * current Microsoft compilers it is near impossible to convince it to
+ * build code that would use msvcrt.dll. The last Microsoft compiler
+ * version that supported using msvcrt.dll as the C runtime was version
+ * 6. The GNU compiler and toolchain for Windows, also known as Mingw,
+ * fully supports msvcrt.dll.
+ *
+ * If you have created a #GIOChannel for a file descriptor and started
+ * watching (polling) it, you shouldn't call read() on the file
+ * descriptor. This is because adding polling for a file descriptor is
+ * implemented in GLib on Windows 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().
+ *
+ * This function is available only in GLib on Windows.
+ *
+ * Returns: a new #GIOChannel.
+ **/
GIOChannel *
g_io_channel_win32_new_fd (gint fd)
{
- struct stat st;
+ struct _stati64 st;
- if (fstat (fd, &st) == -1)
+ if (_fstati64 (fd, &st) == -1)
{
g_warning ("g_io_channel_win32_new_fd: %d isn't an open file descriptor in the C library GLib uses.", fd);
return NULL;
return win32_channel->fd;
}
+/**
+ * g_io_channel_win32_new_socket:
+ * @socket: a Winsock socket
+ *
+ * Creates a new #GIOChannel given a socket on Windows.
+ *
+ * This function works for sockets created by Winsock. It's available
+ * only in GLib on Windows.
+ *
+ * Polling a #GSource created to watch a channel for a socket puts the
+ * socket in non-blocking mode. This is a side-effect of the
+ * implementation and unavoidable.
+ *
+ * Returns: a new #GIOChannel
+ **/
GIOChannel *
g_io_channel_win32_new_socket (int socket)
{
g_io_channel_unix_new (gint fd)
{
gboolean is_fd, is_socket;
- struct stat st;
+ struct _stati64 st;
int optval, optlen;
- is_fd = (fstat (fd, &st) == 0);
+ is_fd = (_fstati64 (fd, &st) == 0);
optlen = sizeof (optval);
is_socket = (getsockopt (fd, SOL_SOCKET, SO_TYPE, (char *) &optval, &optlen) != SOCKET_ERROR);
}
#endif
-
-#define __G_IO_WIN32_C__
-#include "galiasdef.c"