1
0
mirror of https://github.com/moparisthebest/wget synced 2024-07-03 16:38:41 -04:00

[svn] Small cleanup of mswindows.c by Paul Bludov.

Published in <wget-patches@sunsite.auc.dk>.
This commit is contained in:
hniksic 2001-04-03 11:22:04 -07:00
parent d62d112aed
commit a3eea37c91
2 changed files with 21 additions and 32 deletions

View File

@ -1,3 +1,11 @@
2001-04-03 Paul Bludov <paul@ozero.net>
* mswindows.c (sleep): Use SleepEx() instead of Sleep().
(ws_changetitle): Use alloca() instead of malloc() to avoid memory
leak.
(ws_mypath): Use GetModuleFileName instead of argv[0].
(ws_startup): Use data.wVersion for comparison.
2001-04-02 Hrvoje Niksic <hniksic@arsdigita.com> 2001-04-02 Hrvoje Niksic <hniksic@arsdigita.com>
* http.c (http_loop): Ditto. * http.c (http_loop): Ditto.

View File

@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
/* #### Someone document these functions! */ /* #### Someone please document what these functions do! */
#include <config.h> #include <config.h>
@ -35,8 +35,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
extern int errno; extern int errno;
#endif #endif
char *argv0;
/* Defined in log.c. */ /* Defined in log.c. */
void redirect_output (const char *); void redirect_output (const char *);
@ -47,11 +45,7 @@ static int windows_nt_p;
unsigned int unsigned int
sleep (unsigned seconds) sleep (unsigned seconds)
{ {
Sleep (1000 * seconds); return SleepEx (1000 * seconds, TRUE) ? 0U : 1000 * seconds;
/* Unix sleep() is interruptible. To make it semi-usable, it
returns a value that says how much it "really" slept, or some
junk like that. Ignore it. */
return 0U;
} }
static char * static char *
@ -100,8 +94,6 @@ windows_main_junk (int *argc, char **argv, char **exec_name)
{ {
char *p; char *p;
argv0 = argv[0];
/* Remove .EXE from filename if it has one. */ /* Remove .EXE from filename if it has one. */
*exec_name = xstrdup (*exec_name); *exec_name = xstrdup (*exec_name);
p = strrchr (*exec_name, '.'); p = strrchr (*exec_name, '.');
@ -176,10 +168,8 @@ ws_changetitle (char *url, int nurl)
if (!nurl) if (!nurl)
return; return;
title_buf = (char *)xmalloc (strlen (url) + 20); title_buf = (char *)alloca (strlen (url) + 20);
sprintf (title_buf, "Wget %s%s", url, nurl == 1 ? "" : " ..."); sprintf (title_buf, "Wget %s%s", url, nurl == 1 ? "" : " ...");
/* #### What are the semantics of SetConsoleTitle? Will it free the
given memory later? */
SetConsoleTitle (title_buf); SetConsoleTitle (title_buf);
} }
@ -187,34 +177,26 @@ char *
ws_mypath (void) ws_mypath (void)
{ {
static char *wspathsave; static char *wspathsave;
char *buffer; char buffer[MAX_PATH];
int rrr;
char *ptr; char *ptr;
if (wspathsave) if (wspathsave)
{ {
return wspathsave; return wspathsave;
} }
ptr = strrchr (argv0, '\\');
GetModuleFileName (NULL, buffer, MAX_PATH);
ptr = strrchr (buffer, '\\');
if (ptr) if (ptr)
{ {
*(ptr + 1) = '\0'; *(ptr + 1) = '\0';
wspathsave = (char*) xmalloc (strlen(argv0)+1); wspathsave = (char*) xmalloc (strlen (buffer) + 1);
strcpy (wspathsave, argv0);
return wspathsave;
}
buffer = (char*) xmalloc (256);
rrr = SearchPath (NULL, argv0, strchr (argv0, '.') ? NULL : ".EXE",
256, buffer, &ptr);
if (rrr && rrr <= 256)
{
*ptr = '\0';
wspathsave = (char*) xmalloc (strlen(buffer)+1);
strcpy (wspathsave, buffer); strcpy (wspathsave, buffer);
return wspathsave;
} }
xfree (buffer); else
return NULL; wspathsave = NULL;
return wspathsave;
} }
void void
@ -261,8 +243,7 @@ ws_startup (void)
exit (1); exit (1);
} }
if (LOBYTE (requested) < 1 || (LOBYTE (requested) == 1 && if (data.wVersion < requested)
HIBYTE (requested) < 1))
{ {
fprintf (stderr, _("%s: Couldn't find usable socket driver.\n"), fprintf (stderr, _("%s: Couldn't find usable socket driver.\n"),
exec_name); exec_name);