]> sjero.net Git - wget/blobdiff - src/utils.c
[svn] Move fnmatch() to cmpt.c and don't use it under GNU libc.
[wget] / src / utils.c
index fb180e8da5a2754a9e116ab732a41148a8020de0..c78b170866a047add504f679206de31c10f3e6c6 100644 (file)
@@ -92,7 +92,6 @@ so, delete this exception statement from your version.  */
 
 #include "wget.h"
 #include "utils.h"
-#include "fnmatch.h"
 #include "hash.h"
 
 #ifndef errno
@@ -574,6 +573,8 @@ file_size (const char *filename)
      that way we can also verify whether the file is readable.
      Inspired by the POST patch by Arnaud Wylie.  */
   FILE *fp = fopen (filename, "rb");
+  if (!fp)
+    return -1;
   fseek (fp, 0, SEEK_END);
   size = ftell (fp);
   fclose (fp);
@@ -872,6 +873,18 @@ suffix (const char *str)
     return NULL;
 }
 
+/* Return non-zero if S contains globbing wildcards (`*', `?', `[' or
+   `]').  */
+
+int
+has_wildcards_p (const char *s)
+{
+  for (; *s; s++)
+    if (*s == '*' || *s == '?' || *s == '[' || *s == ']')
+      return 1;
+  return 0;
+}
+
 /* Return non-zero if FNAME ends with a typical HTML suffix.  The
    following (case-insensitive) suffixes are presumed to be HTML files:
    
@@ -898,8 +911,8 @@ has_html_suffix_p (const char *fname)
 }
 
 /* Read a line from FP and return the pointer to freshly allocated
-   storage.  The stoarage space is obtained through malloc() and
-   should be freed with free() when it is no longer needed.
+   storage.  The storage space is obtained through malloc() and should
+   be freed with free() when it is no longer needed.
 
    The length of the line is not limited, except by available memory.
    The newline character at the end of line is retained.  The line is
@@ -1033,7 +1046,7 @@ read_file (const char *file)
          /* Normally, we grow SIZE exponentially to make the number
              of calls to read() and realloc() logarithmic in relation
              to file size.  However, read() can read an amount of data
-             smaller than requested, and it would be unreasonably to
+             smaller than requested, and it would be unreasonable to
              double SIZE every time *something* was read.  Therefore,
              we double SIZE only when the length exceeds half of the
              entire allocated size.  */
@@ -1960,7 +1973,7 @@ abort_run_with_timeout (int sig)
      if we longjumped out of the handler at this point, SIGALRM would
      remain blocked.  We must unblock it manually. */
   int mask = siggetmask ();
-  mask &= ~sigmask(SIGALRM);
+  mask &= ~sigmask (SIGALRM);
   sigsetmask (mask);
 
   /* Now it's safe to longjump. */
@@ -2017,8 +2030,9 @@ alarm_cancel (void)
 #endif /* not ITIMER_REAL */
 }
 
-/* Run FUN(ARG) for not more than TIMEOUT seconds.  Returns non-zero
-   if the function was interrupted with a timeout, zero otherwise.
+/* 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.
 
    This works by setting up SIGALRM to be delivered in TIMEOUT seconds
    using setitimer() or alarm().  The timeout is enforced by