Another update from Larry:
[oweals/busybox.git] / tar.c
diff --git a/tar.c b/tar.c
index 15d050c5a1b72759f7577097c9ea41cab95f0803..eb085c770ded64efa645219ff971b72bdfa49285 100644 (file)
--- a/tar.c
+++ b/tar.c
 #include <stdlib.h>
 #include <unistd.h>
 #include "busybox.h"
-#define BB_DECLARE_EXTERN
-#define bb_need_io_error
-#define bb_need_name_longer_than_foo
-#include "messages.c"
 
 /* Tar file constants  */
 #ifndef MAJOR
@@ -133,7 +129,7 @@ struct TarInfo
 typedef struct TarInfo TarInfo;
 
 /* Local procedures to restore files from a tar file.  */
-extern int readTarFile(int tarFd, int extractFlag, int listFlag, 
+static int readTarFile(int tarFd, int extractFlag, int listFlag, 
                int tostdoutFlag, int verboseFlag, char** extractList,
                char** excludeList);
 
@@ -571,7 +567,7 @@ static int extract_file(char **extract_files, const char *file)
  * Read a tar file and extract or list the specified files within it.
  * If the list is empty than all files are extracted or listed.
  */
-extern int readTarFile(int tarFd, int extractFlag, int listFlag, 
+static int readTarFile(int tarFd, int extractFlag, int listFlag, 
                int tostdoutFlag, int verboseFlag, char** extractList,
                char** excludeList)
 {
@@ -599,7 +595,7 @@ extern int readTarFile(int tarFd, int extractFlag, int listFlag,
                        }
                }
                if ( *(header.name) == '\0' )
-                               goto endgame;
+                       continue;
                header.tarFd = tarFd;
 
                /* Skip funky extra GNU headers that precede long files */
@@ -710,7 +706,7 @@ extern int readTarFile(int tarFd, int extractFlag, int listFlag,
                        case REGTYPE0:
                                /* If the name ends in a '/' then assume it is
                                 * supposed to be a directory, and fall through */
-                               if (header.name[strlen(header.name)-1] != '/') {
+                               if (!last_char_is(header.name,'/')) {
                                        if (tarExtractRegularFile(&header, extractFlag, tostdoutFlag)==FALSE)
                                                errorFlag=TRUE;
                                        break;
@@ -925,16 +921,10 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *header_name,
                header.typeflag = LNKTYPE;
                strncpy(header.linkname, tbInfo->hlInfo->name, sizeof(header.linkname));
        } else if (S_ISLNK(statbuf->st_mode)) {
-               int link_size=0;
-               char buffer[BUFSIZ];
+               char *lpath = xreadlink(real_name);
                header.typeflag  = SYMTYPE;
-               link_size = readlink(real_name, buffer, sizeof(buffer) - 1);
-               if ( link_size < 0) {
-                       perror_msg("Error reading symlink '%s'", header.name);
-                       return ( FALSE);
-               }
-               buffer[link_size] = '\0';
-               strncpy(header.linkname, buffer, sizeof(header.linkname)); 
+               strncpy(header.linkname, lpath, sizeof(header.linkname)); 
+               free(lpath);
        } else if (S_ISDIR(statbuf->st_mode)) {
                header.typeflag  = DIRTYPE;
                strncat(header.name, "/", sizeof(header.name));