#ifdef HAVE_PWD_H
# include <pwd.h>
#endif
-#ifdef HAVE_LIMITS_H
-# include <limits.h>
-#endif
#ifdef HAVE_UTIME_H
# include <utime.h>
#endif
#endif
/* Needed for run_with_timeout. */
-#undef USE_SIGNAL_TIMEOUT
-#ifdef HAVE_SIGNAL_H
-# include <signal.h>
-#endif
+#include <signal.h>
#ifdef HAVE_SETJMP_H
# include <setjmp.h>
#endif
# endif
#endif
-#ifdef HAVE_SIGNAL
-# ifdef HAVE_SIGSETJMP
-# define USE_SIGNAL_TIMEOUT
-# endif
-# ifdef HAVE_SIGBLOCK
-# define USE_SIGNAL_TIMEOUT
-# endif
+#undef USE_SIGNAL_TIMEOUT
+#if defined(HAVE_SIGSETJMP) || defined(HAVE_SIGBLOCK)
+# define USE_SIGNAL_TIMEOUT
#endif
#include "wget.h"
char *
strdupdelim (const char *beg, const char *end)
{
- char *res = (char *)xmalloc (end - beg + 1);
+ char *res = xmalloc (end - beg + 1);
memcpy (res, beg, end - beg);
res[end - beg] = '\0';
return res;
{
if (*s == ',')
{
- res = (char **)xrealloc (res, (i + 2) * sizeof (char *));
+ res = xrealloc (res, (i + 2) * sizeof (char *));
res[i] = strdupdelim (p, s);
res[++i] = NULL;
++s;
else
++s;
}
- res = (char **)xrealloc (res, (i + 2) * sizeof (char *));
+ res = xrealloc (res, (i + 2) * sizeof (char *));
res[i] = strdupdelim (p, s);
res[i + 1] = NULL;
return res;
if (!cut)
return xstrdup (file);
- result = (char *)xmalloc (cut - base + 1 + strlen (file) + 1);
+ result = xmalloc (cut - base + 1 + strlen (file) + 1);
memcpy (result, base, cut - base);
result[cut - base] = '/';
strcpy (result + (cut - base) + 1, file);
{
int length = 0;
int bufsize = 82;
- char *line = (char *)xmalloc (bufsize);
+ char *line = xmalloc (bufsize);
while (fgets (line + length, bufsize - length, fp))
{
/* Count v2. */
for (j = 0; v2[j]; j++);
/* Reallocate v1. */
- v1 = (char **)xrealloc (v1, (i + j + 1) * sizeof (char **));
+ v1 = xrealloc (v1, (i + j + 1) * sizeof (char **));
memcpy (v1 + i, v2, (j + 1) * sizeof (char *));
xfree (v2);
return v1;
would just use "%j" and intmax_t, but many systems don't support
it, so it's used only if nothing else works. */
#if SIZEOF_LONG >= SIZEOF_WGINT
-# define SPRINTF_WGINT(buf, n) sprintf (buf, "%ld", (long) (n))
+# define SPRINTF_WGINT(buf, n) sprintf (buf, "%ld", (long) (n))
+#elif SIZEOF_LONG_LONG >= SIZEOF_WGINT
+# define SPRINTF_WGINT(buf, n) sprintf (buf, "%lld", (long long) (n))
+#elif defined(WINDOWS)
+# define SPRINTF_WGINT(buf, n) sprintf (buf, "%I64", (__int64) (n))
#else
-# if SIZEOF_LONG_LONG >= SIZEOF_WGINT
-# define SPRINTF_WGINT(buf, n) sprintf (buf, "%lld", (long long) (n))
-# else
-# ifdef WINDOWS
-# define SPRINTF_WGINT(buf, n) sprintf (buf, "%I64", (__int64) (n))
-# else
-# define SPRINTF_WGINT(buf, n) sprintf (buf, "%j", (intmax_t) (n))
-# endif
-# endif
+# define SPRINTF_WGINT(buf, n) sprintf (buf, "%j", (intmax_t) (n))
#endif
/* Shorthand for casting to wgint. */
return 0; /* most likely ENOTTY */
return wsz.ws_col;
-#else /* not TIOCGWINSZ */
-# ifdef WINDOWS
+#elif defined(WINDOWS)
CONSOLE_SCREEN_BUFFER_INFO csbi;
if (!GetConsoleScreenBufferInfo (GetStdHandle (STD_ERROR_HANDLE), &csbi))
return 0;
return csbi.dwSize.X;
-# else /* neither WINDOWS nor TIOCGWINSZ */
+#else /* neither TIOCGWINSZ nor WINDOWS */
return 0;
-#endif /* neither WINDOWS nor TIOCGWINSZ */
-#endif /* not TIOCGWINSZ */
+#endif /* neither TIOCGWINSZ nor WINDOWS */
}
/* Return a random number between 0 and MAX-1, inclusive.
static sigjmp_buf run_with_timeout_env;
-static RETSIGTYPE
+static void
abort_run_with_timeout (int sig)
{
assert (sig == SIGALRM);
static jmp_buf run_with_timeout_env;
-static RETSIGTYPE
+static void
abort_run_with_timeout (int sig)
{
assert (sig == SIGALRM);
/* If nanosleep has been interrupted by a signal, adjust the
sleeping period and return to sleep. */
sleep = remaining;
-#else /* not HAVE_NANOSLEEP */
-#ifdef HAVE_USLEEP
+#elif defined(HAVE_USLEEP)
/* If usleep is available, use it in preference to select. */
if (seconds >= 1)
{
seconds -= (long) seconds;
}
usleep (seconds * 1000000);
-#else /* not HAVE_USLEEP */
-#ifdef HAVE_SELECT
- /* Note that, although Windows supports select, this sleeping
- strategy doesn't work there because Winsock's select doesn't
- implement timeout when it is passed NULL pointers for all fd
- sets. (But it does work under Cygwin, which implements its own
- select.) */
+#else /* fall back select */
+ /* Note that, although Windows supports select, it can't be used to
+ implement sleeping because Winsock's select doesn't implement
+ timeout when it is passed NULL pointers for all fd sets. (But it
+ does under Cygwin, which implements Unix-compatible select.) */
struct timeval sleep;
sleep.tv_sec = (long) seconds;
sleep.tv_usec = 1000000 * (seconds - (long) seconds);
interrupted by a signal. But without knowing how long we've
actually slept, we can't return to sleep. Using gettimeofday to
track sleeps is slow and unreliable due to clock skew. */
-#else /* not HAVE_SELECT */
- sleep (seconds);
-#endif /* not HAVE_SELECT */
-#endif /* not HAVE_USLEEP */
-#endif /* not HAVE_NANOSLEEP */
+#endif
}
#endif /* not WINDOWS */