aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
Diffstat (limited to 'procps')
-rw-r--r--procps/smemcap.c43
1 files changed, 10 insertions, 33 deletions
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"
24struct 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
48struct fileblock { 25struct fileblock {
49 struct fileblock *next; 26 struct fileblock *next;
50 char data[512]; 27 char data[TAR_BLOCK_SIZE];
51}; 28};
52 29
53static void writeheader(const char *path, struct stat *sb, int type) 30static 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
83static void archivefile(const char *path) 60static 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);