X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fisapipe.c;h=495cba6a6af3de0b3cc089c1021604a7f4caab82;hb=a0092d82930eaf9bcbdf1840b2133e24997d2311;hp=e71dc2b29df4f9ab6c4e62fe7b1287eaa2106799;hpb=57fdfd3f8ec62b105c53bcdf6f127c35c7fe7391;p=gnulib.git diff --git a/lib/isapipe.c b/lib/isapipe.c index e71dc2b29..495cba6a6 100644 --- a/lib/isapipe.c +++ b/lib/isapipe.c @@ -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 -#include -#include -#include -#include + +#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. @@ -88,3 +115,5 @@ isapipe (int fd) (st.st_nlink <= pipe_link_count_max && (check_for_fifo ? S_ISFIFO (st.st_mode) : S_ISSOCK (st.st_mode))); } + +#endif