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! */
31 #ifdef HACK_BCC_UTIME_BUG
37 # ifdef HAVE_SYS_UTIME_H
38 # include <sys/utime.h>
50 /* Defined in log.c. */
51 void log_request_redirect_output PARAMS ((const char *));
53 static int windows_nt_p;
56 /* Emulation of Unix sleep. */
59 sleep (unsigned seconds)
61 return SleepEx (1000 * seconds, TRUE) ? 0U : 1000 * seconds;
64 /* Emulation of Unix usleep(). This has a granularity of
65 milliseconds, but that's ok because:
67 a) Wget is only using it with milliseconds;
69 b) You can't rely on usleep's granularity anyway. If a caller
70 expects usleep to respect every microsecond, he's in for a
74 usleep (unsigned long usec)
76 SleepEx (usec / 1000, TRUE);
81 read_registry (HKEY hkey, char *subkey, char *valuename, char *buf, int *len)
86 if (RegOpenKeyEx (hkey, subkey, NULL, KEY_READ, &result) != ERROR_SUCCESS)
88 if (RegQueryValueEx (result, valuename, NULL, &type, buf, &size) != ERROR_SUCCESS)
96 windows_main_junk (int *argc, char **argv, char **exec_name)
100 /* Remove .EXE from filename if it has one. */
101 *exec_name = xstrdup (*exec_name);
102 p = strrchr (*exec_name, '.');
118 log_request_redirect_output ("CTRL+Break");
122 fork_to_background (void)
124 /* Whether we arrange our own version of opt.lfilename here. */
129 opt.lfilename = unique_name (DEFAULT_LOGFILE);
132 printf (_("Continuing in background.\n"));
134 printf (_("Output will be written to `%s'.\n"), opt.lfilename);
142 ws_handler (DWORD dwEvent)
149 #ifdef CTRLBREAK_BACKGND
150 case CTRL_BREAK_EVENT:
152 fork_to_background ();
154 case CTRL_SHUTDOWN_EVENT:
155 case CTRL_CLOSE_EVENT:
156 case CTRL_LOGOFF_EVENT:
165 ws_changetitle (char *url, int nurl)
171 title_buf = (char *)alloca (strlen (url) + 20);
172 sprintf (title_buf, "Wget %s%s", url, nurl == 1 ? "" : " ...");
173 SetConsoleTitle (title_buf);
179 static char *wspathsave;
180 char buffer[MAX_PATH];
188 GetModuleFileName (NULL, buffer, MAX_PATH);
190 ptr = strrchr (buffer, '\\');
194 wspathsave = (char*) xmalloc (strlen (buffer) + 1);
195 strcpy (wspathsave, buffer);
203 ws_help (const char *name)
205 char *mypath = ws_mypath ();
210 char *buf = (char *)alloca (strlen (mypath) + strlen (name) + 4 + 1);
211 sprintf (buf, "%s%s.HLP", mypath, name);
212 if (stat (buf, &sbuf) == 0)
214 printf (_("Starting WinHelp %s\n"), buf);
215 WinHelp (NULL, buf, HELP_INDEX, NULL);
219 printf ("%s: %s\n", buf, strerror (errno));
232 if (GetVersionEx (&os) == TRUE
233 && os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
236 requested = MAKEWORD (1, 1);
237 err = WSAStartup (requested, &data);
241 fprintf (stderr, _("%s: Couldn't find usable socket driver.\n"),
246 if (data.wVersion < requested)
248 fprintf (stderr, _("%s: Couldn't find usable socket driver.\n"),
254 SetConsoleCtrlHandler (ws_handler, TRUE);
257 /* Replacement utime function for buggy Borland C++Builder 5.5 compiler.
258 (The Borland utime function only works on Windows NT.) */
260 #ifdef HACK_BCC_UTIME_BUG
261 int borland_utime(const char *path, const struct utimbuf *times)
268 if ((fd = open (path, O_RDWR)) < 0)
271 ptr_tm = localtime (×->modtime);
272 ft.ft_tsec = ptr_tm->tm_sec >> 1;
273 ft.ft_min = ptr_tm->tm_min;
274 ft.ft_hour = ptr_tm->tm_hour;
275 ft.ft_day = ptr_tm->tm_mday;
276 ft.ft_month = ptr_tm->tm_mon + 1;
277 ft.ft_year = ptr_tm->tm_year - 80;
278 res = setftime (fd, &ft);