Compare commits
552
Commits
1_15_stable
...
1_16_2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b5656e9bb | ||
|
|
d0db975a9f | ||
|
|
58cdca3984 | ||
|
|
e52b735231 | ||
|
|
da879ec2e9 | ||
|
|
1aaf1cb096 | ||
|
|
24928ffd8d | ||
|
|
3581c62515 | ||
|
|
46685a46bb | ||
|
|
307b24c851 | ||
|
|
2315c8854c | ||
|
|
6b01b71e83 | ||
|
|
9f93d62192 | ||
|
|
5da9f96ad8 | ||
|
|
dfd38a480b | ||
|
|
24dc9ab2f4 | ||
|
|
9882b34fe2 | ||
|
|
31416d589e | ||
|
|
8b8d32ea56 | ||
|
|
6f99c91e43 | ||
|
|
feadfe742a | ||
|
|
94ca6943bc | ||
|
|
0d478334b3 | ||
|
|
2e5fa4a69d | ||
|
|
94a6fd1eeb | ||
|
|
404f14407c | ||
|
|
4de4cb6b9b | ||
|
|
b32aa0c274 | ||
|
|
fe1ce2e43e | ||
|
|
b7a044043c | ||
|
|
302af9e3d1 | ||
|
|
7be97c5b6b | ||
|
|
573ba4e92e | ||
|
|
9e0879a1cb | ||
|
|
032bf65533 | ||
|
|
d4a7728dc3 | ||
|
|
f3fc9ac166 | ||
|
|
9c3b84a304 | ||
|
|
b972f94957 | ||
|
|
33f9dc08e5 | ||
|
|
96a6bdcb77 | ||
|
|
57f46c1afd | ||
|
|
9b20adca4b | ||
|
|
5b9a910749 | ||
|
|
e208279722 | ||
|
|
1e9bc2603d | ||
|
|
d084cb9dc7 | ||
|
|
a40f0624db | ||
|
|
662078f9fd | ||
|
|
60b9524bf7 | ||
|
|
bb16f57e5d | ||
|
|
4fc82e0067 | ||
|
|
c041e239db | ||
|
|
85d286efc8 | ||
|
|
25d9b91d94 | ||
|
|
03d81ef43a | ||
|
|
03dad22f8a | ||
|
|
045f4ad92c | ||
|
|
7306727d1b | ||
|
|
6c93b24ce9 | ||
|
|
e89a241b9e | ||
|
|
f3ec0fb1b4 | ||
|
|
b70cef71eb | ||
|
|
f2c8aa6676 | ||
|
|
cb23d93c68 | ||
|
|
385cc59117 | ||
|
|
65d722bb0d | ||
|
|
12628b7797 | ||
|
|
725b5a387a | ||
|
|
38d3e64d25 | ||
|
|
1fbcb805a3 | ||
|
|
ce9b97f18b | ||
|
|
8ced1e5dc5 | ||
|
|
4653e442ba | ||
|
|
02dd96f688 | ||
|
|
607f65d171 | ||
|
|
93ac7d8468 | ||
|
|
dc698bb038 | ||
|
|
0681137972 | ||
|
|
6fd42b3d00 | ||
|
|
866710a056 | ||
|
|
8cd04d1cb6 | ||
|
|
c3c1fb676b | ||
|
|
999e442d5c | ||
|
|
f422a722bb | ||
|
|
9037787eae | ||
|
|
ef3817c6dc | ||
|
|
b8f0e8036d | ||
|
|
ae47335dc4 | ||
|
|
053ffeeeda | ||
|
|
0c58cc706f | ||
|
|
6959f6bc23 | ||
|
|
5e3b14069e | ||
|
|
695fa51c80 | ||
|
|
06667f21d6 | ||
|
|
ede737b7cf | ||
|
|
79ae534ac7 | ||
|
|
aa4977d8e5 | ||
|
|
86350f8d5f | ||
|
|
bde70230e8 | ||
|
|
d0f601f066 | ||
|
|
839fd71077 | ||
|
|
251912443c | ||
|
|
af1c8e8be0 | ||
|
|
074e8dcba7 | ||
|
|
28055028a7 | ||
|
|
d2b1ba6fde | ||
|
|
4928f3b90b | ||
|
|
40e5a30b66 | ||
|
|
2ec91aead5 | ||
|
|
a355da0775 | ||
|
|
a4899efd03 | ||
|
|
4168fdd8e6 | ||
|
|
d6459685c1 | ||
|
|
2d3253d1f9 | ||
|
|
d498ff0ac4 | ||
|
|
510f56aa6f | ||
|
|
0b002812a8 | ||
|
|
185e691ec1 | ||
|
|
c066472b0c | ||
|
|
1ee5afdce2 | ||
|
|
f25252c69e | ||
|
|
2e36eb8f27 | ||
|
|
d9109e3b48 | ||
|
|
a9aaeda0e9 | ||
|
|
e4844b8a5f | ||
|
|
61313117a0 | ||
|
|
bfc2a32d88 | ||
|
|
dd6673bac5 | ||
|
|
8a428d9b15 | ||
|
|
d2fe69f9dc | ||
|
|
bd1de181ad | ||
|
|
6879a7ae43 | ||
|
|
4b6abf6655 | ||
|
|
afa2d33aa4 | ||
|
|
e99c8d2ef5 | ||
|
|
8a936cfab7 | ||
|
|
425ad9c93b | ||
|
|
dbc6a7a8fd | ||
|
|
cc428147c1 | ||
|
|
b7a0e13d1c | ||
|
|
cb37637b47 | ||
|
|
4e60f304d4 | ||
|
|
d7171c1140 | ||
|
|
1a8de6f8a2 | ||
|
|
18f89128e5 | ||
|
|
bcc6ec9b7e | ||
|
|
6be918d0ae | ||
|
|
78fcec4dc7 | ||
|
|
aa42d13e32 | ||
|
|
31e2e7b863 | ||
|
|
1315c30fef | ||
|
|
800ff7cc75 | ||
|
|
9f5a577a32 | ||
|
|
d2c879da25 | ||
|
|
a3aa3e3095 | ||
|
|
4662de0511 | ||
|
|
8656676a21 | ||
|
|
46a1477107 | ||
|
|
11a802a0fa | ||
|
|
982bc7176d | ||
|
|
f92874e747 | ||
|
|
a7329667b4 | ||
|
|
14b0f4feb3 | ||
|
|
e9ac32a067 | ||
|
|
359da5e3be | ||
|
|
285ad155c4 | ||
|
|
7a7b034482 | ||
|
|
6b5accbfc1 | ||
|
|
6dc0ace109 | ||
|
|
6a110c969f | ||
|
|
7cb1d6ccf3 | ||
|
|
907647fb15 | ||
|
|
4bd5189370 | ||
|
|
ebde6f10fb | ||
|
|
f91e63cbc3 | ||
|
|
386960a38e | ||
|
|
fae9f499b2 | ||
|
|
8eda4a9005 | ||
|
|
d0f9d0ed58 | ||
|
|
1284774d60 | ||
|
|
cdeda16ee4 | ||
|
|
dcbfaba264 | ||
|
|
bf22475e95 | ||
|
|
d43d628f8b | ||
|
|
f94c9bf288 | ||
|
|
2ce42e98d7 | ||
|
|
068d386a6c | ||
|
|
76bc2d6deb | ||
|
|
0337e038a9 | ||
|
|
cd71683ae6 | ||
|
|
e992bae6f9 | ||
|
|
86cfb70ca5 | ||
|
|
160b9ca731 | ||
|
|
1361aa2e2d | ||
|
|
57be1eefab | ||
|
|
1e1136025b | ||
|
|
650a7011a8 | ||
|
|
5b6fe34cee | ||
|
|
fa1e7177fb | ||
|
|
b2e5fc35eb | ||
|
|
18221506e5 | ||
|
|
b24c1139fb | ||
|
|
b1278a38bc | ||
|
|
9cc60d7e6b | ||
|
|
f42fa1b21e | ||
|
|
75b7397675 | ||
|
|
363e89b1ee | ||
|
|
ca6c7e42f9 | ||
|
|
887d963037 | ||
|
|
c14bf21332 | ||
|
|
6ccaa23f2b | ||
|
|
8d580c72f4 | ||
|
|
74f8e7810b | ||
|
|
4c06531d5e | ||
|
|
0d56568654 | ||
|
|
11f3a8b7ed | ||
|
|
b1585064fd | ||
|
|
d095fd4d95 | ||
|
|
102ff76c84 | ||
|
|
85164fa06e | ||
|
|
c270454f8f | ||
|
|
ad7d94bdc7 | ||
|
|
8684cbb5cc | ||
|
|
5b0a7f1a6e | ||
|
|
995f15452a | ||
|
|
f3e2818895 | ||
|
|
160746b603 | ||
|
|
5b2db97703 | ||
|
|
d8389ad760 | ||
|
|
00243b0a1a | ||
|
|
a7ccdeef39 | ||
|
|
647553a4fc | ||
|
|
ff1822aed1 | ||
|
|
6e54249e05 | ||
|
|
72ac6901f4 | ||
|
|
0d7e2e7c3e | ||
|
|
389cca4b9e | ||
|
|
a307af1af6 | ||
|
|
cc8b6871a7 | ||
|
|
e3600a042e | ||
|
|
5799248976 | ||
|
|
6331cf059c | ||
|
|
f4fee418ae | ||
|
|
ab19ede655 | ||
|
|
c096a6c208 | ||
|
|
13ad90627c | ||
|
|
b6d221ac9c | ||
|
|
002bdc3e2a | ||
|
|
391dd92ce2 | ||
|
|
c3896850f7 | ||
|
|
6528abeb6a | ||
|
|
1e9ac9f685 | ||
|
|
adc08ef194 | ||
|
|
8bd0af9962 | ||
|
|
bbd423530f | ||
|
|
f5914992f3 | ||
|
|
f5c2f72917 | ||
|
|
44f8d01399 | ||
|
|
bf40f564ae | ||
|
|
5a34d021cb | ||
|
|
6eaac025a1 | ||
|
|
9be4f31da0 | ||
|
|
6e8e666bd9 | ||
|
|
1612c757d0 | ||
|
|
27094cac7f | ||
|
|
245a4f84be | ||
|
|
0d8c0b810e | ||
|
|
8fdf066323 | ||
|
|
6cf7f01256 | ||
|
|
85bb843f47 | ||
|
|
05ed00f09a | ||
|
|
eacbca5735 | ||
|
|
78824f38a3 | ||
|
|
caa79406aa | ||
|
|
f8a73bfa33 | ||
|
|
b57eee8beb | ||
|
|
ded688c6f6 | ||
|
|
692bcff577 | ||
|
|
68c67469aa | ||
|
|
c6fb2a6b5f | ||
|
|
26c64bade8 | ||
|
|
53283adb24 | ||
|
|
8131eea3dc | ||
|
|
0d8ea64af6 | ||
|
|
d784b65be7 | ||
|
|
893009644f | ||
|
|
662e8b79d0 | ||
|
|
e62a2463ec | ||
|
|
4214f8b537 | ||
|
|
fe4e23f9de | ||
|
|
95a036e125 | ||
|
|
85ca327529 | ||
|
|
1f6d2307ba | ||
|
|
4dc08262cf | ||
|
|
00f0ef4a0c | ||
|
|
e039e689e3 | ||
|
|
a48308701a | ||
|
|
ca254490d7 | ||
|
|
b04f058e76 | ||
|
|
933993a461 | ||
|
|
6531f0923b | ||
|
|
b35e3a8612 | ||
|
|
21a542d7d7 | ||
|
|
d83bbf4193 | ||
|
|
eb62d7c383 | ||
|
|
1502a8b4ce | ||
|
|
12450dbeef | ||
|
|
52b971f516 | ||
|
|
b204e6b61a | ||
|
|
dac863a4cc | ||
|
|
7b28415483 | ||
|
|
727e1b536e | ||
|
|
d31a8793eb | ||
|
|
0f91b3d0dc | ||
|
|
180f585ac3 | ||
|
|
9d71fc6381 | ||
|
|
a17eeb847e | ||
|
|
77c066ea5c | ||
|
|
30f3c1d5fd | ||
|
|
f645037ffb | ||
|
|
b87d972817 | ||
|
|
6f2ebae843 | ||
|
|
0939f2ebd2 | ||
|
|
4b8b37f981 | ||
|
|
17c838bc6d | ||
|
|
1dacfbb1f4 | ||
|
|
337a31b074 | ||
|
|
50be9631e1 | ||
|
|
d93fc61725 | ||
|
|
ca22cda709 | ||
|
|
9d57a8073a | ||
|
|
11c12c4720 | ||
|
|
a7a1fd02cb | ||
|
|
56b3eec162 | ||
|
|
f2cbb03a37 | ||
|
|
7b4cd6f7b0 | ||
|
|
c1947f18f5 | ||
|
|
c0dab37d0a | ||
|
|
6935ec9c0b | ||
|
|
f125b6d341 | ||
|
|
46e364dbfe | ||
|
|
09bbb2892d | ||
|
|
c1ab01b61b | ||
|
|
838e07aace | ||
|
|
149a32a19b | ||
|
|
3945bc1534 | ||
|
|
481ca9604d | ||
|
|
a46317b6f3 | ||
|
|
010fb00708 | ||
|
|
eaba48467c | ||
|
|
1d6e4473fa | ||
|
|
ece01ee8ca | ||
|
|
2ee2724a41 | ||
|
|
2288d86a54 | ||
|
|
5e1dbd5bc3 | ||
|
|
e707a3000b | ||
|
|
a4e4a65484 | ||
|
|
c708a6d000 | ||
|
|
82d6433abe | ||
|
|
cbeb452824 | ||
|
|
95484c8706 | ||
|
|
69f2e2cdeb | ||
|
|
05647b5551 | ||
|
|
3ef4f77620 | ||
|
|
a8df4c09fb | ||
|
|
aaa22d2493 | ||
|
|
36df04837a | ||
|
|
3b3ccdc5bc | ||
|
|
8bc7f2c5aa | ||
|
|
c0836530f1 | ||
|
|
e8405619fa | ||
|
|
f9d3a91a89 | ||
|
|
77da1cae94 | ||
|
|
f37eb3999b | ||
|
|
7673e7fda4 | ||
|
|
28736c36ca | ||
|
|
69d9edc6f8 | ||
|
|
6a8cfdca99 | ||
|
|
9c2708ebf9 | ||
|
|
7d8ab846d1 | ||
|
|
4588775182 | ||
|
|
823b4e6f26 | ||
|
|
8dbe9bba8e | ||
|
|
2ace0ad2d7 | ||
|
|
944d275175 | ||
|
|
f5a295d5a8 | ||
|
|
4ebc76c8a2 | ||
|
|
ccb1959aa5 | ||
|
|
db67a20595 | ||
|
|
7eabffafa5 | ||
|
|
04bb6b6a5a | ||
|
|
a68bd4b2ae | ||
|
|
a1a3972f28 | ||
|
|
4e5b07b0fe | ||
|
|
d31575a3ae | ||
|
|
94466b8b8c | ||
|
|
0bf44d00a4 | ||
|
|
76ace254e1 | ||
|
|
3c39e702d0 | ||
|
|
4db34d6e27 | ||
|
|
8c66a9d07a | ||
|
|
e7670ff81d | ||
|
|
0e5e4eaf7b | ||
|
|
f26e98f4e9 | ||
|
|
84e1caf51c | ||
|
|
e3c6e19015 | ||
|
|
3dc4a3e4dc | ||
|
|
69d1f45c16 | ||
|
|
cbe0b7fb59 | ||
|
|
20b3d144e9 | ||
|
|
3ea2e82dc7 | ||
|
|
a05b2b856b | ||
|
|
dea478855f | ||
|
|
3f11f35124 | ||
|
|
219757fee9 | ||
|
|
6332151641 | ||
|
|
784d095877 | ||
|
|
ef5bc2c39c | ||
|
|
adf922ec28 | ||
|
|
a7bb3c1396 | ||
|
|
57ce977a97 | ||
|
|
d5fddcd57f | ||
|
|
d427689eee | ||
|
|
7bb346f23c | ||
|
|
8d680b5114 | ||
|
|
07697859ae | ||
|
|
dcd27abcc4 | ||
|
|
be168b1197 | ||
|
|
301f5ecb8d | ||
|
|
4d8873f997 | ||
|
|
b618dba103 | ||
|
|
76622dbd16 | ||
|
|
fd2dc53ba4 | ||
|
|
1d63f046d0 | ||
|
|
cae409c6aa | ||
|
|
ffd4774ad2 | ||
|
|
0683d4d633 | ||
|
|
76c7d9500a | ||
|
|
87c150c7cc | ||
|
|
26ff18b424 | ||
|
|
88a37689a7 | ||
|
|
f228913fed | ||
|
|
963f52fc59 | ||
|
|
acabf8fcb8 | ||
|
|
3a7034c27b | ||
|
|
1b34d4f0b1 | ||
|
|
c34c033c42 | ||
|
|
8f7a6d294f | ||
|
|
2f3f09c287 | ||
|
|
db9c57eed1 | ||
|
|
e74aaf9385 | ||
|
|
6c750f1518 | ||
|
|
48f116198d | ||
|
|
67f7186403 | ||
|
|
4ea0ca8193 | ||
|
|
8f88d85e34 | ||
|
|
726e1a04f7 | ||
|
|
e305c28285 | ||
|
|
c297ea97e2 | ||
|
|
21d87d495a | ||
|
|
0800e3af75 | ||
|
|
7188540257 | ||
|
|
2f7894b1bb | ||
|
|
ecb179b6d7 | ||
|
|
606291beab | ||
|
|
1f27ab0d4b | ||
|
|
8d338173a4 | ||
|
|
844f990926 | ||
|
|
91836baf85 | ||
|
|
af3fd14e4d | ||
|
|
ed4ff0e8cb | ||
|
|
200d522fb8 | ||
|
|
4ff1ce0639 | ||
|
|
11c8238d1b | ||
|
|
d75295c80b | ||
|
|
69b1cef921 | ||
|
|
bc3e9479c2 | ||
|
|
46a0be5304 | ||
|
|
d8dd25a2a7 | ||
|
|
3e02050314 | ||
|
|
532609e36e | ||
|
|
9aff29997e | ||
|
|
2bf6634ef4 | ||
|
|
b410d4ada7 | ||
|
|
f00cfdfae5 | ||
|
|
ae0045e31a | ||
|
|
885583ebe3 | ||
|
|
d57d62686d | ||
|
|
1166d7b136 | ||
|
|
b0d63383dd | ||
|
|
795633463a | ||
|
|
ddf7850f2b | ||
|
|
8dc0e1929e | ||
|
|
f2c184be83 | ||
|
|
ba98603264 | ||
|
|
772c2db971 | ||
|
|
aa7da73880 | ||
|
|
7649bd024c | ||
|
|
6683745bf7 | ||
|
|
c541a8955d | ||
|
|
fe73798135 | ||
|
|
27726cb6aa | ||
|
|
873273da94 | ||
|
|
3a0f6f2328 | ||
|
|
ae357bd713 | ||
|
|
0052882200 | ||
|
|
56573cb4f7 | ||
|
|
db4a67628d | ||
|
|
33d8d08f78 | ||
|
|
d069e5398d | ||
|
|
e66ccfaa2c | ||
|
|
108b8c5367 | ||
|
|
db57fc22a6 | ||
|
|
62298ab13d | ||
|
|
40c221334f | ||
|
|
0c6914e50c | ||
|
|
f9c814b0ee | ||
|
|
386bc9fda3 | ||
|
|
3de3f57c6d | ||
|
|
043b1e5d99 | ||
|
|
5370bfb123 | ||
|
|
90a9904e9e | ||
|
|
1f7c167b23 | ||
|
|
6db4784d27 | ||
|
|
2cc709139e | ||
|
|
ed1667e8ee | ||
|
|
cfc216345e | ||
|
|
4b624d0770 | ||
|
|
44f174e61b | ||
|
|
a00329ca8e | ||
|
|
630dde1cef | ||
|
|
1249dbb2c7 | ||
|
|
a9c9bf5055 | ||
|
|
0aec9ff6b8 | ||
|
|
7218af9f83 | ||
|
|
22cbfbd996 | ||
|
|
b9762922d1 | ||
|
|
ecc2a2e015 | ||
|
|
9f2e82ad2e | ||
|
|
c8334a40c9 | ||
|
|
b6c8434896 | ||
|
|
e6c483ec30 | ||
|
|
0a130d510d | ||
|
|
7f2149489f | ||
|
|
b34759251d | ||
|
|
33d7b72d33 | ||
|
|
691161a7a7 | ||
|
|
ca899efd6c | ||
|
|
bcb163d8f8 | ||
|
|
a12af2d9f3 | ||
|
|
bd73f1d85a |
No files matched your search
@@ -171,3 +171,6 @@ Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
|
||||
|
||||
Mike Frysinger <vapier@gentoo.org>
|
||||
initial e2fsprogs, printenv, setarch, sum, misc
|
||||
|
||||
Jie Zhang <jie.zhang@analog.com>
|
||||
fixed two bugs in msh and hush (exitcode of killed processes)
|
||||
@@ -30,6 +30,23 @@ config EXTRA_COMPAT
|
||||
some GNU extensions in libc. You probably only need this option
|
||||
if you plan to run busybox on desktop.
|
||||
|
||||
config INCLUDE_SUSv2
|
||||
bool "Enable obsolete features removed before SUSv3"
|
||||
default y
|
||||
help
|
||||
This option will enable backwards compatibility with SuSv2,
|
||||
specifically, old-style numeric options ('command -1 <file>')
|
||||
will be supported in head, tail, and fold. (Note: should
|
||||
affect renice too.)
|
||||
|
||||
config USE_PORTABLE_CODE
|
||||
bool "Avoid using GCC-specific code constructs"
|
||||
default n
|
||||
help
|
||||
Use this option if you are trying to compile busybox with
|
||||
compiler other than gcc.
|
||||
If you do use gcc, this option may needlessly increase code size.
|
||||
|
||||
choice
|
||||
prompt "Buffer allocation policy"
|
||||
default FEATURE_BUFFERS_USE_MALLOC
|
||||
@@ -503,17 +520,8 @@ config EFENCE
|
||||
|
||||
endchoice
|
||||
|
||||
config INCLUDE_SUSv2
|
||||
bool "Enable obsolete features removed before SUSv3?"
|
||||
default y
|
||||
help
|
||||
This option will enable backwards compatibility with SuSv2,
|
||||
specifically, old-style numeric options ('command -1 <file>')
|
||||
will be supported in head, tail, and fold. (Note: should
|
||||
affect renice too.)
|
||||
|
||||
### config PARSE
|
||||
### bool "Uniform config file parser debugging applet: parse"
|
||||
### bool "Uniform config file parser debugging applet: parse"
|
||||
|
||||
endmenu
|
||||
|
||||
|
||||
@@ -19,11 +19,24 @@ it, is to enable all features and then use "standalone shell" mode with a
|
||||
blank command $PATH.
|
||||
|
||||
To enable all features, use "make defconfig", which produces the largest
|
||||
general-purpose configuration. (It's allyesconfig minus debugging options,
|
||||
general-purpose configuration. It's allyesconfig minus debugging options,
|
||||
optional packaging choices, and a few special-purpose features requiring
|
||||
extra configuration to use.)
|
||||
extra configuration to use. Then enable "standalone shell" feature:
|
||||
|
||||
make defconfig
|
||||
make menuconfig
|
||||
# select Busybox Settings
|
||||
# then General Configuration
|
||||
# then exec prefers applets
|
||||
# exit back to top level menu
|
||||
# select Shells
|
||||
# then Standalone shell
|
||||
# exit back to top level menu
|
||||
# exit and save new configuration
|
||||
# OR
|
||||
# use these commands to modify .config directly:
|
||||
sed -e 's/.*FEATURE_PREFER_APPLETS.*/CONFIG_FEATURE_PREFER_APPLETS=y/' -i .config
|
||||
sed -e 's/.*FEATURE_SH_STANDALONE.*/CONFIG_FEATURE_SH_STANDALONE=y/' -i .config
|
||||
make
|
||||
PATH= ./busybox ash
|
||||
|
||||
@@ -104,7 +117,7 @@ somewhere else.
|
||||
|
||||
To build out of tree, cd to an empty directory and configure busybox from there:
|
||||
|
||||
make -f /path/to/source/Makefile defconfig
|
||||
make KBUILD_SRC=/path/to/source -f /path/to/source/Makefile defconfig
|
||||
make
|
||||
make install
|
||||
|
||||
@@ -121,5 +134,4 @@ More Information:
|
||||
|
||||
Se also the busybox FAQ, under the questions "How can I get started using
|
||||
BusyBox" and "How do I build a BusyBox-based system?" The BusyBox FAQ is
|
||||
available from http://www.busybox.net/FAQ.html or as the file
|
||||
docs/busybox.net/FAQ.html in this tarball.
|
||||
available from http://www.busybox.net/FAQ.html
|
||||
@@ -1,6 +1,6 @@
|
||||
VERSION = 1
|
||||
PATCHLEVEL = 15
|
||||
SUBLEVEL = 0
|
||||
PATCHLEVEL = 16
|
||||
SUBLEVEL = 2
|
||||
EXTRAVERSION =
|
||||
NAME = Unnamed
|
||||
|
||||
@@ -358,6 +358,15 @@ scripts_basic:
|
||||
# To avoid any implicit rule to kick in, define an empty command.
|
||||
scripts/basic/%: scripts_basic ;
|
||||
|
||||
# bbox: we have helpers in applets/
|
||||
# we depend on scripts_basic, since scripts/basic/fixdep
|
||||
# must be built before any other host prog
|
||||
PHONY += applets_dir
|
||||
applets_dir: scripts_basic
|
||||
$(Q)$(MAKE) $(build)=applets
|
||||
|
||||
applets/%: applets_dir ;
|
||||
|
||||
PHONY += outputmakefile
|
||||
# outputmakefile generates a Makefile in the output directory, if using a
|
||||
# separate output directory. This allows convenient use of make in the
|
||||
@@ -797,7 +806,7 @@ ifneq ($(KBUILD_MODULES),)
|
||||
$(Q)rm -f $(MODVERDIR)/*
|
||||
endif
|
||||
|
||||
archprepare: prepare1 scripts_basic
|
||||
archprepare: prepare1 scripts_basic applets_dir
|
||||
|
||||
prepare0: archprepare FORCE
|
||||
$(Q)$(MAKE) $(build)=.
|
||||
|
||||
+10
-8
@@ -111,15 +111,19 @@ doc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
|
||||
silent_cmd_doc =
|
||||
disp_doc = $($(quiet)cmd_doc)
|
||||
|
||||
# sed adds newlines after "Options:" etc,
|
||||
# this is needed in order to get good BusyBox.{1,txt,html}
|
||||
docs/busybox.pod: $(srctree)/docs/busybox_header.pod \
|
||||
$(srctree)/include/usage.h \
|
||||
$(srctree)/docs/busybox_footer.pod \
|
||||
$(srctree)/docs/autodocifier.pl
|
||||
applets/usage_pod
|
||||
$(disp_doc)
|
||||
$(Q)-mkdir -p docs
|
||||
$(Q)-( cat $(srctree)/docs/busybox_header.pod ; \
|
||||
$(srctree)/docs/autodocifier.pl $(srctree)/include/usage.h ; \
|
||||
cat $(srctree)/docs/busybox_footer.pod ; ) > docs/busybox.pod
|
||||
$(Q)-( \
|
||||
cat $(srctree)/docs/busybox_header.pod; \
|
||||
applets/usage_pod | sed 's/^[A-Za-z][A-Za-z ]*[a-z]:$$/&\n/'; \
|
||||
cat $(srctree)/docs/busybox_footer.pod; \
|
||||
) > docs/busybox.pod
|
||||
|
||||
docs/BusyBox.txt: docs/busybox.pod
|
||||
$(disp_doc)
|
||||
@@ -129,8 +133,7 @@ docs/BusyBox.txt: docs/busybox.pod
|
||||
docs/BusyBox.1: docs/busybox.pod
|
||||
$(disp_doc)
|
||||
$(Q)-mkdir -p docs
|
||||
$(Q)-pod2man --center=BusyBox --release="version $(VERSION)" \
|
||||
$< > $@
|
||||
$(Q)-pod2man --center=BusyBox --release="version $(KERNELVERSION)" $< > $@
|
||||
|
||||
docs/BusyBox.html: docs/busybox.net/BusyBox.html
|
||||
$(disp_doc)
|
||||
@@ -140,8 +143,7 @@ docs/BusyBox.html: docs/busybox.net/BusyBox.html
|
||||
|
||||
docs/busybox.net/BusyBox.html: docs/busybox.pod
|
||||
$(Q)-mkdir -p docs/busybox.net
|
||||
$(Q)-pod2html --noindex $< > \
|
||||
docs/busybox.net/BusyBox.html
|
||||
$(Q)-pod2html --noindex $< > $@
|
||||
$(Q)-rm -f pod2htm*
|
||||
|
||||
# documentation, cross-reference
|
||||
|
||||
@@ -68,9 +68,9 @@ Downloading the current source code:
|
||||
|
||||
http://www.busybox.net/cgi-bin/viewcvs.cgi/trunk/busybox/
|
||||
|
||||
Anonymous SVN access is available. For instructions, check out:
|
||||
Anonymous GIT access is available. For instructions, check out:
|
||||
|
||||
http://busybox.net/subversion.html
|
||||
http://www.busybox.net/source.html
|
||||
|
||||
For those that are actively contributing and would like to check files in,
|
||||
see:
|
||||
|
||||
@@ -6,11 +6,8 @@ do one of these bounce an email off the person it's listed under to see if they
|
||||
have any suggestions how they plan to go about it, and to minimize conflicts
|
||||
between your work and theirs. But otherwise, all of these are fair game.
|
||||
|
||||
Rob Landley suggested these:
|
||||
Add a libbb/platform.c
|
||||
Implement fdprintf() for platforms that haven't got one.
|
||||
Implement bb_realpath() that can handle NULL on non-glibc.
|
||||
Cleanup bb_asprintf()
|
||||
Rob Landley suggested this:
|
||||
Implement bb_realpath() that can handle NULL on non-glibc.
|
||||
|
||||
Remove obsolete _() wrapper crud for internationalization we don't do.
|
||||
Figure out where we need utf8 support, and add it.
|
||||
@@ -20,6 +17,7 @@ Rob Landley suggested these:
|
||||
shells that don't really share any code, and the "standalone shell" doesn't
|
||||
work all that well (especially not in a chroot environment), due to apps not
|
||||
being reentrant.
|
||||
|
||||
Do a SUSv3 audit
|
||||
Look at the full Single Unix Specification version 3 (available online at
|
||||
"http://www.opengroup.org/onlinepubs/009695399/nfindex.html") and
|
||||
@@ -28,6 +26,7 @@ Rob Landley suggested these:
|
||||
|
||||
Even better would be some kind of automated compliance test harness that
|
||||
exercises each command line option and the various corner cases.
|
||||
|
||||
Internationalization
|
||||
How much internationalization should we do?
|
||||
|
||||
@@ -269,7 +268,8 @@ Minor stuff:
|
||||
in_ether duplicated in network/{interface,ifconfig}.c
|
||||
---
|
||||
unify progress_meter. wget, flash_eraseall, pipe_progress, fbsplash, setfiles.
|
||||
|
||||
---
|
||||
support start-stop-daemon -d <chdir-path>
|
||||
|
||||
Code cleanup:
|
||||
|
||||
@@ -314,3 +314,64 @@ vdprintf() -> similar sized functionality
|
||||
most likely there is more
|
||||
|
||||
* even more support for statistics: mpstat, iostat, powertop....
|
||||
|
||||
|
||||
Unicode work needed:
|
||||
|
||||
Unicode support uses libc multibyte functions if LOCALE_SUPPORT is on
|
||||
(in this case, the code will also support many more encodings),
|
||||
or uses a limited subset of re-implemented multibyte functions
|
||||
which only understand "one byte == one char" and unicode.
|
||||
This is useful if you build against uclibc with locale support disabled.
|
||||
|
||||
Unicode-dependent applets must call check_unicode_in_env() when they
|
||||
begin executing.
|
||||
|
||||
Applet code may conditionalize on FEATURE_ASSUME_UNICODE
|
||||
in order to use more efficient code if unicode support is not requested.
|
||||
|
||||
Available functions (if you need more, implement them in libbb/unicode.c
|
||||
so that they work without LOCALE_SUPPORT too):
|
||||
|
||||
int bb_mbstrlen(str) - multibyte-aware strlen
|
||||
size_t mbstowcs(wdest, src, n)
|
||||
size_t wcstombs(dest, wsrc, n)
|
||||
size_t wcrtomb(str, wc, wstate)
|
||||
int iswspace(wc)
|
||||
int iswalnum(wc)
|
||||
int iswpunct(wc)
|
||||
|
||||
Applets which only need to align columns on screen correctly:
|
||||
|
||||
ls - already done, use source as an example
|
||||
df
|
||||
dumpleases
|
||||
lsmod
|
||||
|
||||
Applets which need to account for Unicode chars
|
||||
while processing the output:
|
||||
|
||||
[un]expand
|
||||
fold
|
||||
man
|
||||
watch
|
||||
cut (-b and -c are currently the same, needs fixing)
|
||||
|
||||
These applets need to ensure that unicode input
|
||||
is handled correctly (say, <unicode><backspace> sequence):
|
||||
|
||||
getty, login
|
||||
rm -i
|
||||
unzip (overwrite prompt)
|
||||
|
||||
Viewers/editors are more difficult (many cases to get right).
|
||||
libbb/lineedit.c is an example how to do it:
|
||||
|
||||
less, most, ed, vi
|
||||
awk
|
||||
[ef]grep
|
||||
sed
|
||||
|
||||
Probably needs some specialized work:
|
||||
|
||||
loadkeys
|
||||
+33
-12
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# Automatically generated make config: don't edit
|
||||
# Busybox version: 1.15.0.svn
|
||||
# Fri Aug 21 00:13:18 2009
|
||||
# Busybox version: 1.16.0
|
||||
# Wed Jan 27 21:01:26 2010
|
||||
#
|
||||
CONFIG_HAVE_DOT_CONFIG=y
|
||||
|
||||
@@ -14,6 +14,8 @@ CONFIG_HAVE_DOT_CONFIG=y
|
||||
#
|
||||
CONFIG_DESKTOP=y
|
||||
CONFIG_EXTRA_COMPAT=y
|
||||
CONFIG_INCLUDE_SUSv2=y
|
||||
# CONFIG_USE_PORTABLE_CODE is not set
|
||||
CONFIG_FEATURE_BUFFERS_USE_MALLOC=y
|
||||
# CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set
|
||||
# CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set
|
||||
@@ -59,7 +61,6 @@ CONFIG_EXTRA_CFLAGS=""
|
||||
CONFIG_NO_DEBUG_LIB=y
|
||||
# CONFIG_DMALLOC is not set
|
||||
# CONFIG_EFENCE is not set
|
||||
CONFIG_INCLUDE_SUSv2=y
|
||||
|
||||
#
|
||||
# Installation Options
|
||||
@@ -120,6 +121,7 @@ CONFIG_DPKG_DEB=y
|
||||
CONFIG_FEATURE_DPKG_DEB_EXTRACT_ONLY=y
|
||||
CONFIG_GUNZIP=y
|
||||
CONFIG_GZIP=y
|
||||
CONFIG_FEATURE_GZIP_LONG_OPTIONS=y
|
||||
CONFIG_LZOP=y
|
||||
CONFIG_LZOP_COMPR_HIGH=y
|
||||
CONFIG_RPM2CPIO=y
|
||||
@@ -133,6 +135,7 @@ CONFIG_FEATURE_TAR_OLDSUN_COMPATIBILITY=y
|
||||
CONFIG_FEATURE_TAR_GNU_EXTENSIONS=y
|
||||
CONFIG_FEATURE_TAR_LONG_OPTIONS=y
|
||||
CONFIG_FEATURE_TAR_UNAME_GNAME=y
|
||||
CONFIG_FEATURE_TAR_NOPRESERVE_TIME=y
|
||||
CONFIG_UNCOMPRESS=y
|
||||
CONFIG_UNLZMA=y
|
||||
CONFIG_FEATURE_LZMA_FAST=y
|
||||
@@ -148,15 +151,19 @@ CONFIG_CATV=y
|
||||
CONFIG_CHGRP=y
|
||||
CONFIG_CHMOD=y
|
||||
CONFIG_CHOWN=y
|
||||
CONFIG_FEATURE_CHOWN_LONG_OPTIONS=y
|
||||
CONFIG_CHROOT=y
|
||||
CONFIG_CKSUM=y
|
||||
CONFIG_COMM=y
|
||||
CONFIG_CP=y
|
||||
CONFIG_FEATURE_CP_LONG_OPTIONS=y
|
||||
CONFIG_CUT=y
|
||||
CONFIG_DATE=y
|
||||
CONFIG_FEATURE_DATE_ISOFMT=y
|
||||
CONFIG_FEATURE_DATE_COMPAT=y
|
||||
CONFIG_DD=y
|
||||
CONFIG_FEATURE_DD_SIGNAL_HANDLING=y
|
||||
CONFIG_FEATURE_DD_THIRD_STATUS_LINE=y
|
||||
CONFIG_FEATURE_DD_IBS_OBS=y
|
||||
CONFIG_DF=y
|
||||
CONFIG_FEATURE_DF_FANCY=y
|
||||
@@ -271,7 +278,7 @@ CONFIG_FEATURE_AUTOWIDTH=y
|
||||
CONFIG_FEATURE_HUMAN_READABLE=y
|
||||
|
||||
#
|
||||
# Common options for md5sum, sha1sum
|
||||
# Common options for md5sum, sha1sum, sha256sum, sha512sum
|
||||
#
|
||||
CONFIG_FEATURE_MD5_SHA1_SUM_CHECK=y
|
||||
|
||||
@@ -318,9 +325,8 @@ CONFIG_AWK=y
|
||||
CONFIG_FEATURE_AWK_LIBM=y
|
||||
CONFIG_CMP=y
|
||||
CONFIG_DIFF=y
|
||||
CONFIG_FEATURE_DIFF_BINARY=y
|
||||
CONFIG_FEATURE_DIFF_LONG_OPTIONS=y
|
||||
CONFIG_FEATURE_DIFF_DIR=y
|
||||
CONFIG_FEATURE_DIFF_MINIMAL=y
|
||||
CONFIG_ED=y
|
||||
CONFIG_PATCH=y
|
||||
CONFIG_SED=y
|
||||
@@ -364,6 +370,7 @@ CONFIG_FEATURE_FIND_DELETE=y
|
||||
CONFIG_FEATURE_FIND_PATH=y
|
||||
CONFIG_FEATURE_FIND_REGEX=y
|
||||
CONFIG_FEATURE_FIND_CONTEXT=y
|
||||
CONFIG_FEATURE_FIND_LINKS=y
|
||||
CONFIG_GREP=y
|
||||
CONFIG_FEATURE_GREP_EGREP_ALIAS=y
|
||||
CONFIG_FEATURE_GREP_FGREP_ALIAS=y
|
||||
@@ -453,6 +460,7 @@ CONFIG_FEATURE_MODPROBE_SMALL_CHECK_ALREADY_LOADED=y
|
||||
# Options common to multiple modutils
|
||||
#
|
||||
# CONFIG_FEATURE_2_4_MODULES is not set
|
||||
CONFIG_FEATURE_INSMOD_TRY_MMAP=y
|
||||
# CONFIG_FEATURE_INSMOD_VERSION_CHECKING is not set
|
||||
# CONFIG_FEATURE_INSMOD_KSYMOOPS_SYMBOLS is not set
|
||||
# CONFIG_FEATURE_INSMOD_LOADINKMEM is not set
|
||||
@@ -488,12 +496,14 @@ CONFIG_FEATURE_FDISK_ADVANCED=y
|
||||
CONFIG_FINDFS=y
|
||||
CONFIG_FREERAMDISK=y
|
||||
CONFIG_FSCK_MINIX=y
|
||||
CONFIG_MKFS_EXT2=y
|
||||
CONFIG_MKFS_MINIX=y
|
||||
|
||||
#
|
||||
# Minix filesystem support
|
||||
#
|
||||
CONFIG_FEATURE_MINIX2=y
|
||||
CONFIG_MKFS_REISER=y
|
||||
CONFIG_MKFS_VFAT=y
|
||||
CONFIG_GETOPT=y
|
||||
CONFIG_FEATURE_GETOPT_LONG=y
|
||||
@@ -506,6 +516,8 @@ CONFIG_FEATURE_HWCLOCK_ADJTIME_FHS=y
|
||||
CONFIG_IPCRM=y
|
||||
CONFIG_IPCS=y
|
||||
CONFIG_LOSETUP=y
|
||||
CONFIG_LSPCI=y
|
||||
CONFIG_LSUSB=y
|
||||
CONFIG_MDEV=y
|
||||
CONFIG_FEATURE_MDEV_CONF=y
|
||||
CONFIG_FEATURE_MDEV_RENAME=y
|
||||
@@ -518,6 +530,7 @@ CONFIG_MORE=y
|
||||
CONFIG_FEATURE_USE_TERMIOS=y
|
||||
CONFIG_VOLUMEID=y
|
||||
CONFIG_FEATURE_VOLUMEID_EXT=y
|
||||
CONFIG_FEATURE_VOLUMEID_BTRFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_REISERFS=y
|
||||
CONFIG_FEATURE_VOLUMEID_FAT=y
|
||||
CONFIG_FEATURE_VOLUMEID_HFS=y
|
||||
@@ -595,6 +608,7 @@ CONFIG_DEVMEM=y
|
||||
CONFIG_EJECT=y
|
||||
CONFIG_FEATURE_EJECT_SCSI=y
|
||||
CONFIG_FBSPLASH=y
|
||||
CONFIG_FLASHCP=y
|
||||
# CONFIG_FLASH_LOCK is not set
|
||||
# CONFIG_FLASH_UNLOCK is not set
|
||||
# CONFIG_FLASH_ERASEALL is not set
|
||||
@@ -638,6 +652,7 @@ CONFIG_TIME=y
|
||||
CONFIG_TIMEOUT=y
|
||||
CONFIG_TTYSIZE=y
|
||||
CONFIG_VOLNAME=y
|
||||
CONFIG_WALL=y
|
||||
CONFIG_WATCHDOG=y
|
||||
|
||||
#
|
||||
@@ -657,6 +672,7 @@ CONFIG_ETHER_WAKE=y
|
||||
CONFIG_FAKEIDENTD=y
|
||||
CONFIG_FTPD=y
|
||||
CONFIG_FEATURE_FTP_WRITE=y
|
||||
CONFIG_FEATURE_FTPD_ACCEPT_BROKEN_LIST=y
|
||||
CONFIG_FTPGET=y
|
||||
CONFIG_FTPPUT=y
|
||||
CONFIG_FEATURE_FTPGETPUT_LONG_OPTIONS=y
|
||||
@@ -722,6 +738,8 @@ CONFIG_NETSTAT=y
|
||||
CONFIG_FEATURE_NETSTAT_WIDE=y
|
||||
CONFIG_FEATURE_NETSTAT_PRG=y
|
||||
CONFIG_NSLOOKUP=y
|
||||
CONFIG_NTPD=y
|
||||
CONFIG_FEATURE_NTPD_SERVER=y
|
||||
CONFIG_PING=y
|
||||
CONFIG_PING6=y
|
||||
CONFIG_FEATURE_FANCY_PING=y
|
||||
@@ -733,22 +751,25 @@ CONFIG_FEATURE_TELNET_TTYPE=y
|
||||
CONFIG_FEATURE_TELNET_AUTOLOGIN=y
|
||||
CONFIG_TELNETD=y
|
||||
CONFIG_FEATURE_TELNETD_STANDALONE=y
|
||||
CONFIG_FEATURE_TELNETD_INETD_WAIT=y
|
||||
CONFIG_TFTP=y
|
||||
CONFIG_TFTPD=y
|
||||
CONFIG_FEATURE_TFTP_GET=y
|
||||
CONFIG_FEATURE_TFTP_PUT=y
|
||||
CONFIG_FEATURE_TFTP_BLOCKSIZE=y
|
||||
CONFIG_FEATURE_TFTP_PROGRESS_BAR=y
|
||||
CONFIG_TFTP_DEBUG=y
|
||||
CONFIG_TRACEROUTE=y
|
||||
CONFIG_TRACEROUTE6=y
|
||||
CONFIG_FEATURE_TRACEROUTE_VERBOSE=y
|
||||
CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE=y
|
||||
CONFIG_FEATURE_TRACEROUTE_USE_ICMP=y
|
||||
CONFIG_APP_UDHCPD=y
|
||||
CONFIG_APP_DHCPRELAY=y
|
||||
CONFIG_APP_DUMPLEASES=y
|
||||
CONFIG_UDHCPD=y
|
||||
CONFIG_DHCPRELAY=y
|
||||
CONFIG_DUMPLEASES=y
|
||||
CONFIG_FEATURE_UDHCPD_WRITE_LEASES_EARLY=y
|
||||
CONFIG_DHCPD_LEASES_FILE="/var/lib/misc/udhcpd.leases"
|
||||
CONFIG_APP_UDHCPC=y
|
||||
CONFIG_UDHCPC=y
|
||||
CONFIG_FEATURE_UDHCPC_ARPING=y
|
||||
CONFIG_FEATURE_UDHCP_PORT=y
|
||||
CONFIG_UDHCP_DEBUG=9
|
||||
@@ -813,6 +834,7 @@ CONFIG_FEATURE_TOP_SMP_CPU=y
|
||||
CONFIG_FEATURE_TOP_DECIMALS=y
|
||||
CONFIG_FEATURE_TOP_SMP_PROCESS=y
|
||||
CONFIG_FEATURE_TOPMEM=y
|
||||
CONFIG_FEATURE_SHOW_THREADS=y
|
||||
CONFIG_UPTIME=y
|
||||
CONFIG_WATCH=y
|
||||
|
||||
@@ -859,8 +881,6 @@ CONFIG_FEATURE_SH_IS_HUSH=y
|
||||
# CONFIG_ASH is not set
|
||||
# CONFIG_ASH_BASH_COMPAT is not set
|
||||
# CONFIG_ASH_JOB_CONTROL is not set
|
||||
# CONFIG_ASH_READ_NCHARS is not set
|
||||
# CONFIG_ASH_READ_TIMEOUT is not set
|
||||
# CONFIG_ASH_ALIAS is not set
|
||||
# CONFIG_ASH_GETOPTS is not set
|
||||
# CONFIG_ASH_BUILTIN_ECHO is not set
|
||||
@@ -883,6 +903,7 @@ CONFIG_HUSH_CASE=y
|
||||
CONFIG_HUSH_FUNCTIONS=y
|
||||
CONFIG_HUSH_LOCAL=y
|
||||
CONFIG_HUSH_EXPORT_N=y
|
||||
CONFIG_HUSH_RANDOM_SUPPORT=y
|
||||
CONFIG_LASH=y
|
||||
CONFIG_MSH=y
|
||||
CONFIG_SH_MATH_SUPPORT=y
|
||||
|
||||
+6
-5
@@ -8,7 +8,7 @@ obj-y :=
|
||||
obj-y += applets.o
|
||||
|
||||
hostprogs-y:=
|
||||
hostprogs-y += usage applet_tables
|
||||
hostprogs-y += usage usage_pod applet_tables
|
||||
|
||||
always:= $(hostprogs-y)
|
||||
|
||||
@@ -22,13 +22,14 @@ else
|
||||
srctree_slash = $(srctree)/
|
||||
endif
|
||||
|
||||
|
||||
HOSTCFLAGS_usage.o = -I$(srctree_slash)include
|
||||
HOSTCFLAGS_usage.o = -I$(srctree_slash)include -Iinclude
|
||||
HOSTCFLAGS_usage_pod.o = -I$(srctree_slash)include -Iinclude
|
||||
|
||||
applets/applets.o: include/usage_compressed.h include/applet_tables.h
|
||||
|
||||
applets/usage: .config $(srctree_slash)applets/usage_compressed
|
||||
applets/applet_tables: .config
|
||||
applets/applet_tables: .config $(srctree_slash)include/applets.h
|
||||
applets/usage: .config $(srctree_slash)include/applets.h
|
||||
applets/usage_pod: .config include/applet_tables.h $(srctree_slash)include/applets.h
|
||||
|
||||
quiet_cmd_gen_usage_compressed = GEN include/usage_compressed.h
|
||||
cmd_gen_usage_compressed = $(srctree_slash)applets/usage_compressed include/usage_compressed.h applets
|
||||
|
||||
+15
-10
@@ -70,29 +70,33 @@ int main(int argc, char **argv)
|
||||
|
||||
/* Keep in sync with include/busybox.h! */
|
||||
|
||||
puts("/* This is a generated file, don't edit */\n");
|
||||
printf("/* This is a generated file, don't edit */\n\n");
|
||||
|
||||
printf("#define NUM_APPLETS %u\n", NUM_APPLETS);
|
||||
if (NUM_APPLETS == 1) {
|
||||
printf("#define SINGLE_APPLET_STR \"%s\"\n", applets[0].name);
|
||||
printf("#define SINGLE_APPLET_MAIN %s_main\n", applets[0].name);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
puts("\nconst char applet_names[] ALIGN1 = \"\"");
|
||||
printf("#ifndef SKIP_definitions\n");
|
||||
printf("const char applet_names[] ALIGN1 = \"\"\n");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
printf("\"%s\" \"\\0\"\n", applets[i].name);
|
||||
if (MAX_APPLET_NAME_LEN < strlen(applets[i].name))
|
||||
MAX_APPLET_NAME_LEN = strlen(applets[i].name);
|
||||
}
|
||||
puts(";");
|
||||
printf(";\n\n");
|
||||
|
||||
puts("\nint (*const applet_main[])(int argc, char **argv) = {");
|
||||
printf("#ifndef SKIP_applet_main\n");
|
||||
printf("int (*const applet_main[])(int argc, char **argv) = {\n");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
printf("%s_main,\n", applets[i].main);
|
||||
}
|
||||
puts("};");
|
||||
printf("};\n");
|
||||
printf("#endif\n\n");
|
||||
|
||||
puts("const uint16_t applet_nameofs[] ALIGN2 = {");
|
||||
printf("const uint16_t applet_nameofs[] ALIGN2 = {\n");
|
||||
for (i = 0; i < NUM_APPLETS; i++) {
|
||||
printf("0x%04x,\n",
|
||||
offset[i]
|
||||
@@ -105,10 +109,10 @@ int main(int argc, char **argv)
|
||||
#endif
|
||||
);
|
||||
}
|
||||
puts("};");
|
||||
printf("};\n\n");
|
||||
|
||||
#if ENABLE_FEATURE_INSTALLER
|
||||
puts("const uint8_t applet_install_loc[] ALIGN1 = {");
|
||||
printf("const uint8_t applet_install_loc[] ALIGN1 = {\n");
|
||||
i = 0;
|
||||
while (i < NUM_APPLETS) {
|
||||
int v = applets[i].install_loc; /* 3 bits */
|
||||
@@ -117,9 +121,10 @@ int main(int argc, char **argv)
|
||||
printf("0x%02x,\n", v);
|
||||
i++;
|
||||
}
|
||||
puts("};\n");
|
||||
printf("};\n");
|
||||
#endif
|
||||
|
||||
printf("#endif /* SKIP_definitions */\n");
|
||||
printf("\n");
|
||||
printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN);
|
||||
|
||||
return 0;
|
||||
|
||||
+7
-7
@@ -8,17 +8,17 @@
|
||||
|
||||
/* Just #include "autoconf.h" doesn't work for builds in separate
|
||||
* object directory */
|
||||
#include "../include/autoconf.h"
|
||||
#include "autoconf.h"
|
||||
|
||||
/* Since we can't use platform.h, have to do this again by hand: */
|
||||
#if ENABLE_NOMMU
|
||||
#define BB_MMU 0
|
||||
#define USE_FOR_NOMMU(...) __VA_ARGS__
|
||||
#define USE_FOR_MMU(...)
|
||||
# define BB_MMU 0
|
||||
# define USE_FOR_NOMMU(...) __VA_ARGS__
|
||||
# define USE_FOR_MMU(...)
|
||||
#else
|
||||
#define BB_MMU 1
|
||||
#define USE_FOR_NOMMU(...)
|
||||
#define USE_FOR_MMU(...) __VA_ARGS__
|
||||
# define BB_MMU 1
|
||||
# define USE_FOR_NOMMU(...)
|
||||
# define USE_FOR_MMU(...) __VA_ARGS__
|
||||
#endif
|
||||
|
||||
static const char usage_messages[] = ""
|
||||
|
||||
@@ -7,6 +7,7 @@ test "$target" || exit 1
|
||||
test "$loc" || loc=.
|
||||
test -x "$loc/usage" || exit 1
|
||||
test "$SED" || SED=sed
|
||||
test "$DD" || DD=dd
|
||||
|
||||
sz=`"$loc/usage" | wc -c` || exit 1
|
||||
|
||||
@@ -20,15 +21,15 @@ echo 'static const char packed_usage[] ALIGN1 = {'
|
||||
##
|
||||
## "$loc/usage" | bzip2 -1 | od -v -x \
|
||||
## | $SED -e 's/^[^ ]*//' \
|
||||
## | $SED -e 's/ //g' \
|
||||
## | grep -v '^$' \
|
||||
## | $SED -e 's/\(..\)\(..\)/0x\2,0x\1,/g'
|
||||
## -e 's/ //g' \
|
||||
## -e '/^$/d' \
|
||||
## -e 's/\(..\)\(..\)/0x\2,0x\1,/g'
|
||||
|
||||
"$loc/usage" | bzip2 -1 | dd bs=2 skip=1 | od -v -t x1 \
|
||||
"$loc/usage" | bzip2 -1 | $DD bs=2 skip=1 2>/dev/null | od -v -t x1 \
|
||||
| $SED -e 's/^[^ ]*//' \
|
||||
| $SED -e 's/ //g' \
|
||||
| grep -v '^$' \
|
||||
| $SED -e 's/\(..\)/0x\1,/g'
|
||||
-e 's/ //g' \
|
||||
-e '/^$/d' \
|
||||
-e 's/\(..\)/0x\1,/g'
|
||||
|
||||
echo '};'
|
||||
echo '#define SIZEOF_usage_messages' `expr 0 + $sz`
|
||||
@@ -0,0 +1,100 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (C) 2009 Denys Vlasenko.
|
||||
*
|
||||
* Licensed under GPLv2, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/* Just #include "autoconf.h" doesn't work for builds in separate
|
||||
* object directory */
|
||||
#include "autoconf.h"
|
||||
|
||||
#define SKIP_applet_main
|
||||
#define ALIGN1 /* nothing, just to placate applet_tables.h */
|
||||
#define ALIGN2 /* nothing, just to placate applet_tables.h */
|
||||
#include "applet_tables.h"
|
||||
|
||||
/* Since we can't use platform.h, have to do this again by hand: */
|
||||
#if ENABLE_NOMMU
|
||||
# define BB_MMU 0
|
||||
# define USE_FOR_NOMMU(...) __VA_ARGS__
|
||||
# define USE_FOR_MMU(...)
|
||||
#else
|
||||
# define BB_MMU 1
|
||||
# define USE_FOR_NOMMU(...)
|
||||
# define USE_FOR_MMU(...) __VA_ARGS__
|
||||
#endif
|
||||
|
||||
static const char usage_messages[] = ""
|
||||
#define MAKE_USAGE
|
||||
#include "usage.h"
|
||||
#include "applets.h"
|
||||
;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const char *names;
|
||||
const char *usage;
|
||||
int col, len2;
|
||||
|
||||
col = 0;
|
||||
names = applet_names;
|
||||
while (*names) {
|
||||
len2 = strlen(names) + 2;
|
||||
if (col >= 76 - len2) {
|
||||
printf(",\n");
|
||||
col = 0;
|
||||
}
|
||||
if (col == 0) {
|
||||
col = 6;
|
||||
printf("\t");
|
||||
} else {
|
||||
printf(", ");
|
||||
}
|
||||
printf(names);
|
||||
col += len2;
|
||||
names += len2 - 1;
|
||||
}
|
||||
printf("\n\n");
|
||||
|
||||
printf("=head1 COMMAND DESCRIPTIONS\n\n");
|
||||
printf("=over 4\n\n");
|
||||
|
||||
names = applet_names;
|
||||
usage = usage_messages;
|
||||
while (*names) {
|
||||
if (*names >= 'a' && *names <= 'z'
|
||||
&& *usage != NOUSAGE_STR[0]
|
||||
) {
|
||||
printf("=item B<%s>\n\n", names);
|
||||
if (*usage)
|
||||
printf("%s %s\n\n", names, usage);
|
||||
else
|
||||
printf("%s\n\n", names);
|
||||
}
|
||||
names += strlen(names) + 1;
|
||||
usage += strlen(usage) + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* TODO: we used to make options bold with B<> and output an example too:
|
||||
|
||||
=item B<cat>
|
||||
|
||||
cat [B<-u>] [FILE]...
|
||||
|
||||
Concatenate FILE(s) and print them to stdout
|
||||
|
||||
Options:
|
||||
-u Use unbuffered i/o (ignored)
|
||||
|
||||
Example:
|
||||
$ cat /proc/uptime
|
||||
110716.72 17.67
|
||||
|
||||
*/
|
||||
@@ -165,6 +165,13 @@ config GZIP
|
||||
gzip is used to compress files.
|
||||
It's probably the most widely used UNIX compression program.
|
||||
|
||||
config FEATURE_GZIP_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on GZIP && LONG_OPTS
|
||||
help
|
||||
Enable use of long options, increases size by about 106 Bytes
|
||||
|
||||
config LZOP
|
||||
bool "lzop"
|
||||
default n
|
||||
@@ -269,6 +276,14 @@ config FEATURE_TAR_UNAME_GNAME
|
||||
listings (-t) and preserving permissions when unpacking (-p).
|
||||
+200 bytes.
|
||||
|
||||
config FEATURE_TAR_NOPRESERVE_TIME
|
||||
bool "Enable -m (do not preserve time) option"
|
||||
default n
|
||||
depends on TAR
|
||||
help
|
||||
With this option busybox supports GNU tar -m
|
||||
(do not preserve time) option.
|
||||
|
||||
endif #tar
|
||||
|
||||
config UNCOMPRESS
|
||||
|
||||
+6
-5
@@ -38,7 +38,7 @@ static void FAST_FUNC header_verbose_list_ar(const file_header_t *file_header)
|
||||
#define AR_OPT_INSERT 0x40
|
||||
|
||||
int ar_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int ar_main(int argc, char **argv)
|
||||
int ar_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
static const char msg_unsupported_err[] ALIGN1 =
|
||||
"archive %s is not supported";
|
||||
@@ -51,6 +51,7 @@ int ar_main(int argc, char **argv)
|
||||
/* Prepend '-' to the first argument if required */
|
||||
opt_complementary = "--:p:t:x:-1:p--tx:t--px:x--pt";
|
||||
opt = getopt32(argv, "ptxovcr");
|
||||
argv += optind;
|
||||
|
||||
if (opt & AR_CTX_PRINT) {
|
||||
archive_handle->action_data = data_extract_to_stdout;
|
||||
@@ -62,7 +63,7 @@ int ar_main(int argc, char **argv)
|
||||
archive_handle->action_data = data_extract_all;
|
||||
}
|
||||
if (opt & AR_OPT_PRESERVE_DATE) {
|
||||
archive_handle->ah_flags |= ARCHIVE_PRESERVE_DATE;
|
||||
archive_handle->ah_flags |= ARCHIVE_RESTORE_DATE;
|
||||
}
|
||||
if (opt & AR_OPT_VERBOSE) {
|
||||
archive_handle->action_header = header_verbose_list_ar;
|
||||
@@ -74,11 +75,11 @@ int ar_main(int argc, char **argv)
|
||||
bb_error_msg_and_die(msg_unsupported_err, "insertion");
|
||||
}
|
||||
|
||||
archive_handle->src_fd = xopen(argv[optind++], O_RDONLY);
|
||||
archive_handle->src_fd = xopen(*argv++, O_RDONLY);
|
||||
|
||||
while (optind < argc) {
|
||||
while (*argv) {
|
||||
archive_handle->filter = filter_accept_list;
|
||||
llist_add_to(&(archive_handle->accept), argv[optind++]);
|
||||
llist_add_to(&archive_handle->accept, *argv++);
|
||||
}
|
||||
|
||||
unpack_ar_archive(archive_handle);
|
||||
|
||||
+9
-9
@@ -98,22 +98,22 @@ int FAST_FUNC bbunpack(char **argv,
|
||||
status = unpacker(&info);
|
||||
if (status < 0)
|
||||
exitcode = 1;
|
||||
xclose(STDOUT_FILENO); /* with error check! */
|
||||
|
||||
if (filename) {
|
||||
char *del = new_name;
|
||||
if (status >= 0) {
|
||||
/* TODO: restore other things? */
|
||||
if (info.mtime) {
|
||||
struct utimbuf times;
|
||||
struct timeval times[2];
|
||||
|
||||
times.actime = info.mtime;
|
||||
times.modtime = info.mtime;
|
||||
/* Close first.
|
||||
* On some systems calling utime
|
||||
* then closing resets the mtime. */
|
||||
close(STDOUT_FILENO);
|
||||
/* Ignoring errors */
|
||||
utime(new_name, ×);
|
||||
times[1].tv_sec = times[0].tv_sec = info.mtime;
|
||||
times[1].tv_usec = times[0].tv_usec = 0;
|
||||
/* Note: we closed it first.
|
||||
* On some systems calling utimes
|
||||
* then closing resets the mtime
|
||||
* back to current time. */
|
||||
utimes(new_name, times); /* ignoring errors */
|
||||
}
|
||||
|
||||
/* Delete _compressed_ file */
|
||||
|
||||
@@ -585,7 +585,7 @@ uint8_t mmed3(uint8_t a, uint8_t b, uint8_t c)
|
||||
#define MAIN_QSORT_DEPTH_THRESH (BZ_N_RADIX + BZ_N_QSORT)
|
||||
#define MAIN_QSORT_STACK_SIZE 100
|
||||
|
||||
static
|
||||
static NOINLINE
|
||||
void mainQSort3(uint32_t* ptr,
|
||||
uint8_t* block,
|
||||
uint16_t* quadrant,
|
||||
|
||||
+33
-30
@@ -117,7 +117,7 @@ static off_t cpio_pad4(off_t size)
|
||||
|
||||
/* Return value will become exit code.
|
||||
* It's ok to exit instead of return. */
|
||||
static int cpio_o(void)
|
||||
static NOINLINE int cpio_o(void)
|
||||
{
|
||||
static const char trailer[] ALIGN1 = "TRAILER!!!";
|
||||
struct name_s {
|
||||
@@ -252,7 +252,7 @@ static int cpio_o(void)
|
||||
free(lpath);
|
||||
} else { /* S_ISREG */
|
||||
int fd = xopen(name, O_RDONLY);
|
||||
fflush(stdout);
|
||||
fflush_all();
|
||||
/* We must abort if file got shorter too! */
|
||||
bb_copyfd_exact_size(fd, STDOUT_FILENO, st.st_size);
|
||||
bytes += st.st_size;
|
||||
@@ -298,25 +298,40 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
;
|
||||
#endif
|
||||
|
||||
archive_handle = init_handle();
|
||||
/* archive_handle->src_fd = STDIN_FILENO; - done by init_handle */
|
||||
archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER;
|
||||
|
||||
/* As of now we do not enforce this: */
|
||||
/* -i,-t,-o,-p are mutually exclusive */
|
||||
/* -u,-d,-m make sense only with -i or -p */
|
||||
/* -L makes sense only with -o or -p */
|
||||
|
||||
#if !ENABLE_FEATURE_CPIO_O
|
||||
/* no parameters */
|
||||
opt_complementary = "=0";
|
||||
opt = getopt32(argv, OPTION_STR, &cpio_filename);
|
||||
if (opt & CPIO_OPT_FILE) { /* -F */
|
||||
xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
|
||||
}
|
||||
#else
|
||||
/* _exactly_ one parameter for -p, thus <= 1 param if -p is allowed */
|
||||
opt_complementary = ENABLE_FEATURE_CPIO_P ? "?1" : "=0";
|
||||
opt = getopt32(argv, OPTION_STR "oH:" IF_FEATURE_CPIO_P("p"), &cpio_filename, &cpio_fmt);
|
||||
argv += optind;
|
||||
if ((opt & (CPIO_OPT_FILE|CPIO_OPT_CREATE)) == CPIO_OPT_FILE) { /* -F without -o */
|
||||
xmove_fd(xopen(cpio_filename, O_RDONLY), STDIN_FILENO);
|
||||
}
|
||||
if (opt & CPIO_OPT_PASSTHROUGH) {
|
||||
pid_t pid;
|
||||
struct fd_pair pp;
|
||||
|
||||
if (argv[optind] == NULL)
|
||||
if (argv[0] == NULL)
|
||||
bb_show_usage();
|
||||
if (opt & CPIO_OPT_CREATE_LEADING_DIR)
|
||||
mkdir(argv[optind], 0777);
|
||||
mkdir(argv[0], 0777);
|
||||
/* Crude existence check:
|
||||
* close(xopen(argv[optind], O_RDONLY | O_DIRECTORY));
|
||||
* close(xopen(argv[0], O_RDONLY | O_DIRECTORY));
|
||||
* We can also xopen, fstat, IS_DIR, later fchdir.
|
||||
* This would check for existence earlier and cleaner.
|
||||
* As it stands now, if we fail xchdir later,
|
||||
@@ -335,41 +350,32 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
#else
|
||||
xpiped_pair(pp);
|
||||
#endif
|
||||
pid = fork_or_rexec(argv);
|
||||
pid = fork_or_rexec(argv - optind);
|
||||
if (pid == 0) { /* child */
|
||||
close(pp.rd);
|
||||
xmove_fd(pp.wr, STDOUT_FILENO);
|
||||
goto dump;
|
||||
}
|
||||
/* parent */
|
||||
xchdir(argv[optind++]);
|
||||
xchdir(*argv++);
|
||||
close(pp.wr);
|
||||
xmove_fd(pp.rd, STDIN_FILENO);
|
||||
opt &= ~CPIO_OPT_PASSTHROUGH;
|
||||
//opt &= ~CPIO_OPT_PASSTHROUGH;
|
||||
opt |= CPIO_OPT_EXTRACT;
|
||||
goto skip;
|
||||
}
|
||||
/* -o */
|
||||
if (opt & CPIO_OPT_CREATE) {
|
||||
if (*cpio_fmt != 'n') /* we _require_ "-H newc" */
|
||||
if (cpio_fmt[0] != 'n') /* we _require_ "-H newc" */
|
||||
bb_show_usage();
|
||||
if (opt & CPIO_OPT_FILE) {
|
||||
fclose(stdout);
|
||||
stdout = fopen_for_write(cpio_filename);
|
||||
/* Paranoia: I don't trust libc that much */
|
||||
xdup2(fileno(stdout), STDOUT_FILENO);
|
||||
xmove_fd(xopen3(cpio_filename, O_WRONLY | O_CREAT | O_TRUNC, 0666), STDOUT_FILENO);
|
||||
}
|
||||
dump:
|
||||
return cpio_o();
|
||||
}
|
||||
skip:
|
||||
#endif
|
||||
argv += optind;
|
||||
|
||||
archive_handle = init_handle();
|
||||
archive_handle->src_fd = STDIN_FILENO;
|
||||
archive_handle->seek = seek_by_read;
|
||||
archive_handle->ah_flags = ARCHIVE_EXTRACT_NEWER;
|
||||
|
||||
/* One of either extract or test options must be given */
|
||||
if ((opt & (CPIO_OPT_TEST | CPIO_OPT_EXTRACT)) == 0) {
|
||||
@@ -387,7 +393,7 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
archive_handle->action_data = data_extract_to_stdout;
|
||||
}
|
||||
if (opt & CPIO_OPT_UNCONDITIONAL) {
|
||||
archive_handle->ah_flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
archive_handle->ah_flags |= ARCHIVE_UNLINK_OLD;
|
||||
archive_handle->ah_flags &= ~ARCHIVE_EXTRACT_NEWER;
|
||||
}
|
||||
if (opt & CPIO_OPT_VERBOSE) {
|
||||
@@ -397,32 +403,29 @@ int cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
archive_handle->action_header = header_list;
|
||||
}
|
||||
}
|
||||
if (opt & CPIO_OPT_FILE) { /* -F */
|
||||
archive_handle->src_fd = xopen(cpio_filename, O_RDONLY);
|
||||
archive_handle->seek = seek_by_jump;
|
||||
}
|
||||
if (opt & CPIO_OPT_CREATE_LEADING_DIR) {
|
||||
archive_handle->ah_flags |= ARCHIVE_CREATE_LEADING_DIRS;
|
||||
}
|
||||
if (opt & CPIO_OPT_PRESERVE_MTIME) {
|
||||
archive_handle->ah_flags |= ARCHIVE_PRESERVE_DATE;
|
||||
archive_handle->ah_flags |= ARCHIVE_RESTORE_DATE;
|
||||
}
|
||||
|
||||
while (*argv) {
|
||||
archive_handle->filter = filter_accept_list;
|
||||
llist_add_to(&(archive_handle->accept), *argv);
|
||||
llist_add_to(&archive_handle->accept, *argv);
|
||||
argv++;
|
||||
}
|
||||
|
||||
/* see get_header_cpio */
|
||||
archive_handle->ah_priv[2] = (void*) ~(ptrdiff_t)0;
|
||||
archive_handle->cpio__blocks = (off_t)-1;
|
||||
while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
|
||||
continue;
|
||||
|
||||
if (archive_handle->ah_priv[2] != (void*) ~(ptrdiff_t)0
|
||||
if (archive_handle->cpio__blocks != (off_t)-1
|
||||
&& !(opt & CPIO_OPT_QUIET)
|
||||
)
|
||||
printf("%lu blocks\n", (unsigned long)(ptrdiff_t)(archive_handle->ah_priv[2]));
|
||||
) {
|
||||
fprintf(stderr, "%"OFF_FMT"u blocks\n", archive_handle->cpio__blocks);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+42
-23
@@ -493,7 +493,7 @@ static void free_package(common_node_t *node)
|
||||
}
|
||||
|
||||
/*
|
||||
* Gets the next package field from package_buffer, seperated into the field name
|
||||
* Gets the next package field from package_buffer, separated into the field name
|
||||
* and field value, it returns the int offset to the first character of the next field
|
||||
*/
|
||||
static int read_package_field(const char *package_buffer, char **field_name, char **field_value)
|
||||
@@ -806,7 +806,7 @@ static void write_status_file(deb_file_t **deb_file)
|
||||
write_flag = FALSE;
|
||||
tmp_string = strstr(control_buffer, "Status:");
|
||||
if (tmp_string != NULL) {
|
||||
/* Seperate the status value from the control buffer */
|
||||
/* Separate the status value from the control buffer */
|
||||
tmp_string += 7;
|
||||
tmp_string += strspn(tmp_string, " \n\t");
|
||||
status_from_file = xstrndup(tmp_string, strcspn(tmp_string, "\n"));
|
||||
@@ -912,7 +912,7 @@ static void write_status_file(deb_file_t **deb_file)
|
||||
/* Create a separate backfile to dpkg */
|
||||
if (rename("/var/lib/dpkg/status", "/var/lib/dpkg/status.udeb.bak") == -1) {
|
||||
if (errno != ENOENT)
|
||||
bb_error_msg_and_die("cannot create backup status file");
|
||||
bb_error_msg_and_die("can't create backup status file");
|
||||
/* Its ok if renaming the status file fails because status
|
||||
* file doesnt exist, maybe we are starting from scratch */
|
||||
bb_error_msg("no status file found, creating new one");
|
||||
@@ -1446,7 +1446,7 @@ static void init_archive_deb_control(archive_handle_t *ar_handle)
|
||||
#endif
|
||||
|
||||
/* Assign the tar handle as a subarchive of the ar handle */
|
||||
ar_handle->sub_archive = tar_handle;
|
||||
ar_handle->dpkg__sub_archive = tar_handle;
|
||||
}
|
||||
|
||||
static void init_archive_deb_data(archive_handle_t *ar_handle)
|
||||
@@ -1466,28 +1466,47 @@ static void init_archive_deb_data(archive_handle_t *ar_handle)
|
||||
#endif
|
||||
|
||||
/* Assign the tar handle as a subarchive of the ar handle */
|
||||
ar_handle->sub_archive = tar_handle;
|
||||
ar_handle->dpkg__sub_archive = tar_handle;
|
||||
}
|
||||
|
||||
static void FAST_FUNC data_extract_to_buffer(archive_handle_t *archive_handle)
|
||||
{
|
||||
unsigned size = archive_handle->file_header->size;
|
||||
|
||||
archive_handle->dpkg__buffer = xzalloc(size + 1);
|
||||
xread(archive_handle->src_fd, archive_handle->dpkg__buffer, size);
|
||||
}
|
||||
|
||||
static char *deb_extract_control_file_to_buffer(archive_handle_t *ar_handle, llist_t *myaccept)
|
||||
{
|
||||
ar_handle->sub_archive->action_data = data_extract_to_buffer;
|
||||
ar_handle->sub_archive->accept = myaccept;
|
||||
ar_handle->sub_archive->filter = filter_accept_list;
|
||||
ar_handle->dpkg__sub_archive->action_data = data_extract_to_buffer;
|
||||
ar_handle->dpkg__sub_archive->accept = myaccept;
|
||||
ar_handle->dpkg__sub_archive->filter = filter_accept_list;
|
||||
|
||||
unpack_ar_archive(ar_handle);
|
||||
close(ar_handle->src_fd);
|
||||
|
||||
return ar_handle->sub_archive->buffer;
|
||||
return ar_handle->dpkg__sub_archive->dpkg__buffer;
|
||||
}
|
||||
|
||||
static void FAST_FUNC data_extract_all_prefix(archive_handle_t *archive_handle)
|
||||
{
|
||||
char *name_ptr = archive_handle->file_header->name;
|
||||
|
||||
name_ptr += strspn(name_ptr, "./");
|
||||
/* Skip all leading "/" */
|
||||
while (*name_ptr == '/')
|
||||
name_ptr++;
|
||||
/* Skip all leading "./" and "../" */
|
||||
while (name_ptr[0] == '.') {
|
||||
if (name_ptr[1] == '.' && name_ptr[2] == '/')
|
||||
name_ptr++;
|
||||
if (name_ptr[1] != '/')
|
||||
break;
|
||||
name_ptr += 2;
|
||||
}
|
||||
|
||||
if (name_ptr[0] != '\0') {
|
||||
archive_handle->file_header->name = xasprintf("%s%s", archive_handle->buffer, name_ptr);
|
||||
archive_handle->file_header->name = xasprintf("%s%s", archive_handle->dpkg__buffer, name_ptr);
|
||||
data_extract_all(archive_handle);
|
||||
}
|
||||
}
|
||||
@@ -1527,11 +1546,11 @@ static void unpack_package(deb_file_t *deb_file)
|
||||
llist_add_to(&accept_list, c);
|
||||
i++;
|
||||
}
|
||||
archive_handle->sub_archive->accept = accept_list;
|
||||
archive_handle->sub_archive->filter = filter_accept_list;
|
||||
archive_handle->sub_archive->action_data = data_extract_all_prefix;
|
||||
archive_handle->sub_archive->buffer = info_prefix;
|
||||
archive_handle->sub_archive->ah_flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
archive_handle->dpkg__sub_archive->accept = accept_list;
|
||||
archive_handle->dpkg__sub_archive->filter = filter_accept_list;
|
||||
archive_handle->dpkg__sub_archive->action_data = data_extract_all_prefix;
|
||||
archive_handle->dpkg__sub_archive->dpkg__buffer = info_prefix;
|
||||
archive_handle->dpkg__sub_archive->ah_flags |= ARCHIVE_UNLINK_OLD;
|
||||
unpack_ar_archive(archive_handle);
|
||||
|
||||
/* Run the preinst prior to extracting */
|
||||
@@ -1540,19 +1559,19 @@ static void unpack_package(deb_file_t *deb_file)
|
||||
/* Extract data.tar.gz to the root directory */
|
||||
archive_handle = init_archive_deb_ar(deb_file->filename);
|
||||
init_archive_deb_data(archive_handle);
|
||||
archive_handle->sub_archive->action_data = data_extract_all_prefix;
|
||||
archive_handle->sub_archive->buffer = (char*)"/"; /* huh? */
|
||||
archive_handle->sub_archive->ah_flags |= ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
archive_handle->dpkg__sub_archive->action_data = data_extract_all_prefix;
|
||||
archive_handle->dpkg__sub_archive->dpkg__buffer = (char*)"/"; /* huh? */
|
||||
archive_handle->dpkg__sub_archive->ah_flags |= ARCHIVE_UNLINK_OLD;
|
||||
unpack_ar_archive(archive_handle);
|
||||
|
||||
/* Create the list file */
|
||||
list_filename = xasprintf("/var/lib/dpkg/info/%s.%s", package_name, "list");
|
||||
out_stream = xfopen_for_write(list_filename);
|
||||
while (archive_handle->sub_archive->passed) {
|
||||
while (archive_handle->dpkg__sub_archive->passed) {
|
||||
/* the leading . has been stripped by data_extract_all_prefix already */
|
||||
fputs(archive_handle->sub_archive->passed->data, out_stream);
|
||||
fputs(archive_handle->dpkg__sub_archive->passed->data, out_stream);
|
||||
fputc('\n', out_stream);
|
||||
archive_handle->sub_archive->passed = archive_handle->sub_archive->passed->link;
|
||||
archive_handle->dpkg__sub_archive->passed = archive_handle->dpkg__sub_archive->passed->link;
|
||||
}
|
||||
fclose(out_stream);
|
||||
|
||||
@@ -1646,7 +1665,7 @@ int dpkg_main(int argc UNUSED_PARAM, char **argv)
|
||||
init_archive_deb_control(archive_handle);
|
||||
deb_file[deb_count]->control_file = deb_extract_control_file_to_buffer(archive_handle, control_list);
|
||||
if (deb_file[deb_count]->control_file == NULL) {
|
||||
bb_error_msg_and_die("cannot extract control file");
|
||||
bb_error_msg_and_die("can't extract control file");
|
||||
}
|
||||
deb_file[deb_count]->filename = xstrdup(argv[0]);
|
||||
package_num = fill_package_struct(deb_file[deb_count]->control_file);
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ int dpkg_deb_main(int argc, char **argv)
|
||||
|
||||
/* Setup an ar archive handle that refers to the gzip sub archive */
|
||||
ar_archive = init_handle();
|
||||
ar_archive->sub_archive = tar_archive;
|
||||
ar_archive->dpkg__sub_archive = tar_archive;
|
||||
ar_archive->filter = filter_accept_list_reassign;
|
||||
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ
|
||||
|
||||
+23
-4
@@ -1173,7 +1173,7 @@ static void gen_codes(ct_data * tree, int max_code)
|
||||
|
||||
Tracec(tree != G2.static_ltree,
|
||||
(stderr, "\nn %3d %c l %2d c %4x (%x) ", n,
|
||||
(isgraph(n) ? n : ' '), len, tree[n].Code,
|
||||
(n > ' ' ? n : ' '), len, tree[n].Code,
|
||||
next_code[len] - 1));
|
||||
}
|
||||
}
|
||||
@@ -1541,7 +1541,7 @@ static void compress_block(ct_data * ltree, ct_data * dtree)
|
||||
lc = G1.l_buf[lx++];
|
||||
if ((flag & 1) == 0) {
|
||||
SEND_CODE(lc, ltree); /* send a literal byte */
|
||||
Tracecv(isgraph(lc), (stderr, " '%c' ", lc));
|
||||
Tracecv(lc > ' ', (stderr, " '%c' ", lc));
|
||||
} else {
|
||||
/* Here, lc is the match length - MIN_MATCH */
|
||||
code = G2.length_code[lc];
|
||||
@@ -2043,6 +2043,23 @@ IF_DESKTOP(long long) int pack_gzip(unpack_info_t *info UNUSED_PARAM)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
|
||||
static const char gzip_longopts[] ALIGN1 =
|
||||
"stdout\0" No_argument "c"
|
||||
"to-stdout\0" No_argument "c"
|
||||
"force\0" No_argument "f"
|
||||
"verbose\0" No_argument "v"
|
||||
#if ENABLE_GUNZIP
|
||||
"decompress\0" No_argument "d"
|
||||
"uncompress\0" No_argument "d"
|
||||
"test\0" No_argument "t"
|
||||
#endif
|
||||
"quiet\0" No_argument "q"
|
||||
"fast\0" No_argument "1"
|
||||
"best\0" No_argument "9"
|
||||
;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Linux kernel build uses gzip -d -n. We accept and ignore it.
|
||||
* Man page says:
|
||||
@@ -2066,6 +2083,9 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
unsigned opt;
|
||||
|
||||
#if ENABLE_FEATURE_GZIP_LONG_OPTIONS
|
||||
applet_long_options = gzip_longopts;
|
||||
#endif
|
||||
/* Must match bbunzip's constants OPT_STDOUT, OPT_FORCE! */
|
||||
opt = getopt32(argv, "cfv" IF_GUNZIP("dt") "q123456789n");
|
||||
#if ENABLE_GUNZIP /* gunzip_main may not be visible... */
|
||||
@@ -2078,9 +2098,8 @@ int gzip_main(int argc UNUSED_PARAM, char **argv)
|
||||
//if (opt & 0x4) // -v
|
||||
argv += optind;
|
||||
|
||||
SET_PTR_TO_GLOBALS(xzalloc(sizeof(struct globals) + sizeof(struct globals2))
|
||||
SET_PTR_TO_GLOBALS((char *)xzalloc(sizeof(struct globals)+sizeof(struct globals2))
|
||||
+ sizeof(struct globals));
|
||||
barrier();
|
||||
|
||||
/* Allocate all global buffers (for DYN_ALLOC option) */
|
||||
ALLOC(uch, G1.l_buf, INBUFSIZ);
|
||||
|
||||
@@ -11,7 +11,6 @@ COMMON_FILES:= \
|
||||
data_skip.o \
|
||||
data_extract_all.o \
|
||||
data_extract_to_stdout.o \
|
||||
data_extract_to_buffer.o \
|
||||
\
|
||||
filter_accept_all.o \
|
||||
filter_accept_list.o \
|
||||
|
||||
@@ -10,6 +10,6 @@ void FAST_FUNC data_align(archive_handle_t *archive_handle, unsigned boundary)
|
||||
{
|
||||
unsigned skip_amount = (boundary - (archive_handle->offset % boundary)) % boundary;
|
||||
|
||||
archive_handle->seek(archive_handle, skip_amount);
|
||||
archive_handle->seek(archive_handle->src_fd, skip_amount);
|
||||
archive_handle->offset += skip_amount;
|
||||
}
|
||||
@@ -13,31 +13,33 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
int res;
|
||||
|
||||
if (archive_handle->ah_flags & ARCHIVE_CREATE_LEADING_DIRS) {
|
||||
char *name = xstrdup(file_header->name);
|
||||
bb_make_directory(dirname(name), -1, FILEUTILS_RECUR);
|
||||
free(name);
|
||||
char *slash = strrchr(file_header->name, '/');
|
||||
if (slash) {
|
||||
*slash = '\0';
|
||||
bb_make_directory(file_header->name, -1, FILEUTILS_RECUR);
|
||||
*slash = '/';
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the file already exists */
|
||||
if (archive_handle->ah_flags & ARCHIVE_EXTRACT_UNCONDITIONAL) {
|
||||
if (archive_handle->ah_flags & ARCHIVE_UNLINK_OLD) {
|
||||
/* Remove the entry if it exists */
|
||||
if ((!S_ISDIR(file_header->mode))
|
||||
&& (unlink(file_header->name) == -1)
|
||||
&& (errno != ENOENT)
|
||||
) {
|
||||
bb_perror_msg_and_die("cannot remove old file %s",
|
||||
bb_perror_msg_and_die("can't remove old file %s",
|
||||
file_header->name);
|
||||
}
|
||||
}
|
||||
else if (archive_handle->ah_flags & ARCHIVE_EXTRACT_NEWER) {
|
||||
/* Remove the existing entry if its older than the extracted entry */
|
||||
struct stat statbuf;
|
||||
if (lstat(file_header->name, &statbuf) == -1) {
|
||||
struct stat existing_sb;
|
||||
if (lstat(file_header->name, &existing_sb) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("cannot stat old file");
|
||||
bb_perror_msg_and_die("can't stat old file");
|
||||
}
|
||||
}
|
||||
else if (statbuf.st_mtime <= file_header->mtime) {
|
||||
else if (existing_sb.st_mtime >= file_header->mtime) {
|
||||
if (!(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_error_msg("%s not created: newer or "
|
||||
"same age file exists", file_header->name);
|
||||
@@ -46,20 +48,21 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
return;
|
||||
}
|
||||
else if ((unlink(file_header->name) == -1) && (errno != EISDIR)) {
|
||||
bb_perror_msg_and_die("cannot remove old file %s",
|
||||
bb_perror_msg_and_die("can't remove old file %s",
|
||||
file_header->name);
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle hard links separately
|
||||
* We identified hard links as regular files of size 0 with a symlink */
|
||||
if (S_ISREG(file_header->mode) && (file_header->link_target)
|
||||
&& (file_header->size == 0)
|
||||
if (S_ISREG(file_header->mode)
|
||||
&& file_header->link_target
|
||||
&& file_header->size == 0
|
||||
) {
|
||||
/* hard link */
|
||||
res = link(file_header->link_target, file_header->name);
|
||||
if ((res == -1) && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) {
|
||||
bb_perror_msg("cannot create %slink "
|
||||
bb_perror_msg("can't create %slink "
|
||||
"from %s to %s", "hard",
|
||||
file_header->name,
|
||||
file_header->link_target);
|
||||
@@ -69,8 +72,13 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
switch (file_header->mode & S_IFMT) {
|
||||
case S_IFREG: {
|
||||
/* Regular file */
|
||||
dst_fd = xopen3(file_header->name, O_WRONLY | O_CREAT | O_EXCL,
|
||||
file_header->mode);
|
||||
int flags = O_WRONLY | O_CREAT | O_EXCL;
|
||||
if (archive_handle->ah_flags & ARCHIVE_O_TRUNC)
|
||||
flags = O_WRONLY | O_CREAT | O_TRUNC;
|
||||
dst_fd = xopen3(file_header->name,
|
||||
flags,
|
||||
file_header->mode
|
||||
);
|
||||
bb_copyfd_exact_size(archive_handle->src_fd, dst_fd, file_header->size);
|
||||
close(dst_fd);
|
||||
break;
|
||||
@@ -82,7 +90,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
&& (errno != EEXIST)
|
||||
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("cannot make dir %s", file_header->name);
|
||||
bb_perror_msg("can't make dir %s", file_header->name);
|
||||
}
|
||||
break;
|
||||
case S_IFLNK:
|
||||
@@ -91,7 +99,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
if ((res == -1)
|
||||
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("cannot create %slink "
|
||||
bb_perror_msg("can't create %slink "
|
||||
"from %s to %s", "sym",
|
||||
file_header->name,
|
||||
file_header->link_target);
|
||||
@@ -105,7 +113,7 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
if ((res == -1)
|
||||
&& !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)
|
||||
) {
|
||||
bb_perror_msg("cannot create node %s", file_header->name);
|
||||
bb_perror_msg("can't create node %s", file_header->name);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -113,37 +121,41 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle)
|
||||
}
|
||||
}
|
||||
|
||||
if (!(archive_handle->ah_flags & ARCHIVE_NOPRESERVE_OWN)) {
|
||||
if (!(archive_handle->ah_flags & ARCHIVE_DONT_RESTORE_OWNER)) {
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
if (!(archive_handle->ah_flags & ARCHIVE_NUMERIC_OWNER)) {
|
||||
uid_t uid = file_header->uid;
|
||||
gid_t gid = file_header->gid;
|
||||
|
||||
if (file_header->uname) {
|
||||
struct passwd *pwd = getpwnam(file_header->uname);
|
||||
if (file_header->tar__uname) {
|
||||
//TODO: cache last name/id pair?
|
||||
struct passwd *pwd = getpwnam(file_header->tar__uname);
|
||||
if (pwd) uid = pwd->pw_uid;
|
||||
}
|
||||
if (file_header->gname) {
|
||||
struct group *grp = getgrnam(file_header->gname);
|
||||
if (file_header->tar__gname) {
|
||||
struct group *grp = getgrnam(file_header->tar__gname);
|
||||
if (grp) gid = grp->gr_gid;
|
||||
}
|
||||
lchown(file_header->name, uid, gid);
|
||||
/* GNU tar 1.15.1 uses chown, not lchown */
|
||||
chown(file_header->name, uid, gid);
|
||||
} else
|
||||
#endif
|
||||
lchown(file_header->name, file_header->uid, file_header->gid);
|
||||
chown(file_header->name, file_header->uid, file_header->gid);
|
||||
}
|
||||
if (S_ISLNK(file_header->mode)) {
|
||||
if (!S_ISLNK(file_header->mode)) {
|
||||
/* uclibc has no lchmod, glibc is even stranger -
|
||||
* it has lchmod which seems to do nothing!
|
||||
* so we use chmod... */
|
||||
if (!(archive_handle->ah_flags & ARCHIVE_NOPRESERVE_PERM)) {
|
||||
if (!(archive_handle->ah_flags & ARCHIVE_DONT_RESTORE_PERM)) {
|
||||
chmod(file_header->name, file_header->mode);
|
||||
}
|
||||
/* same for utime */
|
||||
if (archive_handle->ah_flags & ARCHIVE_PRESERVE_DATE) {
|
||||
struct utimbuf t;
|
||||
t.actime = t.modtime = file_header->mtime;
|
||||
utime(file_header->name, &t);
|
||||
if (archive_handle->ah_flags & ARCHIVE_RESTORE_DATE) {
|
||||
struct timeval t[2];
|
||||
|
||||
t[1].tv_sec = t[0].tv_sec = file_header->mtime;
|
||||
t[1].tv_usec = t[0].tv_usec = 0;
|
||||
utimes(file_header->name, t);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright 2002 Glenn McGrath
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void FAST_FUNC data_extract_to_buffer(archive_handle_t *archive_handle)
|
||||
{
|
||||
unsigned int size = archive_handle->file_header->size;
|
||||
|
||||
archive_handle->buffer = xzalloc(size + 1);
|
||||
xread(archive_handle->src_fd, archive_handle->buffer, size);
|
||||
}
|
||||
@@ -8,5 +8,5 @@
|
||||
|
||||
void FAST_FUNC data_skip(archive_handle_t *archive_handle)
|
||||
{
|
||||
archive_handle->seek(archive_handle, archive_handle->file_header->size);
|
||||
archive_handle->seek(archive_handle->src_fd, archive_handle->file_header->size);
|
||||
}
|
||||
@@ -49,6 +49,8 @@ typedef struct {
|
||||
static size_inline void rc_read(rc_t *rc)
|
||||
{
|
||||
int buffer_size = safe_read(rc->fd, RC_BUFFER, RC_BUFFER_SIZE);
|
||||
//TODO: return -1 instead
|
||||
//This will make unlzma delete broken unpacked file on unpack errors
|
||||
if (buffer_size <= 0)
|
||||
bb_error_msg_and_die("unexpected EOF");
|
||||
rc->ptr = RC_BUFFER;
|
||||
@@ -70,10 +72,10 @@ static ALWAYS_INLINE rc_t* rc_init(int fd) /*, int buffer_size) */
|
||||
int i;
|
||||
rc_t *rc;
|
||||
|
||||
rc = xmalloc(sizeof(*rc) + RC_BUFFER_SIZE);
|
||||
rc = xzalloc(sizeof(*rc) + RC_BUFFER_SIZE);
|
||||
|
||||
rc->fd = fd;
|
||||
rc->ptr = rc->buffer_end;
|
||||
/* rc->ptr = rc->buffer_end; */
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
#if ENABLE_FEATURE_LZMA_FAST
|
||||
@@ -154,7 +156,7 @@ typedef struct {
|
||||
uint8_t pos;
|
||||
uint32_t dict_size;
|
||||
uint64_t dst_size;
|
||||
} __attribute__ ((packed)) lzma_header_t;
|
||||
} PACKED lzma_header_t;
|
||||
|
||||
|
||||
/* #defines will force compiler to compute/optimize each one with each usage.
|
||||
@@ -218,14 +220,11 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
int lc, pb, lp;
|
||||
uint32_t pos_state_mask;
|
||||
uint32_t literal_pos_mask;
|
||||
uint32_t pos;
|
||||
uint16_t *p;
|
||||
uint16_t *prob;
|
||||
uint16_t *prob_lit;
|
||||
int num_bits;
|
||||
int num_probs;
|
||||
rc_t *rc;
|
||||
int i, mi;
|
||||
int i;
|
||||
uint8_t *buffer;
|
||||
uint8_t previous_byte = 0;
|
||||
size_t buffer_pos = 0, global_pos = 0;
|
||||
@@ -233,14 +232,17 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
int state = 0;
|
||||
uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
|
||||
|
||||
xread(src_fd, &header, sizeof(header));
|
||||
if (full_read(src_fd, &header, sizeof(header)) != sizeof(header)
|
||||
|| header.pos >= (9 * 5 * 5)
|
||||
) {
|
||||
bb_error_msg("bad lzma header");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (header.pos >= (9 * 5 * 5))
|
||||
bb_error_msg_and_die("bad header");
|
||||
mi = header.pos / 9;
|
||||
i = header.pos / 9;
|
||||
lc = header.pos % 9;
|
||||
pb = mi / 5;
|
||||
lp = mi % 5;
|
||||
pb = i / 5;
|
||||
lp = i % 5;
|
||||
pos_state_mask = (1 << pb) - 1;
|
||||
literal_pos_mask = (1 << lp) - 1;
|
||||
|
||||
@@ -262,10 +264,13 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
|
||||
while (global_pos + buffer_pos < header.dst_size) {
|
||||
int pos_state = (buffer_pos + global_pos) & pos_state_mask;
|
||||
uint16_t *prob = p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;
|
||||
|
||||
prob = p + LZMA_IS_MATCH + (state << LZMA_NUM_POS_BITS_MAX) + pos_state;
|
||||
if (!rc_is_bit_1(rc, prob)) {
|
||||
mi = 1;
|
||||
static const char next_state[LZMA_NUM_STATES] =
|
||||
{ 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 };
|
||||
int mi = 1;
|
||||
|
||||
prob = (p + LZMA_LITERAL
|
||||
+ (LZMA_LIT_SIZE * ((((buffer_pos + global_pos) & literal_pos_mask) << lc)
|
||||
+ (previous_byte >> (8 - lc))
|
||||
@@ -275,8 +280,8 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
|
||||
if (state >= LZMA_NUM_LIT_STATES) {
|
||||
int match_byte;
|
||||
uint32_t pos = buffer_pos - rep0;
|
||||
|
||||
pos = buffer_pos - rep0;
|
||||
while (pos >= header.dict_size)
|
||||
pos += header.dict_size;
|
||||
match_byte = buffer[pos];
|
||||
@@ -285,22 +290,16 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
|
||||
match_byte <<= 1;
|
||||
bit = match_byte & 0x100;
|
||||
prob_lit = prob + 0x100 + bit + mi;
|
||||
bit ^= (rc_get_bit(rc, prob_lit, &mi) << 8); /* 0x100 or 0 */
|
||||
bit ^= (rc_get_bit(rc, prob + 0x100 + bit + mi, &mi) << 8); /* 0x100 or 0 */
|
||||
if (bit)
|
||||
break;
|
||||
} while (mi < 0x100);
|
||||
}
|
||||
while (mi < 0x100) {
|
||||
prob_lit = prob + mi;
|
||||
rc_get_bit(rc, prob_lit, &mi);
|
||||
rc_get_bit(rc, prob + mi, &mi);
|
||||
}
|
||||
|
||||
state -= 3;
|
||||
if (state < 4-3)
|
||||
state = 0;
|
||||
if (state >= 10-3)
|
||||
state -= 6-3;
|
||||
state = next_state[state];
|
||||
|
||||
previous_byte = (uint8_t) mi;
|
||||
#if ENABLE_FEATURE_LZMA_FAST
|
||||
@@ -319,31 +318,33 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
#endif
|
||||
} else {
|
||||
int offset;
|
||||
uint16_t *prob_len;
|
||||
uint16_t *prob2;
|
||||
#define prob_len prob2
|
||||
|
||||
prob = p + LZMA_IS_REP + state;
|
||||
if (!rc_is_bit_1(rc, prob)) {
|
||||
prob2 = p + LZMA_IS_REP + state;
|
||||
if (!rc_is_bit_1(rc, prob2)) {
|
||||
rep3 = rep2;
|
||||
rep2 = rep1;
|
||||
rep1 = rep0;
|
||||
state = state < LZMA_NUM_LIT_STATES ? 0 : 3;
|
||||
prob = p + LZMA_LEN_CODER;
|
||||
prob2 = p + LZMA_LEN_CODER;
|
||||
} else {
|
||||
prob += LZMA_IS_REP_G0 - LZMA_IS_REP;
|
||||
if (!rc_is_bit_1(rc, prob)) {
|
||||
prob = (p + LZMA_IS_REP_0_LONG
|
||||
prob2 += LZMA_IS_REP_G0 - LZMA_IS_REP;
|
||||
if (!rc_is_bit_1(rc, prob2)) {
|
||||
prob2 = (p + LZMA_IS_REP_0_LONG
|
||||
+ (state << LZMA_NUM_POS_BITS_MAX)
|
||||
+ pos_state
|
||||
);
|
||||
if (!rc_is_bit_1(rc, prob)) {
|
||||
state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
|
||||
if (!rc_is_bit_1(rc, prob2)) {
|
||||
#if ENABLE_FEATURE_LZMA_FAST
|
||||
pos = buffer_pos - rep0;
|
||||
uint32_t pos = buffer_pos - rep0;
|
||||
state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
|
||||
while (pos >= header.dict_size)
|
||||
pos += header.dict_size;
|
||||
previous_byte = buffer[pos];
|
||||
goto one_byte1;
|
||||
#else
|
||||
state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
|
||||
len = 1;
|
||||
goto string;
|
||||
#endif
|
||||
@@ -351,12 +352,12 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
} else {
|
||||
uint32_t distance;
|
||||
|
||||
prob += LZMA_IS_REP_G1 - LZMA_IS_REP_G0;
|
||||
prob2 += LZMA_IS_REP_G1 - LZMA_IS_REP_G0;
|
||||
distance = rep1;
|
||||
if (rc_is_bit_1(rc, prob)) {
|
||||
prob += LZMA_IS_REP_G2 - LZMA_IS_REP_G1;
|
||||
if (rc_is_bit_1(rc, prob2)) {
|
||||
prob2 += LZMA_IS_REP_G2 - LZMA_IS_REP_G1;
|
||||
distance = rep2;
|
||||
if (rc_is_bit_1(rc, prob)) {
|
||||
if (rc_is_bit_1(rc, prob2)) {
|
||||
distance = rep3;
|
||||
rep3 = rep2;
|
||||
}
|
||||
@@ -366,27 +367,27 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
rep0 = distance;
|
||||
}
|
||||
state = state < LZMA_NUM_LIT_STATES ? 8 : 11;
|
||||
prob = p + LZMA_REP_LEN_CODER;
|
||||
prob2 = p + LZMA_REP_LEN_CODER;
|
||||
}
|
||||
|
||||
prob_len = prob + LZMA_LEN_CHOICE;
|
||||
prob_len = prob2 + LZMA_LEN_CHOICE;
|
||||
num_bits = LZMA_LEN_NUM_LOW_BITS;
|
||||
if (!rc_is_bit_1(rc, prob_len)) {
|
||||
prob_len += LZMA_LEN_LOW - LZMA_LEN_CHOICE
|
||||
+ (pos_state << LZMA_LEN_NUM_LOW_BITS);
|
||||
offset = 0;
|
||||
num_bits = LZMA_LEN_NUM_LOW_BITS;
|
||||
} else {
|
||||
prob_len += LZMA_LEN_CHOICE_2 - LZMA_LEN_CHOICE;
|
||||
if (!rc_is_bit_1(rc, prob_len)) {
|
||||
prob_len += LZMA_LEN_MID - LZMA_LEN_CHOICE_2
|
||||
+ (pos_state << LZMA_LEN_NUM_MID_BITS);
|
||||
offset = 1 << LZMA_LEN_NUM_LOW_BITS;
|
||||
num_bits = LZMA_LEN_NUM_MID_BITS;
|
||||
num_bits += LZMA_LEN_NUM_MID_BITS - LZMA_LEN_NUM_LOW_BITS;
|
||||
} else {
|
||||
prob_len += LZMA_LEN_HIGH - LZMA_LEN_CHOICE_2;
|
||||
offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
|
||||
+ (1 << LZMA_LEN_NUM_MID_BITS));
|
||||
num_bits = LZMA_LEN_NUM_HIGH_BITS;
|
||||
num_bits += LZMA_LEN_NUM_HIGH_BITS - LZMA_LEN_NUM_LOW_BITS;
|
||||
}
|
||||
}
|
||||
rc_bit_tree_decode(rc, prob_len, num_bits, &len);
|
||||
@@ -394,35 +395,34 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
|
||||
if (state < 4) {
|
||||
int pos_slot;
|
||||
uint16_t *prob3;
|
||||
|
||||
state += LZMA_NUM_LIT_STATES;
|
||||
prob = p + LZMA_POS_SLOT +
|
||||
prob3 = p + LZMA_POS_SLOT +
|
||||
((len < LZMA_NUM_LEN_TO_POS_STATES ? len :
|
||||
LZMA_NUM_LEN_TO_POS_STATES - 1)
|
||||
<< LZMA_NUM_POS_SLOT_BITS);
|
||||
rc_bit_tree_decode(rc, prob,
|
||||
rc_bit_tree_decode(rc, prob3,
|
||||
LZMA_NUM_POS_SLOT_BITS, &pos_slot);
|
||||
rep0 = pos_slot;
|
||||
if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
|
||||
num_bits = (pos_slot >> 1) - 1;
|
||||
int i2, mi2, num_bits2 = (pos_slot >> 1) - 1;
|
||||
rep0 = 2 | (pos_slot & 1);
|
||||
prob = p + LZMA_ALIGN;
|
||||
if (pos_slot < LZMA_END_POS_MODEL_INDEX) {
|
||||
rep0 <<= num_bits;
|
||||
prob += LZMA_SPEC_POS - LZMA_ALIGN - 1 + rep0 - pos_slot;
|
||||
rep0 <<= num_bits2;
|
||||
prob3 = p + LZMA_SPEC_POS + rep0 - pos_slot - 1;
|
||||
} else {
|
||||
num_bits -= LZMA_NUM_ALIGN_BITS;
|
||||
while (num_bits--)
|
||||
for (; num_bits2 != LZMA_NUM_ALIGN_BITS; num_bits2--)
|
||||
rep0 = (rep0 << 1) | rc_direct_bit(rc);
|
||||
rep0 <<= LZMA_NUM_ALIGN_BITS;
|
||||
num_bits = LZMA_NUM_ALIGN_BITS;
|
||||
prob3 = p + LZMA_ALIGN;
|
||||
}
|
||||
i = 1;
|
||||
mi = 1;
|
||||
while (num_bits--) {
|
||||
if (rc_get_bit(rc, prob + mi, &mi))
|
||||
rep0 |= i;
|
||||
i <<= 1;
|
||||
i2 = 1;
|
||||
mi2 = 1;
|
||||
while (num_bits2--) {
|
||||
if (rc_get_bit(rc, prob3 + mi2, &mi2))
|
||||
rep0 |= i2;
|
||||
i2 <<= 1;
|
||||
}
|
||||
}
|
||||
if (++rep0 == 0)
|
||||
@@ -432,7 +432,7 @@ unpack_lzma_stream(int src_fd, int dst_fd)
|
||||
len += LZMA_MATCH_MIN_LEN;
|
||||
IF_NOT_FEATURE_LZMA_FAST(string:)
|
||||
do {
|
||||
pos = buffer_pos - rep0;
|
||||
uint32_t pos = buffer_pos - rep0;
|
||||
while (pos >= header.dict_size)
|
||||
pos += header.dict_size;
|
||||
previous_byte = buffer[pos];
|
||||
|
||||
@@ -503,7 +503,7 @@ static void inflate_codes_setup(STATE_PARAM unsigned my_bl, unsigned my_bd)
|
||||
md = mask_bits[bd];
|
||||
}
|
||||
/* called once from inflate_get_next_window */
|
||||
static int inflate_codes(STATE_PARAM_ONLY)
|
||||
static NOINLINE int inflate_codes(STATE_PARAM_ONLY)
|
||||
{
|
||||
unsigned e; /* table entry flag/number of extra bits */
|
||||
huft_t *t; /* pointer to table entry */
|
||||
@@ -1117,7 +1117,7 @@ static int check_header_gzip(STATE_PARAM unpack_info_t *info)
|
||||
uint32_t mtime;
|
||||
uint8_t xtra_flags_UNUSED;
|
||||
uint8_t os_flags_UNUSED;
|
||||
} __attribute__((packed)) formatted;
|
||||
} PACKED formatted;
|
||||
} header;
|
||||
struct BUG_header {
|
||||
char BUG_header[sizeof(header) == 8 ? 1 : -1];
|
||||
|
||||
@@ -31,19 +31,19 @@ char FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle)
|
||||
if (ENABLE_FEATURE_SEAMLESS_GZ
|
||||
&& strcmp(name_ptr, "gz") == 0
|
||||
) {
|
||||
archive_handle->action_data_subarchive = get_header_tar_gz;
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar_gz;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
&& strcmp(name_ptr, "bz2") == 0
|
||||
) {
|
||||
archive_handle->action_data_subarchive = get_header_tar_bz2;
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar_bz2;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (ENABLE_FEATURE_SEAMLESS_LZMA
|
||||
&& strcmp(name_ptr, "lzma") == 0
|
||||
) {
|
||||
archive_handle->action_data_subarchive = get_header_tar_lzma;
|
||||
archive_handle->dpkg__action_data_subarchive = get_header_tar_lzma;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,20 @@
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
static unsigned read_num(const char *str, int base)
|
||||
{
|
||||
/* This code works because
|
||||
* on misformatted numbers bb_strtou returns all-ones */
|
||||
int err = bb_strtou(str, NULL, base);
|
||||
if (err == -1)
|
||||
bb_error_msg_and_die("invalid ar header");
|
||||
return err;
|
||||
}
|
||||
|
||||
char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
{
|
||||
int err;
|
||||
file_header_t *typed = archive_handle->file_header;
|
||||
unsigned size;
|
||||
union {
|
||||
char raw[60];
|
||||
struct {
|
||||
@@ -49,57 +59,60 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
if (ar.formatted.magic[0] != '`' || ar.formatted.magic[1] != '\n')
|
||||
bb_error_msg_and_die("invalid ar header");
|
||||
|
||||
/* FIXME: more thorough routine would be in order here */
|
||||
/* (we have something like that in tar) */
|
||||
/* but for now we are lax. This code works because */
|
||||
/* on misformatted numbers bb_strtou returns all-ones */
|
||||
typed->mode = err = bb_strtou(ar.formatted.mode, NULL, 8);
|
||||
if (err == -1) bb_error_msg_and_die("invalid ar header");
|
||||
typed->mtime = err = bb_strtou(ar.formatted.date, NULL, 10);
|
||||
if (err == -1) bb_error_msg_and_die("invalid ar header");
|
||||
typed->uid = err = bb_strtou(ar.formatted.uid, NULL, 10);
|
||||
if (err == -1) bb_error_msg_and_die("invalid ar header");
|
||||
typed->gid = err = bb_strtou(ar.formatted.gid, NULL, 10);
|
||||
if (err == -1) bb_error_msg_and_die("invalid ar header");
|
||||
typed->size = err = bb_strtou(ar.formatted.size, NULL, 10);
|
||||
if (err == -1) bb_error_msg_and_die("invalid ar header");
|
||||
/* FIXME: more thorough routine would be in order here
|
||||
* (we have something like that in tar)
|
||||
* but for now we are lax. */
|
||||
typed->size = size = read_num(ar.formatted.size, 10);
|
||||
|
||||
/* long filenames have '/' as the first character */
|
||||
/* special filenames have '/' as the first character */
|
||||
if (ar.formatted.name[0] == '/') {
|
||||
#if ENABLE_FEATURE_AR_LONG_FILENAMES
|
||||
unsigned long_offset;
|
||||
|
||||
if (ar.formatted.name[1] == '/') {
|
||||
/* If the second char is a '/' then this entries data section
|
||||
* stores long filename for multiple entries, they are stored
|
||||
* in static variable long_names for use in future entries */
|
||||
ar_long_name_size = typed->size;
|
||||
ar_long_names = xmalloc(ar_long_name_size);
|
||||
xread(archive_handle->src_fd, ar_long_names, ar_long_name_size);
|
||||
archive_handle->offset += ar_long_name_size;
|
||||
/* This ar entries data section only contained filenames for other records
|
||||
* they are stored in the static ar_long_names for future reference */
|
||||
return get_header_ar(archive_handle); /* Return next header */
|
||||
}
|
||||
|
||||
if (ar.formatted.name[1] == ' ') {
|
||||
/* This is the index of symbols in the file for compilers */
|
||||
data_skip(archive_handle);
|
||||
archive_handle->offset += typed->size;
|
||||
archive_handle->offset += size;
|
||||
return get_header_ar(archive_handle); /* Return next header */
|
||||
}
|
||||
#if ENABLE_FEATURE_AR_LONG_FILENAMES
|
||||
if (ar.formatted.name[1] == '/') {
|
||||
/* If the second char is a '/' then this entries data section
|
||||
* stores long filename for multiple entries, they are stored
|
||||
* in static variable long_names for use in future entries
|
||||
*/
|
||||
ar_long_name_size = size;
|
||||
free(ar_long_names);
|
||||
ar_long_names = xmalloc(size);
|
||||
xread(archive_handle->src_fd, ar_long_names, size);
|
||||
archive_handle->offset += size;
|
||||
/* Return next header */
|
||||
return get_header_ar(archive_handle);
|
||||
}
|
||||
#else
|
||||
bb_error_msg_and_die("long filenames not supported");
|
||||
#endif
|
||||
}
|
||||
/* Only size is always present, the rest may be missing in
|
||||
* long filename pseudo file. Thus we decode the rest
|
||||
* after dealing with long filename pseudo file.
|
||||
*/
|
||||
typed->mode = read_num(ar.formatted.mode, 8);
|
||||
typed->mtime = read_num(ar.formatted.date, 10);
|
||||
typed->uid = read_num(ar.formatted.uid, 10);
|
||||
typed->gid = read_num(ar.formatted.gid, 10);
|
||||
|
||||
#if ENABLE_FEATURE_AR_LONG_FILENAMES
|
||||
if (ar.formatted.name[0] == '/') {
|
||||
unsigned long_offset;
|
||||
|
||||
/* The number after the '/' indicates the offset in the ar data section
|
||||
* (saved in variable long_name) that conatains the real filename */
|
||||
long_offset = atoi(&ar.formatted.name[1]);
|
||||
* (saved in ar_long_names) that conatains the real filename */
|
||||
long_offset = read_num(&ar.formatted.name[1], 10);
|
||||
if (long_offset >= ar_long_name_size) {
|
||||
bb_error_msg_and_die("can't resolve long filename");
|
||||
}
|
||||
typed->name = xstrdup(ar_long_names + long_offset);
|
||||
#else
|
||||
bb_error_msg_and_die("long filenames not supported");
|
||||
} else
|
||||
#endif
|
||||
} else {
|
||||
{
|
||||
/* short filenames */
|
||||
typed->name = xstrndup(ar.formatted.name, 16);
|
||||
}
|
||||
@@ -109,8 +122,8 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
|
||||
archive_handle->action_header(typed);
|
||||
#if ENABLE_DPKG || ENABLE_DPKG_DEB
|
||||
if (archive_handle->sub_archive) {
|
||||
while (archive_handle->action_data_subarchive(archive_handle->sub_archive) == EXIT_SUCCESS)
|
||||
if (archive_handle->dpkg__sub_archive) {
|
||||
while (archive_handle->dpkg__action_data_subarchive(archive_handle->dpkg__sub_archive) == EXIT_SUCCESS)
|
||||
continue;
|
||||
} else
|
||||
#endif
|
||||
|
||||
@@ -25,15 +25,6 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
int major, minor, nlink, mode, inode;
|
||||
unsigned size, uid, gid, mtime;
|
||||
|
||||
#define hardlinks_to_create (*(hardlinks_t **)(&archive_handle->ah_priv[0]))
|
||||
#define created_hardlinks (*(hardlinks_t **)(&archive_handle->ah_priv[1]))
|
||||
#define block_count (archive_handle->ah_priv[2])
|
||||
// if (!archive_handle->ah_priv_inited) {
|
||||
// archive_handle->ah_priv_inited = 1;
|
||||
// hardlinks_to_create = NULL;
|
||||
// created_hardlinks = NULL;
|
||||
// }
|
||||
|
||||
/* There can be padding before archive header */
|
||||
data_align(archive_handle, 4);
|
||||
|
||||
@@ -70,6 +61,15 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
file_header->name = xzalloc(namesize + 1);
|
||||
/* Read in filename */
|
||||
xread(archive_handle->src_fd, file_header->name, namesize);
|
||||
if (file_header->name[0] == '/') {
|
||||
/* Testcase: echo /etc/hosts | cpio -pvd /tmp
|
||||
* Without this code, it tries to unpack /etc/hosts
|
||||
* into "/etc/hosts", not "etc/hosts".
|
||||
*/
|
||||
char *p = file_header->name;
|
||||
do p++; while (*p == '/');
|
||||
overlapping_strcpy(file_header->name, p);
|
||||
}
|
||||
archive_handle->offset += namesize;
|
||||
|
||||
/* Update offset amount and skip padding before file contents */
|
||||
@@ -77,7 +77,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
|
||||
if (strcmp(file_header->name, "TRAILER!!!") == 0) {
|
||||
/* Always round up. ">> 9" divides by 512 */
|
||||
block_count = (void*)(ptrdiff_t) ((archive_handle->offset + 511) >> 9);
|
||||
archive_handle->cpio__blocks = (uoff_t)(archive_handle->offset + 511) >> 9;
|
||||
goto create_hardlinks;
|
||||
}
|
||||
|
||||
@@ -103,18 +103,22 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
strcpy(new->name, file_header->name);
|
||||
/* Put file on a linked list for later */
|
||||
if (size == 0) {
|
||||
new->next = hardlinks_to_create;
|
||||
hardlinks_to_create = new;
|
||||
new->next = archive_handle->cpio__hardlinks_to_create;
|
||||
archive_handle->cpio__hardlinks_to_create = new;
|
||||
return EXIT_SUCCESS; /* Skip this one */
|
||||
/* TODO: this breaks cpio -t (it does not show hardlinks) */
|
||||
}
|
||||
new->next = created_hardlinks;
|
||||
created_hardlinks = new;
|
||||
new->next = archive_handle->cpio__created_hardlinks;
|
||||
archive_handle->cpio__created_hardlinks = new;
|
||||
}
|
||||
file_header->device = makedev(major, minor);
|
||||
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
|
||||
archive_handle->action_data(archive_handle);
|
||||
//TODO: run "echo /etc/hosts | cpio -pv /tmp" twice. On 2nd run:
|
||||
//cpio: etc/hosts not created: newer or same age file exists
|
||||
//etc/hosts <-- should NOT show it
|
||||
//2 blocks <-- should say "0 blocks"
|
||||
archive_handle->action_header(file_header);
|
||||
} else {
|
||||
data_skip(archive_handle);
|
||||
@@ -133,11 +137,11 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
free(file_header->link_target);
|
||||
free(file_header->name);
|
||||
|
||||
while (hardlinks_to_create) {
|
||||
while (archive_handle->cpio__hardlinks_to_create) {
|
||||
hardlinks_t *cur;
|
||||
hardlinks_t *make_me = hardlinks_to_create;
|
||||
hardlinks_t *make_me = archive_handle->cpio__hardlinks_to_create;
|
||||
|
||||
hardlinks_to_create = make_me->next;
|
||||
archive_handle->cpio__hardlinks_to_create = make_me->next;
|
||||
|
||||
memset(file_header, 0, sizeof(*file_header));
|
||||
file_header->mtime = make_me->mtime;
|
||||
@@ -149,7 +153,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
/*file_header->link_target = NULL;*/
|
||||
|
||||
/* Try to find a file we are hardlinked to */
|
||||
cur = created_hardlinks;
|
||||
cur = archive_handle->cpio__created_hardlinks;
|
||||
while (cur) {
|
||||
/* TODO: must match maj/min too! */
|
||||
if (cur->inode == make_me->inode) {
|
||||
@@ -167,14 +171,14 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle)
|
||||
if (archive_handle->filter(archive_handle) == EXIT_SUCCESS)
|
||||
archive_handle->action_data(archive_handle);
|
||||
/* Move to the list of created hardlinked files */
|
||||
make_me->next = created_hardlinks;
|
||||
created_hardlinks = make_me;
|
||||
make_me->next = archive_handle->cpio__created_hardlinks;
|
||||
archive_handle->cpio__created_hardlinks = make_me;
|
||||
next_link: ;
|
||||
}
|
||||
|
||||
while (created_hardlinks) {
|
||||
hardlinks_t *p = created_hardlinks;
|
||||
created_hardlinks = p->next;
|
||||
while (archive_handle->cpio__created_hardlinks) {
|
||||
hardlinks_t *p = archive_handle->cpio__created_hardlinks;
|
||||
archive_handle->cpio__created_hardlinks = p->next;
|
||||
free(p);
|
||||
}
|
||||
|
||||
|
||||
@@ -87,11 +87,13 @@ static unsigned long long getOctal(char *str, int len)
|
||||
{
|
||||
unsigned long long v;
|
||||
/* NB: leading spaces are allowed. Using strtoull to handle that.
|
||||
* The downside is that we accept e.g. "-123" too :)
|
||||
* The downside is that we accept e.g. "-123" too :(
|
||||
*/
|
||||
str[len] = '\0';
|
||||
v = strtoull(str, &str, 8);
|
||||
if (*str && (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY || *str != ' '))
|
||||
/* std: "Each numeric field is terminated by one or more
|
||||
* <space> or NUL characters". We must support ' '! */
|
||||
if (*str != '\0' && *str != ' ')
|
||||
bb_error_msg_and_die("corrupted octal value in tar header");
|
||||
return v;
|
||||
}
|
||||
@@ -133,20 +135,13 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
int parse_names;
|
||||
|
||||
/* Our "private data" */
|
||||
#define p_end (*(smallint *)(&archive_handle->ah_priv[0]))
|
||||
#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
|
||||
#define p_longname (*(char* *)(&archive_handle->ah_priv[1]))
|
||||
#define p_linkname (*(char* *)(&archive_handle->ah_priv[2]))
|
||||
# define p_longname (archive_handle->tar__longname)
|
||||
# define p_linkname (archive_handle->tar__linkname)
|
||||
#else
|
||||
#define p_longname 0
|
||||
#define p_linkname 0
|
||||
# define p_longname 0
|
||||
# define p_linkname 0
|
||||
#endif
|
||||
// if (!archive_handle->ah_priv_inited) {
|
||||
// archive_handle->ah_priv_inited = 1;
|
||||
// p_end = 0;
|
||||
// IF_FEATURE_TAR_GNU_EXTENSIONS(p_longname = NULL;)
|
||||
// IF_FEATURE_TAR_GNU_EXTENSIONS(p_linkname = NULL;)
|
||||
// }
|
||||
|
||||
if (sizeof(tar) != 512)
|
||||
BUG_tar_header_size();
|
||||
@@ -188,7 +183,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
|
||||
/* If there is no filename its an empty header */
|
||||
if (tar.name[0] == 0 && tar.prefix[0] == 0) {
|
||||
if (p_end) {
|
||||
if (archive_handle->tar__end) {
|
||||
/* Second consecutive empty header - end of archive.
|
||||
* Read until the end to empty the pipe from gz or bz2
|
||||
*/
|
||||
@@ -196,10 +191,10 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
continue;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
p_end = 1;
|
||||
archive_handle->tar__end = 1;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
p_end = 0;
|
||||
archive_handle->tar__end = 0;
|
||||
|
||||
/* Check header has valid magic, "ustar" is for the proper tar,
|
||||
* five NULs are for the old tar format */
|
||||
@@ -262,20 +257,21 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
sum_s += ((signed char*)&tar)[i];
|
||||
#endif
|
||||
}
|
||||
#if ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY
|
||||
sum = strtoul(tar.chksum, &cp, 8);
|
||||
if ((*cp && *cp != ' ')
|
||||
|| (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum))
|
||||
) {
|
||||
bb_error_msg_and_die("invalid tar header checksum");
|
||||
}
|
||||
#else
|
||||
/* This field does not need special treatment (getOctal) */
|
||||
sum = xstrtoul(tar.chksum, 8);
|
||||
{
|
||||
char *endp; /* gcc likes temp var for &endp */
|
||||
sum = strtoul(tar.chksum, &endp, 8);
|
||||
if ((*endp != '\0' && *endp != ' ')
|
||||
|| (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum))
|
||||
) {
|
||||
bb_error_msg_and_die("invalid tar header checksum");
|
||||
}
|
||||
}
|
||||
/* don't use xstrtoul, tar.chksum may have leading spaces */
|
||||
sum = strtoul(tar.chksum, NULL, 8);
|
||||
if (sum_u != sum IF_FEATURE_TAR_OLDSUN_COMPATIBILITY(&& sum_s != sum)) {
|
||||
bb_error_msg_and_die("invalid tar header checksum");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* 0 is reserved for high perf file, treat as normal file */
|
||||
if (!tar.typeflag) tar.typeflag = '0';
|
||||
@@ -298,8 +294,8 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
/* Will link_target be free()ed? */
|
||||
}
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
file_header->uname = tar.uname[0] ? xstrndup(tar.uname, sizeof(tar.uname)) : NULL;
|
||||
file_header->gname = tar.gname[0] ? xstrndup(tar.gname, sizeof(tar.gname)) : NULL;
|
||||
file_header->tar__uname = tar.uname[0] ? xstrndup(tar.uname, sizeof(tar.uname)) : NULL;
|
||||
file_header->tar__gname = tar.gname[0] ? xstrndup(tar.gname, sizeof(tar.gname)) : NULL;
|
||||
#endif
|
||||
/* mtime: rudimentally handle GNU tar's "base256 encoding"
|
||||
* People report tarballs with NEGATIVE unix times encoded that way */
|
||||
@@ -446,8 +442,8 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
|
||||
free(file_header->link_target);
|
||||
/* Do not free(file_header->name)! (why?) */
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
free(file_header->uname);
|
||||
free(file_header->gname);
|
||||
free(file_header->tar__uname);
|
||||
free(file_header->tar__gname);
|
||||
#endif
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -7,5 +7,6 @@
|
||||
|
||||
void FAST_FUNC header_list(const file_header_t *file_header)
|
||||
{
|
||||
//TODO: cpio -vp DIR should output "DIR/NAME", not just "NAME" */
|
||||
puts(file_header->name);
|
||||
}
|
||||
@@ -8,47 +8,57 @@
|
||||
|
||||
void FAST_FUNC header_verbose_list(const file_header_t *file_header)
|
||||
{
|
||||
struct tm *mtime = localtime(&(file_header->mtime));
|
||||
struct tm tm_time;
|
||||
struct tm *ptm = &tm_time; //localtime(&file_header->mtime);
|
||||
|
||||
#if ENABLE_FEATURE_TAR_UNAME_GNAME
|
||||
char uid[8];
|
||||
char gid[8];
|
||||
char *user = file_header->uname;
|
||||
char *group = file_header->gname;
|
||||
char uid[sizeof(int)*3 + 2];
|
||||
/*char gid[sizeof(int)*3 + 2];*/
|
||||
char *user;
|
||||
char *group;
|
||||
|
||||
localtime_r(&file_header->mtime, ptm);
|
||||
|
||||
user = file_header->tar__uname;
|
||||
if (user == NULL) {
|
||||
snprintf(uid, sizeof(uid), "%u", (unsigned)file_header->uid);
|
||||
sprintf(uid, "%u", (unsigned)file_header->uid);
|
||||
user = uid;
|
||||
}
|
||||
group = file_header->tar__gname;
|
||||
if (group == NULL) {
|
||||
snprintf(gid, sizeof(gid), "%u", (unsigned)file_header->gid);
|
||||
group = gid;
|
||||
/*sprintf(gid, "%u", (unsigned)file_header->gid);*/
|
||||
group = utoa(file_header->gid);
|
||||
}
|
||||
printf("%s %s/%s %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
|
||||
bb_mode_string(file_header->mode),
|
||||
user,
|
||||
group,
|
||||
file_header->size,
|
||||
1900 + mtime->tm_year,
|
||||
1 + mtime->tm_mon,
|
||||
mtime->tm_mday,
|
||||
mtime->tm_hour,
|
||||
mtime->tm_min,
|
||||
mtime->tm_sec,
|
||||
1900 + ptm->tm_year,
|
||||
1 + ptm->tm_mon,
|
||||
ptm->tm_mday,
|
||||
ptm->tm_hour,
|
||||
ptm->tm_min,
|
||||
ptm->tm_sec,
|
||||
file_header->name);
|
||||
|
||||
#else /* !FEATURE_TAR_UNAME_GNAME */
|
||||
printf("%s %d/%d %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
|
||||
|
||||
localtime_r(&file_header->mtime, ptm);
|
||||
|
||||
printf("%s %u/%u %9"OFF_FMT"u %4u-%02u-%02u %02u:%02u:%02u %s",
|
||||
bb_mode_string(file_header->mode),
|
||||
file_header->uid,
|
||||
file_header->gid,
|
||||
(unsigned)file_header->uid,
|
||||
(unsigned)file_header->gid,
|
||||
file_header->size,
|
||||
1900 + mtime->tm_year,
|
||||
1 + mtime->tm_mon,
|
||||
mtime->tm_mday,
|
||||
mtime->tm_hour,
|
||||
mtime->tm_min,
|
||||
mtime->tm_sec,
|
||||
1900 + ptm->tm_year,
|
||||
1 + ptm->tm_mon,
|
||||
ptm->tm_mday,
|
||||
ptm->tm_hour,
|
||||
ptm->tm_min,
|
||||
ptm->tm_sec,
|
||||
file_header->name);
|
||||
|
||||
#endif /* FEATURE_TAR_UNAME_GNAME */
|
||||
|
||||
if (file_header->link_target) {
|
||||
|
||||
@@ -6,13 +6,13 @@
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
void FAST_FUNC seek_by_jump(const archive_handle_t *archive_handle, unsigned amount)
|
||||
void FAST_FUNC seek_by_jump(int fd, off_t amount)
|
||||
{
|
||||
if (amount
|
||||
&& lseek(archive_handle->src_fd, (off_t) amount, SEEK_CUR) == (off_t) -1
|
||||
&& lseek(fd, amount, SEEK_CUR) == (off_t) -1
|
||||
) {
|
||||
if (errno == ESPIPE)
|
||||
seek_by_read(archive_handle, amount);
|
||||
seek_by_read(fd, amount);
|
||||
else
|
||||
bb_perror_msg_and_die("seek failure");
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
/* If we are reading through a pipe, or from stdin then we can't lseek,
|
||||
* we must read and discard the data to skip over it.
|
||||
*/
|
||||
void FAST_FUNC seek_by_read(const archive_handle_t *archive_handle, unsigned jump_size)
|
||||
void FAST_FUNC seek_by_read(int fd, off_t amount)
|
||||
{
|
||||
if (jump_size)
|
||||
bb_copyfd_exact_size(archive_handle->src_fd, -1, jump_size);
|
||||
if (amount)
|
||||
bb_copyfd_exact_size(fd, -1, amount);
|
||||
}
|
||||
+3
-3
@@ -75,7 +75,7 @@ static void copy3(uint8_t* ip, const uint8_t* m_pos, unsigned off)
|
||||
#define TEST_IP (ip < ip_end)
|
||||
#define TEST_OP (op <= op_end)
|
||||
|
||||
static int lzo1x_optimize(uint8_t *in, unsigned in_len,
|
||||
static NOINLINE int lzo1x_optimize(uint8_t *in, unsigned in_len,
|
||||
uint8_t *out, unsigned *out_len,
|
||||
void* wrkmem UNUSED_PARAM)
|
||||
{
|
||||
@@ -598,7 +598,7 @@ static int lzo_get_method(header_t *h)
|
||||
/**********************************************************************/
|
||||
// compress a file
|
||||
/**********************************************************************/
|
||||
static smallint lzo_compress(const header_t *h)
|
||||
static NOINLINE smallint lzo_compress(const header_t *h)
|
||||
{
|
||||
unsigned block_size = LZO_BLOCK_SIZE;
|
||||
int r = 0; /* LZO_E_OK */
|
||||
@@ -706,7 +706,7 @@ static void lzo_check(uint32_t FAST_FUNC (*fn)(uint32_t, const uint8_t*, unsigne
|
||||
/**********************************************************************/
|
||||
// decompress a file
|
||||
/**********************************************************************/
|
||||
static smallint lzo_decompress(const header_t *h)
|
||||
static NOINLINE smallint lzo_decompress(const header_t *h)
|
||||
{
|
||||
unsigned block_size = LZO_BLOCK_SIZE;
|
||||
int r;
|
||||
|
||||
+10
-8
@@ -116,7 +116,9 @@ int rpm_main(int argc, char **argv)
|
||||
}
|
||||
argv += optind;
|
||||
//argc -= optind;
|
||||
if (!argv[0]) bb_show_usage();
|
||||
if (!argv[0]) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
while (*argv) {
|
||||
rpm_fd = xopen(*argv++, O_RDONLY);
|
||||
@@ -143,13 +145,13 @@ int rpm_main(int argc, char **argv)
|
||||
if (func & rpm_query_info) {
|
||||
/* Do the nice printout */
|
||||
time_t bdate_time;
|
||||
struct tm *bdate;
|
||||
struct tm *bdate_ptm;
|
||||
char bdatestring[50];
|
||||
printf("Name : %-29sRelocations: %s\n", rpm_getstr(TAG_NAME, 0), rpm_getstr(TAG_PREFIXS, 0) ? rpm_getstr(TAG_PREFIXS, 0) : "(not relocateable)");
|
||||
printf("Version : %-34sVendor: %s\n", rpm_getstr(TAG_VERSION, 0), rpm_getstr(TAG_VENDOR, 0) ? rpm_getstr(TAG_VENDOR, 0) : "(none)");
|
||||
bdate_time = rpm_getint(TAG_BUILDTIME, 0);
|
||||
bdate = localtime((time_t *) &bdate_time);
|
||||
strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate);
|
||||
bdate_ptm = localtime(&bdate_time);
|
||||
strftime(bdatestring, 50, "%a %d %b %Y %T %Z", bdate_ptm);
|
||||
printf("Release : %-30sBuild Date: %s\n", rpm_getstr(TAG_RELEASE, 0), bdatestring);
|
||||
printf("Install date: %-30sBuild Host: %s\n", "(not installed)", rpm_getstr(TAG_BUILDHOST, 0));
|
||||
printf("Group : %-30sSource RPM: %s\n", rpm_getstr(TAG_GROUP, 0), rpm_getstr(TAG_SOURCERPM, 0));
|
||||
@@ -202,12 +204,12 @@ static void extract_cpio_gz(int fd)
|
||||
archive_handle->seek = seek_by_read;
|
||||
//archive_handle->action_header = header_list;
|
||||
archive_handle->action_data = data_extract_all;
|
||||
archive_handle->ah_flags = ARCHIVE_PRESERVE_DATE | ARCHIVE_CREATE_LEADING_DIRS
|
||||
archive_handle->ah_flags = ARCHIVE_RESTORE_DATE | ARCHIVE_CREATE_LEADING_DIRS
|
||||
/* compat: overwrite existing files.
|
||||
* try "rpm -i foo.src.rpm" few times in a row -
|
||||
* standard rpm will not complain.
|
||||
* (TODO? real rpm creates "file;1234" and then renames it) */
|
||||
| ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
| ARCHIVE_UNLINK_OLD;
|
||||
archive_handle->src_fd = fd;
|
||||
/*archive_handle->offset = 0; - init_handle() did it */
|
||||
|
||||
@@ -324,7 +326,7 @@ static char *rpm_getstr(int tag, int itemindex)
|
||||
return NULL;
|
||||
if (found[0]->type == RPM_STRING_TYPE || found[0]->type == RPM_I18NSTRING_TYPE || found[0]->type == RPM_STRING_ARRAY_TYPE) {
|
||||
int n;
|
||||
char *tmpstr = (char *) (map + found[0]->offset);
|
||||
char *tmpstr = (char *) map + found[0]->offset;
|
||||
for (n=0; n < itemindex; n++)
|
||||
tmpstr = tmpstr + strlen(tmpstr) + 1;
|
||||
return tmpstr;
|
||||
@@ -343,7 +345,7 @@ static int rpm_getint(int tag, int itemindex)
|
||||
if (!found || itemindex >= found[0]->count)
|
||||
return -1;
|
||||
|
||||
tmpint = (int *) (map + found[0]->offset);
|
||||
tmpint = (int *) ((char *) map + found[0]->offset);
|
||||
|
||||
if (found[0]->type == RPM_INT32_TYPE) {
|
||||
tmpint = (int *) ((char *) tmpint + itemindex*4);
|
||||
|
||||
+57
-36
@@ -9,11 +9,11 @@
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
#define RPM_MAGIC "\355\253\356\333"
|
||||
#define RPM_HEADER_MAGIC "\216\255\350"
|
||||
#define RPM_MAGIC 0xedabeedb
|
||||
#define RPM_MAGIC_STR "\355\253\356\333"
|
||||
|
||||
struct rpm_lead {
|
||||
unsigned char magic[4];
|
||||
uint32_t magic;
|
||||
uint8_t major, minor;
|
||||
uint16_t type;
|
||||
uint16_t archnum;
|
||||
@@ -23,67 +23,88 @@ struct rpm_lead {
|
||||
char reserved[16];
|
||||
};
|
||||
|
||||
#define RPM_HEADER_MAGICnVER 0x8eade801
|
||||
#define RPM_HEADER_MAGIC_STR "\216\255\350"
|
||||
|
||||
struct rpm_header {
|
||||
char magic[3]; /* 3 byte magic: 0x8e 0xad 0xe8 */
|
||||
uint8_t version; /* 1 byte version number */
|
||||
uint32_t magic_and_ver; /* 3 byte magic: 0x8e 0xad 0xe8; 1 byte version */
|
||||
uint32_t reserved; /* 4 bytes reserved */
|
||||
uint32_t entries; /* Number of entries in header (4 bytes) */
|
||||
uint32_t size; /* Size of store (4 bytes) */
|
||||
};
|
||||
|
||||
static void skip_header(int rpm_fd)
|
||||
enum { rpm_fd = STDIN_FILENO };
|
||||
|
||||
static unsigned skip_header(void)
|
||||
{
|
||||
struct rpm_header header;
|
||||
unsigned len;
|
||||
|
||||
xread(rpm_fd, &header, sizeof(struct rpm_header));
|
||||
if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC, 3) != 0) {
|
||||
bb_error_msg_and_die("invalid RPM header magic"); /* Invalid magic */
|
||||
xread(rpm_fd, &header, sizeof(header));
|
||||
// if (strncmp((char *) &header.magic, RPM_HEADER_MAGIC_STR, 3) != 0) {
|
||||
// bb_error_msg_and_die("invalid RPM header magic");
|
||||
// }
|
||||
// if (header.version != 1) {
|
||||
// bb_error_msg_and_die("unsupported RPM header version");
|
||||
// }
|
||||
if (header.magic_and_ver != htonl(RPM_HEADER_MAGICnVER)) {
|
||||
bb_error_msg_and_die("invalid RPM header magic or unsupported version");
|
||||
// ": %x != %x", header.magic_and_ver, htonl(RPM_HEADER_MAGICnVER));
|
||||
}
|
||||
if (header.version != 1) {
|
||||
bb_error_msg_and_die("unsupported RPM header version"); /* This program only supports v1 headers */
|
||||
}
|
||||
header.entries = ntohl(header.entries);
|
||||
header.size = ntohl(header.size);
|
||||
lseek (rpm_fd, 16 * header.entries, SEEK_CUR); /* Seek past index entries */
|
||||
lseek (rpm_fd, header.size, SEEK_CUR); /* Seek past store */
|
||||
|
||||
/* Seek past index entries, and past store */
|
||||
len = 16 * ntohl(header.entries) + ntohl(header.size);
|
||||
seek_by_jump(rpm_fd, len);
|
||||
|
||||
return sizeof(header) + len;
|
||||
}
|
||||
|
||||
/* No getopt required */
|
||||
int rpm2cpio_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int rpm2cpio_main(int argc, char **argv)
|
||||
int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
struct rpm_lead lead;
|
||||
int rpm_fd;
|
||||
unsigned pos;
|
||||
unsigned char magic[2];
|
||||
IF_DESKTOP(long long) int FAST_FUNC (*unpack)(int src_fd, int dst_fd);
|
||||
|
||||
if (argc == 1) {
|
||||
rpm_fd = STDIN_FILENO;
|
||||
} else {
|
||||
rpm_fd = xopen(argv[1], O_RDONLY);
|
||||
if (argv[1]) {
|
||||
xmove_fd(xopen(argv[1], O_RDONLY), rpm_fd);
|
||||
}
|
||||
xread(rpm_fd, &lead, sizeof(lead));
|
||||
|
||||
/* Just check the magic, the rest is irrelevant */
|
||||
if (lead.magic != htonl(RPM_MAGIC)) {
|
||||
bb_error_msg_and_die("invalid RPM magic");
|
||||
}
|
||||
|
||||
xread(rpm_fd, &lead, sizeof(struct rpm_lead));
|
||||
if (strncmp((char *) &lead.magic, RPM_MAGIC, 4) != 0) {
|
||||
bb_error_msg_and_die("invalid RPM magic"); /* Just check the magic, the rest is irrelevant */
|
||||
}
|
||||
|
||||
/* Skip the signature header */
|
||||
skip_header(rpm_fd);
|
||||
lseek(rpm_fd, (8 - (lseek(rpm_fd, 0, SEEK_CUR) % 8)) % 8, SEEK_CUR);
|
||||
/* Skip the signature header, align to 8 bytes */
|
||||
pos = skip_header();
|
||||
seek_by_jump(rpm_fd, (8 - pos) & 7);
|
||||
|
||||
/* Skip the main header */
|
||||
skip_header(rpm_fd);
|
||||
skip_header();
|
||||
|
||||
xread(rpm_fd, &magic, 2);
|
||||
if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
|
||||
bb_error_msg_and_die("invalid gzip magic");
|
||||
unpack = unpack_gz_stream;
|
||||
if (magic[0] != 0x1f || magic[1] != 0x8b) {
|
||||
if (!ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
|| magic[0] != 'B' || magic[1] != 'Z'
|
||||
) {
|
||||
bb_error_msg_and_die("invalid gzip"
|
||||
IF_FEATURE_SEAMLESS_BZ2("/bzip2")
|
||||
" magic");
|
||||
}
|
||||
unpack = unpack_bz2_stream;
|
||||
}
|
||||
|
||||
if (unpack_gz_stream(rpm_fd, STDOUT_FILENO) < 0) {
|
||||
bb_error_msg("error inflating");
|
||||
if (unpack(rpm_fd, STDOUT_FILENO) < 0) {
|
||||
bb_error_msg_and_die("error unpacking");
|
||||
}
|
||||
|
||||
close(rpm_fd);
|
||||
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||
close(rpm_fd);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
+157
-97
@@ -26,13 +26,16 @@
|
||||
#include <fnmatch.h>
|
||||
#include "libbb.h"
|
||||
#include "unarchive.h"
|
||||
|
||||
/* FIXME: Stop using this non-standard feature */
|
||||
#ifndef FNM_LEADING_DIR
|
||||
#define FNM_LEADING_DIR 0
|
||||
# define FNM_LEADING_DIR 0
|
||||
#endif
|
||||
|
||||
|
||||
//#define DBG(fmt, ...) bb_error_msg("%s: " fmt, __func__, ## __VA_ARGS__)
|
||||
#define DBG(...) ((void)0)
|
||||
|
||||
|
||||
#define block_buf bb_common_bufsiz1
|
||||
|
||||
|
||||
@@ -52,8 +55,7 @@
|
||||
/* POSIX tar Header Block, from POSIX 1003.1-1990 */
|
||||
#define NAME_SIZE 100
|
||||
#define NAME_SIZE_STR "100"
|
||||
typedef struct TarHeader TarHeader;
|
||||
struct TarHeader { /* byte offset */
|
||||
typedef struct TarHeader { /* byte offset */
|
||||
char name[NAME_SIZE]; /* 0-99 */
|
||||
char mode[8]; /* 100-107 */
|
||||
char uid[8]; /* 108-115 */
|
||||
@@ -75,39 +77,38 @@ struct TarHeader { /* byte offset */
|
||||
char devminor[8]; /* 337-344 */
|
||||
char prefix[155]; /* 345-499 */
|
||||
char padding[12]; /* 500-512 (pad to exactly TAR_BLOCK_SIZE) */
|
||||
};
|
||||
} TarHeader;
|
||||
|
||||
/*
|
||||
** writeTarFile(), writeFileToTarball(), and writeTarHeader() are
|
||||
** the only functions that deal with the HardLinkInfo structure.
|
||||
** Even these functions use the xxxHardLinkInfo() functions.
|
||||
*/
|
||||
typedef struct HardLinkInfo HardLinkInfo;
|
||||
struct HardLinkInfo {
|
||||
HardLinkInfo *next; /* Next entry in list */
|
||||
dev_t dev; /* Device number */
|
||||
ino_t ino; /* Inode number */
|
||||
short linkCount; /* (Hard) Link Count */
|
||||
char name[1]; /* Start of filename (must be last) */
|
||||
};
|
||||
typedef struct HardLinkInfo {
|
||||
struct HardLinkInfo *next; /* Next entry in list */
|
||||
dev_t dev; /* Device number */
|
||||
ino_t ino; /* Inode number */
|
||||
// short linkCount; /* (Hard) Link Count */
|
||||
char name[1]; /* Start of filename (must be last) */
|
||||
} HardLinkInfo;
|
||||
|
||||
/* Some info to be carried along when creating a new tarball */
|
||||
typedef struct TarBallInfo TarBallInfo;
|
||||
struct TarBallInfo {
|
||||
typedef struct TarBallInfo {
|
||||
int tarFd; /* Open-for-write file descriptor
|
||||
* for the tarball */
|
||||
struct stat statBuf; /* Stat info for the tarball, letting
|
||||
* us know the inode and device that the
|
||||
* tarball lives, so we can avoid trying
|
||||
* to include the tarball into itself */
|
||||
int verboseFlag; /* Whether to print extra stuff or not */
|
||||
const llist_t *excludeList; /* List of files to not include */
|
||||
HardLinkInfo *hlInfoHead; /* Hard Link Tracking Information */
|
||||
HardLinkInfo *hlInfo; /* Hard Link Info for the current file */
|
||||
};
|
||||
//TODO: save only st_dev + st_ino
|
||||
struct stat tarFileStatBuf; /* Stat info for the tarball, letting
|
||||
* us know the inode and device that the
|
||||
* tarball lives, so we can avoid trying
|
||||
* to include the tarball into itself */
|
||||
} TarBallInfo;
|
||||
|
||||
/* A nice enum with all the possible tar file content types */
|
||||
enum TarFileType {
|
||||
enum {
|
||||
REGTYPE = '0', /* regular file */
|
||||
REGTYPE0 = '\0', /* regular file (ancient bug compat) */
|
||||
LNKTYPE = '1', /* hard link */
|
||||
@@ -120,7 +121,6 @@ enum TarFileType {
|
||||
GNULONGLINK = 'K', /* GNU long (>100 chars) link name */
|
||||
GNULONGNAME = 'L', /* GNU long (>100 chars) file name */
|
||||
};
|
||||
typedef enum TarFileType TarFileType;
|
||||
|
||||
/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
|
||||
static void addHardLinkInfo(HardLinkInfo **hlInfoHeadPtr,
|
||||
@@ -135,7 +135,7 @@ static void addHardLinkInfo(HardLinkInfo **hlInfoHeadPtr,
|
||||
*hlInfoHeadPtr = hlInfo;
|
||||
hlInfo->dev = statbuf->st_dev;
|
||||
hlInfo->ino = statbuf->st_ino;
|
||||
hlInfo->linkCount = statbuf->st_nlink;
|
||||
// hlInfo->linkCount = statbuf->st_nlink;
|
||||
strcpy(hlInfo->name, fileName);
|
||||
}
|
||||
|
||||
@@ -155,12 +155,16 @@ static void freeHardLinkInfo(HardLinkInfo **hlInfoHeadPtr)
|
||||
}
|
||||
}
|
||||
|
||||
/* Might be faster (and bigger) if the dev/ino were stored in numeric order;) */
|
||||
/* Might be faster (and bigger) if the dev/ino were stored in numeric order ;) */
|
||||
static HardLinkInfo *findHardLinkInfo(HardLinkInfo *hlInfo, struct stat *statbuf)
|
||||
{
|
||||
while (hlInfo) {
|
||||
if ((statbuf->st_ino == hlInfo->ino) && (statbuf->st_dev == hlInfo->dev))
|
||||
if (statbuf->st_ino == hlInfo->ino
|
||||
&& statbuf->st_dev == hlInfo->dev
|
||||
) {
|
||||
DBG("found hardlink:'%s'", hlInfo->name);
|
||||
break;
|
||||
}
|
||||
hlInfo = hlInfo->next;
|
||||
}
|
||||
return hlInfo;
|
||||
@@ -171,7 +175,7 @@ static HardLinkInfo *findHardLinkInfo(HardLinkInfo *hlInfo, struct stat *statbuf
|
||||
* Stores low-order bits only if whole value does not fit. */
|
||||
static void putOctal(char *cp, int len, off_t value)
|
||||
{
|
||||
char tempBuffer[sizeof(off_t)*3+1];
|
||||
char tempBuffer[sizeof(off_t)*3 + 1];
|
||||
char *tempString = tempBuffer;
|
||||
int width;
|
||||
|
||||
@@ -331,8 +335,8 @@ static int writeTarHeader(struct TarBallInfo *tbInfo,
|
||||
if (sizeof(statbuf->st_size) > 4
|
||||
&& statbuf->st_size > (off_t)0777777777777LL
|
||||
) {
|
||||
bb_error_msg_and_die("cannot store file '%s' "
|
||||
"of size %"OFF_FMT"d, aborting",
|
||||
bb_error_msg_and_die("can't store file '%s' "
|
||||
"of size %"OFF_FMT"u, aborting",
|
||||
fileName, statbuf->st_size);
|
||||
}
|
||||
header.typeflag = REGTYPE;
|
||||
@@ -376,16 +380,19 @@ static int exclude_file(const llist_t *excluded_files, const char *file)
|
||||
while (excluded_files) {
|
||||
if (excluded_files->data[0] == '/') {
|
||||
if (fnmatch(excluded_files->data, file,
|
||||
FNM_PATHNAME | FNM_LEADING_DIR) == 0)
|
||||
FNM_PATHNAME | FNM_LEADING_DIR) == 0)
|
||||
return 1;
|
||||
} else {
|
||||
const char *p;
|
||||
|
||||
for (p = file; p[0] != '\0'; p++) {
|
||||
if ((p == file || p[-1] == '/') && p[0] != '/' &&
|
||||
fnmatch(excluded_files->data, p,
|
||||
FNM_PATHNAME | FNM_LEADING_DIR) == 0)
|
||||
if ((p == file || p[-1] == '/')
|
||||
&& p[0] != '/'
|
||||
&& fnmatch(excluded_files->data, p,
|
||||
FNM_PATHNAME | FNM_LEADING_DIR) == 0
|
||||
) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
excluded_files = excluded_files->link;
|
||||
@@ -394,7 +401,7 @@ static int exclude_file(const llist_t *excluded_files, const char *file)
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
#define exclude_file(excluded_files, file) 0
|
||||
# define exclude_file(excluded_files, file) 0
|
||||
#endif
|
||||
|
||||
static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statbuf,
|
||||
@@ -404,6 +411,8 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
|
||||
const char *header_name;
|
||||
int inputFileFd = -1;
|
||||
|
||||
DBG("writeFileToTarball('%s')", fileName);
|
||||
|
||||
/* Strip leading '/' (must be before memorizing hardlink's name) */
|
||||
header_name = fileName;
|
||||
while (header_name[0] == '/') {
|
||||
@@ -433,17 +442,20 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
|
||||
* by adding the file information to the HardLinkInfo linked list.
|
||||
*/
|
||||
tbInfo->hlInfo = NULL;
|
||||
if (statbuf->st_nlink > 1) {
|
||||
if (!S_ISDIR(statbuf->st_mode) && statbuf->st_nlink > 1) {
|
||||
DBG("'%s': st_nlink > 1", header_name);
|
||||
tbInfo->hlInfo = findHardLinkInfo(tbInfo->hlInfoHead, statbuf);
|
||||
if (tbInfo->hlInfo == NULL)
|
||||
if (tbInfo->hlInfo == NULL) {
|
||||
DBG("'%s': addHardLinkInfo", header_name);
|
||||
addHardLinkInfo(&tbInfo->hlInfoHead, statbuf, header_name);
|
||||
}
|
||||
}
|
||||
|
||||
/* It is a bad idea to store the archive we are in the process of creating,
|
||||
* so check the device and inode to be sure that this particular file isn't
|
||||
* the new tarball */
|
||||
if (tbInfo->statBuf.st_dev == statbuf->st_dev
|
||||
&& tbInfo->statBuf.st_ino == statbuf->st_ino
|
||||
if (tbInfo->tarFileStatBuf.st_dev == statbuf->st_dev
|
||||
&& tbInfo->tarFileStatBuf.st_ino == statbuf->st_ino
|
||||
) {
|
||||
bb_error_msg("%s: file is the archive; skipping", fileName);
|
||||
return TRUE;
|
||||
@@ -505,37 +517,37 @@ static int FAST_FUNC writeFileToTarball(const char *fileName, struct stat *statb
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
#if !(ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2)
|
||||
#define vfork_compressor(tar_fd, gzip) vfork_compressor(tar_fd)
|
||||
#endif
|
||||
# if !(ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2)
|
||||
# define vfork_compressor(tar_fd, gzip) vfork_compressor(tar_fd)
|
||||
# endif
|
||||
/* Don't inline: vfork scares gcc and pessimizes code */
|
||||
static void NOINLINE vfork_compressor(int tar_fd, int gzip)
|
||||
{
|
||||
pid_t gzipPid;
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
# if ENABLE_FEATURE_SEAMLESS_GZ && ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
const char *zip_exec = (gzip == 1) ? "gzip" : "bzip2";
|
||||
#elif ENABLE_FEATURE_SEAMLESS_GZ
|
||||
# elif ENABLE_FEATURE_SEAMLESS_GZ
|
||||
const char *zip_exec = "gzip";
|
||||
#else /* only ENABLE_FEATURE_SEAMLESS_BZ2 */
|
||||
# else /* only ENABLE_FEATURE_SEAMLESS_BZ2 */
|
||||
const char *zip_exec = "bzip2";
|
||||
#endif
|
||||
# endif
|
||||
// On Linux, vfork never unpauses parent early, although standard
|
||||
// allows for that. Do we want to waste bytes checking for it?
|
||||
#define WAIT_FOR_CHILD 0
|
||||
# define WAIT_FOR_CHILD 0
|
||||
volatile int vfork_exec_errno = 0;
|
||||
struct fd_pair gzipDataPipe;
|
||||
#if WAIT_FOR_CHILD
|
||||
# if WAIT_FOR_CHILD
|
||||
struct fd_pair gzipStatusPipe;
|
||||
xpiped_pair(gzipStatusPipe);
|
||||
#endif
|
||||
# endif
|
||||
xpiped_pair(gzipDataPipe);
|
||||
|
||||
signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__
|
||||
# if defined(__GNUC__) && __GNUC__
|
||||
/* Avoid vfork clobbering */
|
||||
(void) &zip_exec;
|
||||
#endif
|
||||
# endif
|
||||
|
||||
gzipPid = vfork();
|
||||
if (gzipPid < 0)
|
||||
@@ -545,12 +557,12 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
|
||||
/* child */
|
||||
/* NB: close _first_, then move fds! */
|
||||
close(gzipDataPipe.wr);
|
||||
#if WAIT_FOR_CHILD
|
||||
# if WAIT_FOR_CHILD
|
||||
close(gzipStatusPipe.rd);
|
||||
/* gzipStatusPipe.wr will close only on exec -
|
||||
* parent waits for this close to happen */
|
||||
fcntl(gzipStatusPipe.wr, F_SETFD, FD_CLOEXEC);
|
||||
#endif
|
||||
# endif
|
||||
xmove_fd(gzipDataPipe.rd, 0);
|
||||
xmove_fd(tar_fd, 1);
|
||||
/* exec gzip/bzip2 program/applet */
|
||||
@@ -562,7 +574,7 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
|
||||
/* parent */
|
||||
xmove_fd(gzipDataPipe.wr, tar_fd);
|
||||
close(gzipDataPipe.rd);
|
||||
#if WAIT_FOR_CHILD
|
||||
# if WAIT_FOR_CHILD
|
||||
close(gzipStatusPipe.wr);
|
||||
while (1) {
|
||||
char buf;
|
||||
@@ -574,7 +586,7 @@ static void NOINLINE vfork_compressor(int tar_fd, int gzip)
|
||||
continue; /* try it again */
|
||||
}
|
||||
close(gzipStatusPipe.rd);
|
||||
#endif
|
||||
# endif
|
||||
if (vfork_exec_errno) {
|
||||
errno = vfork_exec_errno;
|
||||
bb_perror_msg_and_die("can't execute '%s'", zip_exec);
|
||||
@@ -597,8 +609,8 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
|
||||
/* Store the stat info for the tarball's file, so
|
||||
* can avoid including the tarball into itself.... */
|
||||
if (fstat(tbInfo.tarFd, &tbInfo.statBuf) < 0)
|
||||
bb_perror_msg_and_die("cannot stat tar file");
|
||||
if (fstat(tbInfo.tarFd, &tbInfo.tarFileStatBuf) < 0)
|
||||
bb_perror_msg_and_die("can't stat tar file");
|
||||
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
if (gzip)
|
||||
@@ -611,8 +623,8 @@ static NOINLINE int writeTarFile(int tar_fd, int verboseFlag,
|
||||
while (include) {
|
||||
if (!recursive_action(include->data, ACTION_RECURSE |
|
||||
(dereferenceFlag ? ACTION_FOLLOWLINKS : 0),
|
||||
writeFileToTarball, writeFileToTarball, &tbInfo, 0))
|
||||
{
|
||||
writeFileToTarball, writeFileToTarball, &tbInfo, 0)
|
||||
) {
|
||||
errorFlag = TRUE;
|
||||
}
|
||||
include = include->link;
|
||||
@@ -675,7 +687,7 @@ static llist_t *append_file_list_to_list(llist_t *list)
|
||||
return newlist;
|
||||
}
|
||||
#else
|
||||
#define append_file_list_to_list(x) 0
|
||||
# define append_file_list_to_list(x) 0
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_SEAMLESS_Z
|
||||
@@ -700,7 +712,7 @@ static char FAST_FUNC get_header_tar_Z(archive_handle_t *archive_handle)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
#else
|
||||
#define get_header_tar_Z NULL
|
||||
# define get_header_tar_Z NULL
|
||||
#endif
|
||||
|
||||
#ifdef CHECK_FOR_CHILD_EXITCODE
|
||||
@@ -717,7 +729,7 @@ static void handle_SIGCHLD(int status)
|
||||
/* wait failed?! I'm confused... */
|
||||
return;
|
||||
|
||||
if (WIFEXITED(status) && WEXITSTATUS(status)==0)
|
||||
if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
|
||||
/* child exited with 0 */
|
||||
return;
|
||||
/* Cannot happen?
|
||||
@@ -727,7 +739,7 @@ static void handle_SIGCHLD(int status)
|
||||
#endif
|
||||
|
||||
enum {
|
||||
OPTBIT_KEEP_OLD = 7,
|
||||
OPTBIT_KEEP_OLD = 8,
|
||||
IF_FEATURE_TAR_CREATE( OPTBIT_CREATE ,)
|
||||
IF_FEATURE_TAR_CREATE( OPTBIT_DEREFERENCE ,)
|
||||
IF_FEATURE_SEAMLESS_BZ2( OPTBIT_BZIP2 ,)
|
||||
@@ -735,18 +747,22 @@ enum {
|
||||
IF_FEATURE_TAR_FROM( OPTBIT_INCLUDE_FROM,)
|
||||
IF_FEATURE_TAR_FROM( OPTBIT_EXCLUDE_FROM,)
|
||||
IF_FEATURE_SEAMLESS_GZ( OPTBIT_GZIP ,)
|
||||
IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,)
|
||||
OPTBIT_NOPRESERVE_OWN,
|
||||
OPTBIT_NOPRESERVE_PERM,
|
||||
IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,) // 16th bit
|
||||
IF_FEATURE_TAR_NOPRESERVE_TIME(OPTBIT_NOPRESERVE_TIME,)
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
OPTBIT_NUMERIC_OWNER,
|
||||
OPTBIT_NOPRESERVE_PERM,
|
||||
OPTBIT_OVERWRITE,
|
||||
#endif
|
||||
OPT_TEST = 1 << 0, // t
|
||||
OPT_EXTRACT = 1 << 1, // x
|
||||
OPT_BASEDIR = 1 << 2, // C
|
||||
OPT_TARNAME = 1 << 3, // f
|
||||
OPT_2STDOUT = 1 << 4, // O
|
||||
OPT_P = 1 << 5, // p
|
||||
OPT_VERBOSE = 1 << 6, // v
|
||||
OPT_KEEP_OLD = 1 << 7, // k
|
||||
OPT_NOPRESERVE_OWNER = 1 << 5, // o == no-same-owner
|
||||
OPT_P = 1 << 6, // p
|
||||
OPT_VERBOSE = 1 << 7, // v
|
||||
OPT_KEEP_OLD = 1 << 8, // k
|
||||
OPT_CREATE = IF_FEATURE_TAR_CREATE( (1 << OPTBIT_CREATE )) + 0, // c
|
||||
OPT_DEREFERENCE = IF_FEATURE_TAR_CREATE( (1 << OPTBIT_DEREFERENCE )) + 0, // h
|
||||
OPT_BZIP2 = IF_FEATURE_SEAMLESS_BZ2( (1 << OPTBIT_BZIP2 )) + 0, // j
|
||||
@@ -755,9 +771,10 @@ enum {
|
||||
OPT_EXCLUDE_FROM = IF_FEATURE_TAR_FROM( (1 << OPTBIT_EXCLUDE_FROM)) + 0, // X
|
||||
OPT_GZIP = IF_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z
|
||||
OPT_COMPRESS = IF_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z
|
||||
OPT_NOPRESERVE_OWN = 1 << OPTBIT_NOPRESERVE_OWN , // no-same-owner
|
||||
OPT_NOPRESERVE_PERM = 1 << OPTBIT_NOPRESERVE_PERM, // no-same-permissions
|
||||
OPT_NUMERIC_OWNER = 1 << OPTBIT_NUMERIC_OWNER,
|
||||
OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m
|
||||
OPT_NUMERIC_OWNER = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NUMERIC_OWNER )) + 0, // numeric-owner
|
||||
OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions
|
||||
OPT_OVERWRITE = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE )) + 0, // overwrite
|
||||
};
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
static const char tar_longopts[] ALIGN1 =
|
||||
@@ -766,6 +783,10 @@ static const char tar_longopts[] ALIGN1 =
|
||||
"directory\0" Required_argument "C"
|
||||
"file\0" Required_argument "f"
|
||||
"to-stdout\0" No_argument "O"
|
||||
/* do not restore owner */
|
||||
/* Note: GNU tar handles 'o' as no-same-owner only on extract,
|
||||
* on create, 'o' is --old-archive. We do not support --old-archive. */
|
||||
"no-same-owner\0" No_argument "o"
|
||||
"same-permissions\0" No_argument "p"
|
||||
"verbose\0" No_argument "v"
|
||||
"keep-old\0" No_argument "k"
|
||||
@@ -789,12 +810,17 @@ static const char tar_longopts[] ALIGN1 =
|
||||
# if ENABLE_FEATURE_SEAMLESS_Z
|
||||
"compress\0" No_argument "Z"
|
||||
# endif
|
||||
# if ENABLE_FEATURE_TAR_NOPRESERVE_TIME
|
||||
"touch\0" No_argument "m"
|
||||
# endif
|
||||
/* use numeric uid/gid from tar header, not textual */
|
||||
"numeric-owner\0" No_argument "\xfc"
|
||||
"no-same-owner\0" No_argument "\xfd"
|
||||
"no-same-permissions\0" No_argument "\xfe"
|
||||
/* do not restore mode */
|
||||
"no-same-permissions\0" No_argument "\xfd"
|
||||
/* on unpack, open with O_TRUNC and !O_EXCL */
|
||||
"overwrite\0" No_argument "\xfe"
|
||||
/* --exclude takes next bit position in option mask, */
|
||||
/* therefore we have to either put it _after_ --no-same-perm */
|
||||
/* or add OPT[BIT]_EXCLUDE before OPT[BIT]_NOPRESERVE_OWN */
|
||||
/* therefore we have to put it _after_ --no-same-permissions */
|
||||
# if ENABLE_FEATURE_TAR_FROM
|
||||
"exclude\0" Required_argument "\xff"
|
||||
# endif
|
||||
@@ -817,12 +843,12 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* Initialise default values */
|
||||
tar_handle = init_handle();
|
||||
tar_handle->ah_flags = ARCHIVE_CREATE_LEADING_DIRS
|
||||
| ARCHIVE_PRESERVE_DATE
|
||||
| ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
| ARCHIVE_RESTORE_DATE
|
||||
| ARCHIVE_UNLINK_OLD;
|
||||
|
||||
/* Apparently only root's tar preserves perms (see bug 3844) */
|
||||
if (getuid() != 0)
|
||||
tar_handle->ah_flags |= ARCHIVE_NOPRESERVE_PERM;
|
||||
tar_handle->ah_flags |= ARCHIVE_DONT_RESTORE_PERM;
|
||||
|
||||
/* Prepend '-' to the first argument if required */
|
||||
opt_complementary = "--:" // first arg is options
|
||||
@@ -837,15 +863,43 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
IF_NOT_FEATURE_TAR_CREATE("t--x:x--t"); // mutually exclusive
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
applet_long_options = tar_longopts;
|
||||
#endif
|
||||
#if ENABLE_DESKTOP
|
||||
if (argv[1] && argv[1][0] != '-') {
|
||||
/* Compat:
|
||||
* 1st argument without dash handles options with parameters
|
||||
* differently from dashed one: it takes *next argv[i]*
|
||||
* as paramenter even if there are more chars in 1st argument:
|
||||
* "tar fx TARFILE" - "x" is not taken as f's param
|
||||
* but is interpreted as -x option
|
||||
* "tar -xf TARFILE" - dashed equivalent of the above
|
||||
* "tar -fx ..." - "x" is taken as f's param
|
||||
* getopt32 wouldn't handle 1st command correctly.
|
||||
* Unfortunately, people do use such commands.
|
||||
* We massage argv[1] to work around it by moving 'f'
|
||||
* to the end of the string.
|
||||
* More contrived "tar fCx TARFILE DIR" still fails,
|
||||
* but such commands are much less likely to be used.
|
||||
*/
|
||||
char *f = strchr(argv[1], 'f');
|
||||
if (f) {
|
||||
while (f[1] != '\0') {
|
||||
*f = f[1];
|
||||
f++;
|
||||
}
|
||||
*f = 'f';
|
||||
}
|
||||
}
|
||||
#endif
|
||||
opt = getopt32(argv,
|
||||
"txC:f:Opvk"
|
||||
"txC:f:Oopvk"
|
||||
IF_FEATURE_TAR_CREATE( "ch" )
|
||||
IF_FEATURE_SEAMLESS_BZ2( "j" )
|
||||
IF_FEATURE_SEAMLESS_LZMA("a" )
|
||||
IF_FEATURE_TAR_FROM( "T:X:")
|
||||
IF_FEATURE_SEAMLESS_GZ( "z" )
|
||||
IF_FEATURE_SEAMLESS_Z( "Z" )
|
||||
IF_FEATURE_TAR_NOPRESERVE_TIME("m")
|
||||
, &base_dir // -C dir
|
||||
, &tar_filename // -f filename
|
||||
IF_FEATURE_TAR_FROM(, &(tar_handle->accept)) // T
|
||||
@@ -856,6 +910,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
, &verboseFlag // combined count for -t and -v
|
||||
, &verboseFlag // combined count for -t and -v
|
||||
);
|
||||
//bb_error_msg("opt:%08x", opt);
|
||||
argv += optind;
|
||||
|
||||
if (verboseFlag) tar_handle->action_header = header_verbose_list;
|
||||
@@ -868,17 +923,22 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
tar_handle->action_data = data_extract_to_stdout;
|
||||
|
||||
if (opt & OPT_KEEP_OLD)
|
||||
tar_handle->ah_flags &= ~ARCHIVE_EXTRACT_UNCONDITIONAL;
|
||||
|
||||
if (opt & OPT_NOPRESERVE_OWN)
|
||||
tar_handle->ah_flags |= ARCHIVE_NOPRESERVE_OWN;
|
||||
|
||||
if (opt & OPT_NOPRESERVE_PERM)
|
||||
tar_handle->ah_flags |= ARCHIVE_NOPRESERVE_PERM;
|
||||
tar_handle->ah_flags &= ~ARCHIVE_UNLINK_OLD;
|
||||
|
||||
if (opt & OPT_NUMERIC_OWNER)
|
||||
tar_handle->ah_flags |= ARCHIVE_NUMERIC_OWNER;
|
||||
|
||||
if (opt & OPT_NOPRESERVE_OWNER)
|
||||
tar_handle->ah_flags |= ARCHIVE_DONT_RESTORE_OWNER;
|
||||
|
||||
if (opt & OPT_NOPRESERVE_PERM)
|
||||
tar_handle->ah_flags |= ARCHIVE_DONT_RESTORE_PERM;
|
||||
|
||||
if (opt & OPT_OVERWRITE) {
|
||||
tar_handle->ah_flags &= ~ARCHIVE_UNLINK_OLD;
|
||||
tar_handle->ah_flags |= ARCHIVE_O_TRUNC;
|
||||
}
|
||||
|
||||
if (opt & OPT_GZIP)
|
||||
get_header_ptr = get_header_tar_gz;
|
||||
|
||||
@@ -891,9 +951,12 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (opt & OPT_COMPRESS)
|
||||
get_header_ptr = get_header_tar_Z;
|
||||
|
||||
if (opt & OPT_NOPRESERVE_TIME)
|
||||
tar_handle->ah_flags &= ~ARCHIVE_RESTORE_DATE;
|
||||
|
||||
#if ENABLE_FEATURE_TAR_FROM
|
||||
tar_handle->reject = append_file_list_to_list(tar_handle->reject);
|
||||
#if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
# if ENABLE_FEATURE_TAR_LONG_OPTIONS
|
||||
/* Append excludes to reject */
|
||||
while (excludes) {
|
||||
llist_t *next = excludes->link;
|
||||
@@ -901,12 +964,12 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
tar_handle->reject = excludes;
|
||||
excludes = next;
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
tar_handle->accept = append_file_list_to_list(tar_handle->accept);
|
||||
#endif
|
||||
|
||||
/* Setup an array of filenames to work with */
|
||||
/* TODO: This is the same as in ar, separate function ? */
|
||||
/* TODO: This is the same as in ar, make a separate function? */
|
||||
while (*argv) {
|
||||
/* kill trailing '/' unless the string is just "/" */
|
||||
char *cp = last_char_is(*argv, '/');
|
||||
@@ -921,24 +984,21 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
/* Open the tar file */
|
||||
{
|
||||
FILE *tar_stream;
|
||||
int flags;
|
||||
int tar_fd = STDIN_FILENO;
|
||||
int flags = O_RDONLY;
|
||||
|
||||
if (opt & OPT_CREATE) {
|
||||
/* Make sure there is at least one file to tar up. */
|
||||
/* Make sure there is at least one file to tar up */
|
||||
if (tar_handle->accept == NULL)
|
||||
bb_error_msg_and_die("empty archive");
|
||||
|
||||
tar_stream = stdout;
|
||||
tar_fd = STDOUT_FILENO;
|
||||
/* Mimicking GNU tar 1.15.1: */
|
||||
flags = O_WRONLY | O_CREAT | O_TRUNC;
|
||||
} else {
|
||||
tar_stream = stdin;
|
||||
flags = O_RDONLY;
|
||||
}
|
||||
|
||||
if (LONE_DASH(tar_filename)) {
|
||||
tar_handle->src_fd = fileno(tar_stream);
|
||||
tar_handle->src_fd = tar_fd;
|
||||
tar_handle->seek = seek_by_read;
|
||||
} else {
|
||||
if (ENABLE_FEATURE_TAR_AUTODETECT && flags == O_RDONLY) {
|
||||
@@ -960,7 +1020,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
|
||||
signal(SIGCHLD, handle_SIGCHLD);
|
||||
#endif
|
||||
|
||||
/* create an archive */
|
||||
/* Create an archive */
|
||||
if (opt & OPT_CREATE) {
|
||||
#if ENABLE_FEATURE_SEAMLESS_GZ || ENABLE_FEATURE_SEAMLESS_BZ2
|
||||
int zipMode = 0;
|
||||
|
||||
+118
-29
@@ -253,14 +253,16 @@ int unzip_main(int argc, char **argv)
|
||||
enum { O_PROMPT, O_NEVER, O_ALWAYS };
|
||||
|
||||
zip_header_t zip_header;
|
||||
smallint verbose = 1;
|
||||
smallint quiet = 0;
|
||||
IF_NOT_DESKTOP(const) smallint verbose = 0;
|
||||
smallint listing = 0;
|
||||
smallint overwrite = O_PROMPT;
|
||||
#if ENABLE_DESKTOP
|
||||
uint32_t cds_offset;
|
||||
unsigned cds_entries;
|
||||
#endif
|
||||
unsigned total_size;
|
||||
unsigned long total_usize;
|
||||
unsigned long total_size;
|
||||
unsigned total_entries;
|
||||
int dst_fd = -1;
|
||||
char *src_fn = NULL;
|
||||
@@ -273,8 +275,49 @@ int unzip_main(int argc, char **argv)
|
||||
char key_buf[80];
|
||||
struct stat stat_buf;
|
||||
|
||||
/* -q, -l and -v: UnZip 5.52 of 28 February 2005, by Info-ZIP:
|
||||
*
|
||||
* # /usr/bin/unzip -qq -v decompress_unlzma.i.zip
|
||||
* 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i
|
||||
* # /usr/bin/unzip -q -v decompress_unlzma.i.zip
|
||||
* Length Method Size Ratio Date Time CRC-32 Name
|
||||
* -------- ------ ------- ----- ---- ---- ------ ----
|
||||
* 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i
|
||||
* -------- ------- --- -------
|
||||
* 204372 35278 83% 1 file
|
||||
* # /usr/bin/unzip -v decompress_unlzma.i.zip
|
||||
* Archive: decompress_unlzma.i.zip
|
||||
* Length Method Size Ratio Date Time CRC-32 Name
|
||||
* -------- ------ ------- ----- ---- ---- ------ ----
|
||||
* 204372 Defl:N 35278 83% 09-06-09 14:23 0d056252 decompress_unlzma.i
|
||||
* -------- ------- --- -------
|
||||
* 204372 35278 83% 1 file
|
||||
* # unzip -v decompress_unlzma.i.zip
|
||||
* Archive: decompress_unlzma.i.zip
|
||||
* Length Date Time Name
|
||||
* -------- ---- ---- ----
|
||||
* 204372 09-06-09 14:23 decompress_unlzma.i
|
||||
* -------- -------
|
||||
* 204372 1 files
|
||||
* # /usr/bin/unzip -l -qq decompress_unlzma.i.zip
|
||||
* 204372 09-06-09 14:23 decompress_unlzma.i
|
||||
* # /usr/bin/unzip -l -q decompress_unlzma.i.zip
|
||||
* Length Date Time Name
|
||||
* -------- ---- ---- ----
|
||||
* 204372 09-06-09 14:23 decompress_unlzma.i
|
||||
* -------- -------
|
||||
* 204372 1 file
|
||||
* # /usr/bin/unzip -l decompress_unlzma.i.zip
|
||||
* Archive: decompress_unlzma.i.zip
|
||||
* Length Date Time Name
|
||||
* -------- ---- ---- ----
|
||||
* 204372 09-06-09 14:23 decompress_unlzma.i
|
||||
* -------- -------
|
||||
* 204372 1 file
|
||||
*/
|
||||
|
||||
/* '-' makes getopt return 1 for non-options */
|
||||
while ((opt = getopt(argc, argv, "-d:lnopqx")) != -1) {
|
||||
while ((opt = getopt(argc, argv, "-d:lnopqxv")) != -1) {
|
||||
switch (opt_range) {
|
||||
case 0: /* Options */
|
||||
switch (opt) {
|
||||
@@ -294,7 +337,12 @@ int unzip_main(int argc, char **argv)
|
||||
dst_fd = STDOUT_FILENO;
|
||||
|
||||
case 'q': /* Be quiet */
|
||||
verbose = 0;
|
||||
quiet++;
|
||||
break;
|
||||
|
||||
case 'v': /* Verbose list */
|
||||
IF_DESKTOP(verbose++;)
|
||||
listing = 1;
|
||||
break;
|
||||
|
||||
case 1: /* The zip file */
|
||||
@@ -373,14 +421,21 @@ int unzip_main(int argc, char **argv)
|
||||
if (base_dir)
|
||||
xchdir(base_dir);
|
||||
|
||||
if (verbose) {
|
||||
printf("Archive: %s\n", src_fn);
|
||||
if (listing){
|
||||
puts(" Length Date Time Name\n"
|
||||
" -------- ---- ---- ----");
|
||||
if (quiet <= 1) { /* not -qq */
|
||||
if (quiet == 0)
|
||||
printf("Archive: %s\n", src_fn);
|
||||
if (listing) {
|
||||
puts(verbose ?
|
||||
" Length Method Size Ratio Date Time CRC-32 Name\n"
|
||||
"-------- ------ ------- ----- ---- ---- ------ ----"
|
||||
:
|
||||
" Length Date Time Name\n"
|
||||
" -------- ---- ---- ----"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
total_usize = 0;
|
||||
total_size = 0;
|
||||
total_entries = 0;
|
||||
#if ENABLE_DESKTOP
|
||||
@@ -449,20 +504,39 @@ int unzip_main(int argc, char **argv)
|
||||
|
||||
} else { /* Extract entry */
|
||||
if (listing) { /* List entry */
|
||||
if (verbose) {
|
||||
unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16);
|
||||
printf("%9u %02u-%02u-%02u %02u:%02u %s\n",
|
||||
zip_header.formatted.ucmpsize,
|
||||
(dostime & 0x01e00000) >> 21,
|
||||
(dostime & 0x001f0000) >> 16,
|
||||
(((dostime & 0xfe000000) >> 25) + 1980) % 100,
|
||||
(dostime & 0x0000f800) >> 11,
|
||||
(dostime & 0x000007e0) >> 5,
|
||||
dst_fn);
|
||||
total_size += zip_header.formatted.ucmpsize;
|
||||
unsigned dostime = zip_header.formatted.modtime | (zip_header.formatted.moddate << 16);
|
||||
if (!verbose) {
|
||||
// " Length Date Time Name\n"
|
||||
// " -------- ---- ---- ----"
|
||||
printf( "%9u %02u-%02u-%02u %02u:%02u %s\n",
|
||||
(unsigned)zip_header.formatted.ucmpsize,
|
||||
(dostime & 0x01e00000) >> 21,
|
||||
(dostime & 0x001f0000) >> 16,
|
||||
(((dostime & 0xfe000000) >> 25) + 1980) % 100,
|
||||
(dostime & 0x0000f800) >> 11,
|
||||
(dostime & 0x000007e0) >> 5,
|
||||
dst_fn);
|
||||
total_usize += zip_header.formatted.ucmpsize;
|
||||
} else {
|
||||
/* short listing -- filenames only */
|
||||
puts(dst_fn);
|
||||
unsigned long percents = zip_header.formatted.ucmpsize - zip_header.formatted.cmpsize;
|
||||
percents = percents * 100;
|
||||
if (zip_header.formatted.ucmpsize)
|
||||
percents /= zip_header.formatted.ucmpsize;
|
||||
// " Length Method Size Ratio Date Time CRC-32 Name\n"
|
||||
// "-------- ------ ------- ----- ---- ---- ------ ----"
|
||||
printf( "%8u Defl:N" "%9u%4u%% %02u-%02u-%02u %02u:%02u %08x %s\n",
|
||||
(unsigned)zip_header.formatted.ucmpsize,
|
||||
(unsigned)zip_header.formatted.cmpsize,
|
||||
(unsigned)percents,
|
||||
(dostime & 0x01e00000) >> 21,
|
||||
(dostime & 0x001f0000) >> 16,
|
||||
(((dostime & 0xfe000000) >> 25) + 1980) % 100,
|
||||
(dostime & 0x0000f800) >> 11,
|
||||
(dostime & 0x000007e0) >> 5,
|
||||
zip_header.formatted.crc32,
|
||||
dst_fn);
|
||||
total_usize += zip_header.formatted.ucmpsize;
|
||||
total_size += zip_header.formatted.cmpsize;
|
||||
}
|
||||
i = 'n';
|
||||
} else if (dst_fd == STDOUT_FILENO) { /* Extracting to STDOUT */
|
||||
@@ -472,7 +546,7 @@ int unzip_main(int argc, char **argv)
|
||||
if (errno != ENOENT) {
|
||||
bb_perror_msg_and_die("can't stat '%s'", dst_fn);
|
||||
}
|
||||
if (verbose) {
|
||||
if (!quiet) {
|
||||
printf(" creating: %s\n", dst_fn);
|
||||
}
|
||||
unzip_create_leading_dirs(dst_fn);
|
||||
@@ -520,7 +594,7 @@ int unzip_main(int argc, char **argv)
|
||||
unzip_create_leading_dirs(dst_fn);
|
||||
dst_fd = xopen(dst_fn, O_WRONLY | O_CREAT | O_TRUNC);
|
||||
case -1: /* Unzip */
|
||||
if (verbose) {
|
||||
if (!quiet) {
|
||||
printf(" inflating: %s\n", dst_fn);
|
||||
}
|
||||
unzip_extract(&zip_header, dst_fd);
|
||||
@@ -549,17 +623,32 @@ int unzip_main(int argc, char **argv)
|
||||
goto check_file;
|
||||
|
||||
default:
|
||||
printf("error: invalid response [%c]\n",(char)i);
|
||||
printf("error: invalid response [%c]\n", (char)i);
|
||||
goto check_file;
|
||||
}
|
||||
|
||||
total_entries++;
|
||||
}
|
||||
|
||||
if (listing && verbose) {
|
||||
printf(" -------- -------\n"
|
||||
"%9d %d files\n",
|
||||
total_size, total_entries);
|
||||
if (listing && quiet <= 1) {
|
||||
if (!verbose) {
|
||||
// " Length Date Time Name\n"
|
||||
// " -------- ---- ---- ----"
|
||||
printf( " -------- -------\n"
|
||||
"%9lu" " %u files\n",
|
||||
total_usize, total_entries);
|
||||
} else {
|
||||
unsigned long percents = total_usize - total_size;
|
||||
percents = percents * 100;
|
||||
if (total_usize)
|
||||
percents /= total_usize;
|
||||
// " Length Method Size Ratio Date Time CRC-32 Name\n"
|
||||
// "-------- ------ ------- ----- ---- ---- ------ ----"
|
||||
printf( "-------- ------- --- -------\n"
|
||||
"%8lu" "%17lu%4u%% %u files\n",
|
||||
total_usize, total_size, (unsigned)percents,
|
||||
total_entries);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -6,19 +6,12 @@
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
int chvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int chvt_main(int argc, char **argv)
|
||||
int chvt_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
int num;
|
||||
|
||||
if (argc != 2) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
num = xatou_range(argv[1], 1, 63);
|
||||
int num = xatou_range(single_argv(argv), 1, 63);
|
||||
console_make_active(get_console_fd_or_die(), num);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -28,9 +28,9 @@ int dumpkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
{
|
||||
struct kbentry ke;
|
||||
int i, j, fd;
|
||||
RESERVE_CONFIG_BUFFER(flags,MAX_NR_KEYMAPS);
|
||||
RESERVE_CONFIG_BUFFER(flags, MAX_NR_KEYMAPS);
|
||||
|
||||
/* bb_warn_ignoring_args(argc>=2);*/
|
||||
/* bb_warn_ignoring_args(argv[1]);*/
|
||||
|
||||
fd = get_console_fd_or_die();
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ int kbd_mode_main(int argc UNUSED_PARAM, char **argv)
|
||||
const char *tty_name = CURRENT_TTY;
|
||||
|
||||
opt = getopt32(argv, "sakuC:", &tty_name);
|
||||
fd = xopen(tty_name, O_NONBLOCK);
|
||||
fd = xopen_nonblocking(tty_name);
|
||||
opt &= 0xf; /* clear -C bit, see (*) */
|
||||
|
||||
if (!opt) { /* print current setting */
|
||||
|
||||
@@ -277,7 +277,7 @@ int setfont_main(int argc UNUSED_PARAM, char **argv)
|
||||
opts = getopt32(argv, "m:C:", &mapfilename, &tty_name);
|
||||
argv += optind;
|
||||
|
||||
fd = xopen(tty_name, O_NONBLOCK);
|
||||
fd = xopen_nonblocking(tty_name);
|
||||
|
||||
if (sizeof(CONFIG_DEFAULT_SETFONT_DIR) > 1) { // if not ""
|
||||
if (*argv[0] != '/') {
|
||||
|
||||
@@ -30,13 +30,13 @@ int loadkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
int i, j, fd;
|
||||
uint16_t ibuff[NR_KEYS];
|
||||
/* const char *tty_name = CURRENT_TTY; */
|
||||
RESERVE_CONFIG_BUFFER(flags,MAX_NR_KEYMAPS);
|
||||
RESERVE_CONFIG_BUFFER(flags, MAX_NR_KEYMAPS);
|
||||
|
||||
/* bb_warn_ignoring_args(argc >= 2); */
|
||||
/* bb_warn_ignoring_args(argv[1]); */
|
||||
fd = get_console_fd_or_die();
|
||||
/* or maybe:
|
||||
opt = getopt32(argv, "C:", &tty_name);
|
||||
fd = xopen(tty_name, O_NONBLOCK);
|
||||
fd = xopen_nonblocking(tty_name);
|
||||
*/
|
||||
|
||||
xread(STDIN_FILENO, flags, 7);
|
||||
|
||||
@@ -61,9 +61,7 @@ static int get_vt_fd(void)
|
||||
for (fd = 0; fd < 3; fd++)
|
||||
if (!not_vt_fd(fd))
|
||||
return fd;
|
||||
/* _only_ O_NONBLOCK: ask for neither read nor write perms */
|
||||
/*FIXME: use? device_open(DEV_CONSOLE,0); */
|
||||
fd = open(DEV_CONSOLE, O_NONBLOCK);
|
||||
fd = open(DEV_CONSOLE, O_RDONLY | O_NONBLOCK);
|
||||
if (fd >= 0 && !not_vt_fd(fd))
|
||||
return fd;
|
||||
bb_error_msg_and_die("can't find open VT");
|
||||
|
||||
+45
-5
@@ -52,6 +52,13 @@ config CHOWN
|
||||
chown is used to change the user and/or group ownership
|
||||
of files.
|
||||
|
||||
config FEATURE_CHOWN_LONG_OPTIONS
|
||||
bool "Enable long options"
|
||||
default n
|
||||
depends on CHOWN && LONG_OPTS
|
||||
help
|
||||
Enable use of long options
|
||||
|
||||
config CHROOT
|
||||
bool "chroot"
|
||||
default n
|
||||
@@ -78,6 +85,14 @@ config CP
|
||||
help
|
||||
cp is used to copy files and directories.
|
||||
|
||||
config FEATURE_CP_LONG_OPTIONS
|
||||
bool "Enable long options for cp"
|
||||
default n
|
||||
depends on CP && LONG_OPTS
|
||||
help
|
||||
Enable long options for cp.
|
||||
Also add support for --parents option.
|
||||
|
||||
config CUT
|
||||
bool "cut"
|
||||
default n
|
||||
@@ -100,6 +115,22 @@ config FEATURE_DATE_ISOFMT
|
||||
Enable option (-I) to output an ISO-8601 compliant
|
||||
date/time string.
|
||||
|
||||
config FEATURE_DATE_COMPAT
|
||||
bool "Support weird 'date MMDDhhmm[[YY]YY][.ss]' format"
|
||||
default y
|
||||
depends on DATE
|
||||
help
|
||||
System time can be set by 'date -s DATE' and simply 'date DATE',
|
||||
but formats of DATE string are different. 'date DATE' accepts
|
||||
a rather weird MMDDhhmm[[YY]YY][.ss] format with completely
|
||||
unnatural placement of year between minutes and seconds.
|
||||
date -s (and other commands like touch -d) use more sensible
|
||||
formats (for one, ISO format YYYY-MM-DD hh:mm:ss.ssssss).
|
||||
|
||||
With this option off, 'date DATE' is 'date -s DATE' support
|
||||
the same format. With it on, 'date DATE' additionally supports
|
||||
MMDDhhmm[[YY]YY][.ss] format.
|
||||
|
||||
config DD
|
||||
bool "dd"
|
||||
default n
|
||||
@@ -113,13 +144,22 @@ config FEATURE_DD_SIGNAL_HANDLING
|
||||
default y
|
||||
depends on DD
|
||||
help
|
||||
sending a SIGUSR1 signal to a running `dd' process makes it
|
||||
Sending a SIGUSR1 signal to a running `dd' process makes it
|
||||
print to standard error the number of records read and written
|
||||
so far, then to resume copying.
|
||||
|
||||
$ dd if=/dev/zero of=/dev/null&
|
||||
$ pid=$! kill -USR1 $pid; sleep 1; kill $pid
|
||||
10899206+0 records in 10899206+0 records out
|
||||
10899206+0 records in
|
||||
10899206+0 records out
|
||||
|
||||
config FEATURE_DD_THIRD_STATUS_LINE
|
||||
bool "Enable the third status line upon signal"
|
||||
default n
|
||||
depends on DD && FEATURE_DD_SIGNAL_HANDLING
|
||||
help
|
||||
Displays a coreutils-like third status line with transferred bytes,
|
||||
elapsed time and speed.
|
||||
|
||||
config FEATURE_DD_IBS_OBS
|
||||
bool "Enable ibs, obs and conv options"
|
||||
@@ -829,13 +869,13 @@ config FEATURE_HUMAN_READABLE
|
||||
help
|
||||
Allow df, du, and ls to have human readable output.
|
||||
|
||||
comment "Common options for md5sum, sha1sum"
|
||||
depends on MD5SUM || SHA1SUM
|
||||
comment "Common options for md5sum, sha1sum, sha256sum, sha512sum"
|
||||
depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM
|
||||
|
||||
config FEATURE_MD5_SHA1_SUM_CHECK
|
||||
bool "Enable -c, -s and -w options"
|
||||
default n
|
||||
depends on MD5SUM || SHA1SUM
|
||||
depends on MD5SUM || SHA1SUM || SHA256SUM || SHA512SUM
|
||||
help
|
||||
Enabling the -c options allows files to be checked
|
||||
against pre-calculated hash values.
|
||||
|
||||
+36
-15
@@ -16,8 +16,8 @@
|
||||
*
|
||||
* Major size reduction... over 50% (>1.5k) on i386.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unicode.h"
|
||||
|
||||
/* We often use "unsigned" intead of "int", it's easier to div on most CPUs */
|
||||
|
||||
@@ -77,36 +77,42 @@ static char *build_row(char *p, unsigned *dp);
|
||||
#define HEAD_SEP 2 /* spaces between day headings */
|
||||
|
||||
int cal_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int cal_main(int argc, char **argv)
|
||||
int cal_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
struct tm *local_time;
|
||||
struct tm zero_tm;
|
||||
time_t now;
|
||||
unsigned month, year, flags, i;
|
||||
char *month_names[12];
|
||||
char day_headings[28]; /* 28 for julian, 21 for nonjulian */
|
||||
/* normal heading: */
|
||||
/* "Su Mo Tu We Th Fr Sa" */
|
||||
/* -j heading: */
|
||||
/* " Su Mo Tu We Th Fr Sa" */
|
||||
char day_headings[ENABLE_FEATURE_ASSUME_UNICODE ? 28 * 6 : 28];
|
||||
IF_FEATURE_ASSUME_UNICODE(char *hp = day_headings;)
|
||||
char buf[40];
|
||||
|
||||
init_unicode();
|
||||
|
||||
flags = getopt32(argv, "jy");
|
||||
/* This sets julian = flags & 1: */
|
||||
option_mask32 &= 1;
|
||||
month = 0;
|
||||
argv += optind;
|
||||
argc -= optind;
|
||||
|
||||
if (argc > 2) {
|
||||
bb_show_usage();
|
||||
}
|
||||
if (!argv[0]) {
|
||||
struct tm *ptm;
|
||||
|
||||
if (!argc) {
|
||||
time(&now);
|
||||
local_time = localtime(&now);
|
||||
year = local_time->tm_year + 1900;
|
||||
ptm = localtime(&now);
|
||||
year = ptm->tm_year + 1900;
|
||||
if (!(flags & 2)) { /* no -y */
|
||||
month = local_time->tm_mon + 1;
|
||||
month = ptm->tm_mon + 1;
|
||||
}
|
||||
} else {
|
||||
if (argc == 2) {
|
||||
if (argv[1]) {
|
||||
if (argv[2]) {
|
||||
bb_show_usage();
|
||||
}
|
||||
month = xatou_range(*argv++, 1, 12);
|
||||
}
|
||||
year = xatou_range(*argv, 1, 9999);
|
||||
@@ -117,15 +123,30 @@ int cal_main(int argc, char **argv)
|
||||
i = 0;
|
||||
do {
|
||||
zero_tm.tm_mon = i;
|
||||
/* full month name according to locale */
|
||||
strftime(buf, sizeof(buf), "%B", &zero_tm);
|
||||
month_names[i] = xstrdup(buf);
|
||||
|
||||
if (i < 7) {
|
||||
zero_tm.tm_wday = i;
|
||||
/* abbreviated weekday name according to locale */
|
||||
strftime(buf, sizeof(buf), "%a", &zero_tm);
|
||||
#if ENABLE_FEATURE_ASSUME_UNICODE
|
||||
if (julian)
|
||||
*hp++ = ' ';
|
||||
{
|
||||
char *two_wchars = unicode_cut_nchars(2, buf);
|
||||
strcpy(hp, two_wchars);
|
||||
free(two_wchars);
|
||||
}
|
||||
hp += strlen(hp);
|
||||
*hp++ = ' ';
|
||||
#else
|
||||
strncpy(day_headings + i * (3+julian) + julian, buf, 2);
|
||||
#endif
|
||||
}
|
||||
} while (++i < 12);
|
||||
IF_FEATURE_ASSUME_UNICODE(hp[-1] = '\0';)
|
||||
|
||||
if (month) {
|
||||
unsigned row, len, days[MAXDAYS];
|
||||
@@ -147,7 +168,7 @@ int cal_main(int argc, char **argv)
|
||||
unsigned *dp;
|
||||
char lineout[80];
|
||||
|
||||
sprintf(lineout, "%d", year);
|
||||
sprintf(lineout, "%u", year);
|
||||
center(lineout,
|
||||
(WEEK_LEN * 3 + HEAD_SEP * 2)
|
||||
+ julian * (J_WEEK_LEN * 2 + HEAD_SEP
|
||||
@@ -262,7 +283,7 @@ static void trim_trailing_spaces_and_print(char *s)
|
||||
}
|
||||
while (p != s) {
|
||||
--p;
|
||||
if (!(isspace)(*p)) { /* We want the function... not the inline. */
|
||||
if (!isspace(*p)) {
|
||||
p[1] = '\0';
|
||||
break;
|
||||
}
|
||||
|
||||
+20
-5
@@ -8,7 +8,6 @@
|
||||
*/
|
||||
|
||||
/* BB_AUDIT SUSv3 defects - none? */
|
||||
/* BB_AUDIT GNU defects - unsupported long options. */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/chown.html */
|
||||
|
||||
#include "libbb.h"
|
||||
@@ -37,6 +36,20 @@
|
||||
#define BIT_TRAVERSE_TOP (0x20|0x40)
|
||||
#define OPT_TRAVERSE_TOP (IF_DESKTOP(opt & BIT_TRAVERSE_TOP) IF_NOT_DESKTOP(0))
|
||||
|
||||
#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS
|
||||
static const char chown_longopts[] ALIGN1 =
|
||||
"recursive\0" No_argument "R"
|
||||
"dereference\0" No_argument "\xff"
|
||||
"no-dereference\0" No_argument "h"
|
||||
# if ENABLE_DESKTOP
|
||||
"changes\0" No_argument "c"
|
||||
"silent\0" No_argument "f"
|
||||
"quiet\0" No_argument "f"
|
||||
"verbose\0" No_argument "v"
|
||||
# endif
|
||||
;
|
||||
#endif
|
||||
|
||||
typedef int (*chown_fptr)(const char *, uid_t, gid_t);
|
||||
|
||||
struct param_t {
|
||||
@@ -76,13 +89,16 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
param.ugid.uid = -1;
|
||||
param.ugid.gid = -1;
|
||||
param.chown_func = chown;
|
||||
|
||||
#if ENABLE_FEATURE_CHOWN_LONG_OPTIONS
|
||||
applet_long_options = chown_longopts;
|
||||
#endif
|
||||
opt_complementary = "-2";
|
||||
opt = getopt32(argv, OPT_STR);
|
||||
argv += optind;
|
||||
|
||||
/* This matches coreutils behavior (almost - see below) */
|
||||
param.chown_func = chown;
|
||||
if (OPT_NODEREF
|
||||
/* || (OPT_RECURSE && !OPT_TRAVERSE_TOP): */
|
||||
IF_DESKTOP( || (opt & (BIT_RECURSE|BIT_TRAVERSE_TOP)) == BIT_RECURSE)
|
||||
@@ -101,8 +117,7 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
|
||||
parse_chown_usergroup_or_die(¶m.ugid, argv[0]);
|
||||
|
||||
/* Ok, ready to do the deed now */
|
||||
argv++;
|
||||
do {
|
||||
while (*++argv) {
|
||||
if (!recursive_action(*argv,
|
||||
flags, /* flags */
|
||||
fileAction, /* file action */
|
||||
@@ -112,7 +127,7 @@ int chown_main(int argc UNUSED_PARAM, char **argv)
|
||||
) {
|
||||
retval = EXIT_FAILURE;
|
||||
}
|
||||
} while (*++argv);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
+4
-6
@@ -12,18 +12,16 @@
|
||||
#include "libbb.h"
|
||||
|
||||
int chroot_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int chroot_main(int argc, char **argv)
|
||||
int chroot_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
if (argc < 2) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
++argv;
|
||||
if (!*argv)
|
||||
bb_show_usage();
|
||||
xchroot(*argv);
|
||||
xchdir("/");
|
||||
|
||||
++argv;
|
||||
if (argc == 2) {
|
||||
if (!*argv) { /* no 2nd param (PROG), use shell */
|
||||
argv -= 2;
|
||||
argv[0] = getenv("SHELL");
|
||||
if (!argv[0]) {
|
||||
|
||||
+2
-2
@@ -4,8 +4,8 @@
|
||||
*
|
||||
* Copyright (C) 2006 by Rob Sullivan, with ideas from code by Walter Harms
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */
|
||||
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
|
||||
int cksum_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
|
||||
+56
-20
@@ -20,7 +20,6 @@
|
||||
|
||||
/* This is a NOEXEC applet. Be very careful! */
|
||||
|
||||
|
||||
int cp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int cp_main(int argc, char **argv)
|
||||
{
|
||||
@@ -31,12 +30,15 @@ int cp_main(int argc, char **argv)
|
||||
int s_flags;
|
||||
int d_flags;
|
||||
int flags;
|
||||
int status = 0;
|
||||
int status;
|
||||
enum {
|
||||
OPT_a = 1 << (sizeof(FILEUTILS_CP_OPTSTR)-1),
|
||||
OPT_r = 1 << (sizeof(FILEUTILS_CP_OPTSTR)),
|
||||
OPT_P = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+1),
|
||||
OPT_H = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
|
||||
OPT_v = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
|
||||
#endif
|
||||
};
|
||||
|
||||
// Need at least two arguments
|
||||
@@ -45,9 +47,23 @@ int cp_main(int argc, char **argv)
|
||||
// -r and -R are the same
|
||||
// -R (and therefore -r) turns on -d (coreutils does this)
|
||||
// -a = -pdR
|
||||
opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR:HL";
|
||||
opt_complementary = "-2:l--s:s--l:Pd:rRd:Rd:apdR";
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
applet_long_options =
|
||||
"archive\0" No_argument "a"
|
||||
"force\0" No_argument "f"
|
||||
"interactive\0" No_argument "i"
|
||||
"link\0" No_argument "l"
|
||||
"dereference\0" No_argument "L"
|
||||
"no-dereference\0" No_argument "P"
|
||||
"recursive\0" No_argument "R"
|
||||
"symbolic-link\0" No_argument "s"
|
||||
"verbose\0" No_argument "v"
|
||||
"parents\0" No_argument "\xff"
|
||||
;
|
||||
#endif
|
||||
// -v (--verbose) is ignored
|
||||
flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPHv");
|
||||
flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv");
|
||||
/* Options of cp from GNU coreutils 6.10:
|
||||
* -a, --archive
|
||||
* -f, --force
|
||||
@@ -62,8 +78,9 @@ int cp_main(int argc, char **argv)
|
||||
* -d same as --no-dereference --preserve=links
|
||||
* -p same as --preserve=mode,ownership,timestamps
|
||||
* -c same as --preserve=context
|
||||
* --parents
|
||||
* use full source file name under DIRECTORY
|
||||
* NOT SUPPORTED IN BBOX:
|
||||
* long options are not supported (even those above).
|
||||
* --backup[=CONTROL]
|
||||
* make a backup of each existing destination file
|
||||
* -b like --backup but does not accept an argument
|
||||
@@ -73,8 +90,6 @@ int cp_main(int argc, char **argv)
|
||||
* preserve attributes (default: mode,ownership,timestamps),
|
||||
* if possible additional attributes: security context,links,all
|
||||
* --no-preserve=ATTR_LIST
|
||||
* --parents
|
||||
* use full source file name under DIRECTORY
|
||||
* --remove-destination
|
||||
* remove each existing destination file before attempting to open
|
||||
* --sparse=WHEN
|
||||
@@ -97,17 +112,14 @@ int cp_main(int argc, char **argv)
|
||||
*/
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
flags ^= FILEUTILS_DEREFERENCE; /* the sense of this flag was reversed */
|
||||
/* Reverse this bit. If there is -d, bit is not set: */
|
||||
flags ^= FILEUTILS_DEREFERENCE;
|
||||
/* coreutils 6.9 compat:
|
||||
* by default, "cp" derefs symlinks (creates regular dest files),
|
||||
* but "cp -R" does not. We switch off deref if -r or -R (see above).
|
||||
* However, "cp -RL" must still deref symlinks: */
|
||||
if (flags & FILEUTILS_DEREF_SOFTLINK) /* -L */
|
||||
flags |= FILEUTILS_DEREFERENCE;
|
||||
/* The behavior of -H is *almost* like -L, but not quite, so let's
|
||||
* just ignore it too for fun. TODO.
|
||||
if (flags & OPT_H) ... // deref command-line params only
|
||||
*/
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
if (flags & FILEUTILS_PRESERVE_SECURITY_CONTEXT) {
|
||||
@@ -115,38 +127,62 @@ int cp_main(int argc, char **argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
status = EXIT_SUCCESS;
|
||||
last = argv[argc - 1];
|
||||
/* If there are only two arguments and... */
|
||||
if (argc == 2) {
|
||||
s_flags = cp_mv_stat2(*argv, &source_stat,
|
||||
(flags & FILEUTILS_DEREFERENCE) ? stat : lstat);
|
||||
(flags & FILEUTILS_DEREFERENCE) ? stat : lstat);
|
||||
if (s_flags < 0)
|
||||
return EXIT_FAILURE;
|
||||
d_flags = cp_mv_stat(last, &dest_stat);
|
||||
if (d_flags < 0)
|
||||
return EXIT_FAILURE;
|
||||
|
||||
/* ...if neither is a directory or... */
|
||||
if ( !((s_flags | d_flags) & 2) ||
|
||||
/* ...recursing, the 1st is a directory, and the 2nd doesn't exist... */
|
||||
((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags)
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
if (flags & OPT_parents) {
|
||||
if (!(d_flags & 2)) {
|
||||
bb_error_msg_and_die("with --parents, the destination must be a directory");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ...if neither is a directory... */
|
||||
if (!((s_flags | d_flags) & 2)
|
||||
/* ...or: recursing, the 1st is a directory, and the 2nd doesn't exist... */
|
||||
|| ((flags & FILEUTILS_RECUR) && (s_flags & 2) && !d_flags)
|
||||
) {
|
||||
/* ...do a simple copy. */
|
||||
/* Do a simple copy */
|
||||
dest = last;
|
||||
goto DO_COPY; /* NB: argc==2 -> *++argv==last */
|
||||
}
|
||||
}
|
||||
|
||||
while (1) {
|
||||
#if ENABLE_FEATURE_CP_LONG_OPTIONS
|
||||
if (flags & OPT_parents) {
|
||||
char *dest_dup;
|
||||
char *dest_dir;
|
||||
dest = concat_path_file(last, *argv);
|
||||
dest_dup = xstrdup(dest);
|
||||
dest_dir = dirname(dest_dup);
|
||||
if (bb_make_directory(dest_dir, -1, FILEUTILS_RECUR)) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
free(dest_dup);
|
||||
goto DO_COPY;
|
||||
}
|
||||
#endif
|
||||
dest = concat_path_file(last, bb_get_last_path_component_strip(*argv));
|
||||
DO_COPY:
|
||||
if (copy_file(*argv, dest, flags) < 0) {
|
||||
status = 1;
|
||||
status = EXIT_FAILURE;
|
||||
}
|
||||
if (*++argv == last) {
|
||||
/* possibly leaking dest... */
|
||||
break;
|
||||
}
|
||||
/* don't move up: dest may be == last and not malloced! */
|
||||
free((void*)dest);
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -111,7 +111,10 @@ static void cut_file(FILE *file, char delim, const struct cut_list *cut_lists, u
|
||||
int ndelim = -1; /* zero-based / one-based problem */
|
||||
int nfields_printed = 0;
|
||||
char *field = NULL;
|
||||
const char delimiter[2] = { delim, 0 };
|
||||
char delimiter[2];
|
||||
|
||||
delimiter[0] = delim;
|
||||
delimiter[1] = 0;
|
||||
|
||||
/* does this line contain any delimiters? */
|
||||
if (strchr(line, delim) == NULL) {
|
||||
@@ -261,7 +264,7 @@ int cut_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* now that the lists are parsed, we need to sort them to make life
|
||||
* easier on us when it comes time to print the chars / fields / lines
|
||||
*/
|
||||
qsort(cut_lists, nlists, sizeof(struct cut_list), cmpfunc);
|
||||
qsort(cut_lists, nlists, sizeof(cut_lists[0]), cmpfunc);
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
+57
-28
@@ -69,10 +69,23 @@ static void maybe_set_utc(int opt)
|
||||
putenv((char*)"TZ=UTC0");
|
||||
}
|
||||
|
||||
#if ENABLE_LONG_OPTS
|
||||
static const char date_longopts[] ALIGN1 =
|
||||
"rfc-822\0" No_argument "R"
|
||||
"rfc-2822\0" No_argument "R"
|
||||
"set\0" Required_argument "s"
|
||||
"utc\0" No_argument "u"
|
||||
/* "universal\0" No_argument "u" */
|
||||
"date\0" Required_argument "d"
|
||||
"reference\0" Required_argument "r"
|
||||
;
|
||||
#endif
|
||||
|
||||
int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
struct tm tm_time;
|
||||
char buf_fmt_dt2str[64];
|
||||
time_t tm;
|
||||
unsigned opt;
|
||||
int ifmt = -1;
|
||||
@@ -84,6 +97,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
opt_complementary = "d--s:s--d"
|
||||
IF_FEATURE_DATE_ISOFMT(":R--I:I--R");
|
||||
IF_LONG_OPTS(applet_long_options = date_longopts;)
|
||||
opt = getopt32(argv, "Rs:ud:r:"
|
||||
IF_FEATURE_DATE_ISOFMT("I::D:"),
|
||||
&date_str, &date_str, &filename
|
||||
@@ -95,8 +109,8 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
ifmt = 0; /* default is date */
|
||||
if (isofmt_arg) {
|
||||
static const char isoformats[] ALIGN1 =
|
||||
"date\0""hours\0""minutes\0""seconds\0";
|
||||
ifmt = index_in_strings(isoformats, isofmt_arg);
|
||||
"date\0""hours\0""minutes\0""seconds\0"; /* ns? */
|
||||
ifmt = index_in_substrings(isoformats, isofmt_arg);
|
||||
if (ifmt < 0)
|
||||
bb_show_usage();
|
||||
}
|
||||
@@ -104,20 +118,45 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
fmt_dt2str = NULL;
|
||||
if (argv[0] && argv[0][0] == '+') {
|
||||
fmt_dt2str = &argv[0][1]; /* Skip over the '+' */
|
||||
fmt_dt2str = &argv[0][1]; /* skip over the '+' */
|
||||
argv++;
|
||||
}
|
||||
if (!(opt & (OPT_SET | OPT_DATE))) {
|
||||
opt |= OPT_SET;
|
||||
date_str = argv[0]; /* can be NULL */
|
||||
if (date_str)
|
||||
if (date_str) {
|
||||
#if ENABLE_FEATURE_DATE_COMPAT
|
||||
int len = strspn(date_str, "0123456789");
|
||||
if (date_str[len] == '\0'
|
||||
|| (date_str[len] == '.'
|
||||
&& isdigit(date_str[len+1])
|
||||
&& isdigit(date_str[len+2])
|
||||
&& date_str[len+3] == '\0'
|
||||
)
|
||||
) {
|
||||
/* Dreaded MMDDhhmm[[CC]YY][.ss] format!
|
||||
* It does not match -d or -s format.
|
||||
* Some users actually do use it.
|
||||
*/
|
||||
len -= 8;
|
||||
if (len < 0 || len > 4 || (len & 1))
|
||||
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
|
||||
if (len != 0) { /* move YY or CCYY to front */
|
||||
char buf[4];
|
||||
memcpy(buf, date_str + 8, len);
|
||||
memmove(date_str + len, date_str, 8);
|
||||
memcpy(date_str, buf, len);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
argv++;
|
||||
}
|
||||
}
|
||||
if (*argv)
|
||||
bb_show_usage();
|
||||
|
||||
/* Now we have parsed all the information except the date format
|
||||
which depends on whether the clock is being set or read */
|
||||
* which depends on whether the clock is being set or read */
|
||||
|
||||
if (opt & OPT_REFERENCE) {
|
||||
struct stat statbuf;
|
||||
@@ -151,7 +190,7 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
/* if setting time, set it */
|
||||
if ((opt & OPT_SET) && stime(&tm) < 0) {
|
||||
bb_perror_msg("cannot set date");
|
||||
bb_perror_msg("can't set date");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,37 +199,28 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* Deal with format string */
|
||||
if (fmt_dt2str == NULL) {
|
||||
int i;
|
||||
fmt_dt2str = xzalloc(32);
|
||||
fmt_dt2str = buf_fmt_dt2str;
|
||||
if (ENABLE_FEATURE_DATE_ISOFMT && ifmt >= 0) {
|
||||
strcpy(fmt_dt2str, "%Y-%m-%d");
|
||||
if (ifmt > 0) {
|
||||
i = 8;
|
||||
fmt_dt2str[i++] = 'T';
|
||||
fmt_dt2str[i++] = '%';
|
||||
fmt_dt2str[i++] = 'H';
|
||||
if (ifmt > 1) {
|
||||
fmt_dt2str[i++] = ':';
|
||||
fmt_dt2str[i++] = '%';
|
||||
fmt_dt2str[i++] = 'M';
|
||||
if (ifmt > 2) {
|
||||
fmt_dt2str[i++] = ':';
|
||||
fmt_dt2str[i++] = '%';
|
||||
fmt_dt2str[i++] = 'S';
|
||||
}
|
||||
}
|
||||
/* -I[SPEC]: 0:date 1:hours 2:minutes 3:seconds */
|
||||
strcpy(fmt_dt2str, "%Y-%m-%dT%H:%M:%S");
|
||||
i = 8 + 3 * ifmt;
|
||||
if (ifmt != 0) {
|
||||
/* TODO: if (ifmt==4) i += sprintf(&fmt_dt2str[i], ",%09u", nanoseconds); */
|
||||
format_utc:
|
||||
fmt_dt2str[i++] = '%';
|
||||
fmt_dt2str[i] = (opt & OPT_UTC) ? 'Z' : 'z';
|
||||
fmt_dt2str[i++] = (opt & OPT_UTC) ? 'Z' : 'z';
|
||||
}
|
||||
fmt_dt2str[i] = '\0';
|
||||
} else if (opt & OPT_RFC2822) {
|
||||
/* Undo busybox.c for date -R */
|
||||
/* -R. undo busybox.c setlocale */
|
||||
if (ENABLE_LOCALE_SUPPORT)
|
||||
setlocale(LC_TIME, "C");
|
||||
strcpy(fmt_dt2str, "%a, %d %b %Y %H:%M:%S ");
|
||||
i = 22;
|
||||
i = sizeof("%a, %d %b %Y %H:%M:%S ")-1;
|
||||
goto format_utc;
|
||||
} else /* default case */
|
||||
} else { /* default case */
|
||||
fmt_dt2str = (char*)"%a %b %e %H:%M:%S %Z %Y";
|
||||
}
|
||||
}
|
||||
|
||||
#define date_buf bb_common_bufsiz1
|
||||
@@ -202,7 +232,6 @@ int date_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (strncmp(fmt_dt2str, "%f", 2) == 0) {
|
||||
fmt_dt2str = (char*)"%Y.%m.%d-%H:%M:%S";
|
||||
}
|
||||
|
||||
/* Generate output string */
|
||||
strftime(date_buf, sizeof(date_buf), fmt_dt2str, &tm_time);
|
||||
}
|
||||
|
||||
+56
-15
@@ -29,24 +29,57 @@ static const struct suffix_mult dd_suffixes[] = {
|
||||
{ "M", 1048576 },
|
||||
{ "GD", 1000000000 },
|
||||
{ "G", 1073741824 },
|
||||
{ }
|
||||
{ "", 0 }
|
||||
};
|
||||
|
||||
struct globals {
|
||||
off_t out_full, out_part, in_full, in_part;
|
||||
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
|
||||
unsigned long long total_bytes;
|
||||
unsigned long long begin_time_us;
|
||||
#endif
|
||||
};
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
/* We have to zero it out because of NOEXEC */
|
||||
#define INIT_G() memset(&G, 0, sizeof(G))
|
||||
#define INIT_G() do { \
|
||||
/* we have to zero it out because of NOEXEC */ \
|
||||
memset(&G, 0, sizeof(G)); \
|
||||
} while (0)
|
||||
|
||||
|
||||
static void dd_output_status(int UNUSED_PARAM cur_signal)
|
||||
{
|
||||
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
|
||||
double seconds;
|
||||
unsigned long long bytes_sec;
|
||||
unsigned long long now_us = monotonic_us(); /* before fprintf */
|
||||
#endif
|
||||
|
||||
/* Deliberately using %u, not %d */
|
||||
fprintf(stderr, "%"OFF_FMT"u+%"OFF_FMT"u records in\n"
|
||||
"%"OFF_FMT"u+%"OFF_FMT"u records out\n",
|
||||
G.in_full, G.in_part,
|
||||
G.out_full, G.out_part);
|
||||
|
||||
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
|
||||
fprintf(stderr, "%llu bytes (%sB) copied, ",
|
||||
G.total_bytes,
|
||||
/* show fractional digit, use suffixes */
|
||||
make_human_readable_str(G.total_bytes, 1, 0)
|
||||
);
|
||||
/* Corner cases:
|
||||
* ./busybox dd </dev/null >/dev/null
|
||||
* ./busybox dd bs=1M count=2000 </dev/zero >/dev/null
|
||||
* (echo DONE) | ./busybox dd >/dev/null
|
||||
* (sleep 1; echo DONE) | ./busybox dd >/dev/null
|
||||
*/
|
||||
seconds = (now_us - G.begin_time_us) / 1000000.0;
|
||||
bytes_sec = G.total_bytes / seconds;
|
||||
fprintf(stderr, "%f seconds, %sB/s\n",
|
||||
seconds,
|
||||
/* show fractional digit, use suffixes */
|
||||
make_human_readable_str(bytes_sec, 1, 0)
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
static ssize_t full_write_or_warn(const void *buf, size_t len,
|
||||
@@ -68,13 +101,16 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs,
|
||||
G.out_full++;
|
||||
else if (n) /* > 0 */
|
||||
G.out_part++;
|
||||
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
|
||||
G.total_bytes += n;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if ENABLE_LFS
|
||||
#define XATOU_SFX xatoull_sfx
|
||||
# define XATOU_SFX xatoull_sfx
|
||||
#else
|
||||
#define XATOU_SFX xatoul_sfx
|
||||
# define XATOU_SFX xatoul_sfx
|
||||
#endif
|
||||
|
||||
int dd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
@@ -153,11 +189,7 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
memset(&Z, 0, sizeof(Z));
|
||||
INIT_G();
|
||||
//fflush(NULL); - is this needed because of NOEXEC?
|
||||
|
||||
#if ENABLE_FEATURE_DD_SIGNAL_HANDLING
|
||||
signal_SA_RESTART_empty_mask(SIGUSR1, dd_output_status);
|
||||
#endif
|
||||
//fflush_all(); - is this needed because of NOEXEC?
|
||||
|
||||
for (n = 1; argv[n]; n++) {
|
||||
int what;
|
||||
@@ -244,6 +276,14 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
flags |= FLAG_TWOBUFS;
|
||||
obuf = xmalloc(obs);
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_DD_SIGNAL_HANDLING
|
||||
signal_SA_RESTART_empty_mask(SIGUSR1, dd_output_status);
|
||||
#endif
|
||||
#if ENABLE_FEATURE_DD_THIRD_STATUS_LINE
|
||||
G.begin_time_us = monotonic_us();
|
||||
#endif
|
||||
|
||||
if (infile != NULL)
|
||||
xmove_fd(xopen(infile, O_RDONLY), ifd);
|
||||
else {
|
||||
@@ -286,25 +326,26 @@ int dd_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
|
||||
while (!(flags & FLAG_COUNT) || (G.in_full + G.in_part != count)) {
|
||||
if (flags & FLAG_NOERROR) /* Pre-zero the buffer if conv=noerror */
|
||||
memset(ibuf, 0, ibs);
|
||||
n = safe_read(ifd, ibuf, ibs);
|
||||
if (n == 0)
|
||||
break;
|
||||
if (n < 0) {
|
||||
/* "Bad block" */
|
||||
if (!(flags & FLAG_NOERROR))
|
||||
goto die_infile;
|
||||
n = ibs;
|
||||
bb_simple_perror_msg(infile);
|
||||
/* GNU dd with conv=noerror skips over "bad blocks" */
|
||||
/* GNU dd with conv=noerror skips over bad blocks */
|
||||
xlseek(ifd, ibs, SEEK_CUR);
|
||||
/* conv=noerror,sync writes NULs,
|
||||
* conv=noerror just ignores input bad blocks */
|
||||
n = 0;
|
||||
}
|
||||
if ((size_t)n == ibs)
|
||||
G.in_full++;
|
||||
else {
|
||||
G.in_part++;
|
||||
if (flags & FLAG_SYNC) {
|
||||
memset(ibuf + n, '\0', ibs - n);
|
||||
memset(ibuf + n, 0, ibs - n);
|
||||
n = ibs;
|
||||
}
|
||||
}
|
||||
|
||||
+35
-11
@@ -25,6 +25,7 @@
|
||||
#include <mntent.h>
|
||||
#include <sys/vfs.h>
|
||||
#include "libbb.h"
|
||||
#include "unicode.h"
|
||||
|
||||
#if !ENABLE_FEATURE_HUMAN_READABLE
|
||||
static unsigned long kscale(unsigned long b, unsigned long bs)
|
||||
@@ -34,7 +35,7 @@ static unsigned long kscale(unsigned long b, unsigned long bs)
|
||||
#endif
|
||||
|
||||
int df_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int df_main(int argc, char **argv)
|
||||
int df_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
unsigned long blocks_used;
|
||||
unsigned blocks_percent_used;
|
||||
@@ -57,6 +58,8 @@ int df_main(int argc, char **argv)
|
||||
const char *disp_units_hdr = NULL;
|
||||
char *chp;
|
||||
|
||||
init_unicode();
|
||||
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE && ENABLE_FEATURE_DF_FANCY
|
||||
opt_complementary = "k-mB:m-Bk:B-km";
|
||||
#elif ENABLE_FEATURE_HUMAN_READABLE
|
||||
@@ -89,7 +92,10 @@ int df_main(int argc, char **argv)
|
||||
if (disp_units_hdr == NULL) {
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
disp_units_hdr = xasprintf("%s-blocks",
|
||||
make_human_readable_str(df_disp_hr, 0, !!(opt & OPT_POSIX)));
|
||||
/* print df_disp_hr, show no fractionals,
|
||||
* use suffixes if OPT_POSIX is set in opt */
|
||||
make_human_readable_str(df_disp_hr, 0, !!(opt & OPT_POSIX))
|
||||
);
|
||||
#else
|
||||
disp_units_hdr = xasprintf("%lu-blocks", df_disp_hr);
|
||||
#endif
|
||||
@@ -99,7 +105,7 @@ int df_main(int argc, char **argv)
|
||||
|
||||
mount_table = NULL;
|
||||
argv += optind;
|
||||
if (optind >= argc) {
|
||||
if (!argv[0]) {
|
||||
mount_table = setmntent(bb_path_mtab_file, "r");
|
||||
if (!mount_table)
|
||||
bb_perror_msg_and_die(bb_path_mtab_file);
|
||||
@@ -108,6 +114,9 @@ int df_main(int argc, char **argv)
|
||||
while (1) {
|
||||
const char *device;
|
||||
const char *mount_point;
|
||||
#if ENABLE_FEATURE_ASSUME_UNICODE
|
||||
size_t dev_len;
|
||||
#endif
|
||||
|
||||
if (mount_table) {
|
||||
mount_entry = getmntent(mount_table);
|
||||
@@ -158,10 +167,9 @@ int df_main(int argc, char **argv)
|
||||
continue;
|
||||
|
||||
#ifdef WHY_WE_DO_IT_FOR_DEV_ROOT_ONLY
|
||||
/* ... and also this is the only user of find_block_device */
|
||||
if (strcmp(device, "/dev/root") == 0) {
|
||||
/* Adjusts device to be the real root device,
|
||||
* or leaves device alone if it can't find it */
|
||||
* or leaves device alone if it can't find it */
|
||||
device = find_block_device("/");
|
||||
if (!device) {
|
||||
goto set_error;
|
||||
@@ -169,25 +177,41 @@ int df_main(int argc, char **argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_ASSUME_UNICODE
|
||||
dev_len = unicode_strlen(device);
|
||||
if (dev_len > 20) {
|
||||
printf("%s\n%20s", device, "");
|
||||
} else {
|
||||
printf("%s%*s", device, 20 - (int)dev_len, "");
|
||||
}
|
||||
#else
|
||||
if (printf("\n%-20s" + 1, device) > 20)
|
||||
printf("\n%-20s", "");
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
printf(" %9s ",
|
||||
/* f_blocks x f_bsize / df_disp_hr, show one fractional,
|
||||
* use suffixes if df_disp_hr == 0 */
|
||||
make_human_readable_str(s.f_blocks, s.f_bsize, df_disp_hr));
|
||||
|
||||
printf(" %9s " + 1,
|
||||
/* EXPR x f_bsize / df_disp_hr, show one fractional,
|
||||
* use suffixes if df_disp_hr == 0 */
|
||||
make_human_readable_str((s.f_blocks - s.f_bfree),
|
||||
s.f_bsize, df_disp_hr));
|
||||
|
||||
printf("%9s %3u%% %s\n",
|
||||
make_human_readable_str(s.f_bavail, s.f_bsize, df_disp_hr),
|
||||
blocks_percent_used, mount_point);
|
||||
/* f_bavail x f_bsize / df_disp_hr, show one fractional,
|
||||
* use suffixes if df_disp_hr == 0 */
|
||||
make_human_readable_str(s.f_bavail, s.f_bsize, df_disp_hr),
|
||||
blocks_percent_used, mount_point);
|
||||
#else
|
||||
printf(" %9lu %9lu %9lu %3u%% %s\n",
|
||||
kscale(s.f_blocks, s.f_bsize),
|
||||
kscale(s.f_blocks - s.f_bfree, s.f_bsize),
|
||||
kscale(s.f_bavail, s.f_bsize),
|
||||
blocks_percent_used, mount_point);
|
||||
kscale(s.f_blocks, s.f_bsize),
|
||||
kscale(s.f_blocks - s.f_bfree, s.f_bsize),
|
||||
kscale(s.f_bavail, s.f_bsize),
|
||||
blocks_percent_used, mount_point);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
+3
-8
@@ -15,13 +15,8 @@
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
int dirname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int dirname_main(int argc, char **argv)
|
||||
int dirname_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
puts(dirname(argv[1]));
|
||||
|
||||
return fflush(stdout);
|
||||
puts(dirname(single_argv(argv)));
|
||||
return fflush_all();
|
||||
}
|
||||
@@ -42,10 +42,10 @@ static void convert(char *fn, int conv_type)
|
||||
i = mkstemp(temp_fn);
|
||||
if (i == -1
|
||||
|| fchmod(i, st.st_mode) == -1
|
||||
|| !(out = fdopen(i, "w+"))
|
||||
) {
|
||||
bb_simple_perror_msg_and_die(temp_fn);
|
||||
}
|
||||
out = xfdopen_for_write(i);
|
||||
}
|
||||
|
||||
while ((i = fgetc(in)) != EOF) {
|
||||
@@ -69,7 +69,7 @@ static void convert(char *fn, int conv_type)
|
||||
}
|
||||
|
||||
int dos2unix_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int dos2unix_main(int argc, char **argv)
|
||||
int dos2unix_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
int o, conv_type;
|
||||
|
||||
@@ -88,11 +88,11 @@ int dos2unix_main(int argc, char **argv)
|
||||
if (o)
|
||||
conv_type = o;
|
||||
|
||||
argv += optind;
|
||||
do {
|
||||
/* might be convert(NULL) if there is no filename given */
|
||||
convert(argv[optind], conv_type);
|
||||
optind++;
|
||||
} while (optind < argc);
|
||||
convert(*argv, conv_type);
|
||||
} while (*++argv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
+5
-2
@@ -58,14 +58,17 @@ static void print(unsigned long size, const char *filename)
|
||||
{
|
||||
/* TODO - May not want to defer error checking here. */
|
||||
#if ENABLE_FEATURE_HUMAN_READABLE
|
||||
printf("%s\t%s\n", make_human_readable_str(size, 512, G.disp_hr),
|
||||
printf("%s\t%s\n",
|
||||
/* size x 512 / G.disp_hr, show one fractional,
|
||||
* use suffixes if G.disp_hr == 0 */
|
||||
make_human_readable_str(size, 512, G.disp_hr),
|
||||
filename);
|
||||
#else
|
||||
if (G.disp_k) {
|
||||
size++;
|
||||
size >>= 1;
|
||||
}
|
||||
printf("%ld\t%s\n", size, filename);
|
||||
printf("%lu\t%s\n", size, filename);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -141,7 +141,7 @@ int echo_main(int argc UNUSED_PARAM, char **argv)
|
||||
bb_putchar('\n');
|
||||
}
|
||||
ret:
|
||||
return fflush(stdout);
|
||||
return fflush_all();
|
||||
}
|
||||
|
||||
/*-
|
||||
|
||||
+10
-8
@@ -43,21 +43,20 @@ static const char env_longopts[] ALIGN1 =
|
||||
int env_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int env_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
char **ep;
|
||||
unsigned opt;
|
||||
unsigned opts;
|
||||
llist_t *unset_env = NULL;
|
||||
|
||||
opt_complementary = "u::";
|
||||
#if ENABLE_FEATURE_ENV_LONG_OPTIONS
|
||||
applet_long_options = env_longopts;
|
||||
#endif
|
||||
opt = getopt32(argv, "+iu:", &unset_env);
|
||||
opts = getopt32(argv, "+iu:", &unset_env);
|
||||
argv += optind;
|
||||
if (*argv && LONE_DASH(argv[0])) {
|
||||
opt |= 1;
|
||||
if (argv[0] && LONE_DASH(argv[0])) {
|
||||
opts |= 1;
|
||||
++argv;
|
||||
}
|
||||
if (opt & 1) {
|
||||
if (opts & 1) {
|
||||
clearenv();
|
||||
}
|
||||
while (unset_env) {
|
||||
@@ -84,8 +83,11 @@ int env_main(int argc UNUSED_PARAM, char **argv)
|
||||
bb_simple_perror_msg_and_die(*argv);
|
||||
}
|
||||
|
||||
for (ep = environ; *ep; ep++) {
|
||||
puts(*ep);
|
||||
if (environ) { /* clearenv() may set environ == NULL! */
|
||||
char **ep;
|
||||
for (ep = environ; *ep; ep++) {
|
||||
puts(*ep);
|
||||
}
|
||||
}
|
||||
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
|
||||
+33
-18
@@ -20,8 +20,8 @@
|
||||
*
|
||||
* Caveat: this versions of expand and unexpand don't accept tab lists.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unicode.h"
|
||||
|
||||
enum {
|
||||
OPT_INITIAL = 1 << 0,
|
||||
@@ -30,35 +30,37 @@ enum {
|
||||
};
|
||||
|
||||
#if ENABLE_EXPAND
|
||||
static void expand(FILE *file, int tab_size, unsigned opt)
|
||||
static void expand(FILE *file, unsigned tab_size, unsigned opt)
|
||||
{
|
||||
char *line;
|
||||
|
||||
tab_size = -tab_size;
|
||||
|
||||
while ((line = xmalloc_fgets(file)) != NULL) {
|
||||
int pos;
|
||||
unsigned char c;
|
||||
char *ptr = line;
|
||||
char *ptr;
|
||||
char *ptr_strbeg;
|
||||
|
||||
goto start;
|
||||
ptr = ptr_strbeg = line;
|
||||
while ((c = *ptr) != '\0') {
|
||||
if ((opt & OPT_INITIAL) && !isblank(c)) {
|
||||
fputs(ptr, stdout);
|
||||
/* not space or tab */
|
||||
break;
|
||||
}
|
||||
ptr++;
|
||||
if (c == '\t') {
|
||||
c = ' ';
|
||||
while (++pos < 0)
|
||||
bb_putchar(c);
|
||||
}
|
||||
bb_putchar(c);
|
||||
if (++pos >= 0) {
|
||||
start:
|
||||
pos = tab_size;
|
||||
unsigned len;
|
||||
*ptr = '\0';
|
||||
# if ENABLE_FEATURE_ASSUME_UNICODE
|
||||
len = unicode_strlen(ptr_strbeg);
|
||||
# else
|
||||
len = ptr - ptr_strbeg;
|
||||
# endif
|
||||
len = tab_size - (len % tab_size);
|
||||
/*while (ptr[1] == '\t') { ptr++; len += tab_size; } - can handle many tabs at once */
|
||||
printf("%s%*s", ptr_strbeg, len, "");
|
||||
ptr_strbeg = ptr + 1;
|
||||
}
|
||||
ptr++;
|
||||
}
|
||||
fputs(ptr_strbeg, stdout);
|
||||
free(line);
|
||||
}
|
||||
}
|
||||
@@ -75,6 +77,7 @@ static void unexpand(FILE *file, unsigned tab_size, unsigned opt)
|
||||
|
||||
while (*ptr) {
|
||||
unsigned n;
|
||||
unsigned len;
|
||||
|
||||
while (*ptr == ' ') {
|
||||
column++;
|
||||
@@ -97,8 +100,19 @@ static void unexpand(FILE *file, unsigned tab_size, unsigned opt)
|
||||
}
|
||||
n = strcspn(ptr, "\t ");
|
||||
printf("%*s%.*s", column, "", n, ptr);
|
||||
# if ENABLE_FEATURE_ASSUME_UNICODE
|
||||
{
|
||||
char c;
|
||||
c = ptr[n];
|
||||
ptr[n] = '\0';
|
||||
len = unicode_strlen(ptr);
|
||||
ptr[n] = c;
|
||||
}
|
||||
# else
|
||||
len = n;
|
||||
# endif
|
||||
ptr += n;
|
||||
column = (column + n) % tab_size;
|
||||
column = (column + len) % tab_size;
|
||||
}
|
||||
free(line);
|
||||
}
|
||||
@@ -130,6 +144,7 @@ int expand_main(int argc UNUSED_PARAM, char **argv)
|
||||
"all\0" No_argument "a"
|
||||
;
|
||||
#endif
|
||||
init_unicode();
|
||||
|
||||
if (ENABLE_EXPAND && (!ENABLE_UNEXPAND || applet_name[0] == 'e')) {
|
||||
IF_FEATURE_EXPAND_LONG_OPTIONS(applet_long_options = expand_longopts);
|
||||
|
||||
+1
-1
@@ -214,9 +214,9 @@ static arith_t arithmetic_common(VALUE *l, VALUE *r, int op)
|
||||
|
||||
static VALUE *docolon(VALUE *sv, VALUE *pv)
|
||||
{
|
||||
enum { NMATCH = 2 };
|
||||
VALUE *v;
|
||||
regex_t re_buffer;
|
||||
const int NMATCH = 2;
|
||||
regmatch_t re_regs[NMATCH];
|
||||
|
||||
tostring(sv);
|
||||
|
||||
+92
-78
@@ -9,8 +9,8 @@
|
||||
|
||||
Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
||||
*/
|
||||
|
||||
#include "libbb.h"
|
||||
#include "unicode.h"
|
||||
|
||||
/* Must match getopt32 call */
|
||||
#define FLAG_COUNT_BYTES 1
|
||||
@@ -20,39 +20,53 @@
|
||||
/* Assuming the current column is COLUMN, return the column that
|
||||
printing C will move the cursor to.
|
||||
The first column is 0. */
|
||||
static int adjust_column(int column, char c)
|
||||
static int adjust_column(unsigned column, char c)
|
||||
{
|
||||
if (!(option_mask32 & FLAG_COUNT_BYTES)) {
|
||||
if (c == '\b') {
|
||||
if (column > 0)
|
||||
column--;
|
||||
} else if (c == '\r')
|
||||
if (option_mask32 & FLAG_COUNT_BYTES)
|
||||
return ++column;
|
||||
|
||||
if (c == '\t')
|
||||
return column + 8 - column % 8;
|
||||
|
||||
if (c == '\b') {
|
||||
if ((int)--column < 0)
|
||||
column = 0;
|
||||
else if (c == '\t')
|
||||
column = column + 8 - column % 8;
|
||||
else /* if (isprint (c)) */
|
||||
}
|
||||
else if (c == '\r')
|
||||
column = 0;
|
||||
else { /* just a printable char */
|
||||
if (unicode_status != UNICODE_ON /* every byte is a new char */
|
||||
|| (c & 0xc0) != 0x80 /* it isn't a 2nd+ byte of a Unicode char */
|
||||
) {
|
||||
column++;
|
||||
} else
|
||||
column++;
|
||||
}
|
||||
}
|
||||
return column;
|
||||
}
|
||||
|
||||
/* Note that this function can write NULs, unlike fputs etc. */
|
||||
static void write2stdout(const void *buf, unsigned size)
|
||||
{
|
||||
fwrite(buf, 1, size, stdout);
|
||||
}
|
||||
|
||||
int fold_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int fold_main(int argc, char **argv)
|
||||
int fold_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
char *line_out = NULL;
|
||||
int allocated_out = 0;
|
||||
char *w_opt;
|
||||
int width = 80;
|
||||
int i;
|
||||
int errs = 0;
|
||||
const char *w_opt = "80";
|
||||
unsigned width;
|
||||
smallint exitcode = EXIT_SUCCESS;
|
||||
|
||||
init_unicode();
|
||||
|
||||
if (ENABLE_INCLUDE_SUSv2) {
|
||||
/* Turn any numeric options into -w options. */
|
||||
for (i = 1; i < argc; i++) {
|
||||
char const *a = argv[i];
|
||||
|
||||
if (*a++ == '-') {
|
||||
int i;
|
||||
for (i = 1; argv[i]; i++) {
|
||||
const char *a = argv[i];
|
||||
if (*a == '-') {
|
||||
a++;
|
||||
if (*a == '-' && !a[1]) /* "--" */
|
||||
break;
|
||||
if (isdigit(*a))
|
||||
@@ -62,8 +76,7 @@ int fold_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
getopt32(argv, "bsw:", &w_opt);
|
||||
if (option_mask32 & FLAG_WIDTH)
|
||||
width = xatoul_range(w_opt, 1, 10000);
|
||||
width = xatou_range(w_opt, 1, 10000);
|
||||
|
||||
argv += optind;
|
||||
if (!*argv)
|
||||
@@ -72,80 +85,81 @@ int fold_main(int argc, char **argv)
|
||||
do {
|
||||
FILE *istream = fopen_or_warn_stdin(*argv);
|
||||
int c;
|
||||
int column = 0; /* Screen column where next char will go. */
|
||||
int offset_out = 0; /* Index in 'line_out' for next char. */
|
||||
unsigned column = 0; /* Screen column where next char will go */
|
||||
unsigned offset_out = 0; /* Index in 'line_out' for next char */
|
||||
|
||||
if (istream == NULL) {
|
||||
errs |= EXIT_FAILURE;
|
||||
exitcode = EXIT_FAILURE;
|
||||
continue;
|
||||
}
|
||||
|
||||
while ((c = getc(istream)) != EOF) {
|
||||
if (offset_out + 1 >= allocated_out) {
|
||||
allocated_out += 1024;
|
||||
line_out = xrealloc(line_out, allocated_out);
|
||||
/* We grow line_out in chunks of 0x1000 bytes */
|
||||
if ((offset_out & 0xfff) == 0) {
|
||||
line_out = xrealloc(line_out, offset_out + 0x1000);
|
||||
}
|
||||
|
||||
rescan:
|
||||
line_out[offset_out] = c;
|
||||
if (c == '\n') {
|
||||
line_out[offset_out++] = c;
|
||||
fwrite(line_out, sizeof(char), (size_t) offset_out, stdout);
|
||||
write2stdout(line_out, offset_out + 1);
|
||||
column = offset_out = 0;
|
||||
continue;
|
||||
}
|
||||
rescan:
|
||||
column = adjust_column(column, c);
|
||||
|
||||
if (column > width) {
|
||||
/* This character would make the line too long.
|
||||
Print the line plus a newline, and make this character
|
||||
start the next line. */
|
||||
if (option_mask32 & FLAG_BREAK_SPACES) {
|
||||
/* Look for the last blank. */
|
||||
int logical_end;
|
||||
|
||||
for (logical_end = offset_out - 1; logical_end >= 0; logical_end--) {
|
||||
if (isblank(line_out[logical_end])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (logical_end >= 0) {
|
||||
/* Found a blank. Don't output the part after it. */
|
||||
logical_end++;
|
||||
fwrite(line_out, sizeof(char), (size_t) logical_end, stdout);
|
||||
bb_putchar('\n');
|
||||
/* Move the remainder to the beginning of the next line.
|
||||
The areas being copied here might overlap. */
|
||||
memmove(line_out, line_out + logical_end, offset_out - logical_end);
|
||||
offset_out -= logical_end;
|
||||
for (column = i = 0; i < offset_out; i++) {
|
||||
column = adjust_column(column, line_out[i]);
|
||||
}
|
||||
goto rescan;
|
||||
}
|
||||
} else {
|
||||
if (offset_out == 0) {
|
||||
line_out[offset_out++] = c;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
line_out[offset_out++] = '\n';
|
||||
fwrite(line_out, sizeof(char), (size_t) offset_out, stdout);
|
||||
column = offset_out = 0;
|
||||
goto rescan;
|
||||
if (column <= width || offset_out == 0) {
|
||||
/* offset_out == 0 case happens
|
||||
* with small width (say, 1) and tabs.
|
||||
* The very first tab already goes to column 8,
|
||||
* but we must not wrap it */
|
||||
offset_out++;
|
||||
continue;
|
||||
}
|
||||
|
||||
line_out[offset_out++] = c;
|
||||
}
|
||||
/* This character would make the line too long.
|
||||
* Print the line plus a newline, and make this character
|
||||
* start the next line */
|
||||
if (option_mask32 & FLAG_BREAK_SPACES) {
|
||||
unsigned i;
|
||||
unsigned logical_end;
|
||||
|
||||
/* Look for the last blank. */
|
||||
for (logical_end = offset_out - 1; (int)logical_end >= 0; logical_end--) {
|
||||
if (!isblank(line_out[logical_end]))
|
||||
continue;
|
||||
|
||||
/* Found a space or tab.
|
||||
* Output up to and including it, and start a new line */
|
||||
logical_end++;
|
||||
/*line_out[logical_end] = '\n'; - NO! this nukes one buffered character */
|
||||
write2stdout(line_out, logical_end);
|
||||
putchar('\n');
|
||||
/* Move the remainder to the beginning of the next line.
|
||||
* The areas being copied here might overlap. */
|
||||
memmove(line_out, line_out + logical_end, offset_out - logical_end);
|
||||
offset_out -= logical_end;
|
||||
for (column = i = 0; i < offset_out; i++) {
|
||||
column = adjust_column(column, line_out[i]);
|
||||
}
|
||||
goto rescan;
|
||||
}
|
||||
/* No blank found, wrap will split the overlong word */
|
||||
}
|
||||
/* Output what we accumulated up to now, and start a new line */
|
||||
line_out[offset_out] = '\n';
|
||||
write2stdout(line_out, offset_out + 1);
|
||||
column = offset_out = 0;
|
||||
goto rescan;
|
||||
} /* while (not EOF) */
|
||||
|
||||
if (offset_out) {
|
||||
fwrite(line_out, sizeof(char), (size_t) offset_out, stdout);
|
||||
write2stdout(line_out, offset_out);
|
||||
}
|
||||
|
||||
if (fclose_if_not_stdin(istream)) {
|
||||
bb_simple_perror_msg(*argv); /* Avoid multibyte problems. */
|
||||
errs |= EXIT_FAILURE;
|
||||
bb_simple_perror_msg(*argv);
|
||||
exitcode = EXIT_FAILURE;
|
||||
}
|
||||
} while (*++argv);
|
||||
|
||||
fflush_stdout_and_exit(errs);
|
||||
fflush_stdout_and_exit(exitcode);
|
||||
}
|
||||
@@ -7,6 +7,9 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
#include "libbb.h"
|
||||
#ifndef O_NOATIME
|
||||
# define O_NOATIME 0
|
||||
#endif
|
||||
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ static const struct suffix_mult head_suffixes[] = {
|
||||
{ "b", 512 },
|
||||
{ "k", 1024 },
|
||||
{ "m", 1024*1024 },
|
||||
{ }
|
||||
{ "", 0 }
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
+3
-3
@@ -14,13 +14,13 @@
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
int hostid_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int hostid_main(int argc, char **argv UNUSED_PARAM)
|
||||
int hostid_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
{
|
||||
if (argc > 1) {
|
||||
if (argv[1]) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
printf("%lx\n", gethostid());
|
||||
|
||||
return fflush(stdout);
|
||||
return fflush_all();
|
||||
}
|
||||
+1
-1
@@ -175,7 +175,7 @@ int id_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
} else if (n < 0) { /* error in get_groups() */
|
||||
if (!ENABLE_DESKTOP)
|
||||
bb_error_msg_and_die("cannot get groups");
|
||||
bb_error_msg_and_die("can't get groups");
|
||||
else
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ int install_main(int argc, char **argv)
|
||||
#if ENABLE_FEATURE_INSTALL_LONG_OPTIONS
|
||||
applet_long_options = install_longopts;
|
||||
#endif
|
||||
opt_complementary = "s--d:d--s" IF_SELINUX(":Z--\xff:\xff--Z");
|
||||
opt_complementary = "s--d:d--s" IF_FEATURE_INSTALL_LONG_OPTIONS(IF_SELINUX(":Z--\xff:\xff--Z"));
|
||||
/* -c exists for backwards compatibility, it's needed */
|
||||
/* -v is ignored ("print name of each created directory") */
|
||||
/* -b is ignored ("make a backup of each existing destination file") */
|
||||
|
||||
+1
-1
@@ -18,5 +18,5 @@ int length_main(int argc, char **argv)
|
||||
|
||||
printf("%u\n", (unsigned)strlen(*argv));
|
||||
|
||||
return fflush(stdout);
|
||||
return fflush_all();
|
||||
}
|
||||
@@ -29,11 +29,11 @@ int FAST_FUNC cp_mv_stat2(const char *fn, struct stat *fn_stat, stat_func sf)
|
||||
if (errno != ENOENT) {
|
||||
#if ENABLE_FEATURE_VERBOSE_CP_MESSAGE
|
||||
if (errno == ENOTDIR) {
|
||||
bb_error_msg("cannot stat '%s': Path has non-directory component", fn);
|
||||
bb_error_msg("can't stat '%s': Path has non-directory component", fn);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
bb_perror_msg("cannot stat '%s'", fn);
|
||||
bb_perror_msg("can't stat '%s'", fn);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
+8
-11
@@ -26,7 +26,7 @@ int ln_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int ln_main(int argc, char **argv)
|
||||
{
|
||||
int status = EXIT_SUCCESS;
|
||||
int flag;
|
||||
int opts;
|
||||
char *last;
|
||||
char *src_name;
|
||||
char *src;
|
||||
@@ -34,11 +34,8 @@ int ln_main(int argc, char **argv)
|
||||
struct stat statbuf;
|
||||
int (*link_func)(const char *, const char *);
|
||||
|
||||
flag = getopt32(argv, "sfnbS:", &suffix);
|
||||
|
||||
if (argc == optind) {
|
||||
bb_show_usage();
|
||||
}
|
||||
opt_complementary = "-1"; /* min one arg */
|
||||
opts = getopt32(argv, "sfnbS:", &suffix);
|
||||
|
||||
last = argv[argc - 1];
|
||||
argv += optind;
|
||||
@@ -53,7 +50,7 @@ int ln_main(int argc, char **argv)
|
||||
src = last;
|
||||
|
||||
if (is_directory(src,
|
||||
(flag & LN_NODEREFERENCE) ^ LN_NODEREFERENCE,
|
||||
(opts & LN_NODEREFERENCE) ^ LN_NODEREFERENCE,
|
||||
NULL)
|
||||
) {
|
||||
src_name = xstrdup(*argv);
|
||||
@@ -61,7 +58,7 @@ int ln_main(int argc, char **argv)
|
||||
free(src_name);
|
||||
src_name = src;
|
||||
}
|
||||
if (!(flag & LN_SYMLINK) && stat(*argv, &statbuf)) {
|
||||
if (!(opts & LN_SYMLINK) && stat(*argv, &statbuf)) {
|
||||
// coreutils: "ln dangling_symlink new_hardlink" works
|
||||
if (lstat(*argv, &statbuf) || !S_ISLNK(statbuf.st_mode)) {
|
||||
bb_simple_perror_msg(*argv);
|
||||
@@ -71,7 +68,7 @@ int ln_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (flag & LN_BACKUP) {
|
||||
if (opts & LN_BACKUP) {
|
||||
char *backup;
|
||||
backup = xasprintf("%s%s", src, suffix);
|
||||
if (rename(src, backup) < 0 && errno != ENOENT) {
|
||||
@@ -87,12 +84,12 @@ int ln_main(int argc, char **argv)
|
||||
* Therefore, always unlink().
|
||||
*/
|
||||
unlink(src);
|
||||
} else if (flag & LN_FORCE) {
|
||||
} else if (opts & LN_FORCE) {
|
||||
unlink(src);
|
||||
}
|
||||
|
||||
link_func = link;
|
||||
if (flag & LN_SYMLINK) {
|
||||
if (opts & LN_SYMLINK) {
|
||||
link_func = symlink;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -25,18 +25,18 @@
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
int logname_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int logname_main(int argc, char **argv UNUSED_PARAM)
|
||||
int logname_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
{
|
||||
char buf[128];
|
||||
char buf[64];
|
||||
|
||||
if (argc > 1) {
|
||||
if (argv[1]) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
/* Using _r function - avoid pulling in static buffer from libc */
|
||||
if (getlogin_r(buf, sizeof(buf)) == 0) {
|
||||
puts(buf);
|
||||
return fflush(stdout);
|
||||
return fflush_all();
|
||||
}
|
||||
|
||||
bb_perror_msg_and_die("getlogin");
|
||||
|
||||
+211
-171
@@ -17,8 +17,7 @@
|
||||
* it more portable.
|
||||
*
|
||||
* KNOWN BUGS:
|
||||
* 1. ls -l of a directory doesn't give "total <blocks>" header
|
||||
* 2. hidden files can make column width too large
|
||||
* 1. hidden files can make column width too large
|
||||
*
|
||||
* NON-OPTIMAL BEHAVIOUR:
|
||||
* 1. autowidth reads directories twice
|
||||
@@ -233,19 +232,17 @@ static const unsigned opt_flags[] = {
|
||||
/*
|
||||
* a directory entry and its stat info are stored here
|
||||
*/
|
||||
struct dnode { /* the basic node */
|
||||
const char *name; /* the dir entry name */
|
||||
const char *fullname; /* the dir entry name */
|
||||
int allocated;
|
||||
struct dnode {
|
||||
const char *name; /* the dir entry name */
|
||||
const char *fullname; /* the dir entry name */
|
||||
struct dnode *next; /* point at the next node */
|
||||
smallint fname_allocated;
|
||||
struct stat dstat; /* the file stat info */
|
||||
IF_SELINUX(security_context_t sid;)
|
||||
struct dnode *next; /* point at the next node */
|
||||
};
|
||||
|
||||
static struct dnode **list_dir(const char *);
|
||||
static struct dnode **dnalloc(int);
|
||||
static int list_single(const struct dnode *);
|
||||
|
||||
static struct dnode **list_dir(const char *, unsigned *);
|
||||
static unsigned list_single(const struct dnode *);
|
||||
|
||||
struct globals {
|
||||
#if ENABLE_FEATURE_LS_COLOR
|
||||
@@ -264,15 +261,15 @@ struct globals {
|
||||
};
|
||||
#define G (*(struct globals*)&bb_common_bufsiz1)
|
||||
#if ENABLE_FEATURE_LS_COLOR
|
||||
#define show_color (G.show_color )
|
||||
# define show_color (G.show_color )
|
||||
#else
|
||||
enum { show_color = 0 };
|
||||
#endif
|
||||
#define exit_code (G.exit_code )
|
||||
#define all_fmt (G.all_fmt )
|
||||
#define exit_code (G.exit_code )
|
||||
#define all_fmt (G.all_fmt )
|
||||
#if ENABLE_FEATURE_AUTOWIDTH
|
||||
#define tabstops (G.tabstops )
|
||||
#define terminal_width (G.terminal_width)
|
||||
# define tabstops (G.tabstops )
|
||||
# define terminal_width (G.terminal_width)
|
||||
#else
|
||||
enum {
|
||||
tabstops = COLUMN_GAP,
|
||||
@@ -280,8 +277,8 @@ enum {
|
||||
};
|
||||
#endif
|
||||
#define current_time_t (G.current_time_t)
|
||||
/* memset: we have to zero it out because of NOEXEC */
|
||||
#define INIT_G() do { \
|
||||
/* we have to zero it out because of NOEXEC */ \
|
||||
memset(&G, 0, sizeof(G)); \
|
||||
IF_FEATURE_AUTOWIDTH(tabstops = COLUMN_GAP;) \
|
||||
IF_FEATURE_AUTOWIDTH(terminal_width = TERMINAL_WIDTH;) \
|
||||
@@ -319,7 +316,7 @@ static struct dnode *my_stat(const char *fullname, const char *name, int force_f
|
||||
}
|
||||
}
|
||||
|
||||
cur = xmalloc(sizeof(struct dnode));
|
||||
cur = xmalloc(sizeof(*cur));
|
||||
cur->fullname = fullname;
|
||||
cur->name = name;
|
||||
cur->dstat = dstat;
|
||||
@@ -327,7 +324,6 @@ static struct dnode *my_stat(const char *fullname, const char *name, int force_f
|
||||
return cur;
|
||||
}
|
||||
|
||||
|
||||
/* FYI type values: 1:fifo 2:char 4:dir 6:blk 8:file 10:link 12:socket
|
||||
* (various wacky OSes: 13:Sun door 14:BSD whiteout 5:XENIX named file
|
||||
* 3/7:multiplexed char/block device)
|
||||
@@ -389,107 +385,91 @@ static char append_char(mode_t mode)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#define countdirs(A, B) count_dirs((A), (B), 1)
|
||||
#define countsubdirs(A, B) count_dirs((A), (B), 0)
|
||||
static int count_dirs(struct dnode **dn, int nfiles, int notsubdirs)
|
||||
static unsigned count_dirs(struct dnode **dn, int which)
|
||||
{
|
||||
int i, dirs;
|
||||
unsigned dirs, all;
|
||||
|
||||
if (!dn)
|
||||
return 0;
|
||||
dirs = 0;
|
||||
for (i = 0; i < nfiles; i++) {
|
||||
|
||||
dirs = all = 0;
|
||||
for (; *dn; dn++) {
|
||||
const char *name;
|
||||
if (!S_ISDIR(dn[i]->dstat.st_mode))
|
||||
|
||||
all++;
|
||||
if (!S_ISDIR((*dn)->dstat.st_mode))
|
||||
continue;
|
||||
name = dn[i]->name;
|
||||
if (notsubdirs
|
||||
|| name[0]!='.' || (name[1] && (name[1]!='.' || name[2]))
|
||||
name = (*dn)->name;
|
||||
if (which != SPLIT_SUBDIR /* if not requested to skip . / .. */
|
||||
/* or if it's not . or .. */
|
||||
|| name[0] != '.' || (name[1] && (name[1] != '.' || name[2]))
|
||||
) {
|
||||
dirs++;
|
||||
}
|
||||
}
|
||||
return dirs;
|
||||
}
|
||||
|
||||
static int countfiles(struct dnode **dnp)
|
||||
{
|
||||
int nfiles;
|
||||
struct dnode *cur;
|
||||
|
||||
if (dnp == NULL)
|
||||
return 0;
|
||||
nfiles = 0;
|
||||
for (cur = dnp[0]; cur->next; cur = cur->next)
|
||||
nfiles++;
|
||||
nfiles++;
|
||||
return nfiles;
|
||||
return which != SPLIT_FILE ? dirs : all - dirs;
|
||||
}
|
||||
|
||||
/* get memory to hold an array of pointers */
|
||||
static struct dnode **dnalloc(int num)
|
||||
static struct dnode **dnalloc(unsigned num)
|
||||
{
|
||||
if (num < 1)
|
||||
return NULL;
|
||||
|
||||
num++; /* so that we have terminating NULL */
|
||||
return xzalloc(num * sizeof(struct dnode *));
|
||||
}
|
||||
|
||||
#if ENABLE_FEATURE_LS_RECURSIVE
|
||||
static void dfree(struct dnode **dnp, int nfiles)
|
||||
static void dfree(struct dnode **dnp)
|
||||
{
|
||||
int i;
|
||||
unsigned i;
|
||||
|
||||
if (dnp == NULL)
|
||||
return;
|
||||
|
||||
for (i = 0; i < nfiles; i++) {
|
||||
for (i = 0; dnp[i]; i++) {
|
||||
struct dnode *cur = dnp[i];
|
||||
if (cur->allocated)
|
||||
free((char*)cur->fullname); /* free the filename */
|
||||
free(cur); /* free the dnode */
|
||||
if (cur->fname_allocated)
|
||||
free((char*)cur->fullname);
|
||||
free(cur);
|
||||
}
|
||||
free(dnp); /* free the array holding the dnode pointers */
|
||||
free(dnp);
|
||||
}
|
||||
#else
|
||||
#define dfree(...) ((void)0)
|
||||
#endif
|
||||
|
||||
static struct dnode **splitdnarray(struct dnode **dn, int nfiles, int which)
|
||||
/* Returns NULL-terminated malloced vector of pointers (or NULL) */
|
||||
static struct dnode **splitdnarray(struct dnode **dn, int which)
|
||||
{
|
||||
int dncnt, i, d;
|
||||
unsigned dncnt, d;
|
||||
struct dnode **dnp;
|
||||
|
||||
if (dn == NULL || nfiles < 1)
|
||||
if (dn == NULL)
|
||||
return NULL;
|
||||
|
||||
/* count how many dirs and regular files there are */
|
||||
if (which == SPLIT_SUBDIR)
|
||||
dncnt = countsubdirs(dn, nfiles);
|
||||
else {
|
||||
dncnt = countdirs(dn, nfiles); /* assume we are looking for dirs */
|
||||
if (which == SPLIT_FILE)
|
||||
dncnt = nfiles - dncnt; /* looking for files */
|
||||
}
|
||||
/* count how many dirs or files there are */
|
||||
dncnt = count_dirs(dn, which);
|
||||
|
||||
/* allocate a file array and a dir array */
|
||||
dnp = dnalloc(dncnt);
|
||||
|
||||
/* copy the entrys into the file or dir array */
|
||||
for (d = i = 0; i < nfiles; i++) {
|
||||
if (S_ISDIR(dn[i]->dstat.st_mode)) {
|
||||
for (d = 0; *dn; dn++) {
|
||||
if (S_ISDIR((*dn)->dstat.st_mode)) {
|
||||
const char *name;
|
||||
|
||||
if (!(which & (SPLIT_DIR|SPLIT_SUBDIR)))
|
||||
continue;
|
||||
name = dn[i]->name;
|
||||
name = (*dn)->name;
|
||||
if ((which & SPLIT_DIR)
|
||||
|| name[0]!='.' || (name[1] && (name[1]!='.' || name[2]))
|
||||
) {
|
||||
dnp[d++] = dn[i];
|
||||
dnp[d++] = *dn;
|
||||
}
|
||||
} else if (!(which & (SPLIT_DIR|SPLIT_SUBDIR))) {
|
||||
dnp[d++] = dn[i];
|
||||
dnp[d++] = *dn;
|
||||
}
|
||||
}
|
||||
return dnp;
|
||||
@@ -501,35 +481,42 @@ static int sortcmp(const void *a, const void *b)
|
||||
struct dnode *d1 = *(struct dnode **)a;
|
||||
struct dnode *d2 = *(struct dnode **)b;
|
||||
unsigned sort_opts = all_fmt & SORT_MASK;
|
||||
int dif;
|
||||
off_t dif;
|
||||
|
||||
dif = 0; /* assume SORT_NAME */
|
||||
// TODO: use pre-initialized function pointer
|
||||
// instead of branch forest
|
||||
if (sort_opts == SORT_SIZE) {
|
||||
dif = (int) (d2->dstat.st_size - d1->dstat.st_size);
|
||||
dif = (d2->dstat.st_size - d1->dstat.st_size);
|
||||
} else if (sort_opts == SORT_ATIME) {
|
||||
dif = (int) (d2->dstat.st_atime - d1->dstat.st_atime);
|
||||
dif = (d2->dstat.st_atime - d1->dstat.st_atime);
|
||||
} else if (sort_opts == SORT_CTIME) {
|
||||
dif = (int) (d2->dstat.st_ctime - d1->dstat.st_ctime);
|
||||
dif = (d2->dstat.st_ctime - d1->dstat.st_ctime);
|
||||
} else if (sort_opts == SORT_MTIME) {
|
||||
dif = (int) (d2->dstat.st_mtime - d1->dstat.st_mtime);
|
||||
dif = (d2->dstat.st_mtime - d1->dstat.st_mtime);
|
||||
} else if (sort_opts == SORT_DIR) {
|
||||
dif = S_ISDIR(d2->dstat.st_mode) - S_ISDIR(d1->dstat.st_mode);
|
||||
/* } else if (sort_opts == SORT_VERSION) { */
|
||||
/* } else if (sort_opts == SORT_EXT) { */
|
||||
}
|
||||
|
||||
if (dif == 0) {
|
||||
/* sort by name - may be a tie_breaker for time or size cmp */
|
||||
if (ENABLE_LOCALE_SUPPORT) dif = strcoll(d1->name, d2->name);
|
||||
else dif = strcmp(d1->name, d2->name);
|
||||
/* sort by name, or tie_breaker for other sorts */
|
||||
if (ENABLE_LOCALE_SUPPORT)
|
||||
dif = strcoll(d1->name, d2->name);
|
||||
else
|
||||
dif = strcmp(d1->name, d2->name);
|
||||
}
|
||||
|
||||
if (all_fmt & SORT_REVERSE) {
|
||||
dif = -dif;
|
||||
/* Make dif fit into an int */
|
||||
if (sizeof(dif) > sizeof(int)) {
|
||||
enum { BITS_TO_SHIFT = 8 * (sizeof(dif) - sizeof(int)) };
|
||||
/* shift leaving only "int" worth of bits */
|
||||
if (dif != 0) {
|
||||
dif = 1 | (int)((uoff_t)dif >> BITS_TO_SHIFT);
|
||||
}
|
||||
}
|
||||
return dif;
|
||||
|
||||
return (all_fmt & SORT_REVERSE) ? -(int)dif : (int)dif;
|
||||
}
|
||||
|
||||
static void dnsort(struct dnode **dn, int size)
|
||||
@@ -541,22 +528,24 @@ static void dnsort(struct dnode **dn, int size)
|
||||
#endif
|
||||
|
||||
|
||||
static void showfiles(struct dnode **dn, int nfiles)
|
||||
static void showfiles(struct dnode **dn, unsigned nfiles)
|
||||
{
|
||||
int i, ncols, nrows, row, nc;
|
||||
int column = 0;
|
||||
int nexttab = 0;
|
||||
int column_width = 0; /* for STYLE_LONG and STYLE_SINGLE not used */
|
||||
unsigned i, ncols, nrows, row, nc;
|
||||
unsigned column = 0;
|
||||
unsigned nexttab = 0;
|
||||
unsigned column_width = 0; /* for STYLE_LONG and STYLE_SINGLE not used */
|
||||
|
||||
/* Never happens:
|
||||
if (dn == NULL || nfiles < 1)
|
||||
return;
|
||||
*/
|
||||
|
||||
if (all_fmt & STYLE_LONG) {
|
||||
ncols = 1;
|
||||
} else {
|
||||
/* find the longest file name, use that as the column width */
|
||||
for (i = 0; i < nfiles; i++) {
|
||||
int len = bb_mbstrlen(dn[i]->name);
|
||||
for (i = 0; dn[i]; i++) {
|
||||
int len = unicode_strlen(dn[i]->name);
|
||||
if (column_width < len)
|
||||
column_width = len;
|
||||
}
|
||||
@@ -579,9 +568,10 @@ static void showfiles(struct dnode **dn, int nfiles)
|
||||
for (row = 0; row < nrows; row++) {
|
||||
for (nc = 0; nc < ncols; nc++) {
|
||||
/* reach into the array based on the column and row */
|
||||
i = (nc * nrows) + row; /* assume display by column */
|
||||
if (all_fmt & DISP_ROWS)
|
||||
i = (row * ncols) + nc; /* display across row */
|
||||
else
|
||||
i = (nc * nrows) + row; /* display by column */
|
||||
if (i < nfiles) {
|
||||
if (column > 0) {
|
||||
nexttab -= column;
|
||||
@@ -598,66 +588,106 @@ static void showfiles(struct dnode **dn, int nfiles)
|
||||
}
|
||||
|
||||
|
||||
static void showdirs(struct dnode **dn, int ndirs, int first)
|
||||
#if ENABLE_DESKTOP
|
||||
/* http://www.opengroup.org/onlinepubs/9699919799/utilities/ls.html
|
||||
* If any of the -l, -n, -s options is specified, each list
|
||||
* of files within the directory shall be preceded by a
|
||||
* status line indicating the number of file system blocks
|
||||
* occupied by files in the directory in 512-byte units if
|
||||
* the -k option is not specified, or 1024-byte units if the
|
||||
* -k option is specified, rounded up to the next integral
|
||||
* number of units.
|
||||
*/
|
||||
/* by Jorgen Overgaard (jorgen AT antistaten.se) */
|
||||
static off_t calculate_blocks(struct dnode **dn)
|
||||
{
|
||||
int i, nfiles;
|
||||
uoff_t blocks = 1;
|
||||
if (dn) {
|
||||
while (*dn) {
|
||||
/* st_blocks is in 512 byte blocks */
|
||||
blocks += (*dn)->dstat.st_blocks;
|
||||
dn++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Even though standard says use 512 byte blocks, coreutils use 1k */
|
||||
/* Actually, we round up by calculating (blocks + 1) / 2,
|
||||
* "+ 1" was done when we initialized blocks to 1 */
|
||||
return blocks >> 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static void showdirs(struct dnode **dn, int first)
|
||||
{
|
||||
unsigned nfiles;
|
||||
unsigned dndirs;
|
||||
struct dnode **subdnp;
|
||||
int dndirs;
|
||||
struct dnode **dnd;
|
||||
|
||||
if (dn == NULL || ndirs < 1)
|
||||
/* Never happens:
|
||||
if (dn == NULL || ndirs < 1) {
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
for (i = 0; i < ndirs; i++) {
|
||||
for (; *dn; dn++) {
|
||||
if (all_fmt & (DISP_DIRNAME | DISP_RECURSIVE)) {
|
||||
if (!first)
|
||||
bb_putchar('\n');
|
||||
first = 0;
|
||||
printf("%s:\n", dn[i]->fullname);
|
||||
printf("%s:\n", (*dn)->fullname);
|
||||
}
|
||||
subdnp = list_dir(dn[i]->fullname);
|
||||
nfiles = countfiles(subdnp);
|
||||
subdnp = list_dir((*dn)->fullname, &nfiles);
|
||||
#if ENABLE_DESKTOP
|
||||
if ((all_fmt & STYLE_MASK) == STYLE_LONG)
|
||||
printf("total %"OFF_FMT"u\n", calculate_blocks(subdnp));
|
||||
#endif
|
||||
if (nfiles > 0) {
|
||||
/* list all files at this level */
|
||||
dnsort(subdnp, nfiles);
|
||||
showfiles(subdnp, nfiles);
|
||||
if (ENABLE_FEATURE_LS_RECURSIVE) {
|
||||
if (all_fmt & DISP_RECURSIVE) {
|
||||
/* recursive- list the sub-dirs */
|
||||
dnd = splitdnarray(subdnp, nfiles, SPLIT_SUBDIR);
|
||||
dndirs = countsubdirs(subdnp, nfiles);
|
||||
if (dndirs > 0) {
|
||||
dnsort(dnd, dndirs);
|
||||
showdirs(dnd, dndirs, 0);
|
||||
/* free the array of dnode pointers to the dirs */
|
||||
free(dnd);
|
||||
}
|
||||
if (ENABLE_FEATURE_LS_RECURSIVE
|
||||
&& (all_fmt & DISP_RECURSIVE)
|
||||
) {
|
||||
/* recursive - list the sub-dirs */
|
||||
dnd = splitdnarray(subdnp, SPLIT_SUBDIR);
|
||||
dndirs = count_dirs(subdnp, SPLIT_SUBDIR);
|
||||
if (dndirs > 0) {
|
||||
dnsort(dnd, dndirs);
|
||||
showdirs(dnd, 0);
|
||||
/* free the array of dnode pointers to the dirs */
|
||||
free(dnd);
|
||||
}
|
||||
/* free the dnodes and the fullname mem */
|
||||
dfree(subdnp, nfiles);
|
||||
}
|
||||
/* free the dnodes and the fullname mem */
|
||||
dfree(subdnp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static struct dnode **list_dir(const char *path)
|
||||
/* Returns NULL-terminated malloced vector of pointers (or NULL) */
|
||||
static struct dnode **list_dir(const char *path, unsigned *nfiles_p)
|
||||
{
|
||||
struct dnode *dn, *cur, **dnp;
|
||||
struct dirent *entry;
|
||||
DIR *dir;
|
||||
int i, nfiles;
|
||||
unsigned i, nfiles;
|
||||
|
||||
/* Never happens:
|
||||
if (path == NULL)
|
||||
return NULL;
|
||||
*/
|
||||
|
||||
dn = NULL;
|
||||
nfiles = 0;
|
||||
*nfiles_p = 0;
|
||||
dir = warn_opendir(path);
|
||||
if (dir == NULL) {
|
||||
exit_code = EXIT_FAILURE;
|
||||
return NULL; /* could not open the dir */
|
||||
}
|
||||
dn = NULL;
|
||||
nfiles = 0;
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
char *fullname;
|
||||
|
||||
@@ -677,22 +707,26 @@ static struct dnode **list_dir(const char *path)
|
||||
free(fullname);
|
||||
continue;
|
||||
}
|
||||
cur->allocated = 1;
|
||||
cur->fname_allocated = 1;
|
||||
cur->next = dn;
|
||||
dn = cur;
|
||||
nfiles++;
|
||||
}
|
||||
closedir(dir);
|
||||
|
||||
if (dn == NULL)
|
||||
return NULL;
|
||||
|
||||
/* now that we know how many files there are
|
||||
* allocate memory for an array to hold dnode pointers
|
||||
*/
|
||||
if (dn == NULL)
|
||||
return NULL;
|
||||
*nfiles_p = nfiles;
|
||||
dnp = dnalloc(nfiles);
|
||||
for (i = 0, cur = dn; i < nfiles; i++) {
|
||||
dnp[i] = cur; /* save pointer to node in array */
|
||||
cur = cur->next;
|
||||
for (i = 0; /* i < nfiles - detected via !dn below */; i++) {
|
||||
dnp[i] = dn; /* save pointer to node in array */
|
||||
dn = dn->next;
|
||||
if (!dn)
|
||||
break;
|
||||
}
|
||||
|
||||
return dnp;
|
||||
@@ -703,9 +737,9 @@ static int print_name(const char *name)
|
||||
{
|
||||
if (option_mask32 & OPT_Q) {
|
||||
#if ENABLE_FEATURE_ASSUME_UNICODE
|
||||
int len = 2 + bb_mbstrlen(name);
|
||||
unsigned len = 2 + unicode_strlen(name);
|
||||
#else
|
||||
int len = 2;
|
||||
unsigned len = 2;
|
||||
#endif
|
||||
putchar('"');
|
||||
while (*name) {
|
||||
@@ -723,51 +757,41 @@ static int print_name(const char *name)
|
||||
/* No -Q: */
|
||||
#if ENABLE_FEATURE_ASSUME_UNICODE
|
||||
fputs(name, stdout);
|
||||
return bb_mbstrlen(name);
|
||||
return unicode_strlen(name);
|
||||
#else
|
||||
return printf("%s", name);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static int list_single(const struct dnode *dn)
|
||||
static NOINLINE unsigned list_single(const struct dnode *dn)
|
||||
{
|
||||
int column = 0;
|
||||
unsigned column = 0;
|
||||
char *lpath = lpath; /* for compiler */
|
||||
#if ENABLE_FEATURE_LS_TIMESTAMPS
|
||||
char *filetime;
|
||||
time_t ttime, age;
|
||||
#endif
|
||||
#if ENABLE_FEATURE_LS_FILETYPES || ENABLE_FEATURE_LS_COLOR
|
||||
struct stat info;
|
||||
char append;
|
||||
#endif
|
||||
|
||||
/* Never happens:
|
||||
if (dn->fullname == NULL)
|
||||
return 0;
|
||||
*/
|
||||
|
||||
#if ENABLE_FEATURE_LS_TIMESTAMPS
|
||||
ttime = dn->dstat.st_mtime; /* the default time */
|
||||
if (all_fmt & TIME_ACCESS)
|
||||
ttime = dn->dstat.st_atime;
|
||||
if (all_fmt & TIME_CHANGE)
|
||||
ttime = dn->dstat.st_ctime;
|
||||
filetime = ctime(&ttime);
|
||||
#endif
|
||||
#if ENABLE_FEATURE_LS_FILETYPES
|
||||
append = append_char(dn->dstat.st_mode);
|
||||
#endif
|
||||
|
||||
/* Do readlink early, so that if it fails, error message
|
||||
* does not appear *inside* of the "ls -l" line */
|
||||
* does not appear *inside* the "ls -l" line */
|
||||
if (all_fmt & LIST_SYMLINK)
|
||||
if (S_ISLNK(dn->dstat.st_mode))
|
||||
lpath = xmalloc_readlink_or_warn(dn->fullname);
|
||||
|
||||
if (all_fmt & LIST_INO)
|
||||
column += printf("%7lu ", (long) dn->dstat.st_ino);
|
||||
column += printf("%7llu ", (long long) dn->dstat.st_ino);
|
||||
if (all_fmt & LIST_BLOCKS)
|
||||
column += printf("%4"OFF_FMT"u ", (off_t) dn->dstat.st_blocks >> 1);
|
||||
column += printf("%4"OFF_FMT"u ", (off_t) (dn->dstat.st_blocks >> 1));
|
||||
if (all_fmt & LIST_MODEBITS)
|
||||
column += printf("%-10s ", (char *) bb_mode_string(dn->dstat.st_mode));
|
||||
if (all_fmt & LIST_NLINKS)
|
||||
@@ -775,10 +799,10 @@ static int list_single(const struct dnode *dn)
|
||||
#if ENABLE_FEATURE_LS_USERNAME
|
||||
if (all_fmt & LIST_ID_NAME) {
|
||||
if (option_mask32 & OPT_g) {
|
||||
column += printf("%-8.8s",
|
||||
column += printf("%-8.8s ",
|
||||
get_cached_username(dn->dstat.st_uid));
|
||||
} else {
|
||||
column += printf("%-8.8s %-8.8s",
|
||||
column += printf("%-8.8s %-8.8s ",
|
||||
get_cached_username(dn->dstat.st_uid),
|
||||
get_cached_groupname(dn->dstat.st_gid));
|
||||
}
|
||||
@@ -786,9 +810,9 @@ static int list_single(const struct dnode *dn)
|
||||
#endif
|
||||
if (all_fmt & LIST_ID_NUMERIC) {
|
||||
if (option_mask32 & OPT_g)
|
||||
column += printf("%-8u", (int) dn->dstat.st_uid);
|
||||
column += printf("%-8u ", (int) dn->dstat.st_uid);
|
||||
else
|
||||
column += printf("%-8u %-8u",
|
||||
column += printf("%-8u %-8u ",
|
||||
(int) dn->dstat.st_uid,
|
||||
(int) dn->dstat.st_gid);
|
||||
}
|
||||
@@ -799,29 +823,40 @@ static int list_single(const struct dnode *dn)
|
||||
(int) minor(dn->dstat.st_rdev));
|
||||
} else {
|
||||
if (all_fmt & LS_DISP_HR) {
|
||||
column += printf("%9s ",
|
||||
make_human_readable_str(dn->dstat.st_size, 1, 0));
|
||||
column += printf("%"HUMAN_READABLE_MAX_WIDTH_STR"s ",
|
||||
/* print st_size, show one fractional, use suffixes */
|
||||
make_human_readable_str(dn->dstat.st_size, 1, 0)
|
||||
);
|
||||
} else {
|
||||
column += printf("%9"OFF_FMT"u ", (off_t) dn->dstat.st_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
#if ENABLE_FEATURE_LS_TIMESTAMPS
|
||||
if (all_fmt & LIST_FULLTIME)
|
||||
column += printf("%24.24s ", filetime);
|
||||
if (all_fmt & LIST_DATE_TIME)
|
||||
if ((all_fmt & LIST_FULLTIME) == 0) {
|
||||
if (all_fmt & (LIST_FULLTIME|LIST_DATE_TIME)) {
|
||||
char *filetime;
|
||||
time_t ttime = dn->dstat.st_mtime;
|
||||
if (all_fmt & TIME_ACCESS)
|
||||
ttime = dn->dstat.st_atime;
|
||||
if (all_fmt & TIME_CHANGE)
|
||||
ttime = dn->dstat.st_ctime;
|
||||
filetime = ctime(&ttime);
|
||||
/* filetime's format: "Wed Jun 30 21:49:08 1993\n" */
|
||||
if (all_fmt & LIST_FULLTIME)
|
||||
column += printf("%.24s ", filetime);
|
||||
else { /* LIST_DATE_TIME */
|
||||
/* current_time_t ~== time(NULL) */
|
||||
age = current_time_t - ttime;
|
||||
printf("%6.6s ", filetime + 4);
|
||||
time_t age = current_time_t - ttime;
|
||||
printf("%.6s ", filetime + 4); /* "Jun 30" */
|
||||
if (age < 3600L * 24 * 365 / 2 && age > -15 * 60) {
|
||||
/* hh:mm if less than 6 months old */
|
||||
printf("%5.5s ", filetime + 11);
|
||||
} else {
|
||||
printf(" %4.4s ", filetime + 20);
|
||||
printf("%.5s ", filetime + 11);
|
||||
} else { /* year. buggy if year > 9999 ;) */
|
||||
printf(" %.4s ", filetime + 20);
|
||||
}
|
||||
column += 13;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if ENABLE_SELINUX
|
||||
if (all_fmt & LIST_CONTEXT) {
|
||||
@@ -888,10 +923,10 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
|
||||
struct dnode *dn;
|
||||
struct dnode *cur;
|
||||
unsigned opt;
|
||||
int nfiles;
|
||||
int dnfiles;
|
||||
int dndirs;
|
||||
int i;
|
||||
unsigned nfiles;
|
||||
unsigned dnfiles;
|
||||
unsigned dndirs;
|
||||
unsigned i;
|
||||
#if ENABLE_FEATURE_LS_COLOR
|
||||
/* colored LS support by JaWi, janwillem.janssen@lxtreme.nl */
|
||||
/* coreutils 6.10:
|
||||
@@ -914,7 +949,7 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
INIT_G();
|
||||
|
||||
check_unicode_in_env();
|
||||
init_unicode();
|
||||
|
||||
all_fmt = LIST_SHORT |
|
||||
(ENABLE_FEATURE_LS_SORTFILES * (SORT_NAME | SORT_FORWARD));
|
||||
@@ -1018,29 +1053,34 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
|
||||
argv++;
|
||||
if (!cur)
|
||||
continue;
|
||||
cur->allocated = 0;
|
||||
cur->fname_allocated = 0;
|
||||
cur->next = dn;
|
||||
dn = cur;
|
||||
nfiles++;
|
||||
} while (*argv);
|
||||
|
||||
/* nfiles _may_ be 0 here - try "ls doesnt_exist" */
|
||||
if (nfiles == 0)
|
||||
return exit_code;
|
||||
|
||||
/* now that we know how many files there are
|
||||
* allocate memory for an array to hold dnode pointers
|
||||
*/
|
||||
dnp = dnalloc(nfiles);
|
||||
for (i = 0, cur = dn; i < nfiles; i++) {
|
||||
dnp[i] = cur; /* save pointer to node in array */
|
||||
cur = cur->next;
|
||||
for (i = 0; /* i < nfiles - detected via !dn below */; i++) {
|
||||
dnp[i] = dn; /* save pointer to node in array */
|
||||
dn = dn->next;
|
||||
if (!dn)
|
||||
break;
|
||||
}
|
||||
|
||||
if (all_fmt & DISP_NOLIST) {
|
||||
dnsort(dnp, nfiles);
|
||||
if (nfiles > 0)
|
||||
showfiles(dnp, nfiles);
|
||||
showfiles(dnp, nfiles);
|
||||
} else {
|
||||
dnd = splitdnarray(dnp, nfiles, SPLIT_DIR);
|
||||
dnf = splitdnarray(dnp, nfiles, SPLIT_FILE);
|
||||
dndirs = countdirs(dnp, nfiles);
|
||||
dnd = splitdnarray(dnp, SPLIT_DIR);
|
||||
dnf = splitdnarray(dnp, SPLIT_FILE);
|
||||
dndirs = count_dirs(dnp, SPLIT_DIR);
|
||||
dnfiles = nfiles - dndirs;
|
||||
if (dnfiles > 0) {
|
||||
dnsort(dnf, dnfiles);
|
||||
@@ -1050,12 +1090,12 @@ int ls_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
if (dndirs > 0) {
|
||||
dnsort(dnd, dndirs);
|
||||
showdirs(dnd, dndirs, dnfiles == 0);
|
||||
showdirs(dnd, dnfiles == 0);
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(dnd);
|
||||
}
|
||||
}
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
dfree(dnp, nfiles);
|
||||
dfree(dnp);
|
||||
return exit_code;
|
||||
}
|
||||
@@ -101,8 +101,10 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
|
||||
unsigned flags;
|
||||
/*hash_algo_t hash_algo = applet_name[3];*/
|
||||
|
||||
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK)
|
||||
flags = getopt32(argv, "scw");
|
||||
if (ENABLE_FEATURE_MD5_SHA1_SUM_CHECK) {
|
||||
/* -b "binary", -t "text" are ignored (shaNNNsum compat) */
|
||||
flags = getopt32(argv, "scwbt");
|
||||
}
|
||||
else optind = 1;
|
||||
argv += optind;
|
||||
//argc -= optind;
|
||||
@@ -174,7 +176,7 @@ int md5_sha1_sum_main(int argc UNUSED_PARAM, char **argv)
|
||||
}
|
||||
/*
|
||||
if (fclose_if_not_stdin(pre_computed_stream) == EOF) {
|
||||
bb_perror_msg_and_die("cannot close file %s", file_ptr);
|
||||
bb_perror_msg_and_die("can't close file %s", file_ptr);
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
|
||||
+3
-5
@@ -34,7 +34,7 @@ static const char mkdir_longopts[] ALIGN1 =
|
||||
#endif
|
||||
|
||||
int mkdir_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int mkdir_main(int argc, char **argv)
|
||||
int mkdir_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
mode_t mode = (mode_t)(-1);
|
||||
int status = EXIT_SUCCESS;
|
||||
@@ -64,11 +64,9 @@ int mkdir_main(int argc, char **argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (optind == argc) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
argv += optind;
|
||||
if (!argv[0])
|
||||
bb_show_usage();
|
||||
|
||||
do {
|
||||
if (bb_make_directory(*argv, mode, flags)) {
|
||||
|
||||
+3
-3
@@ -87,10 +87,10 @@ int mv_main(int argc, char **argv)
|
||||
if (errno != EXDEV
|
||||
|| (source_exists = cp_mv_stat2(*argv, &source_stat, lstat)) < 1
|
||||
) {
|
||||
bb_perror_msg("cannot rename '%s'", *argv);
|
||||
bb_perror_msg("can't rename '%s'", *argv);
|
||||
} else {
|
||||
static const char fmt[] ALIGN1 =
|
||||
"cannot overwrite %sdirectory with %sdirectory";
|
||||
"can't overwrite %sdirectory with %sdirectory";
|
||||
|
||||
if (dest_exists) {
|
||||
if (dest_exists == 3) {
|
||||
@@ -105,7 +105,7 @@ int mv_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
if (unlink(dest) < 0) {
|
||||
bb_perror_msg("cannot remove '%s'", dest);
|
||||
bb_perror_msg("can't remove '%s'", dest);
|
||||
goto RET_1;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -32,14 +32,16 @@ nohup: redirecting stderr to stdout
|
||||
*/
|
||||
|
||||
int nohup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int nohup_main(int argc, char **argv)
|
||||
int nohup_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
const char *nohupout;
|
||||
char *home;
|
||||
|
||||
xfunc_error_retval = 127;
|
||||
|
||||
if (argc < 2) bb_show_usage();
|
||||
if (!argv[1]) {
|
||||
bb_show_usage();
|
||||
}
|
||||
|
||||
/* If stdin is a tty, detach from it. */
|
||||
if (isatty(STDIN_FILENO)) {
|
||||
|
||||
+5
-8
@@ -20,9 +20,6 @@
|
||||
|
||||
#include "dump.h"
|
||||
|
||||
#define isdecdigit(c) isdigit(c)
|
||||
#define ishexdigit(c) (isxdigit)(c)
|
||||
|
||||
static void
|
||||
odoffset(dumper_t *dumper, int argc, char ***argvp)
|
||||
{
|
||||
@@ -51,8 +48,8 @@ odoffset(dumper_t *dumper, int argc, char ***argvp)
|
||||
|
||||
if ((*p != '+')
|
||||
&& (argc < 2
|
||||
|| (!isdecdigit(p[0])
|
||||
&& ((p[0] != 'x') || !ishexdigit(p[1])))))
|
||||
|| (!isdigit(p[0])
|
||||
&& ((p[0] != 'x') || !isxdigit(p[1])))))
|
||||
return;
|
||||
|
||||
base = 0;
|
||||
@@ -62,7 +59,7 @@ odoffset(dumper_t *dumper, int argc, char ***argvp)
|
||||
*/
|
||||
if (p[0] == '+')
|
||||
++p;
|
||||
if (p[0] == 'x' && ishexdigit(p[1])) {
|
||||
if (p[0] == 'x' && isxdigit(p[1])) {
|
||||
++p;
|
||||
base = 16;
|
||||
} else if (p[0] == '0' && p[1] == 'x') {
|
||||
@@ -72,10 +69,10 @@ odoffset(dumper_t *dumper, int argc, char ***argvp)
|
||||
|
||||
/* skip over the number */
|
||||
if (base == 16)
|
||||
for (num = p; ishexdigit(*p); ++p)
|
||||
for (num = p; isxdigit(*p); ++p)
|
||||
continue;
|
||||
else
|
||||
for (num = p; isdecdigit(*p); ++p)
|
||||
for (num = p; isdigit(*p); ++p)
|
||||
continue;
|
||||
|
||||
/* check for no number */
|
||||
|
||||
@@ -545,7 +545,8 @@ decode_one_format(const char *s_orig, const char *s, struct tspec *tspec)
|
||||
|
||||
c = *s++;
|
||||
p = strchr(CSIL, *s);
|
||||
if (!p) {
|
||||
/* if *s == NUL, p != NULL! Testcase: "od -tx" */
|
||||
if (!p || *p == '\0') {
|
||||
size = sizeof(int);
|
||||
if (isdigit(s[0])) {
|
||||
size = bb_strtou(s, &end, 0);
|
||||
@@ -807,7 +808,7 @@ skip(off_t n_skip)
|
||||
}
|
||||
|
||||
if (n_skip)
|
||||
bb_error_msg_and_die("cannot skip past end of combined input");
|
||||
bb_error_msg_and_die("can't skip past end of combined input");
|
||||
}
|
||||
|
||||
|
||||
@@ -963,7 +964,7 @@ parse_old_offset(const char *s, off_t *offset)
|
||||
static const struct suffix_mult Bb[] = {
|
||||
{ "B", 1024 },
|
||||
{ "b", 512 },
|
||||
{ }
|
||||
{ "", 0 }
|
||||
};
|
||||
char *p;
|
||||
int radix;
|
||||
@@ -1178,7 +1179,7 @@ int od_main(int argc, char **argv)
|
||||
{ "b", 512 },
|
||||
{ "k", 1024 },
|
||||
{ "m", 1024*1024 },
|
||||
{ }
|
||||
{ "", 0 }
|
||||
};
|
||||
enum {
|
||||
OPT_A = 1 << 0,
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ int pwd_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
||||
if (buf != NULL) {
|
||||
puts(buf);
|
||||
free(buf);
|
||||
return fflush(stdout);
|
||||
return fflush_all();
|
||||
}
|
||||
|
||||
return EXIT_FAILURE;
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ int rm_main(int argc UNUSED_PARAM, char **argv)
|
||||
const char *base = bb_get_last_path_component_strip(*argv);
|
||||
|
||||
if (DOT_OR_DOTDOT(base)) {
|
||||
bb_error_msg("cannot remove '.' or '..'");
|
||||
bb_error_msg("can't remove '.' or '..'");
|
||||
} else if (remove_file(*argv, flags) >= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
+1
-1
@@ -95,5 +95,5 @@ int seq_main(int argc, char **argv)
|
||||
if (n) /* if while loop executed at least once */
|
||||
bb_putchar('\n');
|
||||
|
||||
return fflush(stdout);
|
||||
return fflush_all();
|
||||
}
|
||||
+1
-1
@@ -29,7 +29,7 @@ static const struct suffix_mult sfx[] = {
|
||||
{ "m", 60 },
|
||||
{ "h", 60*60 },
|
||||
{ "d", 24*60*60 },
|
||||
{ }
|
||||
{ "", 0 }
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
+37
-21
@@ -128,7 +128,7 @@ static char *get_key(char *str, struct sort_key *key, int flags)
|
||||
/* Handle -i */
|
||||
if (flags & FLAG_i) {
|
||||
for (start = end = 0; str[end]; end++)
|
||||
if (isprint(str[end]))
|
||||
if (isprint_asciionly(str[end]))
|
||||
str[start++] = str[end];
|
||||
str[start] = '\0';
|
||||
}
|
||||
@@ -278,27 +278,32 @@ static unsigned str2u(char **str)
|
||||
int sort_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int sort_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
FILE *fp, *outfile = stdout;
|
||||
char *line, **lines = NULL;
|
||||
char *line, **lines;
|
||||
char *str_ignored, *str_o, *str_t;
|
||||
llist_t *lst_k = NULL;
|
||||
int i, flag;
|
||||
int linecount = 0;
|
||||
int linecount;
|
||||
unsigned opts;
|
||||
|
||||
xfunc_error_retval = 2;
|
||||
|
||||
/* Parse command line options */
|
||||
/* -o and -t can be given at most once */
|
||||
opt_complementary = "o--o:t--t:" /* -t, -o: maximum one of each */
|
||||
opt_complementary = "o--o:t--t:" /* -t, -o: at most one of each */
|
||||
"k::"; /* -k takes list */
|
||||
getopt32(argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t);
|
||||
opts = getopt32(argv, OPT_STR, &str_ignored, &str_ignored, &str_o, &lst_k, &str_t);
|
||||
/* global b strips leading and trailing spaces */
|
||||
if (opts & FLAG_b)
|
||||
option_mask32 |= FLAG_bb;
|
||||
#if ENABLE_FEATURE_SORT_BIG
|
||||
if (option_mask32 & FLAG_o) outfile = xfopen_for_write(str_o);
|
||||
if (option_mask32 & FLAG_t) {
|
||||
if (opts & FLAG_t) {
|
||||
if (!str_t[0] || str_t[1])
|
||||
bb_error_msg_and_die("bad -t parameter");
|
||||
key_separator = str_t[0];
|
||||
}
|
||||
/* note: below this point we use option_mask32, not opts,
|
||||
* since that reduces register pressure and makes code smaller */
|
||||
|
||||
/* parse sort key */
|
||||
while (lst_k) {
|
||||
enum {
|
||||
@@ -315,7 +320,6 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
|
||||
};
|
||||
struct sort_key *key = add_key();
|
||||
char *str_k = llist_pop(&lst_k);
|
||||
const char *temp2;
|
||||
|
||||
i = 0; /* i==0 before comma, 1 after (-k3,6) */
|
||||
while (*str_k) {
|
||||
@@ -327,11 +331,13 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
|
||||
key->range[2*i+1] = str2u(&str_k);
|
||||
}
|
||||
while (*str_k) {
|
||||
const char *temp2;
|
||||
|
||||
if (*str_k == ',' && !i++) {
|
||||
str_k++;
|
||||
break;
|
||||
} /* no else needed: fall through to syntax error
|
||||
because comma isn't in OPT_STR */
|
||||
because comma isn't in OPT_STR */
|
||||
temp2 = strchr(OPT_STR, *str_k);
|
||||
if (!temp2)
|
||||
bb_error_msg_and_die("unknown key option");
|
||||
@@ -339,27 +345,29 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (flag & ~FLAG_allowed_for_k)
|
||||
bb_error_msg_and_die("unknown sort type");
|
||||
/* b after ',' means strip _trailing_ space */
|
||||
if (i && flag == FLAG_b) flag = FLAG_bb;
|
||||
if (i && flag == FLAG_b)
|
||||
flag = FLAG_bb;
|
||||
key->flags |= flag;
|
||||
str_k++;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* global b strips leading and trailing spaces */
|
||||
if (option_mask32 & FLAG_b) option_mask32 |= FLAG_bb;
|
||||
|
||||
/* Open input files and read data */
|
||||
argv += optind;
|
||||
if (!*argv)
|
||||
*--argv = (char*)"-";
|
||||
linecount = 0;
|
||||
lines = NULL;
|
||||
do {
|
||||
/* coreutils 6.9 compat: abort on first open error,
|
||||
* do not continue to next file: */
|
||||
fp = xfopen_stdin(*argv);
|
||||
FILE *fp = xfopen_stdin(*argv);
|
||||
for (;;) {
|
||||
line = GET_LINE(fp);
|
||||
if (!line) break;
|
||||
if (!line)
|
||||
break;
|
||||
lines = xrealloc_vector(lines, 6, linecount);
|
||||
lines[linecount++] = line;
|
||||
}
|
||||
@@ -373,16 +381,17 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* handle -c */
|
||||
if (option_mask32 & FLAG_c) {
|
||||
int j = (option_mask32 & FLAG_u) ? -1 : 0;
|
||||
for (i = 1; i < linecount; i++)
|
||||
for (i = 1; i < linecount; i++) {
|
||||
if (compare_keys(&lines[i-1], &lines[i]) > j) {
|
||||
fprintf(stderr, "Check line %d\n", i);
|
||||
fprintf(stderr, "Check line %u\n", i);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
/* Perform the actual sort */
|
||||
qsort(lines, linecount, sizeof(char *), compare_keys);
|
||||
qsort(lines, linecount, sizeof(lines[0]), compare_keys);
|
||||
/* handle -u */
|
||||
if (option_mask32 & FLAG_u) {
|
||||
flag = 0;
|
||||
@@ -390,17 +399,24 @@ int sort_main(int argc UNUSED_PARAM, char **argv)
|
||||
/* -- disabling last-resort compare... */
|
||||
option_mask32 |= FLAG_s;
|
||||
for (i = 1; i < linecount; i++) {
|
||||
if (!compare_keys(&lines[flag], &lines[i]))
|
||||
if (compare_keys(&lines[flag], &lines[i]) == 0)
|
||||
free(lines[i]);
|
||||
else
|
||||
lines[++flag] = lines[i];
|
||||
}
|
||||
if (linecount) linecount = flag+1;
|
||||
if (linecount)
|
||||
linecount = flag+1;
|
||||
}
|
||||
|
||||
/* Print it */
|
||||
#if ENABLE_FEATURE_SORT_BIG
|
||||
/* Open output file _after_ we read all input ones */
|
||||
if (option_mask32 & FLAG_o)
|
||||
xmove_fd(xopen3(str_o, O_WRONLY, 0666), STDOUT_FILENO);
|
||||
#endif
|
||||
flag = (option_mask32 & FLAG_z) ? '\0' : '\n';
|
||||
for (i = 0; i < linecount; i++)
|
||||
fprintf(outfile, "%s%c", lines[i], flag);
|
||||
printf("%s%c", lines[i], flag);
|
||||
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
+6
-2
@@ -20,7 +20,7 @@ static const struct suffix_mult split_suffices[] = {
|
||||
#if ENABLE_FEATURE_SPLIT_FANCY
|
||||
{ "g", 1024*1024*1024 },
|
||||
#endif
|
||||
{ }
|
||||
{ "", 0 }
|
||||
};
|
||||
|
||||
/* Increment the suffix part of the filename.
|
||||
@@ -79,9 +79,13 @@ int split_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
argv += optind;
|
||||
if (argv[0]) {
|
||||
int fd;
|
||||
if (argv[1])
|
||||
sfx = argv[1];
|
||||
xmove_fd(xopen(argv[0], O_RDONLY), 0);
|
||||
fd = open_or_warn_stdin(argv[0]);
|
||||
if (fd == -1)
|
||||
return EXIT_FAILURE;
|
||||
xmove_fd(fd, STDIN_FILENO);
|
||||
} else {
|
||||
argv[0] = (char *) bb_msg_standard_input;
|
||||
}
|
||||
|
||||
+13
-13
@@ -383,7 +383,7 @@ static bool do_statfs(const char *filename, const char *format)
|
||||
}
|
||||
#endif
|
||||
if (statfs(filename, &statfsbuf) != 0) {
|
||||
bb_perror_msg("cannot read file system information for '%s'", filename);
|
||||
bb_perror_msg("can't read file system information for '%s'", filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -495,7 +495,7 @@ static bool do_stat(const char *filename, const char *format)
|
||||
}
|
||||
#endif
|
||||
if ((option_mask32 & OPT_DEREFERENCE ? stat : lstat) (filename, &statbuf) != 0) {
|
||||
bb_perror_msg("cannot stat '%s'", filename);
|
||||
bb_perror_msg("can't stat '%s'", filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -640,29 +640,29 @@ static bool do_stat(const char *filename, const char *format)
|
||||
}
|
||||
|
||||
int stat_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int stat_main(int argc, char **argv)
|
||||
int stat_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
IF_FEATURE_STAT_FORMAT(char *format = NULL;)
|
||||
int i;
|
||||
int ok = 1;
|
||||
int ok;
|
||||
unsigned opts;
|
||||
statfunc_ptr statfunc = do_stat;
|
||||
|
||||
getopt32(argv, "ftL"
|
||||
opt_complementary = "-1"; /* min one arg */
|
||||
opts = getopt32(argv, "ftL"
|
||||
IF_SELINUX("Z")
|
||||
IF_FEATURE_STAT_FORMAT("c:", &format)
|
||||
);
|
||||
|
||||
if (option_mask32 & OPT_FILESYS) /* -f */
|
||||
if (opts & OPT_FILESYS) /* -f */
|
||||
statfunc = do_statfs;
|
||||
if (argc == optind) /* files */
|
||||
bb_show_usage();
|
||||
|
||||
#if ENABLE_SELINUX
|
||||
if (option_mask32 & OPT_SELINUX) {
|
||||
if (opts & OPT_SELINUX) {
|
||||
selinux_or_die();
|
||||
}
|
||||
#endif /* ENABLE_SELINUX */
|
||||
for (i = optind; i < argc; ++i)
|
||||
#endif
|
||||
ok = 1;
|
||||
argv += optind;
|
||||
for (i = 0; argv[i]; ++i)
|
||||
ok &= statfunc(argv[i] IF_FEATURE_STAT_FORMAT(, format));
|
||||
|
||||
return (ok ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
|
||||
+36
-34
@@ -619,9 +619,9 @@ enum {
|
||||
|
||||
|
||||
struct globals {
|
||||
const char *device_name; // = bb_msg_standard_input;
|
||||
const char *device_name;
|
||||
/* The width of the screen, for output wrapping */
|
||||
unsigned max_col; // = 80;
|
||||
unsigned max_col;
|
||||
/* Current position, to know when to wrap */
|
||||
unsigned current_col;
|
||||
char buf[10];
|
||||
@@ -734,7 +734,13 @@ static void wrapf(const char *message, ...)
|
||||
G.current_col = 0;
|
||||
}
|
||||
|
||||
static void set_window_size(const int rows, const int cols)
|
||||
static void newline(void)
|
||||
{
|
||||
if (G.current_col != 0)
|
||||
wrapf("\n");
|
||||
}
|
||||
|
||||
static void set_window_size(int rows, int cols)
|
||||
{
|
||||
struct winsize win = { 0, 0, 0, 0 };
|
||||
|
||||
@@ -755,7 +761,7 @@ bail:
|
||||
perror_on_device("%s");
|
||||
}
|
||||
|
||||
static void display_window_size(const int fancy)
|
||||
static void display_window_size(int fancy)
|
||||
{
|
||||
const char *fmt_str = "%s\0%s: no size information for this device";
|
||||
unsigned width, height;
|
||||
@@ -765,7 +771,7 @@ static void display_window_size(const int fancy)
|
||||
perror_on_device(fmt_str);
|
||||
}
|
||||
} else {
|
||||
wrapf(fancy ? "rows %d; columns %d;" : "%d %d\n",
|
||||
wrapf(fancy ? "rows %u; columns %u;" : "%u %u\n",
|
||||
height, width);
|
||||
}
|
||||
}
|
||||
@@ -774,7 +780,7 @@ static const struct suffix_mult stty_suffixes[] = {
|
||||
{ "b", 512 },
|
||||
{ "k", 1024 },
|
||||
{ "B", 1024 },
|
||||
{ }
|
||||
{ "", 0 }
|
||||
};
|
||||
|
||||
static const struct mode_info *find_mode(const char *name)
|
||||
@@ -864,21 +870,21 @@ static void display_recoverable(const struct termios *mode,
|
||||
|
||||
static void display_speed(const struct termios *mode, int fancy)
|
||||
{
|
||||
//01234567 8 9
|
||||
//____________________ 01234567 8 9
|
||||
const char *fmt_str = "%lu %lu\n\0ispeed %lu baud; ospeed %lu baud;";
|
||||
unsigned long ispeed, ospeed;
|
||||
|
||||
ospeed = ispeed = cfgetispeed(mode);
|
||||
if (ispeed == 0 || ispeed == (ospeed = cfgetospeed(mode))) {
|
||||
ispeed = ospeed; /* in case ispeed was 0 */
|
||||
//0123 4 5 6 7 8 9
|
||||
//________ 0123 4 5 6 7 8 9
|
||||
fmt_str = "%lu\n\0\0\0\0\0speed %lu baud;";
|
||||
}
|
||||
if (fancy) fmt_str += 9;
|
||||
wrapf(fmt_str, tty_baud_to_value(ispeed), tty_baud_to_value(ospeed));
|
||||
}
|
||||
|
||||
static void do_display(const struct termios *mode, const int all)
|
||||
static void do_display(const struct termios *mode, int all)
|
||||
{
|
||||
int i;
|
||||
tcflag_t *bitsp;
|
||||
@@ -889,9 +895,9 @@ static void do_display(const struct termios *mode, const int all)
|
||||
if (all)
|
||||
display_window_size(1);
|
||||
#ifdef HAVE_C_LINE
|
||||
wrapf("line = %d;\n", mode->c_line);
|
||||
wrapf("line = %u;\n", mode->c_line);
|
||||
#else
|
||||
wrapf("\n");
|
||||
newline();
|
||||
#endif
|
||||
|
||||
for (i = 0; i != CIDX_min; ++i) {
|
||||
@@ -902,7 +908,7 @@ static void do_display(const struct termios *mode, const int all)
|
||||
#endif
|
||||
/* If eof uses the same slot as min, only print whichever applies */
|
||||
#if VEOF == VMIN
|
||||
if ((mode->c_lflag & ICANON) == 0
|
||||
if (!(mode->c_lflag & ICANON)
|
||||
&& (i == CIDX_eof || i == CIDX_eol)
|
||||
) {
|
||||
continue;
|
||||
@@ -914,15 +920,14 @@ static void do_display(const struct termios *mode, const int all)
|
||||
#if VEOF == VMIN
|
||||
if ((mode->c_lflag & ICANON) == 0)
|
||||
#endif
|
||||
wrapf("min = %d; time = %d;", mode->c_cc[VMIN], mode->c_cc[VTIME]);
|
||||
if (G.current_col) wrapf("\n");
|
||||
wrapf("min = %u; time = %u;", mode->c_cc[VMIN], mode->c_cc[VTIME]);
|
||||
newline();
|
||||
|
||||
for (i = 0; i < NUM_mode_info; ++i) {
|
||||
if (mode_info[i].flags & OMIT)
|
||||
continue;
|
||||
if (mode_info[i].type != prev_type) {
|
||||
/* wrapf("\n"); */
|
||||
if (G.current_col) wrapf("\n");
|
||||
newline();
|
||||
prev_type = mode_info[i].type;
|
||||
}
|
||||
|
||||
@@ -939,7 +944,7 @@ static void do_display(const struct termios *mode, const int all)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (G.current_col) wrapf("\n");
|
||||
newline();
|
||||
}
|
||||
|
||||
static void sane_mode(struct termios *mode)
|
||||
@@ -1138,7 +1143,7 @@ static void set_control_char_or_die(const struct control_info *info,
|
||||
value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes);
|
||||
else if (arg[0] == '\0' || arg[1] == '\0')
|
||||
value = arg[0];
|
||||
else if (!strcmp(arg, "^-") || !strcmp(arg, "undef"))
|
||||
else if (strcmp(arg, "^-") == 0 || strcmp(arg, "undef") == 0)
|
||||
value = _POSIX_VDISABLE;
|
||||
else if (arg[0] == '^') { /* Ignore any trailing junk (^Cjunk) */
|
||||
value = arg[1] & 0x1f; /* Non-letters get weird results */
|
||||
@@ -1156,10 +1161,10 @@ static void set_control_char_or_die(const struct control_info *info,
|
||||
#define STTY_noargs (1 << 4)
|
||||
|
||||
int stty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int stty_main(int argc, char **argv)
|
||||
int stty_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
struct termios mode;
|
||||
void (*output_func)(const struct termios *, const int);
|
||||
void (*output_func)(const struct termios *, int);
|
||||
const char *file_name = NULL;
|
||||
int display_all = 0;
|
||||
int stty_state;
|
||||
@@ -1211,8 +1216,10 @@ int stty_main(int argc, char **argv)
|
||||
if (!file_name)
|
||||
bb_error_msg_and_die(bb_msg_requires_arg, "-F");
|
||||
/* remove -F param from arg[vc] */
|
||||
--argc;
|
||||
while (argv[p]) { argv[p] = argv[p+1]; ++p; }
|
||||
while (argv[p]) {
|
||||
argv[p] = argv[p+1];
|
||||
++p;
|
||||
}
|
||||
}
|
||||
goto end_option;
|
||||
default:
|
||||
@@ -1287,23 +1294,17 @@ int stty_main(int argc, char **argv)
|
||||
(STTY_verbose_output | STTY_recoverable_output))
|
||||
bb_error_msg_and_die("verbose and stty-readable output styles are mutually exclusive");
|
||||
/* Specifying -a or -g with non-options is an error */
|
||||
if (!(stty_state & STTY_noargs) &&
|
||||
(stty_state & (STTY_verbose_output | STTY_recoverable_output)))
|
||||
if (!(stty_state & STTY_noargs)
|
||||
&& (stty_state & (STTY_verbose_output | STTY_recoverable_output))
|
||||
) {
|
||||
bb_error_msg_and_die("modes may not be set when specifying an output style");
|
||||
}
|
||||
|
||||
/* Now it is safe to start doing things */
|
||||
if (file_name) {
|
||||
int fd, fdflags;
|
||||
G.device_name = file_name;
|
||||
fd = xopen(G.device_name, O_RDONLY | O_NONBLOCK);
|
||||
if (fd != STDIN_FILENO) {
|
||||
dup2(fd, STDIN_FILENO);
|
||||
close(fd);
|
||||
}
|
||||
fdflags = fcntl(STDIN_FILENO, F_GETFL);
|
||||
if (fdflags < 0 ||
|
||||
fcntl(STDIN_FILENO, F_SETFL, fdflags & ~O_NONBLOCK) < 0)
|
||||
perror_on_device_and_die("%s: cannot reset non-blocking mode");
|
||||
xmove_fd(xopen_nonblocking(G.device_name), STDIN_FILENO);
|
||||
ndelay_off(STDIN_FILENO);
|
||||
}
|
||||
|
||||
/* Initialize to all zeroes so there is no risk memcmp will report a
|
||||
@@ -1366,6 +1367,7 @@ int stty_main(int argc, char **argv)
|
||||
#endif
|
||||
#ifdef TIOCGWINSZ
|
||||
case param_cols:
|
||||
case param_columns:
|
||||
set_window_size(-1, xatoul_sfx(argnext, stty_suffixes));
|
||||
break;
|
||||
case param_size:
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ static unsigned sum_file(const char *file, unsigned type)
|
||||
if (!bytes_read && !r)
|
||||
/* no error */
|
||||
break;
|
||||
bb_perror_msg(file);
|
||||
bb_simple_perror_msg(file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -14,10 +14,10 @@
|
||||
/* This is a NOFORK applet. Be very careful! */
|
||||
|
||||
int sync_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int sync_main(int argc, char **argv UNUSED_PARAM)
|
||||
int sync_main(int argc UNUSED_PARAM, char **argv IF_NOT_DESKTOP(UNUSED_PARAM))
|
||||
{
|
||||
/* coreutils-6.9 compat */
|
||||
bb_warn_ignoring_args(argc - 1);
|
||||
bb_warn_ignoring_args(argv[1]);
|
||||
|
||||
sync();
|
||||
|
||||
|
||||
+3
-2
@@ -30,7 +30,7 @@ static const struct suffix_mult tail_suffixes[] = {
|
||||
{ "b", 512 },
|
||||
{ "k", 1024 },
|
||||
{ "m", 1024*1024 },
|
||||
{ }
|
||||
{ "", 0 }
|
||||
};
|
||||
|
||||
struct globals {
|
||||
@@ -241,7 +241,8 @@ int tail_main(int argc, char **argv)
|
||||
} while (nwrite);
|
||||
}
|
||||
}
|
||||
xwrite(STDOUT_FILENO, buf + nread - nwrite, nwrite);
|
||||
if (nwrite > 0)
|
||||
xwrite(STDOUT_FILENO, buf + nread - nwrite, nwrite);
|
||||
} else if (count) {
|
||||
if (COUNT_BYTES) {
|
||||
taillen += nread;
|
||||
|
||||
+95
-59
@@ -222,7 +222,7 @@ static const char *const TOKSTR[] = {
|
||||
#define unnest_msg_and_return(expr, ...) return expr
|
||||
#endif
|
||||
|
||||
enum token_types {
|
||||
enum {
|
||||
UNOP,
|
||||
BINOP,
|
||||
BUNOP,
|
||||
@@ -231,53 +231,96 @@ enum token_types {
|
||||
};
|
||||
|
||||
struct operator_t {
|
||||
char op_text[4];
|
||||
unsigned char op_num, op_type;
|
||||
};
|
||||
|
||||
static const struct operator_t ops[] = {
|
||||
{ "-r", FILRD , UNOP },
|
||||
{ "-w", FILWR , UNOP },
|
||||
{ "-x", FILEX , UNOP },
|
||||
{ "-e", FILEXIST, UNOP },
|
||||
{ "-f", FILREG , UNOP },
|
||||
{ "-d", FILDIR , UNOP },
|
||||
{ "-c", FILCDEV , UNOP },
|
||||
{ "-b", FILBDEV , UNOP },
|
||||
{ "-p", FILFIFO , UNOP },
|
||||
{ "-u", FILSUID , UNOP },
|
||||
{ "-g", FILSGID , UNOP },
|
||||
{ "-k", FILSTCK , UNOP },
|
||||
{ "-s", FILGZ , UNOP },
|
||||
{ "-t", FILTT , UNOP },
|
||||
{ "-z", STREZ , UNOP },
|
||||
{ "-n", STRNZ , UNOP },
|
||||
{ "-h", FILSYM , UNOP }, /* for backwards compat */
|
||||
static const struct operator_t ops_table[] = {
|
||||
{ /* "-r" */ FILRD , UNOP },
|
||||
{ /* "-w" */ FILWR , UNOP },
|
||||
{ /* "-x" */ FILEX , UNOP },
|
||||
{ /* "-e" */ FILEXIST, UNOP },
|
||||
{ /* "-f" */ FILREG , UNOP },
|
||||
{ /* "-d" */ FILDIR , UNOP },
|
||||
{ /* "-c" */ FILCDEV , UNOP },
|
||||
{ /* "-b" */ FILBDEV , UNOP },
|
||||
{ /* "-p" */ FILFIFO , UNOP },
|
||||
{ /* "-u" */ FILSUID , UNOP },
|
||||
{ /* "-g" */ FILSGID , UNOP },
|
||||
{ /* "-k" */ FILSTCK , UNOP },
|
||||
{ /* "-s" */ FILGZ , UNOP },
|
||||
{ /* "-t" */ FILTT , UNOP },
|
||||
{ /* "-z" */ STREZ , UNOP },
|
||||
{ /* "-n" */ STRNZ , UNOP },
|
||||
{ /* "-h" */ FILSYM , UNOP }, /* for backwards compat */
|
||||
|
||||
{ "-O" , FILUID , UNOP },
|
||||
{ "-G" , FILGID , UNOP },
|
||||
{ "-L" , FILSYM , UNOP },
|
||||
{ "-S" , FILSOCK, UNOP },
|
||||
{ "=" , STREQ , BINOP },
|
||||
{ "==" , STREQ , BINOP },
|
||||
{ "!=" , STRNE , BINOP },
|
||||
{ "<" , STRLT , BINOP },
|
||||
{ ">" , STRGT , BINOP },
|
||||
{ "-eq", INTEQ , BINOP },
|
||||
{ "-ne", INTNE , BINOP },
|
||||
{ "-ge", INTGE , BINOP },
|
||||
{ "-gt", INTGT , BINOP },
|
||||
{ "-le", INTLE , BINOP },
|
||||
{ "-lt", INTLT , BINOP },
|
||||
{ "-nt", FILNT , BINOP },
|
||||
{ "-ot", FILOT , BINOP },
|
||||
{ "-ef", FILEQ , BINOP },
|
||||
{ "!" , UNOT , BUNOP },
|
||||
{ "-a" , BAND , BBINOP },
|
||||
{ "-o" , BOR , BBINOP },
|
||||
{ "(" , LPAREN , PAREN },
|
||||
{ ")" , RPAREN , PAREN },
|
||||
{ /* "-O" */ FILUID , UNOP },
|
||||
{ /* "-G" */ FILGID , UNOP },
|
||||
{ /* "-L" */ FILSYM , UNOP },
|
||||
{ /* "-S" */ FILSOCK , UNOP },
|
||||
{ /* "=" */ STREQ , BINOP },
|
||||
{ /* "==" */ STREQ , BINOP },
|
||||
{ /* "!=" */ STRNE , BINOP },
|
||||
{ /* "<" */ STRLT , BINOP },
|
||||
{ /* ">" */ STRGT , BINOP },
|
||||
{ /* "-eq"*/ INTEQ , BINOP },
|
||||
{ /* "-ne"*/ INTNE , BINOP },
|
||||
{ /* "-ge"*/ INTGE , BINOP },
|
||||
{ /* "-gt"*/ INTGT , BINOP },
|
||||
{ /* "-le"*/ INTLE , BINOP },
|
||||
{ /* "-lt"*/ INTLT , BINOP },
|
||||
{ /* "-nt"*/ FILNT , BINOP },
|
||||
{ /* "-ot"*/ FILOT , BINOP },
|
||||
{ /* "-ef"*/ FILEQ , BINOP },
|
||||
{ /* "!" */ UNOT , BUNOP },
|
||||
{ /* "-a" */ BAND , BBINOP },
|
||||
{ /* "-o" */ BOR , BBINOP },
|
||||
{ /* "(" */ LPAREN , PAREN },
|
||||
{ /* ")" */ RPAREN , PAREN },
|
||||
};
|
||||
/* Please keep these two tables in sync */
|
||||
static const char ops_texts[] ALIGN1 =
|
||||
"-r" "\0"
|
||||
"-w" "\0"
|
||||
"-x" "\0"
|
||||
"-e" "\0"
|
||||
"-f" "\0"
|
||||
"-d" "\0"
|
||||
"-c" "\0"
|
||||
"-b" "\0"
|
||||
"-p" "\0"
|
||||
"-u" "\0"
|
||||
"-g" "\0"
|
||||
"-k" "\0"
|
||||
"-s" "\0"
|
||||
"-t" "\0"
|
||||
"-z" "\0"
|
||||
"-n" "\0"
|
||||
"-h" "\0"
|
||||
|
||||
"-O" "\0"
|
||||
"-G" "\0"
|
||||
"-L" "\0"
|
||||
"-S" "\0"
|
||||
"=" "\0"
|
||||
"==" "\0"
|
||||
"!=" "\0"
|
||||
"<" "\0"
|
||||
">" "\0"
|
||||
"-eq" "\0"
|
||||
"-ne" "\0"
|
||||
"-ge" "\0"
|
||||
"-gt" "\0"
|
||||
"-le" "\0"
|
||||
"-lt" "\0"
|
||||
"-nt" "\0"
|
||||
"-ot" "\0"
|
||||
"-ef" "\0"
|
||||
"!" "\0"
|
||||
"-a" "\0"
|
||||
"-o" "\0"
|
||||
"(" "\0"
|
||||
")" "\0"
|
||||
;
|
||||
|
||||
|
||||
#if ENABLE_FEATURE_TEST_64
|
||||
@@ -384,29 +427,22 @@ static int equalf(const char *f1, const char *f2)
|
||||
*/
|
||||
|
||||
|
||||
static enum token check_operator(char *s)
|
||||
static enum token check_operator(const char *s)
|
||||
{
|
||||
static const struct operator_t no_op = {
|
||||
.op_num = -1,
|
||||
.op_type = -1
|
||||
};
|
||||
const struct operator_t *op;
|
||||
int n;
|
||||
|
||||
last_operator = &no_op;
|
||||
if (s == NULL) {
|
||||
if (s == NULL)
|
||||
return EOI;
|
||||
}
|
||||
|
||||
op = ops;
|
||||
do {
|
||||
if (strcmp(s, op->op_text) == 0) {
|
||||
last_operator = op;
|
||||
return op->op_num;
|
||||
}
|
||||
op++;
|
||||
} while (op < ops + ARRAY_SIZE(ops));
|
||||
|
||||
return OPERAND;
|
||||
n = index_in_strings(ops_texts, s);
|
||||
if (n < 0)
|
||||
return OPERAND;
|
||||
last_operator = &ops_table[n];
|
||||
return ops_table[n].op_num;
|
||||
}
|
||||
|
||||
|
||||
@@ -422,7 +458,7 @@ static int binop(void)
|
||||
|
||||
opnd2 = *++args;
|
||||
if (opnd2 == NULL)
|
||||
syntax(op->op_text, "argument expected");
|
||||
syntax(args[-1], "argument expected");
|
||||
|
||||
if (is_int_op(op->op_num)) {
|
||||
val1 = getn(opnd1);
|
||||
|
||||
+15
-17
@@ -40,6 +40,9 @@
|
||||
int touch_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
int fd;
|
||||
int status = EXIT_SUCCESS;
|
||||
int opts;
|
||||
#if ENABLE_DESKTOP
|
||||
# if ENABLE_LONG_OPTS
|
||||
static const char touch_longopts[] ALIGN1 =
|
||||
@@ -49,17 +52,15 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
"date\0" Required_argument "d"
|
||||
;
|
||||
# endif
|
||||
struct utimbuf timebuf;
|
||||
char *reference_file = NULL;
|
||||
char *date_str = NULL;
|
||||
struct timeval timebuf[2];
|
||||
timebuf[1].tv_usec = timebuf[0].tv_usec = 0;
|
||||
#else
|
||||
# define reference_file NULL
|
||||
# define date_str NULL
|
||||
# define timebuf (*(struct utimbuf*)NULL)
|
||||
# define timebuf ((struct timeval*)NULL)
|
||||
#endif
|
||||
int fd;
|
||||
int status = EXIT_SUCCESS;
|
||||
int opts;
|
||||
|
||||
#if ENABLE_DESKTOP && ENABLE_LONG_OPTS
|
||||
applet_long_options = touch_longopts;
|
||||
@@ -83,8 +84,7 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (reference_file) {
|
||||
struct stat stbuf;
|
||||
xstat(reference_file, &stbuf);
|
||||
timebuf.actime = stbuf.st_atime;
|
||||
timebuf.modtime = stbuf.st_mtime;
|
||||
timebuf[1].tv_sec = timebuf[0].tv_sec = stbuf.st_mtime;
|
||||
}
|
||||
|
||||
if (date_str) {
|
||||
@@ -100,23 +100,21 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
|
||||
tm_time.tm_isdst = -1; /* Be sure to recheck dst */
|
||||
t = validate_tm_time(date_str, &tm_time);
|
||||
|
||||
timebuf.actime = t;
|
||||
timebuf.modtime = t;
|
||||
timebuf[1].tv_sec = timebuf[0].tv_sec = t;
|
||||
}
|
||||
|
||||
do {
|
||||
if (utime(*argv, reference_file ? &timebuf : NULL)) {
|
||||
if (utimes(*argv, (reference_file || date_str) ? timebuf : NULL) != 0) {
|
||||
if (errno == ENOENT) { /* no such file */
|
||||
if (opts) { /* creation is disabled, so ignore */
|
||||
continue;
|
||||
}
|
||||
/* Try to create the file. */
|
||||
fd = open(*argv, O_RDWR | O_CREAT,
|
||||
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH
|
||||
);
|
||||
if ((fd >= 0) && !close(fd)) {
|
||||
if (reference_file)
|
||||
utime(*argv, &timebuf);
|
||||
/* Try to create the file */
|
||||
fd = open(*argv, O_RDWR | O_CREAT, 0666);
|
||||
if (fd >= 0) {
|
||||
xclose(fd);
|
||||
if (reference_file || date_str)
|
||||
utimes(*argv, timebuf);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -153,7 +153,7 @@ static unsigned expand(const char *arg, char **buffer_p)
|
||||
}
|
||||
if (j == CLASS_punct || j == CLASS_cntrl) {
|
||||
for (i = '\0'; i < ASCII; i++) {
|
||||
if ((j == CLASS_punct && isprint(i) && !isalnum(i) && !isspace(i))
|
||||
if ((j == CLASS_punct && isprint_asciionly(i) && !isalnum(i) && !isspace(i))
|
||||
|| (j == CLASS_cntrl && iscntrl(i))
|
||||
) {
|
||||
buffer[pos++] = i;
|
||||
|
||||
+9
-9
@@ -7,13 +7,13 @@
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
/* BB_AUDIT SUSv3 compliant */
|
||||
/* http://www.opengroup.org/onlinepubs/007904975/utilities/tty.html */
|
||||
/* BB_AUDIT SUSv4 compliant */
|
||||
/* http://www.opengroup.org/onlinepubs/9699919799/utilities/tty.html */
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
int tty_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int tty_main(int argc, char **argv IF_NOT_INCLUDE_SUSv2(UNUSED_PARAM))
|
||||
int tty_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
const char *s;
|
||||
IF_INCLUDE_SUSv2(int silent;) /* Note: No longer relevant in SUSv3. */
|
||||
@@ -22,20 +22,20 @@ int tty_main(int argc, char **argv IF_NOT_INCLUDE_SUSv2(UNUSED_PARAM))
|
||||
xfunc_error_retval = 2; /* SUSv3 requires > 1 for error. */
|
||||
|
||||
IF_INCLUDE_SUSv2(silent = getopt32(argv, "s");)
|
||||
IF_INCLUDE_SUSv2(argc -= optind;)
|
||||
IF_NOT_INCLUDE_SUSv2(argc -= 1;)
|
||||
IF_INCLUDE_SUSv2(argv += optind;)
|
||||
IF_NOT_INCLUDE_SUSv2(argv += 1;)
|
||||
|
||||
/* gnu tty outputs a warning that it is ignoring all args. */
|
||||
bb_warn_ignoring_args(argc);
|
||||
bb_warn_ignoring_args(argv[0]);
|
||||
|
||||
retval = 0;
|
||||
retval = EXIT_SUCCESS;
|
||||
|
||||
s = xmalloc_ttyname(0);
|
||||
s = xmalloc_ttyname(STDIN_FILENO);
|
||||
if (s == NULL) {
|
||||
/* According to SUSv3, ttyname can fail with EBADF or ENOTTY.
|
||||
* We know the file descriptor is good, so failure means not a tty. */
|
||||
s = "not a tty";
|
||||
retval = 1;
|
||||
retval = EXIT_FAILURE;
|
||||
}
|
||||
IF_INCLUDE_SUSv2(if (!silent) puts(s);)
|
||||
IF_NOT_INCLUDE_SUSv2(puts(s);)
|
||||
|
||||
+2
-1
@@ -48,8 +48,9 @@
|
||||
* Fix handling of -a to not print "unknown", add -o and -i support.
|
||||
*/
|
||||
|
||||
#include <sys/utsname.h>
|
||||
#include "libbb.h"
|
||||
/* After libbb.h, since it needs sys/types.h on some systems */
|
||||
#include <sys/utsname.h>
|
||||
|
||||
typedef struct {
|
||||
struct utsname name;
|
||||
|
||||
+50
-45
@@ -12,33 +12,19 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
static FILE *xgetoptfile_uniq_s(char **argv, int read0write2)
|
||||
{
|
||||
const char *n;
|
||||
|
||||
n = *argv;
|
||||
if (n != NULL) {
|
||||
if ((*n != '-') || n[1]) {
|
||||
return xfopen(n, "r\0w" + read0write2);
|
||||
}
|
||||
}
|
||||
return (read0write2) ? stdout : stdin;
|
||||
}
|
||||
|
||||
int uniq_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int uniq_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
FILE *in, *out;
|
||||
const char *s0, *e0, *s1, *e1, *input_filename;
|
||||
unsigned long dups;
|
||||
const char *input_filename;
|
||||
unsigned skip_fields, skip_chars, max_chars;
|
||||
unsigned opt;
|
||||
unsigned i;
|
||||
char *cur_line;
|
||||
const char *cur_compare;
|
||||
|
||||
enum {
|
||||
OPT_c = 0x1,
|
||||
OPT_d = 0x2,
|
||||
OPT_u = 0x4,
|
||||
OPT_d = 0x2, /* print only dups */
|
||||
OPT_u = 0x4, /* print only uniq */
|
||||
OPT_f = 0x8,
|
||||
OPT_s = 0x10,
|
||||
OPT_w = 0x20,
|
||||
@@ -51,52 +37,71 @@ int uniq_main(int argc UNUSED_PARAM, char **argv)
|
||||
opt = getopt32(argv, "cduf:s:w:", &skip_fields, &skip_chars, &max_chars);
|
||||
argv += optind;
|
||||
|
||||
input_filename = *argv;
|
||||
input_filename = argv[0];
|
||||
if (input_filename) {
|
||||
const char *output;
|
||||
|
||||
in = xgetoptfile_uniq_s(argv, 0);
|
||||
if (*argv) {
|
||||
++argv;
|
||||
}
|
||||
out = xgetoptfile_uniq_s(argv, 2);
|
||||
if (*argv && argv[1]) {
|
||||
bb_show_usage();
|
||||
if (input_filename[0] != '-' || input_filename[1]) {
|
||||
close(STDIN_FILENO); /* == 0 */
|
||||
xopen(input_filename, O_RDONLY); /* fd will be 0 */
|
||||
}
|
||||
output = argv[1];
|
||||
if (output) {
|
||||
if (argv[2])
|
||||
bb_show_usage();
|
||||
if (output[0] != '-' || output[1]) {
|
||||
// Won't work with "uniq - FILE" and closed stdin:
|
||||
//close(STDOUT_FILENO);
|
||||
//xopen3(output, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
xmove_fd(xopen3(output, O_WRONLY | O_CREAT | O_TRUNC, 0666), STDOUT_FILENO);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s1 = e1 = NULL; /* prime the pump */
|
||||
cur_compare = cur_line = NULL; /* prime the pump */
|
||||
|
||||
do {
|
||||
s0 = s1;
|
||||
e0 = e1;
|
||||
unsigned i;
|
||||
unsigned long dups;
|
||||
char *old_line;
|
||||
const char *old_compare;
|
||||
|
||||
old_line = cur_line;
|
||||
old_compare = cur_compare;
|
||||
dups = 0;
|
||||
|
||||
/* gnu uniq ignores newlines */
|
||||
while ((s1 = xmalloc_fgetline(in)) != NULL) {
|
||||
e1 = s1;
|
||||
while ((cur_line = xmalloc_fgetline(stdin)) != NULL) {
|
||||
cur_compare = cur_line;
|
||||
for (i = skip_fields; i; i--) {
|
||||
e1 = skip_whitespace(e1);
|
||||
e1 = skip_non_whitespace(e1);
|
||||
cur_compare = skip_whitespace(cur_compare);
|
||||
cur_compare = skip_non_whitespace(cur_compare);
|
||||
}
|
||||
for (i = skip_chars; *e1 && i; i--) {
|
||||
++e1;
|
||||
for (i = skip_chars; *cur_compare && i; i--) {
|
||||
++cur_compare;
|
||||
}
|
||||
|
||||
if (!s0 || strncmp(e0, e1, max_chars)) {
|
||||
if (!old_line || strncmp(old_compare, cur_compare, max_chars)) {
|
||||
break;
|
||||
}
|
||||
|
||||
++dups; /* note: testing for overflow seems excessive. */
|
||||
free(cur_line);
|
||||
++dups; /* testing for overflow seems excessive */
|
||||
}
|
||||
|
||||
if (s0) {
|
||||
if (!(opt & (OPT_d << !!dups))) { /* (if dups, opt & OPT_e) */
|
||||
fprintf(out, "\0%ld " + (opt & 1), dups + 1); /* 1 == OPT_c */
|
||||
fprintf(out, "%s\n", s0);
|
||||
if (old_line) {
|
||||
if (!(opt & (OPT_d << !!dups))) { /* (if dups, opt & OPT_u) */
|
||||
if (opt & OPT_c) {
|
||||
/* %7lu matches GNU coreutils 6.9 */
|
||||
printf("%7lu ", dups + 1);
|
||||
}
|
||||
printf("%s\n", old_line);
|
||||
}
|
||||
free((void *)s0);
|
||||
free(old_line);
|
||||
}
|
||||
} while (s1);
|
||||
} while (cur_line);
|
||||
|
||||
die_if_ferror(in, input_filename);
|
||||
die_if_ferror(stdin, input_filename);
|
||||
|
||||
fflush_stdout_and_exit(EXIT_SUCCESS);
|
||||
}
|
||||
@@ -16,7 +16,7 @@ enum {
|
||||
};
|
||||
|
||||
int uuencode_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int uuencode_main(int argc, char **argv)
|
||||
int uuencode_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
struct stat stat_buf;
|
||||
int src_fd = STDIN_FILENO;
|
||||
@@ -32,7 +32,7 @@ int uuencode_main(int argc, char **argv)
|
||||
tbl = bb_uuenc_tbl_base64;
|
||||
}
|
||||
argv += optind;
|
||||
if (argc == optind + 2) {
|
||||
if (argv[1]) {
|
||||
src_fd = xopen(*argv, O_RDONLY);
|
||||
fstat(src_fd, &stat_buf);
|
||||
mode = stat_buf.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
|
||||
+34
-31
@@ -43,22 +43,19 @@
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
#if ENABLE_LOCALE_SUPPORT
|
||||
#define isspace_given_isprint(c) isspace(c)
|
||||
#else
|
||||
#undef isspace
|
||||
#undef isprint
|
||||
#define isspace(c) ((((c) == ' ') || (((unsigned int)((c) - 9)) <= (13 - 9))))
|
||||
#define isprint(c) (((unsigned int)((c) - 0x20)) <= (0x7e - 0x20))
|
||||
#define isspace_given_isprint(c) ((c) == ' ')
|
||||
#if !ENABLE_LOCALE_SUPPORT
|
||||
# undef isprint
|
||||
# undef isspace
|
||||
# define isprint(c) ((unsigned)((c) - 0x20) <= (0x7e - 0x20))
|
||||
# define isspace(c) ((c) == ' ')
|
||||
#endif
|
||||
|
||||
#if ENABLE_FEATURE_WC_LARGE
|
||||
#define COUNT_T unsigned long long
|
||||
#define COUNT_FMT "llu"
|
||||
# define COUNT_T unsigned long long
|
||||
# define COUNT_FMT "llu"
|
||||
#else
|
||||
#define COUNT_T unsigned
|
||||
#define COUNT_FMT "u"
|
||||
# define COUNT_T unsigned
|
||||
# define COUNT_FMT "u"
|
||||
#endif
|
||||
|
||||
enum {
|
||||
@@ -71,19 +68,14 @@ enum {
|
||||
int wc_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
int wc_main(int argc UNUSED_PARAM, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
const char *s, *arg;
|
||||
const char *arg;
|
||||
const char *start_fmt = " %9"COUNT_FMT + 1;
|
||||
const char *fname_fmt = " %s\n";
|
||||
COUNT_T *pcounts;
|
||||
COUNT_T counts[4];
|
||||
COUNT_T totals[4];
|
||||
unsigned linepos;
|
||||
unsigned u;
|
||||
int num_files = 0;
|
||||
int c;
|
||||
int num_files;
|
||||
smallint status = EXIT_SUCCESS;
|
||||
smallint in_word;
|
||||
unsigned print_type;
|
||||
|
||||
print_type = getopt32(argv, "lwcL");
|
||||
@@ -96,6 +88,8 @@ int wc_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (!argv[0]) {
|
||||
*--argv = (char *) bb_msg_standard_input;
|
||||
fname_fmt = "\n";
|
||||
}
|
||||
if (!argv[1]) { /* zero or one filename? */
|
||||
if (!((print_type-1) & print_type)) /* exactly one option? */
|
||||
start_fmt = "%"COUNT_FMT;
|
||||
}
|
||||
@@ -104,7 +98,14 @@ int wc_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
pcounts = counts;
|
||||
|
||||
num_files = 0;
|
||||
while ((arg = *argv++) != 0) {
|
||||
FILE *fp;
|
||||
const char *s;
|
||||
unsigned u;
|
||||
unsigned linepos;
|
||||
smallint in_word;
|
||||
|
||||
++num_files;
|
||||
fp = fopen_or_warn_stdin(arg);
|
||||
if (!fp) {
|
||||
@@ -117,17 +118,26 @@ int wc_main(int argc UNUSED_PARAM, char **argv)
|
||||
in_word = 0;
|
||||
|
||||
do {
|
||||
int c;
|
||||
/* Our -w doesn't match GNU wc exactly... oh well */
|
||||
|
||||
++counts[WC_CHARS];
|
||||
c = getc(fp);
|
||||
if (isprint(c)) {
|
||||
if (c == EOF) {
|
||||
if (ferror(fp)) {
|
||||
bb_simple_perror_msg(arg);
|
||||
status = EXIT_FAILURE;
|
||||
}
|
||||
--counts[WC_CHARS];
|
||||
goto DO_EOF; /* Treat an EOF as '\r'. */
|
||||
}
|
||||
if (isprint_asciionly(c)) {
|
||||
++linepos;
|
||||
if (!isspace_given_isprint(c)) {
|
||||
if (!isspace(c)) {
|
||||
in_word = 1;
|
||||
continue;
|
||||
}
|
||||
} else if (((unsigned int)(c - 9)) <= 4) {
|
||||
} else if ((unsigned)(c - 9) <= 4) {
|
||||
/* \t 9
|
||||
* \n 10
|
||||
* \v 11
|
||||
@@ -137,7 +147,7 @@ int wc_main(int argc UNUSED_PARAM, char **argv)
|
||||
if (c == '\t') {
|
||||
linepos = (linepos | 7) + 1;
|
||||
} else { /* '\n', '\r', '\f', or '\v' */
|
||||
DO_EOF:
|
||||
DO_EOF:
|
||||
if (linepos > counts[WC_LENGTH]) {
|
||||
counts[WC_LENGTH] = linepos;
|
||||
}
|
||||
@@ -148,13 +158,6 @@ int wc_main(int argc UNUSED_PARAM, char **argv)
|
||||
linepos = 0;
|
||||
}
|
||||
}
|
||||
} else if (c == EOF) {
|
||||
if (ferror(fp)) {
|
||||
bb_simple_perror_msg(arg);
|
||||
status = EXIT_FAILURE;
|
||||
}
|
||||
--counts[WC_CHARS];
|
||||
goto DO_EOF; /* Treat an EOF as '\r'. */
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
@@ -173,7 +176,7 @@ int wc_main(int argc UNUSED_PARAM, char **argv)
|
||||
|
||||
fclose_if_not_stdin(fp);
|
||||
|
||||
OUTPUT:
|
||||
OUTPUT:
|
||||
/* coreutils wc tries hard to print pretty columns
|
||||
* (saves results for all files, find max col len etc...)
|
||||
* we won't try that hard, it will bloat us too much */
|
||||
|
||||
Loaded 100 of 557 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user