Add module sockets.
[gnulib.git] / lib / sockets.c
1 /* sockets.c --- wrappers for Windows socket functions
2
3    Copyright (C) 2008 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 /* This includes winsock2.h on MinGW. */
23 #include <sys/socket.h>
24
25 #include "sockets.h"
26
27 int
28 gl_sockets_startup (int version)
29 {
30 #if WINDOWS_SOCKETS
31   WSADATA data;
32   int err;
33
34   err = WSAStartup (version, &data);
35   if (err != 0)
36     return 1;
37
38   if (data.wVersion < version)
39     return 2;
40 #endif
41
42   return 0;
43 }
44
45 int
46 gl_sockets_cleanup (void)
47 {
48 #if WINDOWS_SOCKETS
49   int err;
50
51   err = WSACleanup ();
52   if (err != 0)
53     return 1;
54 #endif
55
56   return 0;
57 }