]> sjero.net Git - wget/blobdiff - src/cmpt.c
[svn] Use bool type for boolean variables and values.
[wget] / src / cmpt.c
index daa1460225fd68cef6ab75919f331306aa01b592..916e54493279ab88917b548617c2d5c9a2dc160d 100644 (file)
@@ -1,5 +1,5 @@
 /* Replacements for routines missing on some systems.
-   Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1995-2005 Free Software Foundation, Inc.
 
 This file is part of GNU Wget.
 
@@ -31,38 +31,29 @@ so, delete this exception statement from your version.  */
 
 #include <stdio.h>
 #include <stdlib.h>
-#ifdef HAVE_STRING_H
-# include <string.h>
-#else
-# include <strings.h>
-#endif /* HAVE_STRING_H */
+#include <string.h>
 
-#include <sys/types.h>
 #ifdef HAVE_UNISTD_H
 # include <unistd.h>
 #endif
-#include <limits.h>
 
 #include <errno.h>
-#ifndef errno
-extern int errno;
-#endif
 
 #include "wget.h"
 
-#ifndef HAVE_STRERROR
-/* A strerror() clone, for systems that don't have it.  */
-char *
-strerror (int err)
-{
-  /* This loses on a system without `sys_errlist'.  */
-  extern char *sys_errlist[];
-  return sys_errlist[err];
-}
-#endif /* not HAVE_STRERROR */
-
-/* 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.  */
@@ -119,106 +110,9 @@ strncasecmp (const char *s1, const char *s2, size_t n)
   return c1 - c2;
 }
 #endif /* not HAVE_STRNCASECMP */
-
-#ifndef HAVE_STRSTR
-/* From GNU libc 2.0.6.  */
-/* Return the first ocurrence of NEEDLE in HAYSTACK.  */
-/*
- * My personal strstr() implementation that beats most other algorithms.
- * Until someone tells me otherwise, I assume that this is the
- * fastest implementation of strstr() in C.
- * I deliberately chose not to comment it.  You should have at least
- * as much fun trying to understand it, as I had to write it :-).
- *
- * Stephen R. van den Berg, berg@pool.informatik.rwth-aachen.de        */
-typedef unsigned chartype;
-
-char *
-strstr (phaystack, pneedle)
-     const char *phaystack;
-     const char *pneedle;
-{
-  register const unsigned char *haystack, *needle;
-  register chartype b, c;
-
-  haystack = (const unsigned char *) phaystack;
-  needle = (const unsigned char *) pneedle;
-
-  b = *needle;
-  if (b != '\0')
-    {
-      haystack--;                              /* possible ANSI violation */
-      do
-       {
-         c = *++haystack;
-         if (c == '\0')
-           goto ret0;
-       }
-      while (c != b);
-
-      c = *++needle;
-      if (c == '\0')
-       goto foundneedle;
-      ++needle;
-      goto jin;
-
-      for (;;)
-        {
-          register chartype a;
-         register const unsigned char *rhaystack, *rneedle;
-
-         do
-           {
-             a = *++haystack;
-             if (a == '\0')
-               goto ret0;
-             if (a == b)
-               break;
-             a = *++haystack;
-             if (a == '\0')
-               goto ret0;
-shloop:            }
-          while (a != b);
-
-jin:     a = *++haystack;
-         if (a == '\0')
-           goto ret0;
-
-         if (a != c)
-           goto shloop;
-
-         rhaystack = haystack-- + 1;
-         rneedle = needle;
-         a = *rneedle;
-
-         if (*rhaystack == a)
-           do
-             {
-               if (a == '\0')
-                 goto foundneedle;
-               ++rhaystack;
-               a = *++needle;
-               if (*rhaystack != a)
-                 break;
-               if (a == '\0')
-                 goto foundneedle;
-               ++rhaystack;
-               a = *++needle;
-             }
-           while (*rhaystack == a);
-
-         needle = rneedle;             /* took the register-poor approach */
-
-         if (a == '\0')
-           break;
-        }
-    }
-foundneedle:
-  return (char*) haystack;
-ret0:
-  return 0;
-}
-#endif /* not HAVE_STRSTR */
+\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.  */
@@ -237,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.  */
@@ -259,7 +157,7 @@ strpbrk (const char *s, const char *accept)
 #endif
 
 #ifndef __P
-# define __P(args) PARAMS (args)
+# define __P(args) args
 #endif  /* Not __P.  */
 
 #ifndef CHAR_BIT
@@ -510,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.  */
@@ -527,7 +428,7 @@ weak_alias (mktime, timelocal)
    this is enough information for determining the date.  */
 
 #ifndef __P
-# define __P(args) PARAMS (args)
+# define __P(args) args
 #endif /* not __P */
 
 #if ! HAVE_LOCALTIME_R && ! defined localtime_r
@@ -1434,31 +1335,21 @@ const unsigned short int __mon_yday[2][13] =
     { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
   };
 #endif
-
-#ifndef HAVE_MEMMOVE
-void *
-memmove (char *dest, const char *source, unsigned length)
-{
-  char *d0 = dest;
-  if (source < dest)
-    /* Moving from low mem to hi mem; start at end.  */
-    for (source += length, dest += length; length; --length)
-      *--dest = *--source;
-  else if (source != dest)
-    {
-      /* Moving from hi mem to low mem; start at beginning.  */
-      for (; length; --length)
-       *dest++ = *source++;
-    }
-  return (void *) d0;
-}
-#endif /* not HAVE_MEMMOVE */
-
-/* fnmatch is a POSIX function, but we include an implementation for
-   the sake of systems that don't have it.  Furthermore, according to
-   anecdotal evidence, historical implementations of fnmatch are buggy
-   and unreliable.  So we use our version, except when compiling under
-   systems where fnmatch is known to work (currently glibc.)  */
+\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
+   to work (currently on GNU libc-based systems and Solaris.)  */
 
 #ifndef SYSTEM_FNMATCH
 
@@ -1467,8 +1358,8 @@ memmove (char *dest, const char *source, unsigned length)
 /* Match STRING against the filename pattern PATTERN, returning zero
    if it matches, FNM_NOMATCH if not.  This implementation comes from
    an earlier version of GNU Bash.  (It doesn't make sense to update
-   it with a newer version because it adds a lot of features Wget
-   doesn't use or care about.)  */
+   it with a newer version because those versions add a lot of
+   features Wget doesn't use or care about.)  */
 
 int
 fnmatch (const char *pattern, const char *string, int flags)