]> Dogcows Code - chaz/tar/blobdiff - src/extract.c
(max): New macro.
[chaz/tar] / src / extract.c
index a9fcb6969c2758d5d8b7cac32acf1eb72f4c692a..e859c169dfdfc0e51d98acbdd2c67dcd297225a7 100644 (file)
@@ -1,5 +1,5 @@
 /* Extract files from a tar archive.
-   Copyright (C) 1988, 92,93,94,96,97,98, 1999 Free Software Foundation, Inc.
+   Copyright 1988, 92,93,94,96,97,98, 1999 Free Software Foundation, Inc.
    Written by John Gilmore, on 1985-11-19.
 
    This program is free software; you can redistribute it and/or modify it
@@ -19,7 +19,9 @@
 #include "system.h"
 
 #include <time.h>
+#ifndef time
 time_t time ();
+#endif
 
 #if HAVE_UTIME_H
 # include <utime.h>
@@ -63,7 +65,7 @@ static struct delayed_set_stat *delayed_set_stat_head;
 void
 extr_init (void)
 {
-  now = time ((time_t *) 0);
+  now = time (0);
   we_are_root = geteuid () == 0;
 
   /* Option -p clears the kernel umask, so it does not affect proper
@@ -247,16 +249,6 @@ make_directories (char *file_name)
 
       if (status == 0)
        {
-         /* Fix ownership.  */
-
-         if (we_are_root)
-           if (chown (file_name, current_stat.st_uid, current_stat.st_gid) < 0)
-             ERROR ((0, errno,
-                     _("%s: Cannot change owner to uid %lu, gid %lu"),
-                     file_name,
-                     (unsigned long) current_stat.st_uid,
-                     (unsigned long) current_stat.st_gid));
-
          print_for_mkdir (file_name, cursor - file_name,
                           ~newdir_umask & MODE_RWX);
          did_something = 1;
@@ -375,6 +367,11 @@ extract_sparse_file (int fd, off_t *sizeleft, off_t totalsize, char *name)
          *sizeleft -= count;
          set_next_block_after (data_block);
          data_block = find_next_block ();
+         if (! data_block)
+           {
+             ERROR ((0, 0, _("Unexpected EOF on archive file")));
+             return;
+           }
        }
 
       count = full_write (fd, data_block->buffer, written);
@@ -447,15 +444,14 @@ extract_archive (void)
   skipcrud = 0;
   while (!absolute_names_option && CURRENT_FILE_NAME[0] == '/')
     {
-      static int warned_once = 0;
+      static int warned_once;
 
-      skipcrud++;              /* force relative path */
       if (!warned_once)
        {
          warned_once = 1;
-         WARN ((0, 0, _("\
-Removing leading `/' from absolute path names in the archive")));
+         WARN ((0, 0, _("Removing leading `/' from archive names")));
        }
+      skipcrud++;              /* force relative path */
     }
 
   /* Take a safety backup of a previously existing file.  */
@@ -498,9 +494,9 @@ Removing leading `/' from absolute path names in the archive")));
       for (counter = 0; counter < SPARSES_IN_OLDGNU_HEADER; counter++)
        {
          sparsearray[counter].offset =
-           OFF_FROM_OCT (current_header->oldgnu_header.sp[counter].offset);
+           OFF_FROM_CHARS (current_header->oldgnu_header.sp[counter].offset);
          sparsearray[counter].numbytes =
-           SIZE_FROM_OCT (current_header->oldgnu_header.sp[counter].numbytes);
+           SIZE_FROM_CHARS (current_header->oldgnu_header.sp[counter].numbytes);
          if (!sparsearray[counter].numbytes)
            break;
        }
@@ -516,6 +512,11 @@ Removing leading `/' from absolute path names in the archive")));
          while (1)
            {
              exhdr = find_next_block ();
+             if (! exhdr)
+               {
+                 ERROR ((0, 0, _("Unexpected EOF on archive file")));
+                 return;
+               }
              for (counter = 0; counter < SPARSES_IN_SPARSE_HEADER; counter++)
                {
                  if (counter + ind > sp_array_size - 1)
@@ -528,14 +529,12 @@ Removing leading `/' from absolute path names in the archive")));
                        xrealloc (sparsearray,
                                  sp_array_size * (sizeof (struct sp_array)));
                    }
-                 /* Compare to 0, or use !(int)..., for Pyramid's dumb
-                    compiler.  */
-                 if (exhdr->sparse_header.sp[counter].numbytes == 0)
+                 if (exhdr->sparse_header.sp[counter].numbytes[0] == 0)
                    break;
                  sparsearray[counter + ind].offset =
-                   OFF_FROM_OCT (exhdr->sparse_header.sp[counter].offset);
+                   OFF_FROM_CHARS (exhdr->sparse_header.sp[counter].offset);
                  sparsearray[counter + ind].numbytes =
-                   SIZE_FROM_OCT (exhdr->sparse_header.sp[counter].numbytes);
+                   SIZE_FROM_CHARS (exhdr->sparse_header.sp[counter].numbytes);
                }
              if (!exhdr->sparse_header.isextended)
                break;
@@ -564,8 +563,8 @@ Removing leading `/' from absolute path names in the archive")));
 
     again_file:
       openflag = (keep_old_files_option || unlink_first_option ?
-                 O_BINARY | O_NDELAY | O_WRONLY | O_CREAT | O_EXCL :
-                 O_BINARY | O_NDELAY | O_WRONLY | O_CREAT | O_TRUNC)
+                 O_WRONLY | O_BINARY | O_NONBLOCK | O_CREAT | O_EXCL :
+                 O_WRONLY | O_BINARY | O_NONBLOCK | O_CREAT | O_TRUNC)
        | ((typeflag == GNUTYPE_SPARSE) ? 0 : O_APPEND);
 
       /* JK - The last | is a kludge to solve the problem the O_APPEND
@@ -759,8 +758,8 @@ Removing leading `/' from absolute path names in the archive")));
        if (!warned_once)
          {
            warned_once = 1;
-           WARN ((0, 0, _("\
-Attempting extraction of symbolic links as hard links")));
+           WARN ((0, 0,
+                  _("Attempting extraction of symbolic links as hard links")));
          }
       }
       /* Fall through.  */
@@ -980,8 +979,8 @@ Attempting extraction of symbolic links as hard links")));
       break;
 
     case GNUTYPE_MULTIVOL:
-      ERROR ((0, 0, _("\
-Cannot extract `%s' -- file is continued from another volume"),
+      ERROR ((0, 0,
+             _("Cannot extract `%s' -- file is continued from another volume"),
              current_file_name));
       skip_file (current_stat.st_size);
       if (backup_option)
This page took 0.028309 seconds and 4 git commands to generate.