/* mswindows.c -- Windows-specific support
- Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 1998, 2004 Free Software Foundation, Inc.
This file is part of GNU Wget.
static DWORD pwr_mode = 0;
static int windows_nt_p;
-#ifndef HAVE_SLEEP
+/* Windows version of xsleep in utils.c. */
-/* Emulation of Unix sleep. */
-
-unsigned int
-sleep (unsigned seconds)
-{
- return SleepEx (1000 * seconds, TRUE) ? 0U : 1000 * seconds;
-}
-#endif
-
-#ifndef HAVE_USLEEP
-/* Emulation of Unix usleep(). This has a granularity of
- milliseconds, but that's ok because:
-
- a) Wget is only using it with milliseconds [not anymore, but b)
- still applies];
-
- b) You can't rely on usleep's granularity anyway. If a caller
- expects usleep to respect every microsecond, he's in for a
- surprise. */
-
-int
-usleep (unsigned long usec)
+void
+xsleep (double seconds)
{
- SleepEx (usec / 1000, TRUE);
- return 0;
+#ifdef HAVE_USLEEP
+ if (seconds > 1000)
+ {
+ /* Explained in utils.c. */
+ sleep (seconds);
+ seconds -= (long) seconds;
+ }
+ usleep (seconds * 1000000L);
+#else /* not HAVE_USLEEP */
+ SleepEx (seconds * 1000, FALSE);
+#endif /* not HAVE_USLEEP */
}
-#endif /* HAVE_USLEEP */
void
windows_main_junk (int *argc, char **argv, char **exec_name)
ws_mypath (void)
{
static char *wspathsave = NULL;
- char buffer[MAX_PATH];
- char *ptr;
- if (wspathsave)
+ if (!wspathsave)
{
- return wspathsave;
- }
+ char buf[MAX_PATH + 1];
+ char *p;
+ DWORD len;
- if (GetModuleFileName (NULL, buffer, MAX_PATH) &&
- (ptr = strrchr (buffer, PATH_SEPARATOR)) != NULL)
- {
- *(ptr + 1) = '\0';
- wspathsave = xstrdup (buffer);
- }
- else
- wspathsave = NULL;
- return wspathsave;
-}
+ len = GetModuleFileName (GetModuleHandle (NULL), buf, sizeof (buf));
+ if (!len || (len >= sizeof (buf)))
+ return NULL;
-void
-ws_help (const char *name)
-{
- char *mypath = ws_mypath ();
+ p = strrchr (buf, PATH_SEPARATOR);
+ if (!p)
+ return NULL;
- if (mypath)
- {
- struct stat sbuf;
- char *buf = (char *)alloca (strlen (mypath) + strlen (name) + 4 + 1);
- sprintf (buf, "%s%s.HLP", mypath, name);
- if (stat (buf, &sbuf) == 0)
- {
- printf (_("Starting WinHelp %s\n"), buf);
- WinHelp (NULL, buf, HELP_INDEX, 0);
- }
- else
- {
- printf ("%s: %s\n", buf, strerror (errno));
- }
+ *p = '\0';
+ wspathsave = xstrdup (buf);
}
+
+ return wspathsave;
}
void
return 0;
}
-/*
- * Run FUN with timeout. This is done by creating a thread for 'fun'
- * to run in and terminating the thread if it doesn't finish in
- * SECONDS time.
- */
+/* Call FUN(ARG), but don't allow it to run for more than TIMEOUT
+ seconds. Returns non-zero if the function was interrupted with a
+ timeout, zero otherwise.
+
+ This works by running FUN in a separate thread and terminating the
+ thread if it doesn't finish in the specified time. */
int
run_with_timeout (double seconds, void (*fun) (void *), void *arg)