#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. */
__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;
+ bool negative;
if (base != 0 && (base < 2 || base > 36))
{
++nptr;
if (*nptr == '-')
{
- negative = 1;
+ negative = true;
++nptr;
}
else if (*nptr == '+')
{
- negative = 0;
+ negative = false;
++nptr;
}
else
- negative = 0;
+ negative = false;
/* If base is 0, determine the real base based on the beginning on
the number; octal numbers begin with "0", hexadecimal with "0x",
__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;
}
struct fake_fork_info
{
HANDLE event;
- int logfile_changed;
+ bool logfile_changed;
char lfilename[MAX_PATH + 1];
};
event = info->event;
- info->logfile_changed = 0;
+ info->logfile_changed = false;
if (!opt.lfilename)
{
/* See utils:fork_to_background for explanation. */
- FILE *new_log_fp = unique_create (DEFAULT_LOGFILE, 0, &opt.lfilename);
+ FILE *new_log_fp = unique_create (DEFAULT_LOGFILE, false, &opt.lfilename);
if (new_log_fp)
{
- info->logfile_changed = 1;
+ info->logfile_changed = true;
strncpy (info->lfilename, opt.lfilename, sizeof (info->lfilename));
info->lfilename[sizeof (info->lfilename) - 1] = '\0';
fclose (new_log_fp);
{
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);
}
/* 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.
+ seconds. Returns true if the function was interrupted with a
+ timeout, false otherwise.
This works by running FUN in a separate thread and terminating the
thread if it doesn't finish in the specified time. */
-int
+bool
run_with_timeout (double seconds, void (*fun) (void *), void *arg)
{
static HANDLE thread_hnd = NULL;
struct thread_data thread_arg;
DWORD thread_id;
- int rc;
+ bool rc;
DEBUGP (("seconds %.2f, ", seconds));
{
blocking_fallback:
fun (arg);
- return 0;
+ return false;
}
/* Should never happen, but test for recursivety anyway. */
so the caller can inspect it. */
WSASetLastError (thread_arg.ws_error);
DEBUGP (("Winsock error: %d\n", WSAGetLastError ()));
- rc = 0;
+ rc = false;
}
else
{
TerminateThread (thread_hnd, 1);
- rc = 1;
+ rc = true;
}
CloseHandle (thread_hnd); /* Clear-up after TerminateThread(). */