windows-library-cleanup-20060702
[openafs.git] / src / util / winsock_nt.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /* winsock.c contains winsock related routines. */
11
12 #include <afsconfig.h>
13 #include <afs/param.h>
14
15 RCSID
16     ("$Header$");
17
18 #ifdef AFS_NT40_ENV
19 #include <winsock2.h>
20 #include <sys/timeb.h>
21 #include <afs/afsutil.h>
22
23 /* afs_wsInit - LWP version
24  * Initialize the winsock 2 environment.
25  * 
26  * Returns 0 on success, -1 on error.
27  */
28 static int once = 1;
29
30 int
31 afs_winsockInit(void)
32 {
33     if (once) {
34         int code;
35         WSADATA data;
36         WORD sockVersion;
37
38         once = 0;
39
40         sockVersion = 2;
41         code = WSAStartup(sockVersion, &data);
42         if (code)
43             return -1;
44
45         if (data.wVersion != 2)
46             return -1;
47     }
48     return 0;
49 }
50
51 void
52 afs_winsockCleanup(void)
53 {
54     WSACleanup();
55     once = 0;
56 }
57
58 /* This function will begin to fail in the year 2038 */
59 int
60 afs_gettimeofday(struct timeval *tv, struct timezone *tz)
61 {
62     struct _timeb myTime;
63
64     _ftime(&myTime);
65     tv->tv_sec = myTime.time;
66     tv->tv_usec = myTime.millitm * 1000;
67     if (tz) {
68         tz->tz_minuteswest = myTime.timezone;
69         tz->tz_dsttime = myTime.dstflag;
70     }
71     return 0;
72 }
73 #endif