diff options
Diffstat (limited to 'tar.c')
-rw-r--r-- | tar.c | 51 |
1 files changed, 22 insertions, 29 deletions
@@ -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 | ||
49 | static const char tar_usage[] = | 39 | static 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 | */ |
99 | static int listFlag; // | 90 | static int listFlag; |
100 | static int extractFlag; // | 91 | static int extractFlag; |
101 | static int createFlag; // | 92 | static int createFlag; |
102 | static int verboseFlag; // | 93 | static int verboseFlag; |
103 | static int tostdoutFlag; // | 94 | static int tostdoutFlag; |
104 | 95 | ||
105 | static int inHeader; // <- check me | 96 | static int inHeader; // <- check me |
106 | static int badHeader; // | 97 | static int badHeader; |
107 | static int errorFlag; // | 98 | static int errorFlag; |
108 | static int skipFileFlag; // | 99 | static int skipFileFlag; |
109 | static int warnedRoot; // | 100 | static int warnedRoot; |
110 | static int eofFlag; // | 101 | static int eofFlag; |
111 | static long dataCc; | 102 | static long dataCc; |
112 | static int outFd; | 103 | static int outFd; |
113 | static char outName[TAR_NAME_SIZE]; | 104 | static 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 | */ |
139 | static void saveFile (const char *fileName, int seeLinks); // | 130 | static void saveFile (const char *fileName, int seeLinks); |
140 | 131 | ||
141 | static void saveRegularFile (const char *fileName, | 132 | static 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 | ||
147 | static int wantFileName (const char *fileName, | 138 | static int wantFileName (const char *fileName, |
148 | int fileCount, char **fileTable); // | 139 | int fileCount, char **fileTable); |
149 | 140 | ||
150 | static void writeHeader (const char *fileName, const struct stat *statbuf); | 141 | static void writeHeader (const char *fileName, const struct stat *statbuf); |
151 | 142 | ||
152 | static void writeTarFile (int fileCount, char **fileTable); | 143 | static void writeTarFile (int fileCount, char **fileTable); |
153 | static void writeTarBlock (const char *buf, int len); | 144 | static void writeTarBlock (const char *buf, int len); |
154 | static int putOctal (char *cp, int len, long value); // | 145 | static int putOctal (char *cp, int len, long value); |
155 | 146 | ||
156 | 147 | ||
157 | extern int tar_main (int argc, char **argv) | 148 | extern 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"); |