]> Dogcows Code - chaz/tar/blobdiff - src/create.c
*** empty log message ***
[chaz/tar] / src / create.c
index 7398017a066d02c4cc0c9d765248e280bc6586a6..018044f7e2794f34dccc4a4f44208a5f2bfbcb7b 100644 (file)
@@ -1,5 +1,5 @@
 /* Create a tar archive.
-   Copyright (C) 1985, 1992 Free Software Foundation
+   Copyright (C) 1985, 1992, 1993 Free Software Foundation
 
 This file is part of GNU Tar.
 
@@ -24,7 +24,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  */
 
 #ifdef _AIX
-#pragma alloca
+ #pragma alloca
 #endif
 #include <sys/types.h>
 #include <stdio.h>
@@ -60,28 +60,6 @@ struct utimbuf
 
 #endif
 
-#if defined(_POSIX_VERSION) || defined(DIRENT)
-#include <dirent.h>
-#ifdef direct
-#undef direct
-#endif /* direct */
-#define direct dirent
-#define DP_NAMELEN(x) strlen((x)->d_name)
-#endif /* _POSIX_VERSION or DIRENT */
-#if !defined(_POSIX_VERSION) && !defined(DIRENT) && defined(BSD42)
-#include <sys/dir.h>
-#define DP_NAMELEN(x)  (x)->d_namlen
-#endif /* not _POSIX_VERSION and BSD42 */
-#ifdef __MSDOS__
-#include "msd_dir.h"
-#define DP_NAMELEN(x)  (x)->d_namlen
-#define direct dirent
-#endif
-#if defined(USG) && !defined(_POSIX_VERSION) && !defined(DIRENT)
-#include <ndir.h>
-#define DP_NAMELEN(x) strlen((x)->d_name)
-#endif /* USG and not _POSIX_VERSION and not DIRENT */
-
 extern struct stat hstat;      /* Stat struct corresponding */
 
 #ifndef __MSDOS__
@@ -124,6 +102,7 @@ void to_oct ();
 void dump_file ();
 void write_dir_file ();
 void write_eot ();
+void write_long ();
 int zero_record ();
 
 /* This code moved from tar.h since create.c is the only file that cares
@@ -191,10 +170,8 @@ create_archive ()
     }
   else
     {
-      p = name_next (1);
-      do
+      while (p = name_next (1))
        dump_file (p, -1, 1);
-      while (p = name_next (1));
     }
 
   write_eot ();
@@ -366,7 +343,7 @@ dump_file (p, curdev, toplevel)
        }
 
       /* Not found.  Add it to the list of possible links. */
-      lp = (struct link *) malloc ((unsigned) (sizeof (struct link) + strlen (p)));
+      lp = (struct link *) ck_malloc ((unsigned) (sizeof (struct link) + strlen (p)));
       if (!lp)
        {
          if (!nolinks)
@@ -557,7 +534,7 @@ dump_file (p, curdev, toplevel)
          /*                    sum += i;
                        if (sum < upperbound)
                                goto extend;*/
-         if (index_offset + i < upperbound)
+         if (index_offset + i <= upperbound)
            {
              index_offset += i;
              exhdr->ext_hdr.isextended++;
@@ -685,7 +662,7 @@ dump_file (p, curdev, toplevel)
   else if (S_ISDIR (hstat.st_mode))
     {
       register DIR *dirp;
-      register struct direct *d;
+      register struct dirent *d;
       char *namebuf;
       int buflen;
       register int len;
@@ -830,9 +807,9 @@ dump_file (p, curdev, toplevel)
          if (is_dot_or_dotdot (d->d_name))
            continue;
 
-         if (DP_NAMELEN (d) + len >= buflen)
+         if (NLENGTH (d) + len >= buflen)
            {
-             buflen = len + DP_NAMELEN (d);
+             buflen = len + NLENGTH (d);
              namebuf = ck_realloc (namebuf, buflen + 1);
              /* namebuf[len]='\0';
                                msg("file name %s%s too long",
@@ -1013,7 +990,7 @@ init_sparsearray ()
   /*
         * Make room for our scratch space -- initially is 10 elts long
         */
-  sparsearray = (struct sp_array *) malloc (sp_array_size * sizeof (struct sp_array));
+  sparsearray = (struct sp_array *) ck_malloc (sp_array_size * sizeof (struct sp_array));
   for (i = 0; i < sp_array_size; i++)
     {
       sparsearray[i].offset = 0;
@@ -1078,7 +1055,7 @@ deal_with_sparse (name, header, nulls_at_end)
                 * realloc the scratch area, since we've run out of room --
                 */
          sparsearray = (struct sp_array *)
-           realloc (sparsearray,
+           ck_realloc (sparsearray,
                     2 * sp_array_size * (sizeof (struct sp_array)));
          sp_array_size *= 2;
        }
@@ -1128,6 +1105,11 @@ deal_with_sparse (name, header, nulls_at_end)
     }
   if (amidst_data)
     sparsearray[sparse_ind++].numbytes = numbytes;
+  else
+    {
+      sparsearray[sparse_ind].offset = offset-1;
+      sparsearray[sparse_ind++].numbytes = 1;
+    }
   close (fd);
 
   return sparse_ind - 1;
@@ -1294,7 +1276,7 @@ start_header (name, st)
   strncpy (header->header.arch_name, name, NAMSIZ);
   header->header.arch_name[NAMSIZ - 1] = '\0';
 
-  to_oct ((long) (st->st_mode & 07777),
+  to_oct ((long) (f_oldarch ? (st->st_mode & 07777) : st->st_mode),
          8, header->header.mode);
   to_oct ((long) st->st_uid, 8, header->header.uid);
   to_oct ((long) st->st_gid, 8, header->header.gid);
@@ -1435,6 +1417,7 @@ write_eot ()
 }
 
 /* Write a LF_LONGLINK or LF_LONGNAME record. */
+void
 write_long (p, type)
      char *p;
      char type;
This page took 0.023683 seconds and 4 git commands to generate.