doc: use ASCII in .texi files where UTF-8 isn't needed
[gnulib.git] / lib / sendto.c
index b6cb8b9..6a8fad2 100644 (file)
@@ -1,6 +1,6 @@
 /* sendto.c --- wrappers for Windows sendto function
 
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008-2014 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
 
 #undef sendto
 
-int
-rpl_sendto (int fd, const void *buf, int len, int flags,
-            struct sockaddr *to, int tolen)
+ssize_t
+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;
+    }
 }