chiark / gitweb /
disobedience, playrtp: Have `playrtp' handle volume control.
[disorder] / lib / disorder-win32.c
CommitLineData
9e42afcd
RK
1/*
2 * This file is part of DisOrder.
3 * Copyright (C) 2013 Richard Kettlewell
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/** @file lib/disorder-win32.c
19 * @brief Windows support
20 */
21#include "common.h"
22#include "mem.h"
23#include "log.h"
24#include "vector.h"
25
26int gettimeofday(struct timeval *tv, struct timezone *tz) {
27 FILETIME ft;
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.
34 */
35 tv->tv_usec = (cns % 10000000) / 10;
36 tv->tv_sec = (long)(cns / 10000000 - 86400LL * ((1970 - 1601) * 365
37 + (1970 - 1601) / 4
38 - (1970 - 1601) / 100));
39 return 0;
40}
41
42char *win_wtomb(const wchar_t *ws) {
43 char *s;
44 size_t converted;
45 int rc;
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");
51 return s;
52}
53
54void network_init(void) {
55 WSADATA wsadata;
56 int rc;
57 if((rc = WSAStartup(MAKEWORD(2, 2), &wsadata)))
58 disorder_fatal(0, "WSAStartup: %d", rc);
59}