From: hniksic Date: Wed, 22 Jun 2005 01:01:12 +0000 (-0700) Subject: [svn] Expect existence of C89 functions, as well as of select and gettimeofday. X-Git-Tag: v1.13~973 X-Git-Url: http://sjero.net/git/?p=wget;a=commitdiff_plain;h=b317cb1c6dabd6390c039acf5b89789f1e8d3959 [svn] Expect existence of C89 functions, as well as of select and gettimeofday. --- diff --git a/ChangeLog b/ChangeLog index 8900fb60..9673d2e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2005-06-22 Hrvoje Niksic + + * configure.in: Assume existence of gettimeofday and select. + gettimeofday exists on all platforms we care about (except for + Windows where Windows-specific functions are used instead), and + select exists virtually everywhere. + + * configure.in: Assume existence of strerror, signal, strstr, and + memmove, which are all required by ANSI C. + 2005-06-21 Hrvoje Niksic * Makefile.cvs: Renamed to Makefile.svn. diff --git a/configure.in b/configure.in index 09e9bd5f..1ea9f10e 100644 --- a/configure.in +++ b/configure.in @@ -208,10 +208,10 @@ dnl AC_FUNC_ALLOCA AC_FUNC_MMAP AC_FUNC_FSEEKO -AC_CHECK_FUNCS(strdup strstr strcasecmp strncasecmp strpbrk memmove) -AC_CHECK_FUNCS(gettimeofday mktime strptime strerror snprintf vsnprintf) -AC_CHECK_FUNCS(usleep select ftello sigblock sigsetjmp signal) -AC_CHECK_FUNCS(symlink access isatty) +AC_CHECK_FUNCS(strdup strcasecmp strncasecmp strpbrk) +AC_CHECK_FUNCS(mktime strptime snprintf vsnprintf) +AC_CHECK_FUNCS(usleep ftello sigblock sigsetjmp) +AC_CHECK_FUNCS(symlink isatty) dnl dnl Call Wget's local macros defined in aclocal. diff --git a/src/ChangeLog b/src/ChangeLog index 3a706a4c..01401296 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,18 @@ +2005-06-22 Hrvoje Niksic + + * connect.c (select_fd): Expect select() to exist. + + * utils.c (xsleep): Always use select() as sleep fallback on + non-Windows platforms. + + * ptimer.c: Delete the implementation of PTIMER_TIME. + + * main.c: Assume existence of signal(), test for different signal + names instead. + + * cmpt.c: Better document reasons why certain functions are + included. + 2005-06-22 Hrvoje Niksic * Makefile.in: Remove the manually maintained dependency list; diff --git a/src/cmpt.c b/src/cmpt.c index 7427fc25..916e5449 100644 --- a/src/cmpt.c +++ b/src/cmpt.c @@ -41,8 +41,19 @@ so, delete this exception statement from your version. */ #include "wget.h" -/* Some systems don't have some str* functions in libc. Here we - define them. The same goes for strptime. */ +/* Some systems lack certain functions normally taken for granted. + For example, Windows doesn't have strptime, and some systems lack + strcasecmp and strncasecmp. This file should contain fallback + implementations of the missing functions. It should *not* define + new Wget-specific functions -- those should placed in utils.c or + elsewhere. */ + +/* strcasecmp and strncasecmp apparently originated with BSD 4.4. + SUSv3 seems to be the only standard out there (that I can find) + that requires their existence, so there are systems that lack them + still in use. Note that these don't get defined under Windows + because mswindows.h defines them to the equivalent Windows + functions stricmp and strnicmp. */ #ifndef HAVE_STRCASECMP /* From GNU libc. */ @@ -99,6 +110,9 @@ strncasecmp (const char *s1, const char *s2, size_t n) return c1 - c2; } #endif /* not HAVE_STRNCASECMP */ + +/* strpbrk is required by POSIX and C99, but it is missing from some + older systems and from Windows. */ #ifndef HAVE_STRPBRK /* Find the first ocurrence in S of any character in ACCEPT. */ @@ -117,6 +131,10 @@ strpbrk (const char *s, const char *accept) return 0; } #endif /* HAVE_STRPBRK */ + +/* mktime is a BSD 4.3 function also required by POSIX and C99. I + don't know if there is a widely used system that lacks it, so it + might be a candidate for removal. */ #ifndef HAVE_MKTIME /* From GNU libc 2.0. */ @@ -390,7 +408,10 @@ __mktime_internal (tp, convert, offset) weak_alias (mktime, timelocal) #endif #endif /* not HAVE_MKTIME */ - + +/* strptime is required by POSIX, but it is missing from Windows, + which means we must keep a fallback implementation. It is + reportedly missing or broken on many older systems as well. */ #ifndef HAVE_STRPTIME /* From GNU libc 2.1.3. */ @@ -1314,14 +1335,17 @@ const unsigned short int __mon_yday[2][13] = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 } }; #endif - -/* fnmatch is defined by POSIX, but we include an implementation for - the sake of systems that don't have it. Some systems do have - fnmatch, but Apache installs its own fnmatch.h (incompatible with - the system one) in a system include directory, effectively - rendering fnmatch unusable. - - Additionally according to anecdotal evidence and conventional + +/* fnmatch is required by POSIX, but we include an implementation for + the sake of systems that don't have it, most notably Windows. Some + systems do have fnmatch, but Apache's installation process installs + its own fnmatch.h (incompatible with the system one!) in a system + include directory, effectively rendering fnmatch unusable. This + has been fixed with Apache 2, where fnmatch has been moved to apr + and given a prefix, but many systems out there are still (as of + this writing in 2005) broken and we must cater to them. + + Additionally, according to anecdotal evidence and conventional wisdom I lack courage to challenge, many implementations of fnmatch are notoriously buggy and unreliable. So we use our version by default, except when compiling under systems where fnmatch is known diff --git a/src/connect.c b/src/connect.c index 436258c3..0b58ffad 100644 --- a/src/connect.c +++ b/src/connect.c @@ -611,7 +611,6 @@ retryable_socket_connect_error (int err) int select_fd (int fd, double maxtime, int wait_for) { -#ifdef HAVE_SELECT fd_set fdset; fd_set *rd = NULL, *wr = NULL; struct timeval tmout; @@ -632,23 +631,11 @@ select_fd (int fd, double maxtime, int wait_for) while (result < 0 && errno == EINTR); return result; - -#else /* not HAVE_SELECT */ - - /* If select() unavailable, just return 1. In most usages in Wget, - this is the appropriate response -- "if we can't poll, go ahead - with the blocking operation". If a specific part of code needs - different behavior, it can use #ifdef HAVE_SELECT to test whether - polling really occurs. */ - return 1; - -#endif /* not HAVE_SELECT */ } int test_socket_open (int sock) { -#ifdef HAVE_SELECT fd_set check_set; struct timeval to; @@ -670,10 +657,6 @@ test_socket_open (int sock) } else return 0; -#else - /* Without select, it's hard to know for sure. */ - return 1; -#endif } /* Basic socket operations, mostly EINTR wrappers. */ diff --git a/src/main.c b/src/main.c index 414c1cad..997a2de7 100644 --- a/src/main.c +++ b/src/main.c @@ -900,21 +900,25 @@ Can't timestamp and not clobber old files at the same time.\n")); ws_startup (); #endif +#ifdef SIGHUP /* Setup the signal handler to redirect output when hangup is received. */ -#ifdef HAVE_SIGNAL if (signal(SIGHUP, SIG_IGN) != SIG_IGN) signal(SIGHUP, redirect_output_signal); +#endif /* ...and do the same for SIGUSR1. */ +#ifdef SIGUSR1 signal (SIGUSR1, redirect_output_signal); +#endif +#ifdef SIGPIPE /* Writing to a closed socket normally signals SIGPIPE, and the process exits. What we want is to ignore SIGPIPE and just check for the return value of write(). */ signal (SIGPIPE, SIG_IGN); +#endif #ifdef SIGWINCH signal (SIGWINCH, progress_handle_sigwinch); #endif -#endif /* HAVE_SIGNAL */ status = RETROK; /* initialize it, just-in-case */ /* Retrieve the URLs from argument list. */ @@ -986,7 +990,7 @@ Can't timestamp and not clobber old files at the same time.\n")); return 1; } -#ifdef HAVE_SIGNAL +#if defined(SIGHUP) || defined(SIGUSR1) /* Hangup signal handler. When wget receives SIGHUP or SIGUSR1, it will proceed operation as usual, trying to write into a log file. If that is impossible, the output will be turned off. */ @@ -1001,4 +1005,4 @@ redirect_output_signal (int sig) progress_schedule_redirect (); signal (sig, redirect_output_signal); } -#endif /* HAVE_SIGNAL */ +#endif diff --git a/src/ptimer.c b/src/ptimer.c index f6ad5550..672e1e1f 100644 --- a/src/ptimer.c +++ b/src/ptimer.c @@ -72,23 +72,19 @@ so, delete this exception statement from your version. */ #include "wget.h" #include "ptimer.h" -/* Depending on the OS and availability of gettimeofday(), one and - only one of PTIMER_POSIX, PTIMER_GETTIMEOFDAY, PTIMER_WINDOWS, or - PTIMER_TIME will be defined. */ +/* Depending on the OS, one and only one of PTIMER_POSIX, + PTIMER_GETTIMEOFDAY, or PTIMER_WINDOWS will be defined. */ #undef PTIMER_POSIX #undef PTIMER_GETTIMEOFDAY -#undef PTIMER_TIME #undef PTIMER_WINDOWS #if defined(WINDOWS) || defined(__CYGWIN__) # define PTIMER_WINDOWS /* use Windows timers */ #elif _POSIX_TIMERS - 0 > 0 # define PTIMER_POSIX /* use POSIX timers (clock_gettime) */ -#elif defined(HAVE_GETTIMEOFDAY) -# define PTIMER_GETTIMEOFDAY /* use gettimeofday */ #else -# define PTIMER_TIME +# define PTIMER_GETTIMEOFDAY /* use gettimeofday */ #endif #ifdef PTIMER_POSIX @@ -225,39 +221,6 @@ gettimeofday_resolution (void) } #endif /* PTIMER_GETTIMEOFDAY */ -#ifdef PTIMER_TIME -/* Elapsed time measurement using the time(2) call: system time is - held in time_t, retrieved using time, and resolution is 1 second. - - This method is a catch-all for non-Windows systems without - gettimeofday -- e.g. DOS or really old or non-standard Unix - systems. */ - -typedef time_t ptimer_system_time; - -#define IMPL_measure time_measure -#define IMPL_diff time_diff -#define IMPL_resolution time_resolution - -static inline void -time_measure (ptimer_system_time *pst) -{ - time (pst); -} - -static inline double -time_diff (ptimer_system_time *pst1, ptimer_system_time *pst2) -{ - return 1000.0 * (*pst1 - *pst2); -} - -static inline double -time_resolution (void) -{ - return 1; -} -#endif /* PTIMER_TIME */ - #ifdef PTIMER_WINDOWS /* Elapsed time measurement on Windows: where high-resolution timers are available, time is stored in a LARGE_INTEGER and retrieved diff --git a/src/utils.c b/src/utils.c index fc6aea09..ba7f5a6c 100644 --- a/src/utils.c +++ b/src/utils.c @@ -81,10 +81,8 @@ so, delete this exception statement from your version. */ #endif #undef USE_SIGNAL_TIMEOUT -#ifdef HAVE_SIGNAL -# if defined(HAVE_SIGSETJMP) || defined(HAVE_SIGBLOCK) -# define USE_SIGNAL_TIMEOUT -# endif +#if defined(HAVE_SIGSETJMP) || defined(HAVE_SIGBLOCK) +# define USE_SIGNAL_TIMEOUT #endif #include "wget.h" @@ -1800,12 +1798,11 @@ xsleep (double seconds) seconds -= (long) seconds; } usleep (seconds * 1000000); -#elif defined(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); @@ -1814,8 +1811,6 @@ xsleep (double 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 /* none of the above */ - sleep (seconds); #endif }