bos-mrafs-support-20010212
[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 <afs/param.h>
13 #ifdef AFS_NT40_ENV
14 #include <winsock2.h>
15 #include <sys/timeb.h>
16 #include <afs/afsutil.h>
17
18 /* afs_wsInit - LWP version
19  * Initialize the winsock 2 environment.
20  * 
21  * Returns 0 on success, -1 on error.
22  */
23 int afs_winsockInit(void)
24 {
25     static int once = 1;
26
27     if (once) {
28         int code ;
29         WSADATA data;
30         WORD sockVersion;
31
32         once = 0;
33
34         sockVersion = 2;
35         code = WSAStartup(sockVersion, &data);
36         if (code)
37             return -1;
38
39         if (data.wVersion != 2)
40             return -1;
41     }
42     return 0;
43 }
44
45 int afs_gettimeofday(struct timeval *tv, struct timezone *tz)
46 {
47     struct _timeb myTime;
48
49     _ftime(&myTime);
50     tv->tv_sec = myTime.time;
51     tv->tv_usec = myTime.millitm * 1000;
52     if (tz) {
53         tz->tz_minuteswest = myTime.timezone;
54         tz->tz_dsttime = myTime.dstflag;
55     }
56     return 0;
57 }
58 #endif