]> sjero.net Git - wget/commitdiff
[svn] Expect existence of C89 functions, as well as of select and gettimeofday.
authorhniksic <devnull@localhost>
Wed, 22 Jun 2005 01:01:12 +0000 (18:01 -0700)
committerhniksic <devnull@localhost>
Wed, 22 Jun 2005 01:01:12 +0000 (18:01 -0700)
ChangeLog
configure.in
src/ChangeLog
src/cmpt.c
src/connect.c
src/main.c
src/ptimer.c
src/utils.c

index 8900fb60322090f55609a2d93afdae69a0f9c992..9673d2e6427f6eedd16fd4514dc6ae0d95a0d086 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2005-06-22  Hrvoje Niksic  <hniksic@xemacs.org>
+
+       * 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  <hniksic@xemacs.org>
 
        * Makefile.cvs: Renamed to Makefile.svn.
index 09e9bd5f761992c912d1b18ab4a2bf5d2b2a953c..1ea9f10eddd6949c2ff8f654628b6f6361f77dbd 100644 (file)
@@ -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.
index 3a706a4c37695353804c749701104b009462cc65..01401296a071d480365f9bf572ad6602573882d0 100644 (file)
@@ -1,3 +1,18 @@
+2005-06-22  Hrvoje Niksic  <hniksic@xemacs.org>
+
+       * 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  <hniksic@xemacs.org>
 
        * Makefile.in: Remove the manually maintained dependency list;
index 7427fc2520c8953a6d203c729ea01d568a3ec4f0..916e54493279ab88917b548617c2d5c9a2dc160d 100644 (file)
@@ -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.  */
+\f
+/* 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 */
+\f
+/* 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 */
+\f
+/* 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 */
-
+\f
+/* 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
+\f
+/* 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
index 436258c3f0d2a07fef5082e627e6051901f2573a..0b58ffadae37e5456be93ea4e336cf8b8ad7ecfc 100644 (file)
@@ -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
 }
 \f
 /* Basic socket operations, mostly EINTR wrappers.  */
index 414c1cadc0238249662bb8ed61f0c89f10479a1e..997a2de738f48d4c30941ab1e9b6c6f010ea2705 100644 (file)
@@ -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;
 }
 \f
-#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
index f6ad55507982d796bc01fecd33c6b7f0505a2dc3..672e1e1ff68e82a834cda927472163e27ada70de 100644 (file)
@@ -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
index fc6aea09094c54b821bab487c3129ecafb4aabd3..ba7f5a6c7bdb3dbf11c5e8fb16395c9a5d19327e 100644 (file)
@@ -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
 }