[glib] gio tool: Fix build on Windows/non-GCC



commit b08a8dc949731d237b70614ba5b9f6ff3f080bbe
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Jul 4 12:27:42 2016 +0800

    gio tool: Fix build on Windows/non-GCC
    
    The recently-added GIO tools is intended to be built on all platforms, so
    adjust the code a bit to enable this:
    
    -Use gssize instead of ssize_t, as ssize_t is not supported by all
     compilers.
    -Include io.h on Windows, and define STDIN_FILENO and STDOUT_FILENO if
     necessary on Windows.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=768357

 gio/gio-tool-cat.c  |   14 +++++++++++++-
 gio/gio-tool-save.c |   15 +++++++++++++--
 2 files changed, 26 insertions(+), 3 deletions(-)
---
diff --git a/gio/gio-tool-cat.c b/gio/gio-tool-cat.c
index c4f5189..c057264 100644
--- a/gio/gio-tool-cat.c
+++ b/gio/gio-tool-cat.c
@@ -23,6 +23,18 @@
 #include <gi18n.h>
 #include <errno.h>
 
+#ifdef G_OS_WIN32
+#include <io.h>
+#endif
+
+#ifndef STDOUT_FILENO
+#define STDOUT_FILENO 1
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
 #include "gio-tool.h"
 
 
@@ -56,7 +68,7 @@ cat (GFile *file)
       res = g_input_stream_read (in, buffer, sizeof (buffer) - 1, NULL, &error);
       if (res > 0)
         {
-          ssize_t written;
+          gssize written;
 
           p = buffer;
           while (res > 0)
diff --git a/gio/gio-tool-save.c b/gio/gio-tool-save.c
index 17989ae..a955a24 100644
--- a/gio/gio-tool-save.c
+++ b/gio/gio-tool-save.c
@@ -22,8 +22,19 @@
 #include <gio/gio.h>
 #include <gi18n.h>
 
-#include "gio-tool.h"
+#ifdef G_OS_WIN32
+#include <io.h>
+#endif
+
+#ifndef STDIN_FILENO
+#define STDIN_FILENO 0
+#endif
 
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include "gio-tool.h"
 
 static char *etag = NULL;
 static gboolean backup = FALSE;
@@ -84,7 +95,7 @@ save (GFile *file)
       res = read (STDIN_FILENO, buffer, 1024);
       if (res > 0)
        {
-         ssize_t written;
+         gssize written;
 
          p = buffer;
          while (res > 0)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]