aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-01-16 01:30:52 +0000
committerErik Andersen <andersen@codepoet.org>2000-01-16 01:30:52 +0000
commit05100cd4776d9900c6c12def21eae8cec2cab766 (patch)
tree504f5f30277b8017557235230ddeadd8cf797852
parent83865e3e90c7f67b65d1310c7f51ec4d908f7dac (diff)
downloadbusybox-05100cd4776d9900c6c12def21eae8cec2cab766.tar.gz
tar creation support is now optional.
-Erik
-rw-r--r--Changelog5
-rw-r--r--archival/tar.c212
-rw-r--r--busybox.def.h3
-rw-r--r--busybox.spec6
-rw-r--r--examples/busybox.spec6
-rw-r--r--tar.c212
6 files changed, 262 insertions, 182 deletions
diff --git a/Changelog b/Changelog
index 81d4f11e0..453a69b00 100644
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,8 @@
+0.42
+ * Made tar creation support in busybox tar optional.
+
+ -Erik Andersen
+
0.41
* New Apps: wc, hostid, logname, tty, whoami, yes -- all contributed
by Edward Betts <edward@debian.org>
diff --git a/archival/tar.c b/archival/tar.c
index a53370e85..5c407864f 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -42,13 +42,26 @@
#include <sys/sysmacros.h>
+#ifdef BB_FEATURE_TAR_CREATE
+
static const char tar_usage[] =
"tar -[cxtvOf] [tarFileName] [FILE] ...\n\n"
-"Create, extract, or list files from a tar file\n\n"
+"Create, extract, or list files from a tar file.\n\n"
"Options:\n"
"\tc=create, x=extract, t=list contents, v=verbose,\n"
"\tO=extract to stdout, f=tarfile or \"-\" for stdin\n";
+#else
+
+static const char tar_usage[] =
+"tar -[cxtvOf] [tarFileName] [FILE] ...\n\n"
+"Extract, or list files stored in a tar file. This\n"
+"version of tar does not support creation of tar files.\n\n"
+"Options:\n"
+"\tx=extract, t=list contents, v=verbose,\n"
+"\tO=extract to stdout, f=tarfile or \"-\" for stdin\n";
+
+#endif
/*
@@ -95,7 +108,9 @@ typedef struct {
*/
static int listFlag;
static int extractFlag;
+#ifdef BB_FEATURE_TAR_CREATE
static int createFlag;
+#endif
static int verboseFlag;
static int tostdoutFlag;
@@ -133,7 +148,10 @@ static long getOctal (const char *cp, int len);
static void readHeader (const TarHeader * hp,
int fileCount, char **fileTable);
+static int wantFileName (const char *fileName,
+ int fileCount, char **fileTable);
+#ifdef BB_FEATURE_TAR_CREATE
/*
* Local procedures to save files into a tar file.
*/
@@ -145,15 +163,14 @@ static void saveRegularFile (const char *fileName,
static void saveDirectory (const char *fileName,
const struct stat *statbuf);
-static int wantFileName (const char *fileName,
- int fileCount, char **fileTable);
-
static void writeHeader (const char *fileName, const struct stat *statbuf);
static void writeTarFile (int fileCount, char **fileTable);
static void writeTarBlock (const char *buf, int len);
static int putOctal (char *cp, int len, long value);
+#endif
+
extern int tar_main (int argc, char **argv)
{
@@ -168,7 +185,9 @@ extern int tar_main (int argc, char **argv)
errorFlag = FALSE;
extractFlag = FALSE;
+#ifdef BB_FEATURE_TAR_CREATE
createFlag = FALSE;
+#endif
listFlag = FALSE;
verboseFlag = FALSE;
tostdoutFlag = FALSE;
@@ -204,10 +223,16 @@ extern int tar_main (int argc, char **argv)
case 'x':
extractFlag = TRUE;
break;
-
+#ifdef BB_FEATURE_TAR_CREATE
case 'c':
createFlag = TRUE;
break;
+#else
+ case 'c':
+ fprintf (stderr, "This version of tar was not compiled with tar creation support.\n" );
+
+ exit (FALSE);
+#endif
case 'v':
verboseFlag = TRUE;
@@ -234,7 +259,11 @@ extern int tar_main (int argc, char **argv)
/*
* Validate the options.
*/
- if (extractFlag + listFlag + createFlag != (TRUE+FALSE+FALSE)) {
+ if (extractFlag + listFlag
+#ifdef BB_FEATURE_TAR_CREATE
+ + createFlag
+#endif
+ != (TRUE+FALSE+FALSE)) {
fprintf (stderr,
"Exactly one of 'c', 'x' or 't' must be specified\n");
@@ -245,9 +274,11 @@ extern int tar_main (int argc, char **argv)
* Do the correct type of action supplying the rest of the
* command line arguments as the list of files to process.
*/
+#ifdef BB_FEATURE_TAR_CREATE
if (createFlag==TRUE)
writeTarFile (argc, argv);
else
+#endif
readTarFile (argc, argv);
if (errorFlag==TRUE)
fprintf (stderr, "\n");
@@ -678,6 +709,92 @@ static void readData (const char *cp, int count)
/*
+ * See if the specified file name belongs to one of the specified list
+ * of path prefixes. An empty list implies that all files are wanted.
+ * Returns TRUE if the file is selected.
+ */
+static int
+wantFileName (const char *fileName, int fileCount, char **fileTable)
+{
+ const char *pathName;
+ int fileLength;
+ int pathLength;
+
+ /*
+ * If there are no files in the list, then the file is wanted.
+ */
+ if (fileCount == 0)
+ return TRUE;
+
+ fileLength = strlen (fileName);
+
+ /*
+ * Check each of the test paths.
+ */
+ while (fileCount-- > 0) {
+ pathName = *fileTable++;
+
+ pathLength = strlen (pathName);
+
+ if (fileLength < pathLength)
+ continue;
+
+ if (memcmp (fileName, pathName, pathLength) != 0)
+ continue;
+
+ if ((fileLength == pathLength) || (fileName[pathLength] == '/')) {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+/*
+ * Read an octal value in a field of the specified width, with optional
+ * spaces on both sides of the number and with an optional null character
+ * at the end. Returns -1 on an illegal format.
+ */
+static long getOctal (const char *cp, int len)
+{
+ long val;
+
+ while ((len > 0) && (*cp == ' ')) {
+ cp++;
+ len--;
+ }
+
+ if ((len == 0) || !isOctal (*cp))
+ return -1;
+
+ val = 0;
+
+ while ((len > 0) && isOctal (*cp)) {
+ val = val * 8 + *cp++ - '0';
+ len--;
+ }
+
+ while ((len > 0) && (*cp == ' ')) {
+ cp++;
+ len--;
+ }
+
+ if ((len > 0) && *cp)
+ return -1;
+
+ return val;
+}
+
+
+
+
+/* From here to the end of the file is the tar writing stuff.
+ * If you do not have BB_FEATURE_TAR_CREATE defined, this will
+ * not be built.
+ * */
+#ifdef BB_FEATURE_TAR_CREATE
+
+/*
* Write a tar file containing the specified files.
*/
static void writeTarFile (int fileCount, char **fileTable)
@@ -741,7 +858,6 @@ static void writeTarFile (int fileCount, char **fileTable)
perror (tarName);
}
-
/*
* Save one file into the tar file.
* If the file is a directory, then this will recursively save all of
@@ -1107,42 +1223,6 @@ static void writeTarBlock (const char *buf, int len)
/*
- * Read an octal value in a field of the specified width, with optional
- * spaces on both sides of the number and with an optional null character
- * at the end. Returns -1 on an illegal format.
- */
-static long getOctal (const char *cp, int len)
-{
- long val;
-
- while ((len > 0) && (*cp == ' ')) {
- cp++;
- len--;
- }
-
- if ((len == 0) || !isOctal (*cp))
- return -1;
-
- val = 0;
-
- while ((len > 0) && isOctal (*cp)) {
- val = val * 8 + *cp++ - '0';
- len--;
- }
-
- while ((len > 0) && (*cp == ' ')) {
- cp++;
- len--;
- }
-
- if ((len > 0) && *cp)
- return -1;
-
- return val;
-}
-
-
-/*
* Put an octal string into the specified buffer.
* The number is zero and space padded and possibly null padded.
* Returns TRUE if successful.
@@ -1190,50 +1270,6 @@ static int putOctal (char *cp, int len, long value)
return TRUE;
}
-
-
-/*
- * See if the specified file name belongs to one of the specified list
- * of path prefixes. An empty list implies that all files are wanted.
- * Returns TRUE if the file is selected.
- */
-static int
-wantFileName (const char *fileName, int fileCount, char **fileTable)
-{
- const char *pathName;
- int fileLength;
- int pathLength;
-
- /*
- * If there are no files in the list, then the file is wanted.
- */
- if (fileCount == 0)
- return TRUE;
-
- fileLength = strlen (fileName);
-
- /*
- * Check each of the test paths.
- */
- while (fileCount-- > 0) {
- pathName = *fileTable++;
-
- pathLength = strlen (pathName);
-
- if (fileLength < pathLength)
- continue;
-
- if (memcmp (fileName, pathName, pathLength) != 0)
- continue;
-
- if ((fileLength == pathLength) || (fileName[pathLength] == '/')) {
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-
+#endif
/* END CODE */
diff --git a/busybox.def.h b/busybox.def.h
index b8d7b9730..871b152d3 100644
--- a/busybox.def.h
+++ b/busybox.def.h
@@ -136,3 +136,6 @@
// Enable support for loop devices in mount
#define BB_FEATURE_MOUNT_LOOP
//
+// Enable support for creation of tar files.
+//#define BB_FEATURE_TAR_CREATE
+//
diff --git a/busybox.spec b/busybox.spec
index ae7010186..73f47e191 100644
--- a/busybox.spec
+++ b/busybox.spec
@@ -6,8 +6,8 @@ Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
Copyright: GPL
Packager : Erik Andersen <andersen@lineo.com>
Conflicts: fileutils grep shellutils
-Buildroot: /tmp/%{Name}-%{Version}
-Source: %{Name}-%{Version}.tar.gz
+Buildroot: /tmp/%{name}-%{version}
+Source: %{name}-%{version}.tar.gz
%Description
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
@@ -18,7 +18,7 @@ is makes an excellent environment for a "rescue" disk or any small or
embedded system.
%Prep
-%setup -q -n %{Name}-%{Version}
+%setup -q -n %{name}-%{version}
%Build
make
diff --git a/examples/busybox.spec b/examples/busybox.spec
index ae7010186..73f47e191 100644
--- a/examples/busybox.spec
+++ b/examples/busybox.spec
@@ -6,8 +6,8 @@ Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
Copyright: GPL
Packager : Erik Andersen <andersen@lineo.com>
Conflicts: fileutils grep shellutils
-Buildroot: /tmp/%{Name}-%{Version}
-Source: %{Name}-%{Version}.tar.gz
+Buildroot: /tmp/%{name}-%{version}
+Source: %{name}-%{version}.tar.gz
%Description
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
@@ -18,7 +18,7 @@ is makes an excellent environment for a "rescue" disk or any small or
embedded system.
%Prep
-%setup -q -n %{Name}-%{Version}
+%setup -q -n %{name}-%{version}
%Build
make
diff --git a/tar.c b/tar.c
index a53370e85..5c407864f 100644
--- a/tar.c
+++ b/tar.c
@@ -42,13 +42,26 @@
#include <sys/sysmacros.h>
+#ifdef BB_FEATURE_TAR_CREATE
+
static const char tar_usage[] =
"tar -[cxtvOf] [tarFileName] [FILE] ...\n\n"
-"Create, extract, or list files from a tar file\n\n"
+"Create, extract, or list files from a tar file.\n\n"
"Options:\n"
"\tc=create, x=extract, t=list contents, v=verbose,\n"
"\tO=extract to stdout, f=tarfile or \"-\" for stdin\n";
+#else
+
+static const char tar_usage[] =
+"tar -[cxtvOf] [tarFileName] [FILE] ...\n\n"
+"Extract, or list files stored in a tar file. This\n"
+"version of tar does not support creation of tar files.\n\n"
+"Options:\n"
+"\tx=extract, t=list contents, v=verbose,\n"
+"\tO=extract to stdout, f=tarfile or \"-\" for stdin\n";
+
+#endif
/*
@@ -95,7 +108,9 @@ typedef struct {
*/
static int listFlag;
static int extractFlag;
+#ifdef BB_FEATURE_TAR_CREATE
static int createFlag;
+#endif
static int verboseFlag;
static int tostdoutFlag;
@@ -133,7 +148,10 @@ static long getOctal (const char *cp, int len);
static void readHeader (const TarHeader * hp,
int fileCount, char **fileTable);
+static int wantFileName (const char *fileName,
+ int fileCount, char **fileTable);
+#ifdef BB_FEATURE_TAR_CREATE
/*
* Local procedures to save files into a tar file.
*/
@@ -145,15 +163,14 @@ static void saveRegularFile (const char *fileName,
static void saveDirectory (const char *fileName,
const struct stat *statbuf);
-static int wantFileName (const char *fileName,
- int fileCount, char **fileTable);
-
static void writeHeader (const char *fileName, const struct stat *statbuf);
static void writeTarFile (int fileCount, char **fileTable);
static void writeTarBlock (const char *buf, int len);
static int putOctal (char *cp, int len, long value);
+#endif
+
extern int tar_main (int argc, char **argv)
{
@@ -168,7 +185,9 @@ extern int tar_main (int argc, char **argv)
errorFlag = FALSE;
extractFlag = FALSE;
+#ifdef BB_FEATURE_TAR_CREATE
createFlag = FALSE;
+#endif
listFlag = FALSE;
verboseFlag = FALSE;
tostdoutFlag = FALSE;
@@ -204,10 +223,16 @@ extern int tar_main (int argc, char **argv)
case 'x':
extractFlag = TRUE;
break;
-
+#ifdef BB_FEATURE_TAR_CREATE
case 'c':
createFlag = TRUE;
break;
+#else
+ case 'c':
+ fprintf (stderr, "This version of tar was not compiled with tar creation support.\n" );
+
+ exit (FALSE);
+#endif
case 'v':
verboseFlag = TRUE;
@@ -234,7 +259,11 @@ extern int tar_main (int argc, char **argv)
/*
* Validate the options.
*/
- if (extractFlag + listFlag + createFlag != (TRUE+FALSE+FALSE)) {
+ if (extractFlag + listFlag
+#ifdef BB_FEATURE_TAR_CREATE
+ + createFlag
+#endif
+ != (TRUE+FALSE+FALSE)) {
fprintf (stderr,
"Exactly one of 'c', 'x' or 't' must be specified\n");
@@ -245,9 +274,11 @@ extern int tar_main (int argc, char **argv)
* Do the correct type of action supplying the rest of the
* command line arguments as the list of files to process.
*/
+#ifdef BB_FEATURE_TAR_CREATE
if (createFlag==TRUE)
writeTarFile (argc, argv);
else
+#endif
readTarFile (argc, argv);
if (errorFlag==TRUE)
fprintf (stderr, "\n");
@@ -678,6 +709,92 @@ static void readData (const char *cp, int count)
/*
+ * See if the specified file name belongs to one of the specified list
+ * of path prefixes. An empty list implies that all files are wanted.
+ * Returns TRUE if the file is selected.
+ */
+static int
+wantFileName (const char *fileName, int fileCount, char **fileTable)
+{
+ const char *pathName;
+ int fileLength;
+ int pathLength;
+
+ /*
+ * If there are no files in the list, then the file is wanted.
+ */
+ if (fileCount == 0)
+ return TRUE;
+
+ fileLength = strlen (fileName);
+
+ /*
+ * Check each of the test paths.
+ */
+ while (fileCount-- > 0) {
+ pathName = *fileTable++;
+
+ pathLength = strlen (pathName);
+
+ if (fileLength < pathLength)
+ continue;
+
+ if (memcmp (fileName, pathName, pathLength) != 0)
+ continue;
+
+ if ((fileLength == pathLength) || (fileName[pathLength] == '/')) {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+/*
+ * Read an octal value in a field of the specified width, with optional
+ * spaces on both sides of the number and with an optional null character
+ * at the end. Returns -1 on an illegal format.
+ */
+static long getOctal (const char *cp, int len)
+{
+ long val;
+
+ while ((len > 0) && (*cp == ' ')) {
+ cp++;
+ len--;
+ }
+
+ if ((len == 0) || !isOctal (*cp))
+ return -1;
+
+ val = 0;
+
+ while ((len > 0) && isOctal (*cp)) {
+ val = val * 8 + *cp++ - '0';
+ len--;
+ }
+
+ while ((len > 0) && (*cp == ' ')) {
+ cp++;
+ len--;
+ }
+
+ if ((len > 0) && *cp)
+ return -1;
+
+ return val;
+}
+
+
+
+
+/* From here to the end of the file is the tar writing stuff.
+ * If you do not have BB_FEATURE_TAR_CREATE defined, this will
+ * not be built.
+ * */
+#ifdef BB_FEATURE_TAR_CREATE
+
+/*
* Write a tar file containing the specified files.
*/
static void writeTarFile (int fileCount, char **fileTable)
@@ -741,7 +858,6 @@ static void writeTarFile (int fileCount, char **fileTable)
perror (tarName);
}
-
/*
* Save one file into the tar file.
* If the file is a directory, then this will recursively save all of
@@ -1107,42 +1223,6 @@ static void writeTarBlock (const char *buf, int len)
/*
- * Read an octal value in a field of the specified width, with optional
- * spaces on both sides of the number and with an optional null character
- * at the end. Returns -1 on an illegal format.
- */
-static long getOctal (const char *cp, int len)
-{
- long val;
-
- while ((len > 0) && (*cp == ' ')) {
- cp++;
- len--;
- }
-
- if ((len == 0) || !isOctal (*cp))
- return -1;
-
- val = 0;
-
- while ((len > 0) && isOctal (*cp)) {
- val = val * 8 + *cp++ - '0';
- len--;
- }
-
- while ((len > 0) && (*cp == ' ')) {
- cp++;
- len--;
- }
-
- if ((len > 0) && *cp)
- return -1;
-
- return val;
-}
-
-
-/*
* Put an octal string into the specified buffer.
* The number is zero and space padded and possibly null padded.
* Returns TRUE if successful.
@@ -1190,50 +1270,6 @@ static int putOctal (char *cp, int len, long value)
return TRUE;
}
-
-
-/*
- * See if the specified file name belongs to one of the specified list
- * of path prefixes. An empty list implies that all files are wanted.
- * Returns TRUE if the file is selected.
- */
-static int
-wantFileName (const char *fileName, int fileCount, char **fileTable)
-{
- const char *pathName;
- int fileLength;
- int pathLength;
-
- /*
- * If there are no files in the list, then the file is wanted.
- */
- if (fileCount == 0)
- return TRUE;
-
- fileLength = strlen (fileName);
-
- /*
- * Check each of the test paths.
- */
- while (fileCount-- > 0) {
- pathName = *fileTable++;
-
- pathLength = strlen (pathName);
-
- if (fileLength < pathLength)
- continue;
-
- if (memcmp (fileName, pathName, pathLength) != 0)
- continue;
-
- if ((fileLength == pathLength) || (fileName[pathLength] == '/')) {
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-
+#endif
/* END CODE */