aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2021-06-24 09:31:57 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2021-06-24 09:31:57 +0200
commit87c40cf4de435d1b19b7fb545a495542c6eaf820 (patch)
tree3eaaec39b88cff99d5beee4caac961d7b2b4c7f7
parent9468ea06d2445f774dd923fdfdea04209984fbf4 (diff)
downloadbusybox-w32-87c40cf4de435d1b19b7fb545a495542c6eaf820.tar.gz
busybox-w32-87c40cf4de435d1b19b7fb545a495542c6eaf820.tar.bz2
busybox-w32-87c40cf4de435d1b19b7fb545a495542c6eaf820.zip
e2fsprogs: code shrink
function old new delta print_e2flags_long - 109 +109 list_attributes 248 232 -16 print_e2flags 169 47 -122 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/2 up/down: 109/-138) Total: -29 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--e2fsprogs/e2fs_lib.c59
-rw-r--r--e2fsprogs/e2fs_lib.h5
-rw-r--r--e2fsprogs/lsattr.c4
3 files changed, 36 insertions, 32 deletions
diff --git a/e2fsprogs/e2fs_lib.c b/e2fsprogs/e2fs_lib.c
index 0ec4eb2f2..e32336ae6 100644
--- a/e2fsprogs/e2fs_lib.c
+++ b/e2fsprogs/e2fs_lib.c
@@ -98,36 +98,41 @@ static const char e2attr_flags_lname[] ALIGN1 =
98 "Verity" "\0" 98 "Verity" "\0"
99 /* Another trailing NUL is added by compiler */; 99 /* Another trailing NUL is added by compiler */;
100 100
101void print_e2flags(FILE *f, unsigned flags, unsigned options) 101void print_e2flags_long(unsigned flags)
102{ 102{
103 const uint32_t *fv; 103 const uint32_t *fv;
104 const char *fn; 104 const char *fn;
105 int first = 1;
105 106
106 fv = e2attr_flags_value; 107 fv = e2attr_flags_value;
107 if (options & PFOPT_LONG) { 108 fn = e2attr_flags_lname;
108 int first = 1; 109 do {
109 fn = e2attr_flags_lname; 110 if (flags & *fv) {
110 do { 111 if (!first)
111 if (flags & *fv) { 112 fputs(", ", stdout);
112 if (!first) 113 fputs(fn, stdout);
113 fputs(", ", f); 114 first = 0;
114 fputs(fn, f); 115 }
115 first = 0; 116 fv++;
116 } 117 fn += strlen(fn) + 1;
117 fv++; 118 } while (*fn);
118 fn += strlen(fn) + 1; 119 if (first)
119 } while (*fn); 120 fputs("---", stdout);
120 if (first) 121}
121 fputs("---", f); 122
122 } else { 123void print_e2flags(unsigned flags)
123 fn = e2attr_flags_sname; 124{
124 do { 125 const uint32_t *fv;
125 char c = '-'; 126 const char *fn;
126 if (flags & *fv) 127
127 c = *fn; 128 fv = e2attr_flags_value;
128 fputc(c, f); 129 fn = e2attr_flags_sname;
129 fv++; 130 do {
130 fn++; 131 char c = '-';
131 } while (*fn); 132 if (flags & *fv)
132 } 133 c = *fn;
134 putchar(c);
135 fv++;
136 fn++;
137 } while (*fn);
133} 138}
diff --git a/e2fsprogs/e2fs_lib.h b/e2fsprogs/e2fs_lib.h
index 1a5d092c0..879272f44 100644
--- a/e2fsprogs/e2fs_lib.h
+++ b/e2fsprogs/e2fs_lib.h
@@ -16,10 +16,9 @@ int iterate_on_dir(const char *dir_name,
16 int FAST_FUNC (*func)(const char *, struct dirent *, void *), 16 int FAST_FUNC (*func)(const char *, struct dirent *, void *),
17 void *private); 17 void *private);
18 18
19/* Must be 1 for compatibility with 'int long_format'. */
20#define PFOPT_LONG 1
21/* Print file attributes on an ext2 file system */ 19/* Print file attributes on an ext2 file system */
22void print_e2flags(FILE *f, unsigned flags, unsigned options); 20void print_e2flags_long(unsigned flags);
21void print_e2flags(unsigned flags);
23 22
24extern const uint32_t e2attr_flags_value[]; 23extern const uint32_t e2attr_flags_value[];
25extern const char e2attr_flags_sname[]; 24extern const char e2attr_flags_sname[];
diff --git a/e2fsprogs/lsattr.c b/e2fsprogs/lsattr.c
index 545afa7f5..c9f353ce5 100644
--- a/e2fsprogs/lsattr.c
+++ b/e2fsprogs/lsattr.c
@@ -83,10 +83,10 @@ static void list_attributes(const char *name)
83 83
84 if (option_mask32 & OPT_PF_LONG) { 84 if (option_mask32 & OPT_PF_LONG) {
85 printf("%-28s ", name); 85 printf("%-28s ", name);
86 print_e2flags(stdout, fsflags, PFOPT_LONG); 86 print_e2flags_long(fsflags);
87 bb_putchar('\n'); 87 bb_putchar('\n');
88 } else { 88 } else {
89 print_e2flags(stdout, fsflags, 0); 89 print_e2flags(fsflags);
90 printf(" %s\n", name); 90 printf(" %s\n", name);
91 } 91 }
92 92