1 /* mswindows.c -- Windows-specific support
2 Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
4 This file is part of GNU Wget.
6 GNU Wget is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 GNU Wget is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Wget; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* #### Someone please document what these functions do! */
38 /* Defined in log.c. */
39 void log_request_redirect_output PARAMS ((const char *));
41 static int windows_nt_p;
44 /* Emulation of Unix sleep. */
47 sleep (unsigned seconds)
49 return SleepEx (1000 * seconds, TRUE) ? 0U : 1000 * seconds;
52 /* Emulation of Unix usleep(). This has a granularity of
53 milliseconds, but that's ok because:
55 a) Wget is only using it with milliseconds;
57 b) You can't rely on usleep's granularity anyway. If a caller
58 expects usleep to respect every microsecond, he's in for a
62 usleep (unsigned long usec)
64 SleepEx (usec / 1000, TRUE);
69 read_registry (HKEY hkey, char *subkey, char *valuename, char *buf, int *len)
74 if (RegOpenKeyEx (hkey, subkey, NULL, KEY_READ, &result) != ERROR_SUCCESS)
76 if (RegQueryValueEx (result, valuename, NULL, &type, buf, &size) != ERROR_SUCCESS)
84 windows_main_junk (int *argc, char **argv, char **exec_name)
88 /* Remove .EXE from filename if it has one. */
89 *exec_name = xstrdup (*exec_name);
90 p = strrchr (*exec_name, '.');
106 log_request_redirect_output ("CTRL+Break");
110 fork_to_background (void)
112 /* Whether we arrange our own version of opt.lfilename here. */
117 opt.lfilename = unique_name (DEFAULT_LOGFILE);
120 printf (_("Continuing in background.\n"));
122 printf (_("Output will be written to `%s'.\n"), opt.lfilename);
130 ws_handler (DWORD dwEvent)
137 #ifdef CTRLBREAK_BACKGND
138 case CTRL_BREAK_EVENT:
140 fork_to_background ();
142 case CTRL_SHUTDOWN_EVENT:
143 case CTRL_CLOSE_EVENT:
144 case CTRL_LOGOFF_EVENT:
153 ws_changetitle (char *url, int nurl)
159 title_buf = (char *)alloca (strlen (url) + 20);
160 sprintf (title_buf, "Wget %s%s", url, nurl == 1 ? "" : " ...");
161 SetConsoleTitle (title_buf);
167 static char *wspathsave;
168 char buffer[MAX_PATH];
176 GetModuleFileName (NULL, buffer, MAX_PATH);
178 ptr = strrchr (buffer, '\\');
182 wspathsave = (char*) xmalloc (strlen (buffer) + 1);
183 strcpy (wspathsave, buffer);
191 ws_help (const char *name)
193 char *mypath = ws_mypath ();
198 char *buf = (char *)alloca (strlen (mypath) + strlen (name) + 4 + 1);
199 sprintf (buf, "%s%s.HLP", mypath, name);
200 if (stat (buf, &sbuf) == 0)
202 printf (_("Starting WinHelp %s\n"), buf);
203 WinHelp (NULL, buf, HELP_INDEX, NULL);
207 printf ("%s: %s\n", buf, strerror (errno));
220 if (GetVersionEx (&os) == TRUE
221 && os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
224 requested = MAKEWORD (1, 1);
225 err = WSAStartup (requested, &data);
229 fprintf (stderr, _("%s: Couldn't find usable socket driver.\n"),
234 if (data.wVersion < requested)
236 fprintf (stderr, _("%s: Couldn't find usable socket driver.\n"),
242 SetConsoleCtrlHandler (ws_handler, TRUE);