summaryrefslogtreecommitdiff
path: root/json-glib/json-glib-format.c
diff options
context:
space:
mode:
authorChun-wei Fan <fanchunwei@src.gnome.org>2014-02-07 11:39:29 +0800
committerChun-wei Fan <fanchunwei@src.gnome.org>2014-02-07 18:59:13 +0800
commitd97be101490a46c72f919d3dc45f4bc06e625e0c (patch)
tree26ef5a3550f94438ea1837755bfa25c16b2dd88f /json-glib/json-glib-format.c
parent0b1397ad168078bf2b588ab413ad921c04aab8a2 (diff)
downloadjson-glib-d97be101490a46c72f919d3dc45f4bc06e625e0c.tar.gz
tools: Fix build on Visual Studio
As unistd.h is not universally available, don't include it unconditionally and include the corresponding Windows headers where necessary. Also, use gssize in place of ssize_t and define STDOUT_FILENO on Windows when we don't have unistd.h, which is a constant that is defined in unistd.h. https://bugzilla.gnome.org/show_bug.cgi?id=723813
Diffstat (limited to 'json-glib/json-glib-format.c')
-rw-r--r--json-glib/json-glib-format.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/json-glib/json-glib-format.c b/json-glib/json-glib-format.c
index f10cee9..d39b325 100644
--- a/json-glib/json-glib-format.c
+++ b/json-glib/json-glib-format.c
@@ -23,7 +23,10 @@
#include "config.h"
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
+
#include <stdlib.h>
#include <stdio.h>
#include <locale.h>
@@ -33,6 +36,12 @@
#include <glib/gi18n.h>
#include <json-glib/json-glib.h>
+#if defined (G_OS_WIN32) && !defined (HAVE_UNISTD_H)
+#include <io.h>
+
+#define STDOUT_FILENO 1
+#endif
+
static char **files = NULL;
static gboolean prettify = FALSE;
static int indent_spaces = 2;
@@ -89,7 +98,7 @@ format (JsonParser *parser,
p = data;
while (len > 0)
{
- ssize_t written = write (STDOUT_FILENO, p, len);
+ gssize written = write (STDOUT_FILENO, p, len);
if (written == -1 && errno != EINTR)
{