This source file includes following definitions.
- read_nothrow
 
- rpl_read
 
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 #include <config.h>
  19 
  20 
  21 #include <unistd.h>
  22 
  23 #if defined _WIN32 && ! defined __CYGWIN__
  24 
  25 # include <errno.h>
  26 # include <io.h>
  27 
  28 # define WIN32_LEAN_AND_MEAN  
  29 # include <windows.h>
  30 
  31 # if HAVE_MSVC_INVALID_PARAMETER_HANDLER
  32 #  include "msvc-inval.h"
  33 # endif
  34 # if GNULIB_MSVC_NOTHROW
  35 #  include "msvc-nothrow.h"
  36 # else
  37 #  include <io.h>
  38 # endif
  39 
  40 
  41 # undef GetNamedPipeHandleState
  42 # define GetNamedPipeHandleState GetNamedPipeHandleStateA
  43 
  44 # undef read
  45 
  46 # if HAVE_MSVC_INVALID_PARAMETER_HANDLER
  47 static ssize_t
  48 read_nothrow (int fd, void *buf, size_t count)
     
  49 {
  50   ssize_t result;
  51 
  52   TRY_MSVC_INVAL
  53     {
  54       result = _read (fd, buf, count);
  55     }
  56   CATCH_MSVC_INVAL
  57     {
  58       result = -1;
  59       errno = EBADF;
  60     }
  61   DONE_MSVC_INVAL;
  62 
  63   return result;
  64 }
  65 # else
  66 #  define read_nothrow _read
  67 # endif
  68 
  69 ssize_t
  70 rpl_read (int fd, void *buf, size_t count)
     
  71 {
  72   ssize_t ret = read_nothrow (fd, buf, count);
  73 
  74 # if GNULIB_NONBLOCKING
  75   if (ret < 0
  76       && GetLastError () == ERROR_NO_DATA)
  77     {
  78       HANDLE h = (HANDLE) _get_osfhandle (fd);
  79       if (GetFileType (h) == FILE_TYPE_PIPE)
  80         {
  81           
  82           DWORD state;
  83           if (GetNamedPipeHandleState (h, &state, NULL, NULL, NULL, NULL, 0)
  84               && (state & PIPE_NOWAIT) != 0)
  85             
  86 
  87             errno = EAGAIN;
  88         }
  89     }
  90 # endif
  91 
  92   return ret;
  93 }
  94 
  95 #endif