[glib] glib/tests: Clean up inclusion of unistd.h



commit d262b6fe0ca851a47fede2e624cec4aa041f2f14
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Nov 4 13:07:52 2013 +0800

    glib/tests: Clean up inclusion of unistd.h
    
    Include unistd.h only when G_OS_UNIX is defined (or when G_OS_WIN32 is not
    defined).  This will avoid including unistd.h unconditionally and/or
    unecessarily, which may cause problems in certain scenarios, such as when
    building the tests on Visual C++, which does not come with a unistd.h and
    MinGW, where unistd.h is essentially a wrapper for io.h and process.h.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=711047

 glib/tests/base64.c      |    4 +---
 glib/tests/checksum.c    |    4 +---
 glib/tests/gwakeuptest.c |    4 +++-
 glib/tests/hmac.c        |    4 +---
 glib/tests/mappedfile.c  |    3 +--
 glib/tests/node.c        |   10 +++-------
 glib/tests/protocol.c    |    5 +++--
 glib/tests/thread.c      |    5 +----
 glib/tests/timeout.c     |    2 ++
 9 files changed, 16 insertions(+), 25 deletions(-)
---
diff --git a/glib/tests/base64.c b/glib/tests/base64.c
index 6704c44..e5ac5b9 100644
--- a/glib/tests/base64.c
+++ b/glib/tests/base64.c
@@ -1,8 +1,6 @@
-#include "config.h"
-
 #include <glib.h>
 #include <string.h>
-#ifdef HAVE_UNISTD_H
+#ifdef G_OS_UNIX
 #include <unistd.h>
 #endif
 #include <stdlib.h>
diff --git a/glib/tests/checksum.c b/glib/tests/checksum.c
index 4823c99..a5d2ea0 100644
--- a/glib/tests/checksum.c
+++ b/glib/tests/checksum.c
@@ -1,8 +1,6 @@
-#include "config.h"
-
 #include <glib.h>
 #include <string.h>
-#ifdef HAVE_UNISTD_H
+#ifdef G_OS_UNIX
 #include <unistd.h>
 #endif
 #include <stdlib.h>
diff --git a/glib/tests/gwakeuptest.c b/glib/tests/gwakeuptest.c
index 5c149da..2ec29bd 100644
--- a/glib/tests/gwakeuptest.c
+++ b/glib/tests/gwakeuptest.c
@@ -1,6 +1,8 @@
-#include <unistd.h>
 #include <glib.h>
 #include <glib/gwakeup.h>
+#ifdef G_OS_UNIX
+#include <unistd.h>
+#endif
 
 #ifdef _WIN32
 static void alarm (int sec) { }
diff --git a/glib/tests/hmac.c b/glib/tests/hmac.c
index 008d293..c8215db 100644
--- a/glib/tests/hmac.c
+++ b/glib/tests/hmac.c
@@ -1,8 +1,6 @@
-#include "config.h"
-
 #include <glib.h>
 #include <string.h>
-#ifdef HAVE_UNISTD_H
+#ifdef G_OS_UNIX
 #include <unistd.h>
 #endif
 #include <stdlib.h>
diff --git a/glib/tests/mappedfile.c b/glib/tests/mappedfile.c
index 40e0e60..6b22105 100644
--- a/glib/tests/mappedfile.c
+++ b/glib/tests/mappedfile.c
@@ -1,9 +1,8 @@
 #define GLIB_DISABLE_DEPRECATION_WARNINGS
 
-#include <config.h>
 #include <glib.h>
 #include <string.h>
-#ifdef HAVE_UNISTD_H
+#ifdef G_OS_UNIX
 #include <unistd.h>
 #endif
 #include <glib/gstdio.h>
diff --git a/glib/tests/node.c b/glib/tests/node.c
index 27b5073..b1994eb 100644
--- a/glib/tests/node.c
+++ b/glib/tests/node.c
@@ -27,20 +27,16 @@
 #undef G_DISABLE_ASSERT
 #undef G_LOG_DOMAIN
 
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 
-#ifdef HAVE_UNISTD_H
+#include "glib.h"
+
+#ifdef G_OS_UNIX
 #include <unistd.h>
 #endif
 
-#include "glib.h"
-
 #define C2P(c)          ((gpointer) ((long) (c)))
 #define P2C(p)          ((gchar) ((long) (p)))
 
diff --git a/glib/tests/protocol.c b/glib/tests/protocol.c
index e80b610..28e29f9 100644
--- a/glib/tests/protocol.c
+++ b/glib/tests/protocol.c
@@ -22,9 +22,10 @@
 
 #include <errno.h>  /* errno */
 #include <glib.h>
-#ifndef _WIN32
+#ifdef G_OS_UNIX
 #include <unistd.h> /* pipe() */
-#else
+#endif
+#ifdef G_OS_WIN32
 #include <io.h>
 #include <fcntl.h>
 #define pipe(fds) _pipe(fds, 4096, _O_BINARY)
diff --git a/glib/tests/thread.c b/glib/tests/thread.c
index 539782e..a4f3976 100644
--- a/glib/tests/thread.c
+++ b/glib/tests/thread.c
@@ -26,17 +26,14 @@
 #include <sys/time.h>
 #endif
 #include <sys/types.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
 #ifdef HAVE_SYS_PRCTL_H
 #include <sys/prctl.h>
 #endif
 
-
 #include <glib.h>
 
 #ifndef G_OS_WIN32
+#include <unistd.h>
 #include <sys/resource.h>
 #endif
 
diff --git a/glib/tests/timeout.c b/glib/tests/timeout.c
index 445af22..ce7dd09 100644
--- a/glib/tests/timeout.c
+++ b/glib/tests/timeout.c
@@ -1,5 +1,7 @@
 #include <glib.h>
+#ifdef G_OS_UNIX
 #include <unistd.h>
+#endif
 
 static GMainLoop *loop;
 


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