]> Dogcows Code - chaz/tar/blobdiff - src/names.c
* src/common.h (transform_symlinks_option): New global.
[chaz/tar] / src / names.c
index 234ac42d040957a083aa07b10a7f8d9f4a579fd9..05f89b15d19ab615c793c7dcc4709a436c294ac0 100644 (file)
@@ -1,11 +1,11 @@
 /* Various processing of names.
 
    Copyright (C) 1988, 1992, 1994, 1996, 1997, 1998, 1999, 2000, 2001,
-   2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+   2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
 
    This program is free software; you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by the
-   Free Software Foundation; either version 2, or (at your option) any later
+   Free Software Foundation; either version 3, or (at your option) any later
    version.
 
    This program is distributed in the hope that it will be useful, but
@@ -289,9 +289,8 @@ static int matching_flags; /* exclude_fnmatch options */
    static storage and can't be relied upon across two calls.
 
    If CHANGE_DIRS is true, treat any entries of type NELT_CHDIR as
-   the request to change to the given directory.  If filename_terminator
-   is NUL, CHANGE_DIRS is effectively always false.
-
+   the request to change to the given directory.
+   
    Entries of type NELT_FMASK cause updates of the matching_flags
    value. */
 struct name_elt *
@@ -301,9 +300,6 @@ name_next_elt (int change_dirs)
   const char *source;
   char *cursor;
 
-  if (filename_terminator == '\0')
-    change_dirs = 0;
-
   while (name_index != names)
     {
       struct name_elt *ep;
@@ -392,9 +388,7 @@ name_gather (void)
       if (allocated_size == 0)
        {
          allocated_size = offsetof (struct name, name) + NAME_FIELD_SIZE + 1;
-         buffer = xmalloc (allocated_size);
-         /* FIXME: This memset is overkill, and ugly...  */
-         memset (buffer, 0, allocated_size);
+         buffer = xzalloc (allocated_size);
        }
       
       while ((ep = name_next_elt (0)) && ep->type == NELT_CHDIR)
@@ -471,7 +465,6 @@ addname (char const *string, int change_dir)
   name->matching_flags = matching_flags;
   name->change_dir = change_dir;
   name->dir_contents = NULL;
-  name->explicit = 1;
 
   *nametail = name;
   nametail = &name->next;
@@ -481,7 +474,7 @@ addname (char const *string, int change_dir)
 /* Find a match for FILE_NAME (whose string length is LENGTH) in the name
    list.  */
 static struct name *
-namelist_match (char const *file_name, size_t length, bool exact)
+namelist_match (char const *file_name, size_t length)
 {
   struct name *p;
 
@@ -497,7 +490,7 @@ namelist_match (char const *file_name, size_t length, bool exact)
 
 /* Return true if and only if name FILE_NAME (from an archive) matches any
    name from the namelist.  */
-int
+bool
 name_match (const char *file_name)
 {
   size_t length = strlen (file_name);
@@ -507,17 +500,17 @@ name_match (const char *file_name)
       struct name *cursor = namelist;
 
       if (!cursor)
-       return 1;
-
+       return true;
+      
       if (cursor->name[0] == 0)
        {
          chdir_do (cursor->change_dir);
          namelist = 0;
          nametail = &namelist;
-         return 1;
+         return true;
        }
 
-      cursor = namelist_match (file_name, length, false);
+      cursor = namelist_match (file_name, length);
       if (cursor)
        {
          if (!(ISSLASH (file_name[cursor->length]) && recursion_option)
@@ -544,10 +537,10 @@ name_match (const char *file_name)
        {
          name_gather ();       /* read one more */
          if (namelist->found_count)
-           return 0;
+           return false;
        }
       else
-       return 0;
+       return false;
     }
 }
 
@@ -573,8 +566,7 @@ all_names_found (struct tar_stat_info *p)
   len = strlen (p->file_name);
   for (cursor = namelist; cursor; cursor = cursor->next)
     {
-      if (cursor->matching_flags /* FIXME: check this */
-         || (!WASFOUND (cursor) && cursor->name[0])
+      if ((cursor->name[0] && !WASFOUND (cursor))
          || (len >= cursor->length && ISSLASH (p->file_name[cursor->length])))
        return false;
     }
@@ -736,7 +728,7 @@ static void
 add_hierarchy_to_namelist (struct name *name, dev_t device)
 {
   char *file_name = name->name;
-  char *buffer = get_directory_contents (file_name, device);
+  const char *buffer = get_directory_contents (file_name, device);
 
   if (! buffer)
     name->dir_contents = "\0\0\0\0";
@@ -748,7 +740,7 @@ add_hierarchy_to_namelist (struct name *name, dev_t device)
                                 : NAME_FIELD_SIZE);
       char *namebuf = xmalloc (allocated_length + 1);
                                /* FIXME: + 2 above?  */
-      char *string;
+      const char *string;
       size_t string_length;
       int change_dir = name->change_dir;
 
@@ -781,7 +773,6 @@ add_hierarchy_to_namelist (struct name *name, dev_t device)
                }
              strcpy (namebuf + name_length, string + 1);
              np = addname (namebuf, change_dir);
-             np->explicit = 0;
              add_hierarchy_to_namelist (np, device);
            }
        }
@@ -856,18 +847,15 @@ collect_and_sort_names (void)
     1. It returns a pointer to the name it matched, and doesn't set FOUND
     in structure. The caller will have to do that if it wants to.
     2. If the namelist is empty, it returns null, unlike name_match, which
-    returns TRUE.
-    3. The second argument (EXACT) controls matching algorithm. If it
-    is TRUE, the exact matching is used. However, regular expressions are
-    always matched as such, no matter what the value of EXACT is. */
+    returns TRUE. */
 struct name *
-name_scan (const char *file_name, bool exact)
+name_scan (const char *file_name)
 {
   size_t length = strlen (file_name);
 
   while (1)
     {
-      struct name *cursor = namelist_match (file_name, length, exact);
+      struct name *cursor = namelist_match (file_name, length);
       if (cursor)
        return cursor;
 
@@ -1018,11 +1006,10 @@ contains_dot_dot (char const *name)
       if (p[0] == '.' && p[1] == '.' && (ISSLASH (p[2]) || !p[2]))
        return 1;
 
-      do
+      while (! ISSLASH (*p))
        {
          if (! *p++)
            return 0;
        }
-      while (! ISSLASH (*p));
     }
 }
This page took 0.025025 seconds and 4 git commands to generate.