projects
/
oweals
/
busybox.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Brand new version of xargs. Tested thoroughly by Kent Robotti. (Domo arigato,
[oweals/busybox.git]
/
tar.c
diff --git
a/tar.c
b/tar.c
index e4bdd0a6c092a5e8fe5eaf638d915b9060a2e443..07c0e71052db07e69764057245dbf0e8dd982601 100644
(file)
--- a/
tar.c
+++ b/
tar.c
@@
-36,10
+36,10
@@
*/
*/
-#include "
internal
.h"
+#include "
busybox
.h"
#define BB_DECLARE_EXTERN
#define bb_need_io_error
#define BB_DECLARE_EXTERN
#define bb_need_io_error
-#define bb_need_name_longer_th
e
n_foo
+#define bb_need_name_longer_th
a
n_foo
#include "messages.c"
#include <stdio.h>
#include <dirent.h>
#include "messages.c"
#include <stdio.h>
#include <dirent.h>
@@
-137,8
+137,8
@@
static int readTarFile(const char* tarName, int extractFlag, int listFlag,
#ifdef BB_FEATURE_TAR_CREATE
/* Local procedures to save files into a tar file. */
#ifdef BB_FEATURE_TAR_CREATE
/* Local procedures to save files into a tar file. */
-static int writeTarFile(const char* tarName, int
tostdoutFlag,
-
int verboseFlag, int argc, char **argv,
char** excludeList);
+static int writeTarFile(const char* tarName, int
verboseFlag, char **argv,
+ char** excludeList);
#endif
extern int tar_main(int argc, char **argv)
#endif
extern int tar_main(int argc, char **argv)
@@
-160,13
+160,11
@@
extern int tar_main(int argc, char **argv)
if (argc <= 1)
usage(tar_usage);
if (argc <= 1)
usage(tar_usage);
- /* do normal option parsing */
- while (--argc > 0 && ((*argv && **(++argv) == '-') ||
- (firstOpt==TRUE && strspn(*argv, "-cxt") ))) {
+ while (*(++argv) && (**argv == '-' || firstOpt == TRUE)) {
firstOpt=FALSE;
stopIt=FALSE;
firstOpt=FALSE;
stopIt=FALSE;
- while (stopIt==FALSE && *
argv && *
*argv) {
- switch (*
*argv
) {
+ while (stopIt==FALSE && **argv) {
+ switch (*
((*argv)++)
) {
case 'c':
if (extractFlag == TRUE || listFlag == TRUE)
goto flagError;
case 'c':
if (extractFlag == TRUE || listFlag == TRUE)
goto flagError;
@@
-187,29
+185,22
@@
extern int tar_main(int argc, char **argv)
break;
case 'O':
tostdoutFlag = TRUE;
break;
case 'O':
tostdoutFlag = TRUE;
- tarName = "-";
break;
case 'f':
break;
case 'f':
- if (--argc == 0) {
- fatalError( "Option requires an argument: No file specified\n");
- }
if (*tarName != '-')
fatalError( "Only one 'f' option allowed\n");
tarName = *(++argv);
if (tarName == NULL)
fatalError( "Option requires an argument: No file specified\n");
if (*tarName != '-')
fatalError( "Only one 'f' option allowed\n");
tarName = *(++argv);
if (tarName == NULL)
fatalError( "Option requires an argument: No file specified\n");
- if (!strcmp(tarName, "-") && createFlag == TRUE)
- tostdoutFlag = TRUE;
stopIt=TRUE;
break;
#if defined BB_FEATURE_TAR_EXCLUDE
case 'e':
stopIt=TRUE;
break;
#if defined BB_FEATURE_TAR_EXCLUDE
case 'e':
- if (strcmp(*argv, "-exclude")==0) {
- if (--argc == 0) {
- fatalError( "Option requires an argument: No file specified\n");
- }
+ if (strcmp(*argv, "exclude")==0) {
excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2));
excludeList[excludeListSize] = *(++argv);
excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2));
excludeList[excludeListSize] = *(++argv);
+ if (excludeList[excludeListSize] == NULL)
+ fatalError( "Option requires an argument: No file specified\n");
/* Remove leading "/"s */
if (*excludeList[excludeListSize] =='/')
excludeList[excludeListSize] = (excludeList[excludeListSize])+1;
/* Remove leading "/"s */
if (*excludeList[excludeListSize] =='/')
excludeList[excludeListSize] = (excludeList[excludeListSize])+1;
@@
-224,7
+215,6
@@
extern int tar_main(int argc, char **argv)
default:
usage(tar_usage);
}
default:
usage(tar_usage);
}
- ++(*argv);
}
}
}
}
@@
-236,11
+226,12
@@
extern int tar_main(int argc, char **argv)
#ifndef BB_FEATURE_TAR_CREATE
fatalError( "This version of tar was not compiled with tar creation support.\n");
#else
#ifndef BB_FEATURE_TAR_CREATE
fatalError( "This version of tar was not compiled with tar creation support.\n");
#else
- exit(writeTarFile(tarName,
tostdoutFlag, verboseFlag, argc
, argv, excludeList));
+ exit(writeTarFile(tarName,
verboseFlag
, argv, excludeList));
#endif
}
if (listFlag == TRUE || extractFlag == TRUE) {
#endif
}
if (listFlag == TRUE || extractFlag == TRUE) {
- exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag, verboseFlag, &argv[optind], excludeList));
+ exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag,
+ verboseFlag, argv, excludeList));
}
flagError:
}
flagError:
@@
-544,7
+535,7
@@
static int readTarFile(const char* tarName, int extractFlag, int listFlag,
}
if ( skipNextHeaderFlag == TRUE ) {
skipNextHeaderFlag=FALSE;
}
if ( skipNextHeaderFlag == TRUE ) {
skipNextHeaderFlag=FALSE;
- errorMsg(name_longer_th
e
n_foo, NAME_SIZE);
+ errorMsg(name_longer_th
a
n_foo, NAME_SIZE);
tarExtractRegularFile(&header, FALSE, FALSE);
continue;
}
tarExtractRegularFile(&header, FALSE, FALSE);
continue;
}
@@
-924,7
+915,7
@@
static int writeFileToTarball(const char *fileName, struct stat *statbuf, void*
}
if (strlen(fileName) >= NAME_SIZE) {
}
if (strlen(fileName) >= NAME_SIZE) {
- errorMsg(name_longer_th
e
n_foo, NAME_SIZE);
+ errorMsg(name_longer_th
a
n_foo, NAME_SIZE);
return ( TRUE);
}
return ( TRUE);
}
@@
-967,8
+958,8
@@
static int writeFileToTarball(const char *fileName, struct stat *statbuf, void*
return( TRUE);
}
return( TRUE);
}
-static int writeTarFile(const char* tarName, int
tostdoutFlag,
-
int verboseFlag, int argc, char **argv,
char** excludeList)
+static int writeTarFile(const char* tarName, int
verboseFlag, char **argv,
+ char** excludeList)
{
int tarFd=-1;
int errorFlag=FALSE;
{
int tarFd=-1;
int errorFlag=FALSE;
@@
-977,11
+968,11
@@
static int writeTarFile(const char* tarName, int tostdoutFlag,
tbInfo.verboseFlag = verboseFlag;
/* Make sure there is at least one file to tar up. */
tbInfo.verboseFlag = verboseFlag;
/* Make sure there is at least one file to tar up. */
- if (
argc <= 0
)
+ if (
*argv == NULL
)
fatalError("Cowardly refusing to create an empty archive\n");
/* Open the tar file for writing. */
fatalError("Cowardly refusing to create an empty archive\n");
/* Open the tar file for writing. */
- if (
tostdoutFlag == TRUE
)
+ if (
!strcmp(tarName, "-")
)
tbInfo.tarFd = fileno(stdout);
else
tbInfo.tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644);
tbInfo.tarFd = fileno(stdout);
else
tbInfo.tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644);
@@
-1000,7
+991,7
@@
static int writeTarFile(const char* tarName, int tostdoutFlag,
umask(0);
/* Read the directory/files and iterate over them one at a time */
umask(0);
/* Read the directory/files and iterate over them one at a time */
- while (
argc-- > 0
) {
+ while (
*argv != NULL
) {
if (recursiveAction(*argv++, TRUE, FALSE, FALSE,
writeFileToTarball, writeFileToTarball,
(void*) &tbInfo) == FALSE) {
if (recursiveAction(*argv++, TRUE, FALSE, FALSE,
writeFileToTarball, writeFileToTarball,
(void*) &tbInfo) == FALSE) {
@@
-1013,7
+1004,7
@@
static int writeTarFile(const char* tarName, int tostdoutFlag,
}
/* To be pedantically correct, we would check if the tarball
}
/* To be pedantically correct, we would check if the tarball
- * is smaller th
e
n 20 tar blocks, and pad it if it was smaller,
+ * is smaller th
a
n 20 tar blocks, and pad it if it was smaller,
* but that isn't necessary for GNU tar interoperability, and
* so is considered a waste of space */
* but that isn't necessary for GNU tar interoperability, and
* so is considered a waste of space */