2
* wpa_supplicant/hostapd / OS specific functions for Win32 systems
3
* Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 2 as
7
* published by the Free Software Foundation.
9
* Alternatively, this software may be distributed under the terms of BSD
12
* See README and COPYING for more details.
21
void os_sleep(os_time_t sec, os_time_t usec)
30
int os_get_time(struct os_time *t)
32
#define EPOCHFILETIME (116444736000000000ULL)
41
SystemTimeToFileTime(&st, &ft);
42
#else /* _WIN32_WCE */
43
GetSystemTimeAsFileTime(&ft);
44
#endif /* _WIN32_WCE */
45
li.LowPart = ft.dwLowDateTime;
46
li.HighPart = ft.dwHighDateTime;
47
tt = (li.QuadPart - EPOCHFILETIME) / 10;
48
t->sec = (os_time_t) (tt / 1000000);
49
t->usec = (os_time_t) (tt % 1000000);
55
int os_mktime(int year, int month, int day, int hour, int min, int sec,
60
if (year < 1970 || month < 1 || month > 12 || day < 1 || day > 31 ||
61
hour < 0 || hour > 23 || min < 0 || min > 59 || sec < 0 ||
65
memset(&tm, 0, sizeof(tm));
66
tm.tm_year = year - 1900;
67
tm.tm_mon = month - 1;
73
*t = (os_time_t) mktime(&tm);
78
int os_daemonize(const char *pid_file)
85
void os_daemonize_terminate(const char *pid_file)
90
int os_get_random(unsigned char *buf, size_t len)
95
if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL,
99
ret = CryptGenRandom(prov, len, buf);
100
CryptReleaseContext(prov, 0);
106
unsigned long os_random(void)
112
char * os_rel2abs_path(const char *rel_path)
114
return _strdup(rel_path);
118
int os_program_init(void)
120
#ifdef CONFIG_NATIVE_WINDOWS
122
if (WSAStartup(MAKEWORD(2, 0), &wsaData)) {
123
printf("Could not find a usable WinSock.dll\n");
126
#endif /* CONFIG_NATIVE_WINDOWS */
131
void os_program_deinit(void)
133
#ifdef CONFIG_NATIVE_WINDOWS
135
#endif /* CONFIG_NATIVE_WINDOWS */
139
int os_setenv(const char *name, const char *value, int overwrite)
145
int os_unsetenv(const char *name)
151
char * os_readfile(const char *name, size_t *len)
156
f = fopen(name, "rb");
160
fseek(f, 0, SEEK_END);
162
fseek(f, 0, SEEK_SET);
170
fread(buf, 1, *len, f);
177
void * os_zalloc(size_t size)
179
return calloc(1, size);
183
size_t os_strlcpy(char *dest, const char *src, size_t siz)
189
/* Copy string up to the maximum size of the dest buffer */
190
while (--left != 0) {
191
if ((*dest++ = *s++) == '\0')
197
/* Not enough room for the string; force NUL-termination */
201
; /* determine total src string length */