windows-64-bit-type-safety-20051105
[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 int
29 afs_winsockInit(void)
30 {
31     static int once = 1;
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 /* This function will begin to fail in the year 2038 */
52 int
53 afs_gettimeofday(struct timeval *tv, struct timezone *tz)
54 {
55     struct _timeb myTime;
56
57     _ftime(&myTime);
58     tv->tv_sec = myTime.time;
59     tv->tv_usec = myTime.millitm * 1000;
60     if (tz) {
61         tz->tz_minuteswest = myTime.timezone;
62         tz->tz_dsttime = myTime.dstflag;
63     }
64     return 0;
65 }
66 #endif