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! */
39 /* Defined in log.c. */
40 void log_request_redirect_output PARAMS ((const char *));
42 static int windows_nt_p;
45 /* Emulation of Unix sleep. */
48 sleep (unsigned seconds)
50 return SleepEx (1000 * seconds, TRUE) ? 0U : 1000 * seconds;
53 /* Emulation of Unix usleep(). This has a granularity of
54 milliseconds, but that's ok because:
56 a) Wget is only using it with milliseconds;
58 b) You can't rely on usleep's granularity anyway. If a caller
59 expects usleep to respect every microsecond, he's in for a
63 usleep (unsigned long usec)
65 SleepEx (usec / 1000, TRUE);
70 read_registry (HKEY hkey, char *subkey, char *valuename, char *buf, int *len)
75 if (RegOpenKeyEx (hkey, subkey, NULL, KEY_READ, &result) != ERROR_SUCCESS)
77 if (RegQueryValueEx (result, valuename, NULL, &type, buf, &size) != ERROR_SUCCESS)
85 windows_main_junk (int *argc, char **argv, char **exec_name)
89 /* Remove .EXE from filename if it has one. */
90 *exec_name = xstrdup (*exec_name);
91 p = strrchr (*exec_name, '.');
107 log_request_redirect_output ("CTRL+Break");
111 fork_to_background (void)
113 /* Whether we arrange our own version of opt.lfilename here. */
118 opt.lfilename = unique_name (DEFAULT_LOGFILE);
121 printf (_("Continuing in background.\n"));
123 printf (_("Output will be written to `%s'.\n"), opt.lfilename);
131 ws_handler (DWORD dwEvent)
138 #ifdef CTRLBREAK_BACKGND
139 case CTRL_BREAK_EVENT:
141 fork_to_background ();
143 case CTRL_SHUTDOWN_EVENT:
144 case CTRL_CLOSE_EVENT:
145 case CTRL_LOGOFF_EVENT:
154 ws_changetitle (char *url, int nurl)
160 title_buf = (char *)alloca (strlen (url) + 20);
161 sprintf (title_buf, "Wget %s%s", url, nurl == 1 ? "" : " ...");
162 SetConsoleTitle (title_buf);
168 static char *wspathsave;
169 char buffer[MAX_PATH];
177 GetModuleFileName (NULL, buffer, MAX_PATH);
179 ptr = strrchr (buffer, '\\');
183 wspathsave = (char*) xmalloc (strlen (buffer) + 1);
184 strcpy (wspathsave, buffer);
192 ws_help (const char *name)
194 char *mypath = ws_mypath ();
199 char *buf = (char *)alloca (strlen (mypath) + strlen (name) + 4 + 1);
200 sprintf (buf, "%s%s.HLP", mypath, name);
201 if (stat (buf, &sbuf) == 0)
203 printf (_("Starting WinHelp %s\n"), buf);
204 WinHelp (NULL, buf, HELP_INDEX, NULL);
208 printf ("%s: %s\n", buf, strerror (errno));
221 if (GetVersionEx (&os) == TRUE
222 && os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
225 requested = MAKEWORD (1, 1);
226 err = WSAStartup (requested, &data);
230 fprintf (stderr, _("%s: Couldn't find usable socket driver.\n"),
235 if (data.wVersion < requested)
237 fprintf (stderr, _("%s: Couldn't find usable socket driver.\n"),
243 SetConsoleCtrlHandler (ws_handler, TRUE);