Back to index

nagios-plugins  1.4.16
w32sock.h
Go to the documentation of this file.
00001 /* w32sock.h --- internal auxilliary functions for Windows socket functions
00002 
00003    Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
00004 
00005    This program is free software: you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 3 of the License, or
00008    (at your option) any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00017 
00018 /* Written by Paolo Bonzini */
00019 
00020 #include <errno.h>
00021 
00022 /* Get O_RDWR and O_BINARY.  */
00023 #include <fcntl.h>
00024 
00025 /* Get _get_osfhandle() and _open_osfhandle().  */
00026 #include <io.h>
00027 
00028 #define FD_TO_SOCKET(fd)   ((SOCKET) _get_osfhandle ((fd)))
00029 #define SOCKET_TO_FD(fh)   (_open_osfhandle ((long) (fh), O_RDWR | O_BINARY))
00030 
00031 static inline void
00032 set_winsock_errno (void)
00033 {
00034   int err = WSAGetLastError ();
00035 
00036   /* Map some WSAE* errors to the runtime library's error codes.  */
00037   switch (err)
00038     {
00039     case WSA_INVALID_HANDLE:
00040       errno = EBADF;
00041       break;
00042     case WSA_NOT_ENOUGH_MEMORY:
00043       errno = ENOMEM;
00044       break;
00045     case WSA_INVALID_PARAMETER:
00046       errno = EINVAL;
00047       break;
00048     case WSAEWOULDBLOCK:
00049       errno = EWOULDBLOCK;
00050       break;
00051     case WSAENAMETOOLONG:
00052       errno = ENAMETOOLONG;
00053       break;
00054     case WSAENOTEMPTY:
00055       errno = ENOTEMPTY;
00056       break;
00057     default:
00058       errno = (err > 10000 && err < 10025) ? err - 10000 : err;
00059       break;
00060     }
00061 }