1 /*
2 * libwebsockets - small server side websockets and web server implementation
3 *
4 * Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 * IN THE SOFTWARE.
23 */
24
25 #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS
26 #define _WINSOCK_DEPRECATED_NO_WARNINGS
27 #endif
28 #include "private-lib-core.h"
29
30
31 lws_usec_t
lws_now_usecs(void)32 lws_now_usecs(void)
33 {
34 #ifndef DELTA_EPOCH_IN_MICROSECS
35 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
36 #endif
37 FILETIME filetime;
38 ULARGE_INTEGER datetime;
39
40 #ifdef _WIN32_WCE
41 GetCurrentFT(&filetime);
42 #else
43 GetSystemTimeAsFileTime(&filetime);
44 #endif
45
46 /*
47 * As per Windows documentation for FILETIME, copy the resulting
48 * FILETIME structure to a ULARGE_INTEGER structure using memcpy
49 * (using memcpy instead of direct assignment can prevent alignment
50 * faults on 64-bit Windows).
51 */
52 memcpy(&datetime, &filetime, sizeof(datetime));
53
54 /* Windows file times are in 100s of nanoseconds. */
55 return (datetime.QuadPart / 10) - DELTA_EPOCH_IN_MICROSECS;
56 }
57
58
59 #ifdef _WIN32_WCE
time(time_t * t)60 time_t time(time_t *t)
61 {
62 time_t ret = lws_now_usecs() / 1000000;
63
64 if(t != NULL)
65 *t = ret;
66
67 return ret;
68 }
69 #endif
70
71 size_t
lws_get_random(struct lws_context * context,void * buf,size_t len)72 lws_get_random(struct lws_context *context, void *buf, size_t len)
73 {
74 size_t n;
75 char *p = (char *)buf;
76
77 for (n = 0; n < len; n++)
78 p[n] = (unsigned char)rand();
79
80 return n;
81 }
82
83
84 void
lwsl_emit_syslog(int level,const char * line)85 lwsl_emit_syslog(int level, const char *line)
86 {
87 lwsl_emit_stderr(level, line);
88 }
89
90
kill(int pid,int sig)91 int kill(int pid, int sig)
92 {
93 lwsl_err("Sorry Windows doesn't support kill().");
94 exit(0);
95 }
96
fork(void)97 int fork(void)
98 {
99 lwsl_err("Sorry Windows doesn't support fork().");
100 exit(0);
101 }
102
103
104 int
lws_plat_recommended_rsa_bits(void)105 lws_plat_recommended_rsa_bits(void)
106 {
107 return 4096;
108 }
109
110
111
112