#include "utils.h"
#include "url.h"
-#ifndef errno
-extern int errno;
-#endif
-
#ifndef ES_SYSTEM_REQUIRED
#define ES_SYSTEM_REQUIRED 0x00000001
#endif
/* Defined in log.c. */
-void log_request_redirect_output PARAMS ((const char *));
+void log_request_redirect_output (const char *);
/* Windows version of xsleep in utils.c. */
}
usleep (seconds * 1000000L);
#else /* not HAVE_USLEEP */
- SleepEx (seconds * 1000, FALSE);
+ SleepEx ((DWORD) (seconds * 1000 + .5), FALSE);
#endif /* not HAVE_USLEEP */
}
__int64
str_to_int64 (const char *nptr, char **endptr, int base)
{
-#define OVERFLOW 9223372036854775807I64
-#define UNDERFLOW (-OVERFLOW - 1)
+#define INT64_OVERFLOW 9223372036854775807I64
+#define INT64_UNDERFLOW (-INT64_OVERFLOW - 1)
__int64 result = 0;
int negative;
__int64 newresult = base * result + val;
if (newresult < result)
{
- result = OVERFLOW;
+ result = INT64_OVERFLOW;
errno = ERANGE;
break;
}
__int64 newresult = base * result - val;
if (newresult > result)
{
- result = UNDERFLOW;
+ result = INT64_UNDERFLOW;
errno = ERANGE;
break;
}
/* Create the child process detached form the current console and in a
suspended state. */
- memset (&si, 0, sizeof (si));
+ xzero (si);
si.cb = sizeof (si);
rv = CreateProcess (exe, GetCommandLine (), NULL, NULL, TRUE,
CREATE_SUSPENDED | DETACHED_PROCESS,
{
xfree_null (title_buf);
xfree_null (curr_url);
- title_buf = (char *)xmalloc (strlen (url) + 20);
+ title_buf = xmalloc (strlen (url) + 20);
curr_url = xstrdup (url);
old_percentage = -1;
sprintf (title_buf, "Wget %s", curr_url);
void
ws_startup (void)
{
- WORD requested;
WSADATA data;
- int err;
-
- requested = MAKEWORD (1, 1);
- err = WSAStartup (requested, &data);
+ WORD requested = MAKEWORD (1, 1);
+ int err = WSAStartup (requested, &data);
if (err != 0)
{
fprintf (stderr, _("%s: Couldn't find usable socket driver.\n"),
return rc;
}
\f
-/* Wget expects network calls such as bind, connect, etc., to set errno.
- To achieve that, we place Winsock calls in wrapper functions that, in
- case of error, sets errno to the value of GetLastError(). In addition,
- we provide a wrapper around strerror, which recognizes Winsock errors
- and prints the appropriate error message. */
+/* Wget expects network calls such as connect, recv, send, etc., to set
+ errno on failure. To achieve that, Winsock calls are wrapped with code
+ that, in case of error, sets errno to the value of WSAGetLastError().
+ In addition, we provide a wrapper around strerror, which recognizes
+ Winsock errors and prints the appropriate error message. */
/* Define a macro that creates a function definition that wraps FUN into
a function that sets errno the way the rest of the code expects. */
-#define WRAP(fun, decl, call) int wrap_##fun decl { \
+#define WRAP(fun, decl, call) int wrapped_##fun decl { \
int retval = fun call; \
if (retval < 0) \
errno = WSAGetLastError (); \
WRAP (getpeername, (int s, struct sockaddr *n, int *nlen), (s, n, nlen))
WRAP (setsockopt, (int s, int level, int opt, const void *val, int len),
(s, level, opt, val, len))
+WRAP (closesocket, (int s), (s))
/* Return the text of the error message for Winsock error WSERR. */