1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include "qemu/osdep.h"
26#include <windows.h>
27#include <mmsystem.h>
28#include "sysemu/sysemu.h"
29#include "qemu-options.h"
30
31
32
33
34int setenv(const char *name, const char *value, int overwrite)
35{
36 int result = 0;
37 if (overwrite || !getenv(name)) {
38 size_t length = strlen(name) + strlen(value) + 2;
39 char *string = g_malloc(length);
40 snprintf(string, length, "%s=%s", name, value);
41 result = putenv(string);
42
43
44
45
46
47
48 g_free(string);
49 }
50 return result;
51}
52
53void *rawmemchr(const void *s, int c)
54{
55 const char *s8 = s;
56 while (*s8 != c) {
57 s8++;
58 }
59 return (void *) s8;
60}
61
62static BOOL WINAPI qemu_ctrl_handler(DWORD type)
63{
64 qemu_system_shutdown_request();
65
66
67
68
69 Sleep(10000);
70
71 return TRUE;
72}
73
74static TIMECAPS mm_tc;
75
76static void os_undo_timer_resolution(void)
77{
78 timeEndPeriod(mm_tc.wPeriodMin);
79}
80
81void os_setup_early_signal_handling(void)
82{
83 SetConsoleCtrlHandler(qemu_ctrl_handler, TRUE);
84 timeGetDevCaps(&mm_tc, sizeof(mm_tc));
85 timeBeginPeriod(mm_tc.wPeriodMin);
86 atexit(os_undo_timer_resolution);
87}
88
89
90char *os_find_datadir(void)
91{
92 return qemu_get_exec_dir();
93}
94
95void os_set_line_buffering(void)
96{
97 setbuf(stdout, NULL);
98 setbuf(stderr, NULL);
99}
100
101
102
103
104
105void os_parse_cmd_args(int index, const char *optarg)
106{
107 return;
108}
109
110int qemu_create_pidfile(const char *filename)
111{
112 char buffer[128];
113 int len;
114 HANDLE file;
115 OVERLAPPED overlap;
116 BOOL ret;
117 memset(&overlap, 0, sizeof(overlap));
118
119 file = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL,
120 OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
121
122 if (file == INVALID_HANDLE_VALUE) {
123 return -1;
124 }
125 len = snprintf(buffer, sizeof(buffer), "%d\n", getpid());
126 ret = WriteFile(file, (LPCVOID)buffer, (DWORD)len,
127 NULL, &overlap);
128 CloseHandle(file);
129 if (ret == 0) {
130 return -1;
131 }
132 return 0;
133}
134