X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Fwrite.c;h=2d204219f2d849263f03cd6167e997b68c2b355b;hb=e7086a9a301ffcfef17edbcba9e7c0312c33f7a8;hp=b0ffa94e93145c9929b630b59e0de40f016fcc64;hpb=73899ad375e2b795e1caaac9a75b99bc87cd9aea;p=gnulib.git diff --git a/lib/write.c b/lib/write.c index b0ffa94e9..2d204219f 100644 --- a/lib/write.c +++ b/lib/write.c @@ -1,5 +1,5 @@ /* POSIX compatible write() function. - Copyright (C) 2008-2011 Free Software Foundation, Inc. + Copyright (C) 2008-2013 Free Software Foundation, Inc. Written by Bruno Haible , 2008. This program is free software: you can redistribute it and/or modify @@ -20,35 +20,58 @@ /* Specification. */ #include -/* Replace this function only if module 'nonblocking' or module 'sigpipe' is - requested. */ -#if GNULIB_NONBLOCKING || GNULIB_SIGPIPE - /* On native Windows platforms, SIGPIPE does not exist. When write() is called on a pipe with no readers, WriteFile() fails with error GetLastError() = ERROR_NO_DATA, and write() in consequence fails with error EINVAL. */ -# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ +#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ + +# include +# include +# include + +# define WIN32_LEAN_AND_MEAN /* avoid including junk */ +# include + +# include "msvc-inval.h" +# include "msvc-nothrow.h" -# include -# include -# include +# undef write + +# if HAVE_MSVC_INVALID_PARAMETER_HANDLER +static ssize_t +write_nothrow (int fd, const void *buf, size_t count) +{ + ssize_t result; + + TRY_MSVC_INVAL + { + result = write (fd, buf, count); + } + CATCH_MSVC_INVAL + { + result = -1; + errno = EBADF; + } + DONE_MSVC_INVAL; -# define WIN32_LEAN_AND_MEAN /* avoid including junk */ -# include + return result; +} +# else +# define write_nothrow write +# endif ssize_t rpl_write (int fd, const void *buf, size_t count) -#undef write { for (;;) { - ssize_t ret = write (fd, buf, count); + ssize_t ret = write_nothrow (fd, buf, count); if (ret < 0) { -# if GNULIB_NONBLOCKING +# if GNULIB_NONBLOCKING if (errno == ENOSPC) { HANDLE h = (HANDLE) _get_osfhandle (fd); @@ -99,9 +122,9 @@ rpl_write (int fd, const void *buf, size_t count) } } else -# endif +# endif { -# if GNULIB_SIGPIPE +# if GNULIB_SIGPIPE if (GetLastError () == ERROR_NO_DATA && GetFileType ((HANDLE) _get_osfhandle (fd)) == FILE_TYPE_PIPE) @@ -112,12 +135,11 @@ rpl_write (int fd, const void *buf, size_t count) EINVAL to EPIPE. */ errno = EPIPE; } -# endif +# endif } } return ret; } } -# endif #endif