bug-gnulib
[Top][All Lists]
Advanced

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

isapipe: port to mingw


From: Bruno Haible
Subject: isapipe: port to mingw
Date: Sun, 20 Apr 2008 10:20:55 +0200
User-agent: KMail/1.5.4

Another module that fails to compile on mingw is isapipe.c, because
that platform does not have the pipe() call.

Here is a proposed port of that module:


2008-04-20  Bruno Haible  <address@hidden>

        * lib/isapipe.c: Port to native Windows platforms.

--- lib/isapipe.c.orig  2008-04-20 10:20:16.000000000 +0200
+++ lib/isapipe.c       2008-04-20 10:20:12.000000000 +0200
@@ -1,6 +1,6 @@
 /* Test whether a file descriptor is a pipe.
 
-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006, 2008 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -22,15 +22,42 @@
 #include "isapipe.h"
 
 #include <errno.h>
-#include <stdbool.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
+
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+/* Windows platforms.  */
+
+/* Get _get_osfhandle.  */
+# include <io.h>
+
+/* Get GetFileType.  */
+# include <windows.h>
+
+int
+isapipe (int fd)
+{
+  HANDLE h = (HANDLE) _get_osfhandle (fd);
+
+  if (h == INVALID_HANDLE_VALUE)
+    {
+      errno = EBADF;
+      return -1;
+    }
+
+  return (GetFileType (h) == FILE_TYPE_PIPE);
+}
+
+#else
+/* Unix platforms.  */
+
+# include <stdbool.h>
+# include <sys/types.h>
+# include <sys/stat.h>
+# include <unistd.h>
 
 /* The maximum link count for pipes; (nlink_t) -1 if not known.  */
-#ifndef PIPE_LINK_COUNT_MAX
-# define PIPE_LINK_COUNT_MAX ((nlink_t) (-1))
-#endif
+# ifndef PIPE_LINK_COUNT_MAX
+#  define PIPE_LINK_COUNT_MAX ((nlink_t) (-1))
+# endif
 
 /* Return 1 if FD is a pipe, 0 if not, -1 (setting errno) on error.
 
@@ -88,3 +115,5 @@
     (st.st_nlink <= pipe_link_count_max
      && (check_for_fifo ? S_ISFIFO (st.st_mode) : S_ISSOCK (st.st_mode)));
 }
+
+#endif





reply via email to

[Prev in Thread] Current Thread [Next in Thread]