Maybe works now...

-Erik
This commit is contained in:
Eric Andersen 1999-11-10 19:27:58 +00:00
parent 3e2bb288da
commit 5556c1874b
2 changed files with 82 additions and 80 deletions

View File

@ -40,10 +40,10 @@
* Some time this should be integrated a bit better, but this * Some time this should be integrated a bit better, but this
* does the job for now. * does the job for now.
*/ */
#undef FALSE //#undef FALSE
#undef TRUE //#undef TRUE
#define FALSE ((int) 0) //#define FALSE ((int) 0)
#define TRUE ((int) 1) //#define TRUE ((int) 1)
static const char tar_usage[] = static const char tar_usage[] =
@ -96,18 +96,18 @@ typedef struct {
/* /*
* Static data. * Static data.
*/ */
static int listFlag; static int listFlag; //
static int extractFlag; static int extractFlag; //
static int createFlag; static int createFlag; //
static int verboseFlag; static int verboseFlag; //
static int tostdoutFlag; static int tostdoutFlag; //
static int inHeader; static int inHeader; // <- check me
static int badHeader; static int badHeader; //
static int errorFlag; static int errorFlag; //
static int skipFileFlag; static int skipFileFlag; //
static int warnedRoot; static int warnedRoot; //
static int eofFlag; static int eofFlag; //
static long dataCc; static long dataCc;
static int outFd; static int outFd;
static char outName[TAR_NAME_SIZE]; static char outName[TAR_NAME_SIZE];
@ -136,7 +136,7 @@ static void readHeader (const TarHeader * hp,
/* /*
* Local procedures to save files into a tar file. * Local procedures to save files into a tar file.
*/ */
static void saveFile (const char *fileName, int seeLinks); static void saveFile (const char *fileName, int seeLinks); //
static void saveRegularFile (const char *fileName, static void saveRegularFile (const char *fileName,
const struct stat *statbuf); const struct stat *statbuf);
@ -145,13 +145,13 @@ static void saveDirectory (const char *fileName,
const struct stat *statbuf); const struct stat *statbuf);
static int wantFileName (const char *fileName, static int wantFileName (const char *fileName,
int fileCount, char **fileTable); int fileCount, char **fileTable); //
static void writeHeader (const char *fileName, const struct stat *statbuf); static void writeHeader (const char *fileName, const struct stat *statbuf);
static void writeTarFile (int fileCount, char **fileTable); static void writeTarFile (int fileCount, char **fileTable);
static void writeTarBlock (const char *buf, int len); static void writeTarBlock (const char *buf, int len);
static int putOctal (char *cp, int len, long value); static int putOctal (char *cp, int len, long value); //
extern int tar_main (int argc, char **argv) extern int tar_main (int argc, char **argv)
@ -230,7 +230,8 @@ extern int tar_main (int argc, char **argv)
/* /*
* Validate the options. * Validate the options.
*/ */
if (extractFlag + listFlag + createFlag != 1) { fprintf(stderr, "TRUE=%d FALSE=%d\n", TRUE, FALSE);
if (extractFlag + listFlag + createFlag != (TRUE+FALSE+FALSE)) {
fprintf (stderr, fprintf (stderr,
"Exactly one of 'c', 'x' or 't' must be specified\n"); "Exactly one of 'c', 'x' or 't' must be specified\n");
@ -241,13 +242,13 @@ extern int tar_main (int argc, char **argv)
* Do the correct type of action supplying the rest of the * Do the correct type of action supplying the rest of the
* command line arguments as the list of files to process. * command line arguments as the list of files to process.
*/ */
if (createFlag) if (createFlag==TRUE)
writeTarFile (argc, argv); writeTarFile (argc, argv);
else else
readTarFile (argc, argv); readTarFile (argc, argv);
if (errorFlag) if (errorFlag==TRUE)
fprintf (stderr, "\n"); fprintf (stderr, "\n");
exit (errorFlag); exit (!errorFlag);
} }
@ -292,7 +293,7 @@ static void readTarFile (int fileCount, char **fileTable)
* Read blocks from the file until an end of file header block * Read blocks from the file until an end of file header block
* has been seen. (A real end of file from a read is an error.) * has been seen. (A real end of file from a read is an error.)
*/ */
while (!eofFlag) { while (eofFlag==FALSE) {
/* /*
* Read the next block of data if necessary. * Read the next block of data if necessary.
* This will be a large block if possible, which we will * This will be a large block if possible, which we will
@ -319,7 +320,7 @@ static void readTarFile (int fileCount, char **fileTable)
/* /*
* If we are expecting a header block then examine it. * If we are expecting a header block then examine it.
*/ */
if (inHeader) { if (inHeader==TRUE) {
readHeader ((const TarHeader *) cp, fileCount, fileTable); readHeader ((const TarHeader *) cp, fileCount, fileTable);
cp += TAR_BLOCK_SIZE; cp += TAR_BLOCK_SIZE;
@ -419,7 +420,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
checkSum = getOctal (hp->checkSum, sizeof (hp->checkSum)); checkSum = getOctal (hp->checkSum, sizeof (hp->checkSum));
if ((mode < 0) || (uid < 0) || (gid < 0) || (size < 0)) { if ((mode < 0) || (uid < 0) || (gid < 0) || (size < 0)) {
if (!badHeader) if (badHeader==FALSE)
fprintf (stderr, "Bad tar header, skipping\n"); fprintf (stderr, "Bad tar header, skipping\n");
badHeader = TRUE; badHeader = TRUE;
@ -455,7 +456,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
while (*name == '/') while (*name == '/')
name++; name++;
if (!warnedRoot) { if (warnedRoot==FALSE) {
fprintf (stderr, fprintf (stderr,
"Absolute path detected, removing leading slashes\n"); "Absolute path detected, removing leading slashes\n");
} }
@ -467,9 +468,9 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
* See if we want this file to be restored. * See if we want this file to be restored.
* If not, then set up to skip it. * If not, then set up to skip it.
*/ */
if (!wantFileName (name, fileCount, fileTable)) { if (wantFileName (name, fileCount, fileTable) == FALSE) {
if (!hardLink && !softLink && S_ISREG (mode)) { if (!hardLink && !softLink && S_ISREG (mode)) {
inHeader = (size == 0); inHeader = (size == 0)? TRUE : FALSE;
dataCc = size; dataCc = size;
} }
@ -482,8 +483,8 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
* This file is to be handled. * This file is to be handled.
* If we aren't extracting then just list information about the file. * If we aren't extracting then just list information about the file.
*/ */
if (!extractFlag) { if (extractFlag==FALSE) {
if (verboseFlag) { if (verboseFlag==TRUE) {
printf ("%s %3d/%-d %9ld %s %s", modeString (mode), printf ("%s %3d/%-d %9ld %s %s", modeString (mode),
uid, gid, size, timeString (mtime), name); uid, gid, size, timeString (mtime), name);
} else } else
@ -494,7 +495,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
else if (softLink) else if (softLink)
printf (" (symlink to \"%s\")", hp->linkName); printf (" (symlink to \"%s\")", hp->linkName);
else if (S_ISREG (mode)) { else if (S_ISREG (mode)) {
inHeader = (size == 0); inHeader = (size == 0)? TRUE : FALSE;
dataCc = size; dataCc = size;
} }
@ -506,7 +507,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
/* /*
* We really want to extract the file. * We really want to extract the file.
*/ */
if (verboseFlag) if (verboseFlag==TRUE)
printf ("x %s\n", name); printf ("x %s\n", name);
if (hardLink) { if (hardLink) {
@ -541,7 +542,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
*/ */
createPath (name, 0777); createPath (name, 0777);
inHeader = (size == 0); inHeader = (size == 0)? TRUE : FALSE;
dataCc = size; dataCc = size;
/* /*
@ -587,7 +588,7 @@ static void readData (const char *cp, int count)
* If we aren't extracting files or this file is being * If we aren't extracting files or this file is being
* skipped then do nothing more. * skipped then do nothing more.
*/ */
if (!extractFlag || skipFileFlag) if (extractFlag==FALSE || skipFileFlag==TRUE)
return; return;
/* /*
@ -662,7 +663,7 @@ static void writeTarFile (int fileCount, char **fileTable)
* Append each file name into the archive file. * Append each file name into the archive file.
* Follow symbolic links for these top level file names. * Follow symbolic links for these top level file names.
*/ */
while (!errorFlag && (fileCount-- > 0)) { while (errorFlag==FALSE && (fileCount-- > 0)) {
saveFile (*fileTable++, FALSE); saveFile (*fileTable++, FALSE);
} }
@ -694,7 +695,7 @@ static void saveFile (const char *fileName, int seeLinks)
int mode; int mode;
struct stat statbuf; struct stat statbuf;
if (verboseFlag) if (verboseFlag==TRUE)
printf ("a %s\n", fileName); printf ("a %s\n", fileName);
/* /*
@ -710,7 +711,7 @@ static void saveFile (const char *fileName, int seeLinks)
* Find out about the file. * Find out about the file.
*/ */
#ifdef S_ISLNK #ifdef S_ISLNK
if (seeLinks) if (seeLinks==TRUE)
status = lstat (fileName, &statbuf); status = lstat (fileName, &statbuf);
else else
#endif #endif
@ -810,7 +811,7 @@ saveRegularFile (const char *fileName, const struct stat *statbuf)
*/ */
cc = 0; cc = 0;
if (!sawEof) { if (sawEof==FALSE) {
cc = fullRead (fileFd, data, dataCount); cc = fullRead (fileFd, data, dataCount);
if (cc < 0) { if (cc < 0) {
@ -899,7 +900,7 @@ static void saveDirectory (const char *dirName, const struct stat *statbuf)
* Read all of the directory entries and check them, * Read all of the directory entries and check them,
* except for the current and parent directory entries. * except for the current and parent directory entries.
*/ */
while (!errorFlag && ((entry = readdir (dir)) != NULL)) { while (errorFlag==FALSE && ((entry = readdir (dir)) != NULL)) {
if ((strcmp (entry->d_name, ".") == 0) || if ((strcmp (entry->d_name, ".") == 0) ||
(strcmp (entry->d_name, "..") == 0)) { (strcmp (entry->d_name, "..") == 0)) {
continue; continue;
@ -998,7 +999,7 @@ static void writeTarBlock (const char *buf, int len)
/* /*
* If we had a write error before, then do nothing more. * If we had a write error before, then do nothing more.
*/ */
if (errorFlag) if (errorFlag==TRUE)
return; return;
/* /*

81
tar.c
View File

@ -40,10 +40,10 @@
* Some time this should be integrated a bit better, but this * Some time this should be integrated a bit better, but this
* does the job for now. * does the job for now.
*/ */
#undef FALSE //#undef FALSE
#undef TRUE //#undef TRUE
#define FALSE ((int) 0) //#define FALSE ((int) 0)
#define TRUE ((int) 1) //#define TRUE ((int) 1)
static const char tar_usage[] = static const char tar_usage[] =
@ -96,18 +96,18 @@ typedef struct {
/* /*
* Static data. * Static data.
*/ */
static int listFlag; static int listFlag; //
static int extractFlag; static int extractFlag; //
static int createFlag; static int createFlag; //
static int verboseFlag; static int verboseFlag; //
static int tostdoutFlag; static int tostdoutFlag; //
static int inHeader; static int inHeader; // <- check me
static int badHeader; static int badHeader; //
static int errorFlag; static int errorFlag; //
static int skipFileFlag; static int skipFileFlag; //
static int warnedRoot; static int warnedRoot; //
static int eofFlag; static int eofFlag; //
static long dataCc; static long dataCc;
static int outFd; static int outFd;
static char outName[TAR_NAME_SIZE]; static char outName[TAR_NAME_SIZE];
@ -136,7 +136,7 @@ static void readHeader (const TarHeader * hp,
/* /*
* Local procedures to save files into a tar file. * Local procedures to save files into a tar file.
*/ */
static void saveFile (const char *fileName, int seeLinks); static void saveFile (const char *fileName, int seeLinks); //
static void saveRegularFile (const char *fileName, static void saveRegularFile (const char *fileName,
const struct stat *statbuf); const struct stat *statbuf);
@ -145,13 +145,13 @@ static void saveDirectory (const char *fileName,
const struct stat *statbuf); const struct stat *statbuf);
static int wantFileName (const char *fileName, static int wantFileName (const char *fileName,
int fileCount, char **fileTable); int fileCount, char **fileTable); //
static void writeHeader (const char *fileName, const struct stat *statbuf); static void writeHeader (const char *fileName, const struct stat *statbuf);
static void writeTarFile (int fileCount, char **fileTable); static void writeTarFile (int fileCount, char **fileTable);
static void writeTarBlock (const char *buf, int len); static void writeTarBlock (const char *buf, int len);
static int putOctal (char *cp, int len, long value); static int putOctal (char *cp, int len, long value); //
extern int tar_main (int argc, char **argv) extern int tar_main (int argc, char **argv)
@ -230,7 +230,8 @@ extern int tar_main (int argc, char **argv)
/* /*
* Validate the options. * Validate the options.
*/ */
if (extractFlag + listFlag + createFlag != 1) { fprintf(stderr, "TRUE=%d FALSE=%d\n", TRUE, FALSE);
if (extractFlag + listFlag + createFlag != (TRUE+FALSE+FALSE)) {
fprintf (stderr, fprintf (stderr,
"Exactly one of 'c', 'x' or 't' must be specified\n"); "Exactly one of 'c', 'x' or 't' must be specified\n");
@ -241,13 +242,13 @@ extern int tar_main (int argc, char **argv)
* Do the correct type of action supplying the rest of the * Do the correct type of action supplying the rest of the
* command line arguments as the list of files to process. * command line arguments as the list of files to process.
*/ */
if (createFlag) if (createFlag==TRUE)
writeTarFile (argc, argv); writeTarFile (argc, argv);
else else
readTarFile (argc, argv); readTarFile (argc, argv);
if (errorFlag) if (errorFlag==TRUE)
fprintf (stderr, "\n"); fprintf (stderr, "\n");
exit (errorFlag); exit (!errorFlag);
} }
@ -292,7 +293,7 @@ static void readTarFile (int fileCount, char **fileTable)
* Read blocks from the file until an end of file header block * Read blocks from the file until an end of file header block
* has been seen. (A real end of file from a read is an error.) * has been seen. (A real end of file from a read is an error.)
*/ */
while (!eofFlag) { while (eofFlag==FALSE) {
/* /*
* Read the next block of data if necessary. * Read the next block of data if necessary.
* This will be a large block if possible, which we will * This will be a large block if possible, which we will
@ -319,7 +320,7 @@ static void readTarFile (int fileCount, char **fileTable)
/* /*
* If we are expecting a header block then examine it. * If we are expecting a header block then examine it.
*/ */
if (inHeader) { if (inHeader==TRUE) {
readHeader ((const TarHeader *) cp, fileCount, fileTable); readHeader ((const TarHeader *) cp, fileCount, fileTable);
cp += TAR_BLOCK_SIZE; cp += TAR_BLOCK_SIZE;
@ -419,7 +420,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
checkSum = getOctal (hp->checkSum, sizeof (hp->checkSum)); checkSum = getOctal (hp->checkSum, sizeof (hp->checkSum));
if ((mode < 0) || (uid < 0) || (gid < 0) || (size < 0)) { if ((mode < 0) || (uid < 0) || (gid < 0) || (size < 0)) {
if (!badHeader) if (badHeader==FALSE)
fprintf (stderr, "Bad tar header, skipping\n"); fprintf (stderr, "Bad tar header, skipping\n");
badHeader = TRUE; badHeader = TRUE;
@ -455,7 +456,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
while (*name == '/') while (*name == '/')
name++; name++;
if (!warnedRoot) { if (warnedRoot==FALSE) {
fprintf (stderr, fprintf (stderr,
"Absolute path detected, removing leading slashes\n"); "Absolute path detected, removing leading slashes\n");
} }
@ -467,9 +468,9 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
* See if we want this file to be restored. * See if we want this file to be restored.
* If not, then set up to skip it. * If not, then set up to skip it.
*/ */
if (!wantFileName (name, fileCount, fileTable)) { if (wantFileName (name, fileCount, fileTable) == FALSE) {
if (!hardLink && !softLink && S_ISREG (mode)) { if (!hardLink && !softLink && S_ISREG (mode)) {
inHeader = (size == 0); inHeader = (size == 0)? TRUE : FALSE;
dataCc = size; dataCc = size;
} }
@ -482,8 +483,8 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
* This file is to be handled. * This file is to be handled.
* If we aren't extracting then just list information about the file. * If we aren't extracting then just list information about the file.
*/ */
if (!extractFlag) { if (extractFlag==FALSE) {
if (verboseFlag) { if (verboseFlag==TRUE) {
printf ("%s %3d/%-d %9ld %s %s", modeString (mode), printf ("%s %3d/%-d %9ld %s %s", modeString (mode),
uid, gid, size, timeString (mtime), name); uid, gid, size, timeString (mtime), name);
} else } else
@ -494,7 +495,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
else if (softLink) else if (softLink)
printf (" (symlink to \"%s\")", hp->linkName); printf (" (symlink to \"%s\")", hp->linkName);
else if (S_ISREG (mode)) { else if (S_ISREG (mode)) {
inHeader = (size == 0); inHeader = (size == 0)? TRUE : FALSE;
dataCc = size; dataCc = size;
} }
@ -506,7 +507,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
/* /*
* We really want to extract the file. * We really want to extract the file.
*/ */
if (verboseFlag) if (verboseFlag==TRUE)
printf ("x %s\n", name); printf ("x %s\n", name);
if (hardLink) { if (hardLink) {
@ -541,7 +542,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
*/ */
createPath (name, 0777); createPath (name, 0777);
inHeader = (size == 0); inHeader = (size == 0)? TRUE : FALSE;
dataCc = size; dataCc = size;
/* /*
@ -587,7 +588,7 @@ static void readData (const char *cp, int count)
* If we aren't extracting files or this file is being * If we aren't extracting files or this file is being
* skipped then do nothing more. * skipped then do nothing more.
*/ */
if (!extractFlag || skipFileFlag) if (extractFlag==FALSE || skipFileFlag==TRUE)
return; return;
/* /*
@ -662,7 +663,7 @@ static void writeTarFile (int fileCount, char **fileTable)
* Append each file name into the archive file. * Append each file name into the archive file.
* Follow symbolic links for these top level file names. * Follow symbolic links for these top level file names.
*/ */
while (!errorFlag && (fileCount-- > 0)) { while (errorFlag==FALSE && (fileCount-- > 0)) {
saveFile (*fileTable++, FALSE); saveFile (*fileTable++, FALSE);
} }
@ -694,7 +695,7 @@ static void saveFile (const char *fileName, int seeLinks)
int mode; int mode;
struct stat statbuf; struct stat statbuf;
if (verboseFlag) if (verboseFlag==TRUE)
printf ("a %s\n", fileName); printf ("a %s\n", fileName);
/* /*
@ -710,7 +711,7 @@ static void saveFile (const char *fileName, int seeLinks)
* Find out about the file. * Find out about the file.
*/ */
#ifdef S_ISLNK #ifdef S_ISLNK
if (seeLinks) if (seeLinks==TRUE)
status = lstat (fileName, &statbuf); status = lstat (fileName, &statbuf);
else else
#endif #endif
@ -810,7 +811,7 @@ saveRegularFile (const char *fileName, const struct stat *statbuf)
*/ */
cc = 0; cc = 0;
if (!sawEof) { if (sawEof==FALSE) {
cc = fullRead (fileFd, data, dataCount); cc = fullRead (fileFd, data, dataCount);
if (cc < 0) { if (cc < 0) {
@ -899,7 +900,7 @@ static void saveDirectory (const char *dirName, const struct stat *statbuf)
* Read all of the directory entries and check them, * Read all of the directory entries and check them,
* except for the current and parent directory entries. * except for the current and parent directory entries.
*/ */
while (!errorFlag && ((entry = readdir (dir)) != NULL)) { while (errorFlag==FALSE && ((entry = readdir (dir)) != NULL)) {
if ((strcmp (entry->d_name, ".") == 0) || if ((strcmp (entry->d_name, ".") == 0) ||
(strcmp (entry->d_name, "..") == 0)) { (strcmp (entry->d_name, "..") == 0)) {
continue; continue;
@ -998,7 +999,7 @@ static void writeTarBlock (const char *buf, int len)
/* /*
* If we had a write error before, then do nothing more. * If we had a write error before, then do nothing more.
*/ */
if (errorFlag) if (errorFlag==TRUE)
return; return;
/* /*