|
version 1.1.1.1, 2012/05/29 09:29:42
|
version 1.1.1.2, 2021/03/17 13:38:46
|
|
Line 1
|
Line 1
|
| /* POSIX compatible read() function. |
/* POSIX compatible read() function. |
| Copyright (C) 2008-2011 Free Software Foundation, Inc. | Copyright (C) 2008-2019 Free Software Foundation, Inc. |
| Written by Bruno Haible <bruno@clisp.org>, 2011. |
Written by Bruno Haible <bruno@clisp.org>, 2011. |
| |
|
| This program is free software: you can redistribute it and/or modify |
This program is free software: you can redistribute it and/or modify |
|
Line 13
|
Line 13
|
| GNU General Public License for more details. |
GNU General Public License for more details. |
| |
|
| You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/>. */ | along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
| |
|
| #include <config.h> |
#include <config.h> |
| |
|
| /* Specification. */ |
/* Specification. */ |
| #include <unistd.h> |
#include <unistd.h> |
| |
|
| /* Replace this function only if module 'nonblocking' is requested. */ | #if defined _WIN32 && ! defined __CYGWIN__ |
| #if GNULIB_NONBLOCKING | |
| |
|
| # if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ | # include <errno.h> |
| | # include <io.h> |
| |
|
| # include <errno.h> | # define WIN32_LEAN_AND_MEAN /* avoid including junk */ |
| | # include <windows.h> |
| | |
| | # if HAVE_MSVC_INVALID_PARAMETER_HANDLER |
| | # include "msvc-inval.h" |
| | # endif |
| | # if GNULIB_MSVC_NOTHROW |
| | # include "msvc-nothrow.h" |
| | # else |
| # include <io.h> |
# include <io.h> |
| |
# endif |
| |
|
| # define WIN32_LEAN_AND_MEAN /* avoid including junk */ | # undef read |
| # include <windows.h> | |
| |
|
| |
# if HAVE_MSVC_INVALID_PARAMETER_HANDLER |
| |
static ssize_t |
| |
read_nothrow (int fd, void *buf, size_t count) |
| |
{ |
| |
ssize_t result; |
| |
|
| |
TRY_MSVC_INVAL |
| |
{ |
| |
result = read (fd, buf, count); |
| |
} |
| |
CATCH_MSVC_INVAL |
| |
{ |
| |
result = -1; |
| |
errno = EBADF; |
| |
} |
| |
DONE_MSVC_INVAL; |
| |
|
| |
return result; |
| |
} |
| |
# else |
| |
# define read_nothrow read |
| |
# endif |
| |
|
| ssize_t |
ssize_t |
| rpl_read (int fd, void *buf, size_t count) |
rpl_read (int fd, void *buf, size_t count) |
| #undef read |
|
| { |
{ |
| ssize_t ret = read (fd, buf, count); | ssize_t ret = read_nothrow (fd, buf, count); |
| |
|
| |
# if GNULIB_NONBLOCKING |
| if (ret < 0 |
if (ret < 0 |
| && GetLastError () == ERROR_NO_DATA) |
&& GetLastError () == ERROR_NO_DATA) |
| { |
{ |
|
Line 52 rpl_read (int fd, void *buf, size_t count)
|
Line 83 rpl_read (int fd, void *buf, size_t count)
|
| errno = EAGAIN; |
errno = EAGAIN; |
| } |
} |
| } |
} |
| |
# endif |
| |
|
| return ret; |
return ret; |
| } |
} |
| |
|
| # endif |
|
| #endif |
#endif |