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,
59
time_t t_local, t1, t2;
62
if (year < 1970 || month < 1 || month > 12 || day < 1 || day > 31 ||
63
hour < 0 || hour > 23 || min < 0 || min > 59 || sec < 0 ||
67
memset(&tm, 0, sizeof(tm));
68
tm.tm_year = year - 1900;
69
tm.tm_mon = month - 1;
75
t_local = mktime(&tm);
77
/* figure out offset to UTC */
78
tm1 = localtime(&t_local);
81
tm1 = gmtime(&t_local);
90
*t = (os_time_t) t_local - tz_offset;
95
int os_daemonize(const char *pid_file)
102
void os_daemonize_terminate(const char *pid_file)
107
int os_get_random(unsigned char *buf, size_t len)
112
if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL,
113
CRYPT_VERIFYCONTEXT))
116
ret = CryptGenRandom(prov, len, buf);
117
CryptReleaseContext(prov, 0);
123
unsigned long os_random(void)
129
char * os_rel2abs_path(const char *rel_path)
131
return _strdup(rel_path);
135
int os_program_init(void)
137
#ifdef CONFIG_NATIVE_WINDOWS
139
if (WSAStartup(MAKEWORD(2, 0), &wsaData)) {
140
printf("Could not find a usable WinSock.dll\n");
143
#endif /* CONFIG_NATIVE_WINDOWS */
148
void os_program_deinit(void)
150
#ifdef CONFIG_NATIVE_WINDOWS
152
#endif /* CONFIG_NATIVE_WINDOWS */
156
int os_setenv(const char *name, const char *value, int overwrite)
162
int os_unsetenv(const char *name)
168
char * os_readfile(const char *name, size_t *len)
173
f = fopen(name, "rb");
177
fseek(f, 0, SEEK_END);
179
fseek(f, 0, SEEK_SET);
187
fread(buf, 1, *len, f);
194
void * os_zalloc(size_t size)
196
return calloc(1, size);
200
size_t os_strlcpy(char *dest, const char *src, size_t siz)
206
/* Copy string up to the maximum size of the dest buffer */
207
while (--left != 0) {
208
if ((*dest++ = *s++) == '\0')
214
/* Not enough room for the string; force NUL-termination */
218
; /* determine total src string length */