summaryrefslogtreecommitdiff
path: root/lib/sendto.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2011-09-21 00:20:59 +0200
committerBruno Haible <bruno@clisp.org>2011-09-21 00:20:59 +0200
commit4f86301f09e10e2c88d539392723c4d21385bcab (patch)
tree22addc253dd37dfb9f2c590ba1764e273e3e3c59 /lib/sendto.c
parent8b0c40c0d4dc2668acf7b5ab29211d66792314b2 (diff)
downloadgnulib-4f86301f09e10e2c88d539392723c4d21385bcab.tar.gz
Ensure EBADF returns for socket functions on mingw.
* lib/accept.c (rpl_accept): Fail with error EBADF if the file descriptor is invalid. * lib/bind.c (rpl_bind): Likewise. * lib/connect.c (rpl_connect): Likewise. * lib/getpeername.c (rpl_getpeername): Likewise. * lib/getsockname.c (rpl_getsockname): Likewise. * lib/getsockopt.c (rpl_getsockopt): Likewise. * lib/listen.c (rpl_listen): Likewise. * lib/recv.c (rpl_recv): Likewise. * lib/recvfrom.c (rpl_recvfrom): Likewise. * lib/send.c (rpl_send): Likewise. * lib/sendto.c (rpl_sendto): Likewise. * lib/setsockopt.c (rpl_setsockopt): Likewise. * lib/shutdown.c (rpl_shutdown): Likewise.
Diffstat (limited to 'lib/sendto.c')
-rw-r--r--lib/sendto.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/sendto.c b/lib/sendto.c
index e301626dfb..95efab8885 100644
--- a/lib/sendto.c
+++ b/lib/sendto.c
@@ -33,9 +33,18 @@ rpl_sendto (int fd, const void *buf, size_t len, int flags,
const struct sockaddr *to, socklen_t tolen)
{
SOCKET sock = FD_TO_SOCKET (fd);
- int r = sendto (sock, buf, len, flags, to, tolen);
- if (r < 0)
- set_winsock_errno ();
- return r;
+ if (sock == INVALID_SOCKET)
+ {
+ errno = EBADF;
+ return -1;
+ }
+ else
+ {
+ int r = sendto (sock, buf, len, flags, to, tolen);
+ if (r < 0)
+ set_winsock_errno ();
+
+ return r;
+ }
}