2 * This file is part of DisOrder.
3 * Copyright (C) 2013 Richard Kettlewell
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.
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.
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/>.
18 /** @file lib/disorder-win32.c
19 * @brief Windows support
26 int gettimeofday(struct timeval
*tv
, struct timezone
*tz
) {
28 unsigned long long cns
;
29 GetSystemTimeAsFileTime(&ft
);
30 cns
= ((unsigned long long)ft
.dwHighDateTime
<< 32) + ft
.dwLowDateTime
;
31 /* This gives the count of 100ns intervals since the start of 1601.
32 * WP thinks that this is interpreted according to the proleptic Gregorian
33 * calendar though MS do not say.
35 tv
->tv_usec
= (cns
% 10000000) / 10;
36 tv
->tv_sec
= (long)(cns
/ 10000000 - 86400LL * ((1970 - 1601) * 365
38 - (1970 - 1601) / 100));
42 char *win_wtomb(const wchar_t *ws
) {
46 if((rc
= wcstombs_s(&converted
, NULL
, 0, ws
, 0)))
47 disorder_fatal(rc
, "wcstombs_s");
48 s
= xmalloc(converted
);
49 if((rc
= wcstombs_s(&converted
, s
, converted
, ws
, converted
)))
50 disorder_fatal(rc
, "wcstombs_s");
54 void network_init(void) {
57 if((rc
= WSAStartup(MAKEWORD(2, 2), &wsadata
)))
58 disorder_fatal(0, "WSAStartup: %d", rc
);