1 /* Win32 support fo ELinks. It has pretty different life than rest of ELinks. */
7 /* Get SHGFP_TYPE_CURRENT from <shlobj.h>. */
8 #define _WIN32_IE 0x500
13 #include "osdep/system.h"
28 #include "main/select.h"
29 #include "osdep/win32/win32.h"
30 #include "osdep/osdep.h"
31 #include "terminal/terminal.h"
37 #ifdef CONFIG_OS_WIN32
39 WORD ver
= MAKEWORD(1,1);
43 if (WSAStartup(ver
,&ws
) != 0) {
44 printf("Failed to initialise Winsock ver %d.%d\n", ver
>> 8, ver
& 255);
49 setlocale(LC_ALL
, "");
56 if (!getenv("CHARSET") && cp
> 0)
58 snprintf (buf
, sizeof(buf
), "CHARSET=cp%u", cp
);
78 handle_terminal_resize(int fd
, void (*fn
)())
83 unhandle_terminal_resize(int fd
)
88 get_terminal_size(int fd
, int *x
, int *y
)
90 CONSOLE_SCREEN_BUFFER_INFO csbi
;
92 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE
), &csbi
);
95 *x
= get_e("COLUMNS");
97 *x
= csbi
.srWindow
.Right
- csbi
.srWindow
.Left
+ 1;
102 *y
= csbi
.srWindow
.Bottom
- csbi
.srWindow
.Top
+ 1;
108 exe(unsigned char *path
)
111 unsigned char *shell
= get_shell();
112 unsigned char *x
= *path
!= '"' ? " /c start /wait " : " /c start /wait \"\" ";
113 unsigned char *p
= malloc((strlen(shell
) + strlen(x
) + strlen(path
)) * 2 + 1);
124 memmove(x
+ 1, x
, strlen(x
) + 1);
140 return get_input_handle();
144 #if defined(HAVE_BEGINTHREAD)
147 void (*fn
)(void *, int);
149 unsigned char data
[1];
152 extern void bgt(struct tdata
*t
);
155 start_thread(void (*fn
)(void *, int), void *ptr
, int l
)
163 t
= malloc(sizeof(*t
) + l
);
168 memcpy(t
->data
, ptr
, l
);
169 if (_beginthread((void (*)(void *)) bgt
, 65536, t
) == -1) {
182 get_input_handle(void)
184 static HANDLE hStdIn
= INVALID_HANDLE_VALUE
;
186 if (hStdIn
== INVALID_HANDLE_VALUE
) {
189 SetConsoleTitle("ELinks - Console mode browser");
191 hStdIn
= GetStdHandle(STD_INPUT_HANDLE
);
192 GetConsoleMode(hStdIn
, &dwMode
);
193 dwMode
&= ~(ENABLE_LINE_INPUT
| ENABLE_ECHO_INPUT
);
194 dwMode
|= (ENABLE_WINDOW_INPUT
| ENABLE_MOUSE_INPUT
);
195 SetConsoleMode(hStdIn
, dwMode
);
201 get_output_handle(void)
203 static HANDLE hStdOut
= INVALID_HANDLE_VALUE
;
205 if (hStdOut
== INVALID_HANDLE_VALUE
)
206 hStdOut
= GetStdHandle(STD_OUTPUT_HANDLE
);
207 return (int) hStdOut
;
211 gettimeofday(struct timeval
* p
, void* tz
)
214 long long ns100
; /*time since 1 Jan 1601 in 100ns units */
219 GetSystemTimeAsFileTime (&_now
.ft
);
220 p
->tv_usec
= (long) ((_now
.ns100
/ 10LL) % 1000000LL);
221 p
->tv_sec
= (long) ((_now
.ns100
- 116444736000000000LL) / 10000000LL);
227 mkstemp(char *template)
229 char pathname
[MAX_PATH
];
231 /* Get the directory for temp files */
232 GetTempPath(MAX_PATH
, pathname
);
234 /* Create a temporary file. */
235 GetTempFileName(pathname
, "ABC", 0, template);
237 return open(template, O_WRONLY
| O_BINARY
| O_EXCL
);
241 tcgetattr(int fd
, struct termios
*_termios_p
)
249 tcsetattr(int fd
, int _optional_actions
, const struct termios
*_termios_p
)
252 (void) _optional_actions
;
259 gettext__parse(void *arg
)
266 user_appdata_directory(void)
268 #if _WIN32_WINNT >= 0x0500
269 HWND hwnd
= GetConsoleWindow();
276 hr
= SHGetFolderPath(hwnd
, CSIDL_APPDATA
, NULL
, SHGFP_TYPE_CURRENT
, path
);
277 if (hr
== S_OK
) /* Don't even allow S_FALSE. */
278 return stracpy(path
);