]> Dogcows Code - chaz/tar/blobdiff - src/misc.c
Take into account chdir_fd when extracting from incremental dumps.
[chaz/tar] / src / misc.c
index 5fe80f4bb56e3616010cbb9075ca06e009572b6e..d68d80656c8d76f25c117b073c9e71e9e62785e5 100644 (file)
@@ -1,7 +1,7 @@
 /* Miscellaneous functions, not really specific to GNU tar.
 
-   Copyright (C) 1988, 1992, 1994, 1995, 1996, 1997, 1999, 2000, 2001,
-   2003, 2004, 2005, 2006, 2007, 2009, 2010, 2012 Free Software Foundation, Inc.
+   Copyright 1988, 1992, 1994-1997, 1999-2001, 2003-2007, 2009-2010,
+   2012-2013 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
@@ -14,8 +14,7 @@
    Public License for more details.
 
    You should have received a copy of the GNU General Public License along
-   with this program; if not, write to the Free Software Foundation, Inc.,
-   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+   with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #define COMMON_INLINE _GL_EXTERN_INLINE
 #include <system.h>
@@ -333,7 +332,7 @@ replace_prefix (char **pname, const char *samp, size_t slen,
    the range MINVAL .. -1, represent it with a string representation
    of the negative integer, using leading '-'.  */
 #if ! (INTMAX_MAX <= UINTMAX_MAX / 2)
-# error "strtosysint accepts uintmax_t to represent intmax_t"
+# error "sysinttostr: uintmax_t cannot represent all intmax_t values"
 #endif
 char *
 sysinttostr (uintmax_t value, intmax_t minval, uintmax_t maxval,
@@ -362,7 +361,7 @@ sysinttostr (uintmax_t value, intmax_t minval, uintmax_t maxval,
    On conversion error, return 0 and set errno = EINVAL.
    On overflow, return an extreme value and set errno = ERANGE.  */
 #if ! (INTMAX_MAX <= UINTMAX_MAX)
-# error "strtosysint accepts uintmax_t to represent nonnegative intmax_t"
+# error "strtosysint: nonnegative intmax_t does not fit in uintmax_t"
 #endif
 intmax_t
 strtosysint (char const *arg, char **arglim, intmax_t minval, uintmax_t maxval)
@@ -632,7 +631,7 @@ remove_any_file (const char *file_name, enum remove_option option)
 
        case RECURSIVE_REMOVE_OPTION:
          {
-           char *directory = savedir (file_name);
+           char *directory = tar_savedir (file_name, 0);
            char const *entry;
            size_t entrylen;
 
@@ -1145,3 +1144,31 @@ namebuf_name (namebuf_t buf, const char *name)
   strcpy (buf->buffer + buf->dir_length, name);
   return buf->buffer;
 }
+
+/* Return the filenames in directory NAME, relative to the chdir_fd.
+   If the directory does not exist, report error if MUST_EXIST is
+   true.
+
+   Return NULL on errors.
+*/
+char *
+tar_savedir (const char *name, int must_exist)
+{
+  char *ret = NULL;
+  DIR *dir = NULL;
+  int fd = openat (chdir_fd, name, open_read_flags | O_DIRECTORY);
+  if (fd < 0)
+    {
+      if (!must_exist && errno == ENOENT)
+       return NULL;
+      open_error (name);
+    }
+  else if (! ((dir = fdopendir (fd))
+             && (ret = streamsavedir (dir))))
+    savedir_error (name);
+
+  if (dir ? closedir (dir) != 0 : 0 <= fd && close (fd) != 0)
+    savedir_error (name);
+
+  return ret;
+}
This page took 0.023844 seconds and 4 git commands to generate.