X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fisapipe.c;h=a5349b116f4c3ceed16df0b63a2635517bbcfaa5;hb=b344de996cd51f8a2f2558a3172016b64d99c622;hp=59b6f5481a62a4003fd939972bc876d0bdc8f5dc;hpb=c74addc7bfdbd6b66878adef1f7079a28d3cec83;p=gnulib.git
diff --git a/lib/isapipe.c b/lib/isapipe.c
index 59b6f5481..a5349b116 100644
--- a/lib/isapipe.c
+++ b/lib/isapipe.c
@@ -1,11 +1,11 @@
/* Test whether a file descriptor is a pipe.
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2008-2011 Free Software Foundation, Inc.
- This program is free software; you can redistribute it and/or modify
+ 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
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,8 +13,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+ along with this program. If not, see . */
/* Written by Paul Eggert. */
@@ -23,17 +22,42 @@
#include "isapipe.h"
#include
-#include
-#include
-#include
-#include
-#include "stat-macros.h"
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+/* Windows platforms. */
+
+/* Get _get_osfhandle. */
+# include
+
+/* Get GetFileType. */
+# include
+
+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
+# include
+# include
+# include
/* 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.
@@ -63,31 +87,33 @@ isapipe (int fd)
On Darwin 7.7, pipes are sockets, so check for those instead. */
if (! ((HAVE_FIFO_PIPES == 0 || HAVE_FIFO_PIPES == 1)
- && PIPE_LINK_COUNT_MAX != (nlink_t) -1)
+ && PIPE_LINK_COUNT_MAX != (nlink_t) -1)
&& (S_ISFIFO (st.st_mode) | S_ISSOCK (st.st_mode)))
{
int fd_pair[2];
int pipe_result = pipe (fd_pair);
if (pipe_result != 0)
- return pipe_result;
+ return pipe_result;
else
- {
- struct stat pipe_st;
- int fstat_pipe_result = fstat (fd_pair[0], &pipe_st);
- int fstat_pipe_errno = errno;
- close (fd_pair[0]);
- close (fd_pair[1]);
- if (fstat_pipe_result != 0)
- {
- errno = fstat_pipe_errno;
- return fstat_pipe_result;
- }
- check_for_fifo = (S_ISFIFO (pipe_st.st_mode) != 0);
- pipe_link_count_max = pipe_st.st_nlink;
- }
+ {
+ struct stat pipe_st;
+ int fstat_pipe_result = fstat (fd_pair[0], &pipe_st);
+ int fstat_pipe_errno = errno;
+ close (fd_pair[0]);
+ close (fd_pair[1]);
+ if (fstat_pipe_result != 0)
+ {
+ errno = fstat_pipe_errno;
+ return fstat_pipe_result;
+ }
+ check_for_fifo = (S_ISFIFO (pipe_st.st_mode) != 0);
+ pipe_link_count_max = pipe_st.st_nlink;
+ }
}
return
(st.st_nlink <= pipe_link_count_max
&& (check_for_fifo ? S_ISFIFO (st.st_mode) : S_ISSOCK (st.st_mode)));
}
+
+#endif