Make sockets.h self-contained.
[gnulib.git] / lib / sockets.c
1 /* sockets.c --- wrappers for Windows socket functions
2
3    Copyright (C) 2008-2009 Free Software Foundation, Inc.
4
5    This program is free software: you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published by
7    the Free Software Foundation; either version 3 of the License, or
8    (at your option) any later version.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
17
18 /* Written by Simon Josefsson */
19
20 #include <config.h>
21
22 /* Specification.  */
23 #include "sockets.h"
24
25 /* This includes winsock2.h on MinGW. */
26 #include <sys/socket.h>
27
28 int
29 gl_sockets_startup (int version)
30 {
31 #if WINDOWS_SOCKETS
32   WSADATA data;
33   int err;
34
35   err = WSAStartup (version, &data);
36   if (err != 0)
37     return 1;
38
39   if (data.wVersion < version)
40     return 2;
41 #endif
42
43   return 0;
44 }
45
46 int
47 gl_sockets_cleanup (void)
48 {
49 #if WINDOWS_SOCKETS
50   int err;
51
52   err = WSACleanup ();
53   if (err != 0)
54     return 1;
55 #endif
56
57   return 0;
58 }