aboutsummaryrefslogtreecommitdiff
path: root/tar.c
diff options
context:
space:
mode:
Diffstat (limited to 'tar.c')
-rw-r--r--tar.c51
1 files changed, 22 insertions, 29 deletions
diff --git a/tar.c b/tar.c
index c23805993..ed6f3b6b5 100644
--- a/tar.c
+++ b/tar.c
@@ -35,22 +35,13 @@
35#include <signal.h> 35#include <signal.h>
36#include <time.h> 36#include <time.h>
37 37
38/* Note that tar.c expects TRUE and FALSE to be defined
39 * exactly the opposite of how they are used everywhere else.
40 * Some time this should be integrated a bit better, but this
41 * does the job for now.
42 */
43//#undef FALSE
44//#undef TRUE
45//#define FALSE ((int) 0)
46//#define TRUE ((int) 1)
47
48 38
49static const char tar_usage[] = 39static const char tar_usage[] =
50 "tar -[cxtvOf] [tarFileName] [FILE] ...\n" 40"tar -[cxtvOf] [tarFileName] [FILE] ...\n\n"
51 "Create, extract, or list files from a tar file\n\n" 41"Create, extract, or list files from a tar file\n\n"
52 "\tc=create, x=extract, t=list contents, v=verbose,\n" 42"Options:\n"
53 "\tO=extract to stdout, f=tarfile or \"-\" for stdin\n"; 43"\tc=create, x=extract, t=list contents, v=verbose,\n"
44"\tO=extract to stdout, f=tarfile or \"-\" for stdin\n";
54 45
55 46
56 47
@@ -96,18 +87,18 @@ typedef struct {
96/* 87/*
97 * Static data. 88 * Static data.
98 */ 89 */
99static int listFlag; // 90static int listFlag;
100static int extractFlag; // 91static int extractFlag;
101static int createFlag; // 92static int createFlag;
102static int verboseFlag; // 93static int verboseFlag;
103static int tostdoutFlag; // 94static int tostdoutFlag;
104 95
105static int inHeader; // <- check me 96static int inHeader; // <- check me
106static int badHeader; // 97static int badHeader;
107static int errorFlag; // 98static int errorFlag;
108static int skipFileFlag; // 99static int skipFileFlag;
109static int warnedRoot; // 100static int warnedRoot;
110static int eofFlag; // 101static int eofFlag;
111static long dataCc; 102static long dataCc;
112static int outFd; 103static int outFd;
113static char outName[TAR_NAME_SIZE]; 104static char outName[TAR_NAME_SIZE];
@@ -136,7 +127,7 @@ static void readHeader (const TarHeader * hp,
136/* 127/*
137 * Local procedures to save files into a tar file. 128 * Local procedures to save files into a tar file.
138 */ 129 */
139static void saveFile (const char *fileName, int seeLinks); // 130static void saveFile (const char *fileName, int seeLinks);
140 131
141static void saveRegularFile (const char *fileName, 132static void saveRegularFile (const char *fileName,
142 const struct stat *statbuf); 133 const struct stat *statbuf);
@@ -145,13 +136,13 @@ static void saveDirectory (const char *fileName,
145 const struct stat *statbuf); 136 const struct stat *statbuf);
146 137
147static int wantFileName (const char *fileName, 138static int wantFileName (const char *fileName,
148 int fileCount, char **fileTable); // 139 int fileCount, char **fileTable);
149 140
150static void writeHeader (const char *fileName, const struct stat *statbuf); 141static void writeHeader (const char *fileName, const struct stat *statbuf);
151 142
152static void writeTarFile (int fileCount, char **fileTable); 143static void writeTarFile (int fileCount, char **fileTable);
153static void writeTarBlock (const char *buf, int len); 144static void writeTarBlock (const char *buf, int len);
154static int putOctal (char *cp, int len, long value); // 145static int putOctal (char *cp, int len, long value);
155 146
156 147
157extern int tar_main (int argc, char **argv) 148extern int tar_main (int argc, char **argv)
@@ -217,10 +208,13 @@ extern int tar_main (int argc, char **argv)
217 break; 208 break;
218 209
219 case '-': 210 case '-':
211 usage( tar_usage);
220 break; 212 break;
221 213
222 default: 214 default:
223 fprintf (stderr, "Unknown tar flag '%c'\n", *options); 215 fprintf (stderr, "Unknown tar flag '%c'\n"
216 "Try `tar --help' for more information\n",
217 *options);
224 218
225 exit (FALSE); 219 exit (FALSE);
226 } 220 }
@@ -230,7 +224,6 @@ extern int tar_main (int argc, char **argv)
230 /* 224 /*
231 * Validate the options. 225 * Validate the options.
232 */ 226 */
233 fprintf(stderr, "TRUE=%d FALSE=%d\n", TRUE, FALSE);
234 if (extractFlag + listFlag + createFlag != (TRUE+FALSE+FALSE)) { 227 if (extractFlag + listFlag + createFlag != (TRUE+FALSE+FALSE)) {
235 fprintf (stderr, 228 fprintf (stderr,
236 "Exactly one of 'c', 'x' or 't' must be specified\n"); 229 "Exactly one of 'c', 'x' or 't' must be specified\n");