aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2023-05-26 20:17:04 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2023-05-26 20:17:04 +0200
commit6d9427420bab4ef756444fc8800dbf56d7dacf7d (patch)
tree29e4cd2a8812999000a5b324daf308adee83ce25
parent5dcc443dba039b305a510c01883e9f34e42656ae (diff)
downloadbusybox-w32-6d9427420bab4ef756444fc8800dbf56d7dacf7d.tar.gz
busybox-w32-6d9427420bab4ef756444fc8800dbf56d7dacf7d.tar.bz2
busybox-w32-6d9427420bab4ef756444fc8800dbf56d7dacf7d.zip
od: -l,I,L indeed depend on sizeof(long), fix this
function old new delta .rodata 105255 105252 -3 od_main 1917 1901 -16 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-19) Total: -19 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--coreutils/od.c21
-rw-r--r--coreutils/od_bloaty.c10
-rwxr-xr-xtestsuite/od.tests37
3 files changed, 39 insertions, 29 deletions
diff --git a/coreutils/od.c b/coreutils/od.c
index 3684e4ed3..a7b1ba444 100644
--- a/coreutils/od.c
+++ b/coreutils/od.c
@@ -170,12 +170,17 @@ static const char *const add_strings[] ALIGN_PTR = {
170 "4/4 \" %15.7e\"" "\"\n\"", /* 7: f */ 170 "4/4 \" %15.7e\"" "\"\n\"", /* 7: f */
171 "4/4 \" %08x\"" "\"\n\"", /* 8: H, X */ 171 "4/4 \" %08x\"" "\"\n\"", /* 8: H, X */
172 "8/2 \" %04x\"" "\"\n\"", /* 9: h, x */ 172 "8/2 \" %04x\"" "\"\n\"", /* 9: h, x */
173 /* This probably also depends on word width of the arch (what is "long"?) */ 173 "4/4 \" %11d\"" "\"\n\"", /* 10: i */
174 /* should be "2/8" or "4/4" depending on sizeof(long)? */ 174 "4/4 \" %011o\"" "\"\n\"", /* 11: O */
175 "2/8 \" %20lld\"" "\"\n\"", /* 10: I, L, l */ 175 "8/2 \" %6d\"" "\"\n\"", /* 12: s */
176 "4/4 \" %11d\"" "\"\n\"", /* 11: i */ 176 /* -I,L,l: depend on word width of the arch (what is "long"?) */
177 "4/4 \" %011o\"" "\"\n\"", /* 12: O */ 177#if ULONG_MAX > 0xffffffff
178 "8/2 \" %6d\"" "\"\n\"", /* 13: s */ 178 "2/8 \" %20lld\"" "\"\n\"", /* 13: I, L, l */
179#define L_ 13
180#else
181 /* 32-bit arch: -I,L,l are the same as -i */
182#define L_ 10
183#endif
179}; 184};
180 185
181static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxsv"; 186static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxsv";
@@ -183,8 +188,8 @@ static const char od_opts[] ALIGN1 = "aBbcDdeFfHhIiLlOoXxsv";
183static const char od_o2si[] ALIGN1 = { 188static const char od_o2si[] ALIGN1 = {
184 0, 1, 2, 3, 5, /* aBbcD */ 189 0, 1, 2, 3, 5, /* aBbcD */
185 4, 6, 6, 7, 8, /* deFfH */ 190 4, 6, 6, 7, 8, /* deFfH */
186 9, 10, 11, 10, 10, /* hIiLl */ 191 9, L_, 10, L_, L_, /* hIiLl */
187 12, 1, 8, 9, 13 /* OoXxs */ 192 11, 1, 8, 9, 12 /* OoXxs */
188}; 193};
189 194
190int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 195int od_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
diff --git a/coreutils/od_bloaty.c b/coreutils/od_bloaty.c
index 2782adbf6..e886a4ed2 100644
--- a/coreutils/od_bloaty.c
+++ b/coreutils/od_bloaty.c
@@ -1257,11 +1257,15 @@ int od_main(int argc UNUSED_PARAM, char **argv)
1257 if (opt & OPT_f) decode_format_string("fF"); 1257 if (opt & OPT_f) decode_format_string("fF");
1258 if (opt & (OPT_h|OPT_x)) decode_format_string("x2"); 1258 if (opt & (OPT_h|OPT_x)) decode_format_string("x2");
1259 if (opt & (OPT_H|OPT_X)) decode_format_string("xI"); 1259 if (opt & (OPT_H|OPT_X)) decode_format_string("xI");
1260 /* -I,L,l: depend on word width of the arch (what is "long"?) */
1261#if ULONG_MAX > 0xffffffff
1260 if (opt & OPT_i) decode_format_string("dI"); 1262 if (opt & OPT_i) decode_format_string("dI");
1263 if (opt & (OPT_I|OPT_l|OPT_L)) decode_format_string("dL");
1264#else
1265 /* 32-bit arch: -I,L,l are the same as -i */
1266 if (opt & (OPT_i|OPT_I|OPT_l|OPT_L)) decode_format_string("dI");
1267#endif
1261 if (opt & OPT_j) n_bytes_to_skip = xstrtooff_sfx(str_j, 0, bkm_suffixes); 1268 if (opt & OPT_j) n_bytes_to_skip = xstrtooff_sfx(str_j, 0, bkm_suffixes);
1262 /* This probably also depends on word width of the arch (what is "long"?) */
1263 /* should be "d4" or "d8" depending on sizeof(long)? */
1264 if (opt & (OPT_I|OPT_l|OPT_L)) decode_format_string("d8");
1265 if (opt & (OPT_o|OPT_B)) decode_format_string("o2"); 1269 if (opt & (OPT_o|OPT_B)) decode_format_string("o2");
1266 if (opt & OPT_O) decode_format_string("oI"); 1270 if (opt & OPT_O) decode_format_string("oI");
1267 while (lst_t) { 1271 while (lst_t) {
diff --git a/testsuite/od.tests b/testsuite/od.tests
index fce66efbb..4f245a7e8 100755
--- a/testsuite/od.tests
+++ b/testsuite/od.tests
@@ -8,11 +8,11 @@
8 8
9input="$(printf '\001\002\003\nABC\xfe')" 9input="$(printf '\001\002\003\nABC\xfe')"
10 10
11le=false 11little_endian=false
12{ printf '\0\1' | od -s | grep -q 256; } && le=true 12{ printf '\0\1' | od -s | grep -q 256; } && little_endian=true
13readonly le 13readonly little_endian
14 14
15$le || SKIP=1 15$little_endian || SKIP=1
16testing "od (little-endian)" \ 16testing "od (little-endian)" \
17 "od" \ 17 "od" \
18"\ 18"\
@@ -70,7 +70,7 @@ testing "od -B" \
70 "" "$input" 70 "" "$input"
71SKIP= 71SKIP=
72 72
73$le || SKIP=1 73$little_endian || SKIP=1
74testing "od -o (little-endian)" \ 74testing "od -o (little-endian)" \
75 "od -o" \ 75 "od -o" \
76"\ 76"\
@@ -98,7 +98,7 @@ testing "od -c" \
98 "" "$input" 98 "" "$input"
99SKIP= 99SKIP=
100 100
101$le || SKIP=1 101$little_endian || SKIP=1
102testing "od -d (little-endian)" \ 102testing "od -d (little-endian)" \
103 "od -d" \ 103 "od -d" \
104"\ 104"\
@@ -108,7 +108,7 @@ testing "od -d (little-endian)" \
108 "" "$input" 108 "" "$input"
109SKIP= 109SKIP=
110 110
111$le || SKIP=1 111$little_endian || SKIP=1
112testing "od -D (little-endian)" \ 112testing "od -D (little-endian)" \
113 "od -D" \ 113 "od -D" \
114"\ 114"\
@@ -119,7 +119,7 @@ testing "od -D (little-endian)" \
119SKIP= 119SKIP=
120 120
121optional !DESKTOP #DESKTOP: unrecognized option: e 121optional !DESKTOP #DESKTOP: unrecognized option: e
122$le || SKIP=1 122$little_endian || SKIP=1
123testing "od -e (!DESKTOP little-endian)" \ 123testing "od -e (!DESKTOP little-endian)" \
124 "od -e" \ 124 "od -e" \
125"\ 125"\
@@ -130,7 +130,7 @@ testing "od -e (!DESKTOP little-endian)" \
130SKIP= 130SKIP=
131 131
132optional !DESKTOP #DESKTOP: unrecognized option: F 132optional !DESKTOP #DESKTOP: unrecognized option: F
133$le || SKIP=1 133$little_endian || SKIP=1
134testing "od -F (!DESKTOP little-endian)" \ 134testing "od -F (!DESKTOP little-endian)" \
135 "od -F" \ 135 "od -F" \
136"\ 136"\
@@ -140,7 +140,7 @@ testing "od -F (!DESKTOP little-endian)" \
140 "" "$input" 140 "" "$input"
141SKIP= 141SKIP=
142 142
143$le || SKIP=1 143$little_endian || SKIP=1
144testing "od -f (little-endian)" \ 144testing "od -f (little-endian)" \
145 "od -f" \ 145 "od -f" \
146"\ 146"\
@@ -150,7 +150,7 @@ testing "od -f (little-endian)" \
150 "" "$input" 150 "" "$input"
151SKIP= 151SKIP=
152 152
153$le || SKIP=1 153$little_endian || SKIP=1
154testing "od -H (little-endian)" \ 154testing "od -H (little-endian)" \
155 "od -H" \ 155 "od -H" \
156"\ 156"\
@@ -160,7 +160,7 @@ testing "od -H (little-endian)" \
160 "" "$input" 160 "" "$input"
161SKIP= 161SKIP=
162 162
163$le || SKIP=1 163$little_endian || SKIP=1
164testing "od -X (little-endian)" \ 164testing "od -X (little-endian)" \
165 "od -X" \ 165 "od -X" \
166"\ 166"\
@@ -170,7 +170,7 @@ testing "od -X (little-endian)" \
170 "" "$input" 170 "" "$input"
171SKIP= 171SKIP=
172 172
173$le || SKIP=1 173$little_endian || SKIP=1
174testing "od -h (little-endian)" \ 174testing "od -h (little-endian)" \
175 "od -h" \ 175 "od -h" \
176"\ 176"\
@@ -180,7 +180,7 @@ testing "od -h (little-endian)" \
180 "" "$input" 180 "" "$input"
181SKIP= 181SKIP=
182 182
183$le || SKIP=1 183$little_endian || SKIP=1
184testing "od -x (little-endian)" \ 184testing "od -x (little-endian)" \
185 "od -x" \ 185 "od -x" \
186"\ 186"\
@@ -190,7 +190,7 @@ testing "od -x (little-endian)" \
190 "" "$input" 190 "" "$input"
191SKIP= 191SKIP=
192 192
193$le || SKIP=1 193$little_endian || SKIP=1
194testing "od -i (little-endian)" \ 194testing "od -i (little-endian)" \
195 "od -i" \ 195 "od -i" \
196"\ 196"\
@@ -200,7 +200,7 @@ testing "od -i (little-endian)" \
200 "" "$input" 200 "" "$input"
201SKIP= 201SKIP=
202 202
203$le || SKIP=1 203$little_endian || SKIP=1
204testing "od -O (little-endian)" \ 204testing "od -O (little-endian)" \
205 "od -O" \ 205 "od -O" \
206"\ 206"\
@@ -210,8 +210,9 @@ testing "od -O (little-endian)" \
210 "" "$input" 210 "" "$input"
211SKIP= 211SKIP=
212 212
213# This probably also depends on word width of the arch (what is "long"?) 213# 32-bit?
214$le || SKIP=1 214printf '00000000' | od -l | grep -q '808464432 *808464432' && SKIP=1 #yes, skip
215$little_endian || SKIP=1
215testing "od -I (little-endian)" \ 216testing "od -I (little-endian)" \
216 "od -I" \ 217 "od -I" \
217"\ 218"\