diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-26 18:21:36 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-06-26 18:21:36 +0200 |
commit | 52827e3ebcd80f634f990030ee697254a0ae517d (patch) | |
tree | 61cb4b3f65587301b1f2774a42c228d2f221d24e | |
parent | d0a8a0d31243f2ac798531ced2cca45ddf1fea42 (diff) | |
download | busybox-w32-52827e3ebcd80f634f990030ee697254a0ae517d.tar.gz busybox-w32-52827e3ebcd80f634f990030ee697254a0ae517d.tar.bz2 busybox-w32-52827e3ebcd80f634f990030ee697254a0ae517d.zip |
*: tar-related cleanups: move struct to unarchive.h; move help to tar.c
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/libunarchive/get_header_tar.c | 40 | ||||
-rw-r--r-- | archival/tar.c | 107 | ||||
-rw-r--r-- | include/unarchive.h | 33 | ||||
-rw-r--r-- | include/usage.src.h | 48 | ||||
-rw-r--r-- | procps/smemcap.c | 43 |
5 files changed, 118 insertions, 153 deletions
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c index fcddcb834..01c10433e 100644 --- a/archival/libunarchive/get_header_tar.c +++ b/archival/libunarchive/get_header_tar.c | |||
@@ -118,34 +118,10 @@ static char *get_selinux_sctx_from_pax_hdr(archive_handle_t *archive_handle, uns | |||
118 | } | 118 | } |
119 | #endif | 119 | #endif |
120 | 120 | ||
121 | void BUG_tar_header_size(void); | ||
122 | char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) | 121 | char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) |
123 | { | 122 | { |
124 | file_header_t *file_header = archive_handle->file_header; | 123 | file_header_t *file_header = archive_handle->file_header; |
125 | struct { | 124 | struct tar_header_t tar; |
126 | /* ustar header, Posix 1003.1 */ | ||
127 | char name[100]; /* 0-99 */ | ||
128 | char mode[8]; /* 100-107 */ | ||
129 | char uid[8]; /* 108-115 */ | ||
130 | char gid[8]; /* 116-123 */ | ||
131 | char size[12]; /* 124-135 */ | ||
132 | char mtime[12]; /* 136-147 */ | ||
133 | char chksum[8]; /* 148-155 */ | ||
134 | char typeflag; /* 156-156 */ | ||
135 | char linkname[100]; /* 157-256 */ | ||
136 | /* POSIX: "ustar" NUL "00" */ | ||
137 | /* GNU tar: "ustar " NUL */ | ||
138 | /* Normally it's defined as magic[6] followed by | ||
139 | * version[2], but we put them together to simplify code | ||
140 | */ | ||
141 | char magic[8]; /* 257-264 */ | ||
142 | char uname[32]; /* 265-296 */ | ||
143 | char gname[32]; /* 297-328 */ | ||
144 | char devmajor[8]; /* 329-336 */ | ||
145 | char devminor[8]; /* 337-344 */ | ||
146 | char prefix[155]; /* 345-499 */ | ||
147 | char padding[12]; /* 500-512 */ | ||
148 | } tar; | ||
149 | char *cp; | 125 | char *cp; |
150 | int i, sum_u, sum; | 126 | int i, sum_u, sum; |
151 | #if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY | 127 | #if ENABLE_FEATURE_TAR_OLDSUN_COMPATIBILITY |
@@ -162,9 +138,6 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) | |||
162 | # define p_linkname 0 | 138 | # define p_linkname 0 |
163 | #endif | 139 | #endif |
164 | 140 | ||
165 | if (sizeof(tar) != 512) | ||
166 | BUG_tar_header_size(); | ||
167 | |||
168 | #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS || ENABLE_FEATURE_TAR_SELINUX | 141 | #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS || ENABLE_FEATURE_TAR_SELINUX |
169 | again: | 142 | again: |
170 | #endif | 143 | #endif |
@@ -230,18 +203,21 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) | |||
230 | * we can switch to get_header_tar_gz/bz2/lzma(). | 203 | * we can switch to get_header_tar_gz/bz2/lzma(). |
231 | * Needs seekable fd. I wish recv(MSG_PEEK) works | 204 | * Needs seekable fd. I wish recv(MSG_PEEK) works |
232 | * on any fd... */ | 205 | * on any fd... */ |
233 | #if ENABLE_FEATURE_SEAMLESS_GZ | 206 | # if ENABLE_FEATURE_SEAMLESS_GZ |
234 | if (tar.name[0] == 0x1f && tar.name[1] == (char)0x8b) { /* gzip */ | 207 | if (tar.name[0] == 0x1f && tar.name[1] == (char)0x8b) { /* gzip */ |
235 | get_header_ptr = get_header_tar_gz; | 208 | get_header_ptr = get_header_tar_gz; |
236 | } else | 209 | } else |
237 | #endif | 210 | # endif |
238 | #if ENABLE_FEATURE_SEAMLESS_BZ2 | 211 | # if ENABLE_FEATURE_SEAMLESS_BZ2 |
239 | if (tar.name[0] == 'B' && tar.name[1] == 'Z' | 212 | if (tar.name[0] == 'B' && tar.name[1] == 'Z' |
240 | && tar.name[2] == 'h' && isdigit(tar.name[3]) | 213 | && tar.name[2] == 'h' && isdigit(tar.name[3]) |
241 | ) { /* bzip2 */ | 214 | ) { /* bzip2 */ |
242 | get_header_ptr = get_header_tar_bz2; | 215 | get_header_ptr = get_header_tar_bz2; |
243 | } else | 216 | } else |
244 | #endif | 217 | # endif |
218 | # if ENABLE_FEATURE_SEAMLESS_XZ | ||
219 | //TODO | ||
220 | # endif | ||
245 | goto err; | 221 | goto err; |
246 | /* Two different causes for lseek() != 0: | 222 | /* Two different causes for lseek() != 0: |
247 | * unseekable fd (would like to support that too, but...), | 223 | * unseekable fd (would like to support that too, but...), |
diff --git a/archival/tar.c b/archival/tar.c index 344c9dea4..f49fb129e 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -48,37 +48,6 @@ | |||
48 | 48 | ||
49 | #if ENABLE_FEATURE_TAR_CREATE | 49 | #if ENABLE_FEATURE_TAR_CREATE |
50 | 50 | ||
51 | /* Tar file constants */ | ||
52 | |||
53 | #define TAR_BLOCK_SIZE 512 | ||
54 | |||
55 | /* POSIX tar Header Block, from POSIX 1003.1-1990 */ | ||
56 | #define NAME_SIZE 100 | ||
57 | #define NAME_SIZE_STR "100" | ||
58 | typedef struct TarHeader { /* byte offset */ | ||
59 | char name[NAME_SIZE]; /* 0-99 */ | ||
60 | char mode[8]; /* 100-107 */ | ||
61 | char uid[8]; /* 108-115 */ | ||
62 | char gid[8]; /* 116-123 */ | ||
63 | char size[12]; /* 124-135 */ | ||
64 | char mtime[12]; /* 136-147 */ | ||
65 | char chksum[8]; /* 148-155 */ | ||
66 | char typeflag; /* 156-156 */ | ||
67 | char linkname[NAME_SIZE]; /* 157-256 */ | ||
68 | /* POSIX: "ustar" NUL "00" */ | ||
69 | /* GNU tar: "ustar " NUL */ | ||
70 | /* Normally it's defined as magic[6] followed by | ||
71 | * version[2], but we put them together to save code. | ||
72 | */ | ||
73 | char magic[8]; /* 257-264 */ | ||
74 | char uname[32]; /* 265-296 */ | ||
75 | char gname[32]; /* 297-328 */ | ||
76 | char devmajor[8]; /* 329-336 */ | ||
77 | char devminor[8]; /* 337-344 */ | ||
78 | char prefix[155]; /* 345-499 */ | ||
79 | char padding[12]; /* 500-512 (pad to exactly TAR_BLOCK_SIZE) */ | ||
80 | } TarHeader; | ||
81 | |||
82 | /* | 51 | /* |
83 | ** writeTarFile(), writeFileToTarball(), and writeTarHeader() are | 52 | ** writeTarFile(), writeFileToTarball(), and writeTarHeader() are |
84 | ** the only functions that deal with the HardLinkInfo structure. | 53 | ** the only functions that deal with the HardLinkInfo structure. |
@@ -193,7 +162,7 @@ static void putOctal(char *cp, int len, off_t value) | |||
193 | } | 162 | } |
194 | #define PUT_OCTAL(a, b) putOctal((a), sizeof(a), (b)) | 163 | #define PUT_OCTAL(a, b) putOctal((a), sizeof(a), (b)) |
195 | 164 | ||
196 | static void chksum_and_xwrite(int fd, struct TarHeader* hp) | 165 | static void chksum_and_xwrite(int fd, struct tar_header_t* hp) |
197 | { | 166 | { |
198 | /* POSIX says that checksum is done on unsigned bytes | 167 | /* POSIX says that checksum is done on unsigned bytes |
199 | * (Sun and HP-UX gets it wrong... more details in | 168 | * (Sun and HP-UX gets it wrong... more details in |
@@ -235,7 +204,7 @@ static void writeLongname(int fd, int type, const char *name, int dir) | |||
235 | "00000000000", | 204 | "00000000000", |
236 | "00000000000", | 205 | "00000000000", |
237 | }; | 206 | }; |
238 | struct TarHeader header; | 207 | struct tar_header_t header; |
239 | int size; | 208 | int size; |
240 | 209 | ||
241 | dir = !!dir; /* normalize: 0/1 */ | 210 | dir = !!dir; /* normalize: 0/1 */ |
@@ -262,17 +231,13 @@ static void writeLongname(int fd, int type, const char *name, int dir) | |||
262 | #endif | 231 | #endif |
263 | 232 | ||
264 | /* Write out a tar header for the specified file/directory/whatever */ | 233 | /* Write out a tar header for the specified file/directory/whatever */ |
265 | void BUG_tar_header_size(void); | ||
266 | static int writeTarHeader(struct TarBallInfo *tbInfo, | 234 | static int writeTarHeader(struct TarBallInfo *tbInfo, |
267 | const char *header_name, const char *fileName, struct stat *statbuf) | 235 | const char *header_name, const char *fileName, struct stat *statbuf) |
268 | { | 236 | { |
269 | struct TarHeader header; | 237 | struct tar_header_t header; |
270 | |||
271 | if (sizeof(header) != 512) | ||
272 | BUG_tar_header_size(); | ||
273 | |||
274 | memset(&header, 0, sizeof(struct TarHeader)); | ||
275 | 238 | ||
239 | memset(&header, 0, sizeof(header)); | ||
240 | |||
276 | strncpy(header.name, header_name, sizeof(header.name)); | 241 | strncpy(header.name, header_name, sizeof(header.name)); |
277 | 242 | ||
278 | /* POSIX says to mask mode with 07777. */ | 243 | /* POSIX says to mask mode with 07777. */ |
@@ -738,6 +703,68 @@ static void handle_SIGCHLD(int status) | |||
738 | } | 703 | } |
739 | #endif | 704 | #endif |
740 | 705 | ||
706 | //usage:#define tar_trivial_usage | ||
707 | //usage: "-[" IF_FEATURE_TAR_CREATE("c") "xt" IF_FEATURE_SEAMLESS_GZ("z") | ||
708 | //usage: IF_FEATURE_SEAMLESS_BZ2("j") IF_FEATURE_SEAMLESS_LZMA("a") | ||
709 | //usage: IF_FEATURE_SEAMLESS_Z("Z") IF_FEATURE_TAR_NOPRESERVE_TIME("m") "vO] " | ||
710 | //usage: IF_FEATURE_TAR_FROM("[-X FILE] ") | ||
711 | //usage: "[-f TARFILE] [-C DIR] [FILE]..." | ||
712 | //usage:#define tar_full_usage "\n\n" | ||
713 | //usage: IF_FEATURE_TAR_CREATE("Create, extract, ") | ||
714 | //usage: IF_NOT_FEATURE_TAR_CREATE("Extract ") | ||
715 | //usage: "or list files from a tar file\n" | ||
716 | //usage: "\nOperation:" | ||
717 | //usage: IF_FEATURE_TAR_CREATE( | ||
718 | //usage: "\n c Create" | ||
719 | //usage: ) | ||
720 | //usage: "\n x Extract" | ||
721 | //usage: "\n t List" | ||
722 | //usage: "\nOptions:" | ||
723 | //usage: "\n f Name of TARFILE ('-' for stdin/out)" | ||
724 | //usage: "\n C Change to DIR before operation" | ||
725 | //usage: "\n v Verbose" | ||
726 | //usage: IF_FEATURE_SEAMLESS_GZ( | ||
727 | //usage: "\n z (De)compress using gzip" | ||
728 | //usage: ) | ||
729 | //usage: IF_FEATURE_SEAMLESS_BZ2( | ||
730 | //usage: "\n j (De)compress using bzip2" | ||
731 | //usage: ) | ||
732 | //usage: IF_FEATURE_SEAMLESS_LZMA( | ||
733 | //usage: "\n a (De)compress using lzma" | ||
734 | //usage: ) | ||
735 | //usage: IF_FEATURE_SEAMLESS_Z( | ||
736 | //usage: "\n Z (De)compress using compress" | ||
737 | //usage: ) | ||
738 | //usage: "\n O Extract to stdout" | ||
739 | //usage: IF_FEATURE_TAR_CREATE( | ||
740 | //usage: "\n h Follow symlinks" | ||
741 | //usage: ) | ||
742 | //usage: IF_FEATURE_TAR_NOPRESERVE_TIME( | ||
743 | //usage: "\n m Don't restore mtime" | ||
744 | //usage: ) | ||
745 | //usage: IF_FEATURE_TAR_FROM( | ||
746 | //usage: IF_FEATURE_TAR_LONG_OPTIONS( | ||
747 | //usage: "\n exclude File to exclude" | ||
748 | //usage: ) | ||
749 | //usage: "\n X File with names to exclude" | ||
750 | //usage: "\n T File with names to include" | ||
751 | //usage: ) | ||
752 | //usage: | ||
753 | //usage:#define tar_example_usage | ||
754 | //usage: "$ zcat /tmp/tarball.tar.gz | tar -xf -\n" | ||
755 | //usage: "$ tar -cf /tmp/tarball.tar /usr/local\n" | ||
756 | |||
757 | // Supported but aren't in --help: | ||
758 | // o no-same-owner | ||
759 | // p same-permissions | ||
760 | // k keep-old | ||
761 | // numeric-owner | ||
762 | // no-same-permissions | ||
763 | // overwrite | ||
764 | //IF_FEATURE_TAR_TO_COMMAND( | ||
765 | // to-command | ||
766 | //) | ||
767 | |||
741 | enum { | 768 | enum { |
742 | OPTBIT_KEEP_OLD = 8, | 769 | OPTBIT_KEEP_OLD = 8, |
743 | IF_FEATURE_TAR_CREATE( OPTBIT_CREATE ,) | 770 | IF_FEATURE_TAR_CREATE( OPTBIT_CREATE ,) |
diff --git a/include/unarchive.h b/include/unarchive.h index f3aa05d09..b4cf16082 100644 --- a/include/unarchive.h +++ b/include/unarchive.h | |||
@@ -113,6 +113,39 @@ typedef struct archive_handle_t { | |||
113 | #define ARCHIVE_O_TRUNC (1 << 8) | 113 | #define ARCHIVE_O_TRUNC (1 << 8) |
114 | 114 | ||
115 | 115 | ||
116 | /* POSIX tar Header Block, from POSIX 1003.1-1990 */ | ||
117 | #define TAR_BLOCK_SIZE 512 | ||
118 | #define NAME_SIZE 100 | ||
119 | #define NAME_SIZE_STR "100" | ||
120 | typedef struct tar_header_t { /* byte offset */ | ||
121 | char name[NAME_SIZE]; /* 0-99 */ | ||
122 | char mode[8]; /* 100-107 */ | ||
123 | char uid[8]; /* 108-115 */ | ||
124 | char gid[8]; /* 116-123 */ | ||
125 | char size[12]; /* 124-135 */ | ||
126 | char mtime[12]; /* 136-147 */ | ||
127 | char chksum[8]; /* 148-155 */ | ||
128 | char typeflag; /* 156-156 */ | ||
129 | char linkname[NAME_SIZE]; /* 157-256 */ | ||
130 | /* POSIX: "ustar" NUL "00" */ | ||
131 | /* GNU tar: "ustar " NUL */ | ||
132 | /* Normally it's defined as magic[6] followed by | ||
133 | * version[2], but we put them together to save code. | ||
134 | */ | ||
135 | char magic[8]; /* 257-264 */ | ||
136 | char uname[32]; /* 265-296 */ | ||
137 | char gname[32]; /* 297-328 */ | ||
138 | char devmajor[8]; /* 329-336 */ | ||
139 | char devminor[8]; /* 337-344 */ | ||
140 | char prefix[155]; /* 345-499 */ | ||
141 | char padding[12]; /* 500-512 (pad to exactly TAR_BLOCK_SIZE) */ | ||
142 | } tar_header_t; | ||
143 | struct BUG_tar_header { | ||
144 | char c[sizeof(tar_header_t) == TAR_BLOCK_SIZE ? 1 : -1]; | ||
145 | }; | ||
146 | |||
147 | |||
148 | |||
116 | /* Info struct unpackers can fill out to inform users of thing like | 149 | /* Info struct unpackers can fill out to inform users of thing like |
117 | * timestamps of unpacked files */ | 150 | * timestamps of unpacked files */ |
118 | typedef struct unpack_info_t { | 151 | typedef struct unpack_info_t { |
diff --git a/include/usage.src.h b/include/usage.src.h index f30edbc54..f84bb93c7 100644 --- a/include/usage.src.h +++ b/include/usage.src.h | |||
@@ -4273,54 +4273,6 @@ INSERT | |||
4273 | #define tac_full_usage "\n\n" \ | 4273 | #define tac_full_usage "\n\n" \ |
4274 | "Concatenate FILEs and print them in reverse" | 4274 | "Concatenate FILEs and print them in reverse" |
4275 | 4275 | ||
4276 | #define tar_trivial_usage \ | ||
4277 | "-[" IF_FEATURE_TAR_CREATE("c") "xt" IF_FEATURE_SEAMLESS_GZ("z") \ | ||
4278 | IF_FEATURE_SEAMLESS_BZ2("j") IF_FEATURE_SEAMLESS_LZMA("a") \ | ||
4279 | IF_FEATURE_SEAMLESS_Z("Z") IF_FEATURE_TAR_NOPRESERVE_TIME("m") "vO] " \ | ||
4280 | IF_FEATURE_TAR_FROM("[-X FILE] ") \ | ||
4281 | "[-f TARFILE] [-C DIR] [FILE]..." | ||
4282 | #define tar_full_usage "\n\n" \ | ||
4283 | IF_FEATURE_TAR_CREATE("Create, extract, ") \ | ||
4284 | IF_NOT_FEATURE_TAR_CREATE("Extract ") \ | ||
4285 | "or list files from a tar file\n" \ | ||
4286 | "\nOptions:" \ | ||
4287 | IF_FEATURE_TAR_CREATE( \ | ||
4288 | "\n c Create" \ | ||
4289 | ) \ | ||
4290 | "\n x Extract" \ | ||
4291 | "\n t List" \ | ||
4292 | "\nArchive format selection:" \ | ||
4293 | IF_FEATURE_SEAMLESS_GZ( \ | ||
4294 | "\n z Filter the archive through gzip" \ | ||
4295 | ) \ | ||
4296 | IF_FEATURE_SEAMLESS_BZ2( \ | ||
4297 | "\n j Filter the archive through bzip2" \ | ||
4298 | ) \ | ||
4299 | IF_FEATURE_SEAMLESS_LZMA( \ | ||
4300 | "\n a Filter the archive through lzma" \ | ||
4301 | ) \ | ||
4302 | IF_FEATURE_SEAMLESS_Z( \ | ||
4303 | "\n Z Filter the archive through compress" \ | ||
4304 | ) \ | ||
4305 | IF_FEATURE_TAR_NOPRESERVE_TIME( \ | ||
4306 | "\n m Do not restore mtime" \ | ||
4307 | ) \ | ||
4308 | "\nFile selection:" \ | ||
4309 | "\n f Name of TARFILE or \"-\" for stdin" \ | ||
4310 | "\n O Extract to stdout" \ | ||
4311 | IF_FEATURE_TAR_FROM( \ | ||
4312 | IF_FEATURE_TAR_LONG_OPTIONS( \ | ||
4313 | "\n exclude File to exclude" \ | ||
4314 | ) \ | ||
4315 | "\n X File with names to exclude" \ | ||
4316 | ) \ | ||
4317 | "\n C Change to DIR before operation" \ | ||
4318 | "\n v Verbose" \ | ||
4319 | |||
4320 | #define tar_example_usage \ | ||
4321 | "$ zcat /tmp/tarball.tar.gz | tar -xf -\n" \ | ||
4322 | "$ tar -cf /tmp/tarball.tar /usr/local\n" | ||
4323 | |||
4324 | #define taskset_trivial_usage \ | 4276 | #define taskset_trivial_usage \ |
4325 | "[-p] [MASK] [PID | PROG ARGS]" | 4277 | "[-p] [MASK] [PID | PROG ARGS]" |
4326 | #define taskset_full_usage "\n\n" \ | 4278 | #define taskset_full_usage "\n\n" \ |
diff --git a/procps/smemcap.c b/procps/smemcap.c index cdcc891a1..06cf93c85 100644 --- a/procps/smemcap.c +++ b/procps/smemcap.c | |||
@@ -20,42 +20,19 @@ | |||
20 | //config: a memory usage statistic tool. | 20 | //config: a memory usage statistic tool. |
21 | 21 | ||
22 | #include "libbb.h" | 22 | #include "libbb.h" |
23 | 23 | #include "unarchive.h" | |
24 | struct tar_header { | ||
25 | char name[100]; /* 0-99 */ | ||
26 | char mode[8]; /* 100-107 */ | ||
27 | char uid[8]; /* 108-115 */ | ||
28 | char gid[8]; /* 116-123 */ | ||
29 | char size[12]; /* 124-135 */ | ||
30 | char mtime[12]; /* 136-147 */ | ||
31 | char chksum[8]; /* 148-155 */ | ||
32 | char typeflag; /* 156-156 */ | ||
33 | char linkname[100]; /* 157-256 */ | ||
34 | /* POSIX: "ustar" NUL "00" */ | ||
35 | /* GNU tar: "ustar " NUL */ | ||
36 | /* Normally it's defined as magic[6] followed by | ||
37 | * version[2], but we put them together to save code. | ||
38 | */ | ||
39 | char magic[8]; /* 257-264 */ | ||
40 | char uname[32]; /* 265-296 */ | ||
41 | char gname[32]; /* 297-328 */ | ||
42 | char devmajor[8]; /* 329-336 */ | ||
43 | char devminor[8]; /* 337-344 */ | ||
44 | char prefix[155]; /* 345-499 */ | ||
45 | char padding[12]; /* 500-512 (pad to exactly TAR_512) */ | ||
46 | }; | ||
47 | 24 | ||
48 | struct fileblock { | 25 | struct fileblock { |
49 | struct fileblock *next; | 26 | struct fileblock *next; |
50 | char data[512]; | 27 | char data[TAR_BLOCK_SIZE]; |
51 | }; | 28 | }; |
52 | 29 | ||
53 | static void writeheader(const char *path, struct stat *sb, int type) | 30 | static void writeheader(const char *path, struct stat *sb, int type) |
54 | { | 31 | { |
55 | struct tar_header header; | 32 | struct tar_header_t header; |
56 | int i, sum; | 33 | int i, sum; |
57 | 34 | ||
58 | memset(&header, 0, 512); | 35 | memset(&header, 0, TAR_BLOCK_SIZE); |
59 | strcpy(header.name, path); | 36 | strcpy(header.name, path); |
60 | sprintf(header.mode, "%o", sb->st_mode & 0777); | 37 | sprintf(header.mode, "%o", sb->st_mode & 0777); |
61 | /* careful to not overflow fields! */ | 38 | /* careful to not overflow fields! */ |
@@ -73,11 +50,11 @@ static void writeheader(const char *path, struct stat *sb, int type) | |||
73 | * digits, followed by a NUL like the other fields... */ | 50 | * digits, followed by a NUL like the other fields... */ |
74 | header.chksum[7] = ' '; | 51 | header.chksum[7] = ' '; |
75 | sum = ' ' * 7; | 52 | sum = ' ' * 7; |
76 | for (i = 0; i < 512; i++) | 53 | for (i = 0; i < TAR_BLOCK_SIZE; i++) |
77 | sum += ((unsigned char*)&header)[i]; | 54 | sum += ((unsigned char*)&header)[i]; |
78 | sprintf(header.chksum, "%06o", sum); | 55 | sprintf(header.chksum, "%06o", sum); |
79 | 56 | ||
80 | xwrite(STDOUT_FILENO, &header, 512); | 57 | xwrite(STDOUT_FILENO, &header, TAR_BLOCK_SIZE); |
81 | } | 58 | } |
82 | 59 | ||
83 | static void archivefile(const char *path) | 60 | static void archivefile(const char *path) |
@@ -94,10 +71,10 @@ static void archivefile(const char *path) | |||
94 | cur = xzalloc(sizeof(*cur)); | 71 | cur = xzalloc(sizeof(*cur)); |
95 | *prev = cur; | 72 | *prev = cur; |
96 | prev = &cur->next; | 73 | prev = &cur->next; |
97 | r = full_read(fd, cur->data, 512); | 74 | r = full_read(fd, cur->data, TAR_BLOCK_SIZE); |
98 | if (r > 0) | 75 | if (r > 0) |
99 | size += r; | 76 | size += r; |
100 | } while (r == 512); | 77 | } while (r == TAR_BLOCK_SIZE); |
101 | 78 | ||
102 | /* write archive header */ | 79 | /* write archive header */ |
103 | fstat(fd, &s); | 80 | fstat(fd, &s); |
@@ -106,8 +83,8 @@ static void archivefile(const char *path) | |||
106 | writeheader(path, &s, '0'); | 83 | writeheader(path, &s, '0'); |
107 | 84 | ||
108 | /* dump file contents */ | 85 | /* dump file contents */ |
109 | for (cur = start; (int)size > 0; size -= 512) { | 86 | for (cur = start; (int)size > 0; size -= TAR_BLOCK_SIZE) { |
110 | xwrite(STDOUT_FILENO, cur->data, 512); | 87 | xwrite(STDOUT_FILENO, cur->data, TAR_BLOCK_SIZE); |
111 | start = cur; | 88 | start = cur; |
112 | cur = cur->next; | 89 | cur = cur->next; |
113 | free(start); | 90 | free(start); |