Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aec27bca98 | ||
|
|
960be79964 | ||
|
|
be909b1cd5 | ||
|
|
d006c9e630 | ||
|
|
9ebccb2891 | ||
|
|
f1f6d58598 | ||
|
|
0c838af50b | ||
|
|
195fa15caf | ||
|
|
61dc057183 | ||
|
|
df5f6ba115 | ||
|
|
da9841efc1 | ||
|
|
da1d1e763d | ||
|
|
cc54d12ef7 | ||
|
|
dd23b8bb43 | ||
|
|
c674d70699 | ||
|
|
6315ce603b | ||
|
|
85c552035e | ||
|
|
9b2297a34e | ||
|
|
a0053735dc | ||
|
|
3849f9bfcc | ||
|
|
9a8243aa1e | ||
|
|
928faac503 | ||
|
|
34e1941c32 | ||
|
|
0b4551faf5 | ||
|
|
a03d86cf54 | ||
|
|
44735f8744 | ||
|
|
999bf72f49 | ||
|
|
e9b527ae48 | ||
|
|
161cf93404 | ||
|
|
f12724c21a | ||
|
|
a57ba4db64 | ||
|
|
2cd439f7f0 | ||
|
|
bd22ed8067 | ||
|
|
877a71bbf0 | ||
|
|
9cf44e79aa | ||
|
|
8f282f1b02 | ||
|
|
acecc47261 | ||
|
|
e6b9dfa967 | ||
|
|
53a955786d | ||
|
|
a2c83d885e | ||
|
|
03f9c81cec | ||
|
|
bb374a6935 | ||
|
|
4c95a28461 | ||
|
|
3312b0b626 | ||
|
|
2158092344 | ||
|
|
b9eb0233a9 | ||
|
|
b0b732bfe4 | ||
|
|
03f4c27bd6 | ||
|
|
67536ffa43 | ||
|
|
8845adc545 | ||
|
|
02bc25be56 | ||
|
|
e5cec4e3ac | ||
|
|
62bb2d02b6 | ||
|
|
a5dbb39dac | ||
|
|
c8c10c5715 | ||
|
|
f86aee74ce | ||
|
|
b1e379f7f3 | ||
|
|
78eab2f6c6 | ||
|
|
3cfa9ec09c | ||
|
|
6f5e281479 | ||
|
|
b2731b11ef | ||
|
|
1e03add675 | ||
|
|
5d893b6beb | ||
|
|
89bc256c94 | ||
|
|
f7cf2f7ef9 | ||
|
|
57ebebfb01 | ||
|
|
2086e3d679 | ||
|
|
028fb625f5 | ||
|
|
5331025f79 | ||
|
|
b02c54ebee | ||
|
|
72965e3454 | ||
|
|
b54833cde0 | ||
|
|
7c31ea4e29 | ||
|
|
5d41d60f1e | ||
|
|
2e1148b239 | ||
|
|
8bd891cbec | ||
|
|
1ca41775bb | ||
|
|
d37218941c | ||
|
|
268b8c4f38 | ||
|
|
0c96eba3de | ||
|
|
a44790f539 | ||
|
|
a2db097d66 | ||
|
|
1c314ad655 | ||
|
|
47cac6779a | ||
|
|
eb0283333b | ||
|
|
7cdc76dfbf | ||
|
|
d0edef3cbe | ||
|
|
495869f59a | ||
|
|
cb1d841f09 | ||
|
|
27b5924b96 | ||
|
|
8f425dbf9a | ||
|
|
83a949cb22 | ||
|
|
1386e70210 | ||
|
|
ef40aa81c5 | ||
|
|
3adffb7fc8 | ||
|
|
10dc9d4d17 | ||
|
|
8a24a6783a | ||
|
|
4a971aef59 | ||
|
|
3c37598dc2 | ||
|
|
a29dec28cb | ||
|
|
ccd32cbb61 | ||
|
|
9d9610b8de | ||
|
|
6f9985e2f2 | ||
|
|
addc9c28ad | ||
|
|
4fa84e6b54 | ||
|
|
c6cdf58747 | ||
|
|
07edff4ba4 | ||
|
|
45087b1010 | ||
|
|
766c012975 | ||
|
|
c5c5e3d144 | ||
|
|
afa0662860 | ||
|
|
1a804e4b3c | ||
|
|
f929641c51 | ||
|
|
feb47c024a | ||
|
|
f7a01951fb | ||
|
|
7ac06a3ff1 | ||
|
|
0021679b0d | ||
|
|
b405dfa54d | ||
|
|
c03525475e | ||
|
|
e63ad9ba06 | ||
|
|
28c88a9430 | ||
|
|
339b892313 | ||
|
|
4eb1b30411 | ||
|
|
bd4a75f6c8 | ||
|
|
bb245ba0c2 | ||
|
|
9ca57d377e | ||
|
|
e1e23eecab | ||
|
|
5e29c6ffce | ||
|
|
a15cd0be34 | ||
|
|
b7362e36a8 | ||
|
|
67e32304b1 | ||
|
|
be5023a84d | ||
|
|
b610615be9 | ||
|
|
dbb3019d0d | ||
|
|
30f0f2d040 | ||
|
|
b108a5b780 | ||
|
|
110fc0cacc | ||
|
|
74c66ad06e | ||
|
|
98cd53e86d | ||
|
|
852ff13fc4 | ||
|
|
b991395405 | ||
|
|
2e965239ee | ||
|
|
3f75503fa0 | ||
|
|
28c70b3a16 | ||
|
|
e97da40079 | ||
|
|
1af7ed5573 | ||
|
|
3c709b45b3 | ||
|
|
d84990eb1f | ||
|
|
854e11581f | ||
|
|
2b6ab3cbf8 | ||
|
|
053b1462b7 | ||
|
|
baf22bff21 | ||
|
|
c7ccfc99fc | ||
|
|
9f16d61408 | ||
|
|
44760d058c | ||
|
|
5db60a7a7a | ||
|
|
0c6a970eb2 | ||
|
|
b3d235f63b | ||
|
|
b3cf9baeb9 | ||
|
|
049b706591 | ||
|
|
da10ec0eaa | ||
|
|
0024abcbbc | ||
|
|
0b66577368 | ||
|
|
a42982e8f5 | ||
|
|
1f6262b8e2 | ||
|
|
fb8ba506bb | ||
|
|
3232203226 | ||
|
|
d05e3ce5c2 | ||
|
|
eec2f63b3f | ||
|
|
700a5aed75 | ||
|
|
517cab761f | ||
|
|
6ca28ba65c | ||
|
|
680d65a646 | ||
|
|
68480dc30f | ||
|
|
815e904470 | ||
|
|
c389d91181 | ||
|
|
82c0ac7e4f | ||
|
|
f2fffefe49 | ||
|
|
36fe1a30b1 | ||
|
|
926e0e3465 | ||
|
|
afeb683459 | ||
|
|
46a38dbb9b | ||
|
|
ef4268efa7 | ||
|
|
832000f7f3 | ||
|
|
f0c30b71be | ||
|
|
5a0a2aa00b | ||
|
|
808d03ec19 | ||
|
|
9c8ffa02f4 | ||
|
|
3199bda52e | ||
|
|
6082917e34 | ||
|
|
380e58a05f | ||
|
|
ec480c49c2 | ||
|
|
86ab8a32bd | ||
|
|
4062268bc7 | ||
|
|
08e9289ab3 | ||
|
|
b6c6d87a99 | ||
|
|
77bd2db325 | ||
|
|
1624813459 | ||
|
|
b83e0ed3a1 | ||
|
|
89960b8af2 | ||
|
|
b5966368d7 | ||
|
|
deb0331eb6 | ||
|
|
108a44345c | ||
|
|
e511e7c116 | ||
|
|
8ea7d8cdaf | ||
|
|
330fd2b576 | ||
|
|
d356c6e9d1 | ||
|
|
5b46d792f1 | ||
|
|
499f65fb98 | ||
|
|
969f9b0486 | ||
|
|
67a0dd8f3c | ||
|
|
c3f5c9c2ee | ||
|
|
bcd6177853 | ||
|
|
73c8c9cf9a | ||
|
|
23dea9b712 | ||
|
|
7ab9c7ee52 | ||
|
|
3d427ac5ef | ||
|
|
59b9e87024 | ||
|
|
ac130e1dca | ||
|
|
0a027e6880 | ||
|
|
691f49d3c1 | ||
|
|
0e713cef9d | ||
|
|
6c5f2c6021 | ||
|
|
9b15e50835 | ||
|
|
a59d7094a6 | ||
|
|
0a704e8ff6 | ||
|
|
a19bc64653 | ||
|
|
e31c06608e | ||
|
|
03ccce6e30 | ||
|
|
5afc864422 | ||
|
|
3c1217cfad | ||
|
|
8f8d6d5f2d | ||
|
|
d16665810d | ||
|
|
12d1b378be | ||
|
|
9b7d964581 | ||
|
|
f378fced43 | ||
|
|
4625240674 | ||
|
|
94f5e0ba7c | ||
|
|
28c49b6c9c | ||
|
|
25c44c623d | ||
|
|
923ef599f3 | ||
|
|
6ed02a0ee0 | ||
|
|
abc199eb0c | ||
|
|
4f3f757d56 | ||
|
|
227a59b05d | ||
|
|
f93a95de69 | ||
|
|
e90f4045af | ||
|
|
1d1d95051a | ||
|
|
cf8d38a3eb | ||
|
|
7d6ba57bba | ||
|
|
e3ed156eeb | ||
|
|
1101d23604 | ||
|
|
eef658068b | ||
|
|
2e397341d9 | ||
|
|
262dd039eb | ||
|
|
3fe7f9f20b | ||
|
|
a3e57ca700 | ||
|
|
f13df3752c | ||
|
|
9a8195cc03 | ||
|
|
b9167cb67f | ||
|
|
632bb57135 | ||
|
|
c366050a23 | ||
|
|
f29f797f54 | ||
|
|
0a64de9b4f | ||
|
|
229dd2b905 | ||
|
|
5d68857b9c | ||
|
|
a6c752201e | ||
|
|
91e581fa04 | ||
|
|
5a50def0f4 | ||
|
|
6e703034f4 | ||
|
|
26702fe191 | ||
|
|
e5b6c7dd9c | ||
|
|
4fd10fc73b | ||
|
|
200be97e36 | ||
|
|
5a728cfdfe | ||
|
|
3becdfc316 | ||
|
|
53642b066c | ||
|
|
9057b6a918 | ||
|
|
ab01ed12bd | ||
|
|
5e1189e187 | ||
|
|
95c1c1e05f | ||
|
|
d5ba77d03e | ||
|
|
50ed0676ad | ||
|
|
cbd6628c8c | ||
|
|
9cf3bfa7c1 | ||
|
|
b4f8606c05 | ||
|
|
08e7f75ba2 | ||
|
|
f17792ca9b | ||
|
|
61677feff7 | ||
|
|
62dc17a3b1 | ||
|
|
f0657d3229 | ||
|
|
a2685735b1 | ||
|
|
f3b3d17060 | ||
|
|
0817d1372c | ||
|
|
84e09e4437 | ||
|
|
ecd512453c | ||
|
|
5dd853ad2a | ||
|
|
6a34b539db | ||
|
|
825aead68b | ||
|
|
93d6513d93 | ||
|
|
7a4b719486 | ||
|
|
6bd3602988 | ||
|
|
c0dac18d6d | ||
|
|
e9fee653dc | ||
|
|
d4bc1fcad8 | ||
|
|
5661fe078e | ||
|
|
cbb0a4b40d | ||
|
|
b99ca13261 | ||
|
|
68a9ea4208 | ||
|
|
183da4ade1 | ||
|
|
983b51b17b | ||
|
|
3364d78b18 | ||
|
|
6acaa40f27 | ||
|
|
deea048bec | ||
|
|
1ad302ac90 | ||
|
|
e454fb68a3 | ||
|
|
298854f029 | ||
|
|
ec5bd90916 | ||
|
|
016ffe9307 | ||
|
|
0d068a2067 | ||
|
|
c053e41fa0 | ||
|
|
42094cdad5 | ||
|
|
1dbe340eba | ||
|
|
c7c634bd88 | ||
|
|
6c41c44898 | ||
|
|
531bcb6826 | ||
|
|
6273f655c8 | ||
|
|
161220c498 | ||
|
|
13456d1fcd | ||
|
|
d75af99529 | ||
|
|
a967e3c8f0 | ||
|
|
ce91732416 | ||
|
|
3522eb1ab3 | ||
|
|
269bba2514 | ||
|
|
47d3bb3b6d | ||
|
|
54969a1f64 | ||
|
|
692a4502b0 | ||
|
|
2ac2fae728 | ||
|
|
cbd0d625c7 | ||
|
|
06249f24f3 | ||
|
|
ea6b67de65 | ||
|
|
246cc6dddd | ||
|
|
e916d24805 | ||
|
|
9c5c29d442 | ||
|
|
65fc1c70f7 | ||
|
|
fb002d0df0 | ||
|
|
66be5e7e29 | ||
|
|
6437170cb3 | ||
|
|
029011b9ee | ||
|
|
7c4b2f3fe5 | ||
|
|
a51ecdd9e4 | ||
|
|
5b911ddd57 | ||
|
|
dc75a739ac | ||
|
|
f7c49ef2d1 | ||
|
|
3b9522f2af | ||
|
|
6e769df47d | ||
|
|
d07ee46919 | ||
|
|
fa4718efcf | ||
|
|
42387e4964 | ||
|
|
27fdd081ef | ||
|
|
e272915e1f | ||
|
|
bf5f009862 | ||
|
|
08c965a0a1 |
No files matched your search
@@ -1,8 +1,8 @@
|
||||
List of the authors of code contained in busybox.
|
||||
List of the authors of code contained in BusyBox.
|
||||
|
||||
If you should be listed here, or the description of
|
||||
what you have done needs more detail, or is incorect,
|
||||
_please_ let me know.
|
||||
If you have code in BusyBox, you should be listed here. If you should be
|
||||
listed, or the description of what you have done needs more detail, or is
|
||||
incorect, _please_ let me know.
|
||||
|
||||
-Erik
|
||||
|
||||
@@ -12,11 +12,8 @@ Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
Tons of new stuff, major rewrite of most of the
|
||||
core apps, tons of new apps as noted in header files.
|
||||
|
||||
Bruce Perens <bruce@pixar.com>
|
||||
Original author of BusyBox. His code is still in many apps.
|
||||
|
||||
John Beppu <beppu@lineo.com>
|
||||
du, head, tee
|
||||
du, head, nslookup, sort, tee, uniq
|
||||
|
||||
Brian Candler <B.Candler@pobox.com>
|
||||
tiny-ls(ls)
|
||||
@@ -28,6 +25,27 @@ Dave Cinege <dcinege@psychosis.com>
|
||||
more(v2), makedevs, dutmp, modularization, auto links file,
|
||||
various fixes, Linux Router Project maintenance
|
||||
|
||||
Karl M. Hegbloom <karlheg@debian.org>
|
||||
cp_mv.c, the test suite, various fixes to utility.c, &c.
|
||||
|
||||
Daniel Jacobowitz <dan@debian.org>
|
||||
mktemp.c
|
||||
|
||||
Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
||||
documentation, bugfixes
|
||||
|
||||
John Lombardo <john@deltanet.com>
|
||||
dirname, tr
|
||||
|
||||
Glenn McGrath <bug1@netconnect.com.au>
|
||||
ar.c
|
||||
|
||||
Bruce Perens <bruce@pixar.com>
|
||||
Original author of BusyBox. His code is still in many apps.
|
||||
|
||||
Pavel Roskin <proski@gnu.org>
|
||||
Lots of bugs fixes and patches.
|
||||
|
||||
Linus Torvalds <torvalds@transmeta.com>
|
||||
mkswap, fsck.minix, mkfs.minix
|
||||
|
||||
@@ -37,4 +55,3 @@ Charles P. Wright <cpwright@villagenet.com>
|
||||
Enrique Zanardi <ezanardi@ull.es>
|
||||
tarcat (since removed), loadkmap, various fixes, Debian maintenance
|
||||
|
||||
|
||||
@@ -1,3 +1,244 @@
|
||||
0.46
|
||||
|
||||
* Better portability. Now should compile cleanly with libc5,
|
||||
GNU libc 2.0 and 2.1, and various Linux kernels including
|
||||
2.0.x, 2.2.x, and to 2.4.0-test*. (patch for 2.4.x kernels
|
||||
to make /proc/mounts behave included in the kernel-patches dir).
|
||||
* Fixed a _horrible_ bug where 'tar -tvf' could unlink
|
||||
local files that matched tarball contents!!! Fix thanks
|
||||
to Marius Groeger <mgroeger@sysgo.de>
|
||||
* Fixed a nasty bug in tar when could mess up saved symlinks.
|
||||
* Fixed tar creation support when reading from stdin ('tar -cf - . ')
|
||||
thanks to Daniel Quinlan <quinlan@transmeta.com>
|
||||
* Updates to handle Linux 2.4.0 kernels (kludged around the
|
||||
"none" entries in /proc/mounts, added a hack to make sysinfo
|
||||
work with both old and new kernels).
|
||||
* Fixed insmod module option parsing for options lacking an '='.
|
||||
Fix thanks to Marc Nijdam <marc_nijdam@hp.com>
|
||||
* Fixed segfault with 'cut -f 1 -d:' and added 'cut -s' suport.
|
||||
Fix thanks to Arne Bernin <arne@matrix.loopback.org>
|
||||
* Several fixes from Marius Groeger <mag@sysgo.de>
|
||||
- Added support for "sh -c command args..."
|
||||
- Fixed globbing, i.e. 'echo * *' and 'echo "******"' now work.
|
||||
- Added shell environment variable substitution
|
||||
- Added the "read" shell builtin.
|
||||
* Fixed cursor editing in cmdedit.c. The following keyboard sequence
|
||||
used to create an infinite loop: ls, cursor up, left, down.
|
||||
* Added support for being a login shell, so things like
|
||||
'-su' or '-sh' (stuff where argv[0][0]=='-') will now always
|
||||
invoke the shell. Now you can use BusyBox as a login shell.
|
||||
* ls.c now ignores '-g', since some ftp clients like that sort
|
||||
of thing. Patch thanks to David Vrabel <dvrabel@arcom.co.uk>
|
||||
* Fix to init.c from Stuart Menefy <Stuart.Menefy@st.com> so that
|
||||
it always sets the controlling terminal before running any programs
|
||||
* Several fixes from Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
||||
- Fixed tr so it recognizes standard escape sequences.
|
||||
Merged common escape seq. code from tr and echo into utility.c.
|
||||
- Major work in updating/cleaning up the docs, and getting the
|
||||
new SGML based docs into shape.
|
||||
- cleanup of ar.c
|
||||
- BusyBox should now poweroff when asked to do so.
|
||||
- Fixed 'ln -n' and 'ln -s' so they both work properly.
|
||||
* Reorganized signal names in kill.c for better architecture support
|
||||
-- patch thanks to simon wood <simon@mungewell.uklinux.net>
|
||||
* In 0.43, backspace and delete worked properly, but with 0.45,
|
||||
it just echoed a ^? for backspace, and ^H for control-h. This
|
||||
was due to a broken macro in init.c, that is now fixed.
|
||||
* Removed sfdisk from BusyBox. It was buggy, fat, and we really
|
||||
couldn't maintain it very well, so including it was not really
|
||||
very appropriate. Those wanting an fdisk are invited to
|
||||
grab a copy from util-linux.
|
||||
* Added 'dumpkmap' to allow people to dump a binary keymap, which can
|
||||
then be loaded in by 'loadkmap' -- submitted by
|
||||
Arne Bernin <arne@matrix.loopback.org>
|
||||
* Fixed NFS so it supports 2.4.x kernels and NFSv3.
|
||||
* Brand, new versions of grep and sed which use libc regex routines,
|
||||
thanks to Mark Whitley <markw@lineo.com>. The hand-tooled
|
||||
"regexp.[ch]" files have been removed. Much help on these from
|
||||
Matt Kraai as well.
|
||||
|
||||
|
||||
-Erik Andersen
|
||||
|
||||
|
||||
0.45
|
||||
* Now compiles vs libc5 (which can save lots of space for
|
||||
embedded systems).
|
||||
* Added BB_FEATURE_TRIVIAL_HELP which compiles out most all of the
|
||||
help messages (i.e --help). Saves 17k over a full compile.
|
||||
* Added cut and tr from minix, since due to the license change,
|
||||
we can now use minix code. Minix tr saves 4k.
|
||||
* insmod now works. It costs 29k, but imagine an initrd with a
|
||||
staticly linked busybox containing only insmod and sh, a few /dev
|
||||
entries, and a kernel module or two... It doesn't get smaller
|
||||
then this folks (I pity the fool that writes insmod in asm ;-).
|
||||
Many kudos go to Ron Alder <alder@lineo.com> for finishing this off!
|
||||
* Added a mini ar archive utility, especially written for BusyBox by
|
||||
Glenn McGrath <bug1@netconnect.com.au>
|
||||
* Added mktemp, contributed by Daniel Jacobowitz <dan@debian.org>
|
||||
* Added setkeycodes, for those that have wierd keyboard buttons.
|
||||
* Added md5sum, uuencode and uudecode -- thanks to Alfred M. Szmidt
|
||||
<ams@trillian.itslinux.org> for contributing these.
|
||||
* Added 'grep -v' option (inverted search) and updated
|
||||
docs accordingly. -beppu
|
||||
* Wrote which
|
||||
* Replaced the telnet implementation with one written by
|
||||
Tomi Ollila <too@iki.fi> It works great and costs 3k.
|
||||
* BusyBox sh (lash) now supports being used as a standalone shell. When
|
||||
BB_FEATURE_SH_STANDALONE_SHELL is defined, all the busybox commands may
|
||||
be invoked as shell internals. Best used when compiling staticly
|
||||
(i.e. DOSTATIC=true)
|
||||
* BusyBox sh (lash) internals now behave as expected wrt pipes
|
||||
and redirects.
|
||||
* Fixed ping warnings -- fix from Sascha Ziemann <szi@aibon.ping.de>
|
||||
* Fixed update segfault
|
||||
* Fixed mknod -- minor number was always 0
|
||||
* Fixed tar option parsing, so both "tar xvf foo.tar" and
|
||||
"tar -xvf foo.tar" now work (i.e. no "-" before options)
|
||||
(this was very broken in 0.43).
|
||||
* Several contributions from Randolph Chung <tausq@debian.org>.
|
||||
* cp/mv now accepts the -f flag
|
||||
* tail can now accept -<num> commands (e.g. -10) for better
|
||||
compatibility with the standard tail command
|
||||
* added a simple id implementation; doesn't support sup. groups yet
|
||||
* logname used getlogin(3) which uses utmp. Now it doesn't.
|
||||
* whoami used getpwuid(3) which uses libc NSS. Now it behaves.
|
||||
* Add support for "noatime" and "nodiratime" mount flags to mount.
|
||||
* Changed 'umount -f' to mean force, and actually use umount2.
|
||||
* Changed 'umount -l' to mean "Do not free loop device".
|
||||
* Fixed basename to support stripping of suffixes. Patch thanks
|
||||
to xiong jianxin <jxiong@uiuc.edu>
|
||||
* cp -fa now works as expected for symlinks (it didn't before)
|
||||
* zcat now works (wasn't working since option parsing was broken)
|
||||
* Renamed "mnc" to the more correct "nc" (for netcat).
|
||||
* Makefile intelligence updates
|
||||
* Changed the way init parses /etc/inittab entries to avoid problems
|
||||
with commands that contain colons in them. Fix thanks to
|
||||
Pavel Roskin <proski@gnu.org>
|
||||
* Fixed a warning in utility.c due to char being unsigned on Linux/PPC,
|
||||
Fix thanks to Pavel Roskin <proski@gnu.org>
|
||||
* Made "killall" complain (not error and exit) about processes that it
|
||||
cannot find by name -- Pavel Roskin <proski@gnu.org>
|
||||
* Fixed more and ps to have sensible terminal width defaults, thanks
|
||||
to Pavel Roskin.
|
||||
* Fixed all fatalError() calls lacking a "\n", thanks to Pavel Roskin.
|
||||
* Fixed a segfault in yes when no args were given -- Pavel Roskin.
|
||||
* Simplified freeramdisk and added argument checking -- Pavel Roskin.
|
||||
* Fixed segfault caused by "touch -c"
|
||||
* Fixed segfault caused by "rm -f"
|
||||
* Fixed segfault caused by "ln -s -s" and similar abuses. Further fixes
|
||||
and "--" support from Pavel Roskin.
|
||||
* Fixed segfault caused by "cp -a -a" and similar abuses.
|
||||
* Implemented "rm -- <foo>". Implementation fixed by Pavel Roskin.
|
||||
* "which" rewritten to use stat(). Fixes to improve its compatability
|
||||
with traditional implementations -- Pavel Roskin.
|
||||
* "mount" now reports errors from nfsmount() and assumes NFS mount
|
||||
if ':' is present in the device name - Pavel Roskin
|
||||
* Fixed exit status for killall - Pavel Roskin
|
||||
* Fixed 'swapon -a' and 'swapoff -a', which were broken.
|
||||
* Fixed 'mount -a' so it works as expected.
|
||||
* Implemented 'ls -R' (enabled by enabling BB_FEATURE_LS_RECURSIVE)
|
||||
* Implemented "ping -s", fixed error messages and argument parsing -
|
||||
Pavel Roskin
|
||||
* Syslogd will not go to background if "-n" is given. Better help
|
||||
and argument checking -- Pavel Roskin
|
||||
* Fixed a small bug that could cause tar to emit warning messages
|
||||
and not extract the first file in a directory in some cases
|
||||
of nested directories. Thanks to Kevin Traas <kevin@netmaster.com>
|
||||
for helping track this one down.
|
||||
* More doc updates
|
||||
* Fixed grep "Line too long" problem -- John Beppu
|
||||
* Fixed 'grep -q -i B some_file' so it works
|
||||
* math takes input from stdin if no args are given. -- John Beppu
|
||||
* math was renamed to dc. Although it deviates from dc's behaviour,
|
||||
this will probably be remedied in the future. -- John Beppu
|
||||
|
||||
|
||||
-Erik Andersen, June 21, 2000
|
||||
|
||||
|
||||
0.44
|
||||
Previously, an erronous announcement of BusyBox 0.44 was made, so to
|
||||
avoid possible confusion, we are skipping straight to 0.45, and calling
|
||||
it good.
|
||||
|
||||
-Erik Andersen
|
||||
|
||||
|
||||
0.43
|
||||
* Major update to the provided documentation.
|
||||
* Busybox now includes a shell! It currently costs 7.5 k (plus an
|
||||
additional 2.5 k if you compile in command line editing). Handles
|
||||
job control, has the usual set of builtins, and does everything
|
||||
except for handling programming statements (if, while, etc...)
|
||||
* Busybox can now work perfectly when /proc is disabled, thereby
|
||||
saving a bunch of memory (kernel /proc support is not thin). This
|
||||
is done by making use of some nice kernel patches I wrote up to
|
||||
support the features that busybox requires and that /proc usually
|
||||
provides. To enable this, turn on BB_FEATURE_USE_DEVPS_PATCH and
|
||||
patch your kernel with the devps patch in the kernel-patches/
|
||||
directory.
|
||||
* Wrote basename, dirname, killall, and uptime.
|
||||
* tar has been completely rewritten by me. Both tar creation and
|
||||
extraction are now well behaved. Costs 7.6k with all optional
|
||||
tar features enabled, and 5k for just tar extraction support.
|
||||
* Added freeramdisk, which will free up all memory associated
|
||||
with a ram disk. Contributed by Emanuele Caratti <wiz@iol.it>
|
||||
and then adjusted a bit by me.
|
||||
* Added tr from John Lombardo <john@deltanet.com>
|
||||
* Added echo and test (from me).
|
||||
* Added usleep contributed by Nicolas Pitre <nico@cam.org>
|
||||
* BusyBox's bss size has been majorly reduced (was 384668, is now 28740).
|
||||
* Several fixes from Pavel Roskin <proski@gnu.org>:
|
||||
- When `tail' fails to open a file it now exits.
|
||||
- When `syslogd' is given the `-n' option it should still use
|
||||
fork() for running klogd.
|
||||
* nslookup types are now changed to u_int32_t (instead of uint32_t)
|
||||
changed per a patch from Pascal Bellard <pascal.bellard@ascend.com>
|
||||
* Fixed "du" so it gives the same answers as GNU "du" (busybox du used
|
||||
to count hard-linked files more then once). Many thanks to
|
||||
Friedrich Vedder <fwv@myrtle.lahn.de> for the fix.
|
||||
* Removed /proc dependancies for init and free (while maintaining
|
||||
exactly the same functionality). /proc takes up 90k of kernel
|
||||
space, so it is nice to avoid using it at all costs.
|
||||
* init no longer tries to mount /proc (unless there is less the 1 meg
|
||||
free). Use of /proc (or not) is policy that should be set up in
|
||||
/etc/fstab (or in hardcoded scripts), not in init.
|
||||
* Fixed rebooting when init runs as an initrd.
|
||||
* Fixes and updates from Karl M. Hegbloom <karlheg@debian.org>
|
||||
- update.c rewritten to look more like update-2.11
|
||||
- moveed the inode hash out of du.c and into utility.c to make
|
||||
it a common resource that can be used by other apps.
|
||||
- cp_mv.c now checks inodes to see if a source and dest are
|
||||
the same, and prints an error (instead of endlessly looping).
|
||||
- mv now attempts to do a rename, and will fall back to doing
|
||||
a copy only if the rename fails.
|
||||
- Syslogd now supports multiple concurrent connections
|
||||
* Several fixes from Pavel Roskin <proski@gnu.org>:
|
||||
- Fixes to sort. Removed "-g", fixed and added "-r"
|
||||
- Fixes to the makefile for handling "strip"
|
||||
* An initial telnet implementation was added by
|
||||
Randolph Chung <tausq@debian.org>.
|
||||
* Fixed a bug where "sed 's/foo/bar/g'" (i.e. a script w/o a "-e")
|
||||
* ps now supports BB_FEATURE_AUTOWIDTH, and can adjust its width
|
||||
to match the terminal (defaults to width=79 when this is off).
|
||||
* ps now accepts (and ignores) all options except for "--help" (which
|
||||
as would be expected displays help).
|
||||
* Fixed mount'ing loop devices when the filesystem type was not
|
||||
specified. It used to revert to non-loop after the first try.
|
||||
* all mallocs now use xmalloc (and so are OOM error safe), and
|
||||
the common error handling saves a few bytes. Thanks to
|
||||
Bob Tinsley <bob@earthrise.demon.co.uk> for the patch.
|
||||
* Fix "+" parsing bug in date, from "Merle F. McClelland" <mfm@cts.com>.
|
||||
* Fix symlink following bug in chmod -R and friends.
|
||||
* Now allows SYSV style 'chown foo:bar' in addition to 'chown foo.bar'
|
||||
* Fixed a bug in the busybox globbing routine such that 'find /dir -name [i]'
|
||||
no longer segfaults.
|
||||
|
||||
|
||||
-Erik Andersen
|
||||
|
||||
|
||||
0.42
|
||||
|
||||
* Fairly massive restructuring of umount.c to deal with remounting
|
||||
@@ -61,8 +302,8 @@
|
||||
* Fixed a bug where init could have reference already freed memory.
|
||||
Found and fixed by Taketoshi Sano <kgh12351@nifty.ne.jp>
|
||||
* Several contributions from Friedrich Vedder <fwv@myrtle.lahn.de>
|
||||
* Added (and documented) "-n" option for head - Cleanup for a number of
|
||||
* usage messages -- also
|
||||
* Added (and documented) "-n" option for head
|
||||
* Cleanup for a number of usage messages -- also
|
||||
contributed Friedrich Vedder <fwv@myrtle.lahn.de>
|
||||
* Cosmetic fix to busybox.c (Don't print a comma at the
|
||||
end of line if there are no more application names).
|
||||
@@ -73,7 +314,7 @@
|
||||
* Created a tiny tail implementation, removing -c, -q, -v, and making
|
||||
tail -f work only with a single file. This reduced tail from 6k to
|
||||
2.4k. The bigger/more featured tail can still be had by disabling
|
||||
BB_FEATURE_SIMPLE_TAIL in dusybox.defs.h
|
||||
BB_FEATURE_SIMPLE_TAIL in busybox.defs.h
|
||||
* Ping now falls back to doing the right thing if /etc/protocols
|
||||
turns up missing.
|
||||
* Fixed mount and umount. Previously they could leak loop device
|
||||
@@ -83,16 +324,16 @@
|
||||
Randolph Chung <tausq@debian.org>.
|
||||
* cp could, when copying symlinks, change permissions of the
|
||||
files pointed to by the symlinks.
|
||||
* Several fixes from Pavel Roskin <pavel_roskin@geocities.com>:
|
||||
* Several fixes from Pavel Roskin <proski@gnu.org>:
|
||||
- `chown' with 1 argument displayed the error incorrectly
|
||||
- `fdflush', `length' and `printf' crashed if run without arguments
|
||||
- `fdflush' tried to flush itself using *argv
|
||||
- added "skip" and "seek" to dd.
|
||||
- ls no longer messus up output when combining files and
|
||||
directories on the command line
|
||||
* swapoff -a was not working. Now it is. init did not cleanly unmount
|
||||
* filesystems on reboot. Now it does. "sed -ne s/foo/bar/" worked but
|
||||
* "sed -n -e s/foo/bar/" didn't.
|
||||
* swapoff -a was not working. Now it is.
|
||||
* init did not cleanly unmount filesystems on reboot. Now it does.
|
||||
* "sed -ne s/foo/bar/" worked but "sed -n -e s/foo/bar/" didn't.
|
||||
Now both work.
|
||||
* Some architectures (PowerPc) assume chars are unsigned, so they could
|
||||
not distinguish between EOF and '\0xFF' in sed. Sed now uses ints.
|
||||
@@ -444,11 +685,11 @@
|
||||
* from Matthew Grant <grantma@anathoth.gen.nz>
|
||||
to accomodate glibc timezone support. I then ripped out GNU
|
||||
getopt.
|
||||
* mkswap -- new version merged from util-linux. Can now make
|
||||
* >128Meg swaps. Replaced the old and star, unstar, and tarcat
|
||||
* with the tar
|
||||
implementation from sash. Now tar behaves as god intended it
|
||||
to (i.e. tar -xvf <file> and tar -cf <file> <dir> work).
|
||||
* mkswap -- new version merged from util-linux. Can now make
|
||||
>128Meg swaps.
|
||||
* Replaced the old and star, unstar, and tarcat with the tar
|
||||
implementation from sash. Now tar behaves as god intended it
|
||||
to (i.e. tar -xvf <file> and tar -cf <file> <dir> work).
|
||||
* dd -- rewritten. Can with with files, stdin, stdout. Added the
|
||||
* following new apps: loadfont -- added from debian boot floppies
|
||||
* chroot -- added based on a patch from Paolo Molaro
|
||||
|
||||
@@ -18,69 +18,61 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
# PROG := busybox
|
||||
VERSION := 0.42
|
||||
BUILDTIME := $(shell TZ=GMT date "+%Y%m%d-%H%M")
|
||||
PROG := busybox
|
||||
VERSION := 0.46
|
||||
BUILDTIME := $(shell TZ=UTC date --utc "+%Y.%m.%d-%H:%M%z")
|
||||
export VERSION
|
||||
|
||||
# Set the following to `true' to make a debuggable build.
|
||||
# Leave this set to `false' for production use.
|
||||
# eg: `make DODEBUG=true tests'
|
||||
DODEBUG = false
|
||||
|
||||
# If you want a static binary, turn this on. I can't think
|
||||
# of many situations where anybody would ever want it static,
|
||||
# but...
|
||||
# If you want a static binary, turn this on.
|
||||
DOSTATIC = false
|
||||
|
||||
# This will choke on a non-debian system
|
||||
ARCH =`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
|
||||
# To compile vs an alternative libc, you may need to use/adjust
|
||||
# the following lines to meet your needs. This is how I did it...
|
||||
#GCCINCDIR = $(shell gcc -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp")
|
||||
#CFLAGS+=-nostdinc -fno-builtin -I/home/andersen/CVS/uC-libc/include -I$(GCCINCDIR)
|
||||
#LDFLAGS+=-nostdlib
|
||||
#LIBRARIES = /home/andersen/CVS/uC-libc/libc.a
|
||||
|
||||
|
||||
CC = gcc
|
||||
|
||||
GCCMAJVERSION = $(shell $(CC) --version | sed -n "s/^[^0-9]*\([0-9]\)\.\([0-9].*\)[\.].*/\1/p")
|
||||
GCCMINVERSION = $(shell $(CC) --version | sed -n "s/^[^0-9]*\([0-9]\)\.\([0-9].*\)[\.].*/\2/p")
|
||||
# use '-Os' optimization if available, else use -O2
|
||||
OPTIMIZATION = $(shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
|
||||
then echo "-Os"; else echo "-O2" ; fi)
|
||||
|
||||
|
||||
GCCSUPPORTSOPTSIZE = $(shell \
|
||||
if ( test $(GCCMAJVERSION) -eq 2 ) ; then \
|
||||
if ( test $(GCCMINVERSION) -ge 66 ) ; then \
|
||||
echo "true"; \
|
||||
else \
|
||||
echo "false"; \
|
||||
fi; \
|
||||
else \
|
||||
if ( test $(GCCMAJVERSION) -gt 2 ) ; then \
|
||||
echo "true"; \
|
||||
else \
|
||||
echo "false"; \
|
||||
fi; \
|
||||
fi; )
|
||||
|
||||
|
||||
ifeq ($(GCCSUPPORTSOPTSIZE), true)
|
||||
OPTIMIZATION = -Os
|
||||
else
|
||||
OPTIMIZATION = -O2
|
||||
endif
|
||||
|
||||
# Allow alternative stripping tools to be used...
|
||||
ifndef $(STRIPTOOL)
|
||||
STRIPTOOL = strip
|
||||
endif
|
||||
|
||||
|
||||
# -D_GNU_SOURCE is needed because environ is used in init.c
|
||||
ifeq ($(DODEBUG),true)
|
||||
CFLAGS += -Wall -g -D_GNU_SOURCE
|
||||
LDFLAGS =
|
||||
LDFLAGS +=
|
||||
STRIP =
|
||||
else
|
||||
CFLAGS += -Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
|
||||
LDFLAGS = -s
|
||||
STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment
|
||||
CFLAGS += -Wall $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE
|
||||
LDFLAGS += -s
|
||||
STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment $(PROG)
|
||||
#Only staticly link when _not_ debugging
|
||||
ifeq ($(DOSTATIC),true)
|
||||
LDFLAGS += --static
|
||||
#
|
||||
#use '-ffunction-sections -fdata-sections' and '--gc-sections' if they work
|
||||
#to try and strip out any unused junk. Doesn't do much for me, but you may
|
||||
#want to give it a shot...
|
||||
#
|
||||
#ifeq ($(shell $(CC) -ffunction-sections -fdata-sections -S \
|
||||
# -o /dev/null -xc /dev/null 2>/dev/null && $(LD) --gc-sections -v >/dev/null && echo 1),1)
|
||||
# CFLAGS += -ffunction-sections -fdata-sections
|
||||
# LDFLAGS += --gc-sections
|
||||
#endif
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -88,48 +80,92 @@ ifndef $(PREFIX)
|
||||
PREFIX = `pwd`/_install
|
||||
endif
|
||||
|
||||
LIBRARIES =
|
||||
OBJECTS = $(shell ./busybox.sh) messages.o utility.o
|
||||
OBJECTS = $(shell ./busybox.sh) busybox.o messages.o utility.o
|
||||
CFLAGS += -DBB_VER='"$(VERSION)"'
|
||||
CFLAGS += -DBB_BT='"$(BUILDTIME)"'
|
||||
ifdef BB_INIT_SCRIPT
|
||||
CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
|
||||
endif
|
||||
|
||||
all: busybox busybox.links
|
||||
.PHONY: all
|
||||
all: busybox busybox.links doc
|
||||
|
||||
doc: olddoc
|
||||
|
||||
# Old Docs...
|
||||
olddoc: docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
|
||||
|
||||
docs/BusyBox.txt: docs/busybox.pod
|
||||
@echo
|
||||
@echo BusyBox Documentation
|
||||
@echo
|
||||
- pod2text docs/busybox.pod > docs/BusyBox.txt
|
||||
|
||||
docs/BusyBox.1: docs/busybox.pod
|
||||
- pod2man --center=BusyBox --release="version $(VERSION)" docs/busybox.pod > docs/BusyBox.1
|
||||
|
||||
docs/BusyBox.html: docs/busybox.lineo.com/BusyBox.html
|
||||
- rm -f docs/BusyBox.html
|
||||
- ln -s busybox.lineo.com/BusyBox.html docs/BusyBox.html
|
||||
|
||||
docs/busybox.lineo.com/BusyBox.html: docs/busybox.pod
|
||||
- pod2html --noindex docs/busybox.pod > docs/busybox.lineo.com/BusyBox.html
|
||||
- rm -f pod2html*
|
||||
|
||||
|
||||
# New docs based on DOCBOOK SGML
|
||||
newdoc: docs/busybox.txt docs/busybox.pdf docs/busybox/busybox.html
|
||||
|
||||
docs/busybox.txt: docs/busybox.sgml
|
||||
@echo
|
||||
@echo BusyBox Documentation
|
||||
@echo
|
||||
(cd docs; sgmltools -b txt busybox.sgml)
|
||||
|
||||
docs/busybox.dvi: docs/busybox.sgml
|
||||
(cd docs; sgmltools -b dvi busybox.sgml)
|
||||
|
||||
docs/busybox.ps: docs/busybox.sgml
|
||||
(cd docs; sgmltools -b ps busybox.sgml)
|
||||
|
||||
docs/busybox.pdf: docs/busybox.ps
|
||||
(cd docs; ps2pdf busybox.ps)
|
||||
|
||||
docs/busybox/busybox.html: docs/busybox.sgml
|
||||
(cd docs/busybox.lineo.com; sgmltools -b html ../busybox.sgml)
|
||||
|
||||
|
||||
|
||||
busybox: $(OBJECTS)
|
||||
$(CC) $(LDFLAGS) -o $@ $^ $(LIBRARIES)
|
||||
$(STRIP) $@
|
||||
$(STRIP)
|
||||
|
||||
busybox.links: busybox.def.h
|
||||
- ./busybox.mkll | sort >$@
|
||||
|
||||
regexp.o nfsmount.o: %.o: %.h
|
||||
$(OBJECTS): %.o: busybox.def.h internal.h %.c
|
||||
nfsmount.o cmdedit.o: %.o: %.h
|
||||
$(OBJECTS): %.o: busybox.def.h internal.h %.c Makefile
|
||||
|
||||
.PHONY: test tests
|
||||
test tests:
|
||||
cd tests && $(MAKE) all
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
- rm -f busybox.links *~ *.o core
|
||||
- rm -rf _install
|
||||
- cd tests && $(MAKE) clean
|
||||
- rm -f docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
|
||||
docs/busybox.lineo.com/BusyBox.html
|
||||
- rm -f docs/busybox.txt docs/busybox.dvi docs/busybox.ps \
|
||||
docs/busybox.pdf docs/busybox.lineo.com/busybox.html
|
||||
- rm -rf docs/busybox
|
||||
|
||||
.PHONY: distclean
|
||||
distclean: clean
|
||||
- rm -f busybox
|
||||
- cd tests && $(MAKE) distclean
|
||||
|
||||
.PHONY: install
|
||||
install: busybox busybox.links
|
||||
./install.sh $(PREFIX)
|
||||
|
||||
.PHONY: dist release
|
||||
dist release: distclean
|
||||
dist release: distclean doc
|
||||
cd ..; \
|
||||
rm -rf busybox-$(VERSION); \
|
||||
cp -a busybox busybox-$(VERSION); \
|
||||
@@ -144,4 +180,13 @@ dist release: distclean
|
||||
-print \
|
||||
| xargs rm -f; \
|
||||
\
|
||||
find busybox-$(VERSION)/ -type f \
|
||||
-name .\#* \
|
||||
-print \
|
||||
| xargs rm -f; \
|
||||
\
|
||||
tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)/;
|
||||
|
||||
.PHONY: tags
|
||||
tags:
|
||||
ctags -R .
|
||||
@@ -1,23 +1,64 @@
|
||||
Please see the LICENSE file for copyright information.
|
||||
|
||||
BusyBox combines tiny versions of many common UNIX utilities into a single
|
||||
small executable. It provides minimalist replacements for most of the utilities
|
||||
you usually find in fileutils, shellutils, findutils, textutils, grep, gzip,
|
||||
tar, etc. BusyBox provides a fairly complete POSIX environment for any small or
|
||||
emdedded system. The utilities in BusyBox generally have fewer options then
|
||||
their full featured GNU cousins; however, the options that are included provide
|
||||
the expected functionality and behave very much like their GNU counterparts.
|
||||
|
||||
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
|
||||
provides a pretty complete POSIX environment in a very small package.
|
||||
Just add a kernel, "ash" (Keith Almquists tiny Bourne shell clone), and
|
||||
an editor such as "elvis-tiny" or "ae", and you have a working system.
|
||||
Busybox was begun to support the Debian Rescue/Install disks, but it
|
||||
also makes an excellent environment for any small or embedded system.
|
||||
BusyBox has been written with size-optimization and limited resources in mind.
|
||||
It is also extremely modular so you can easily include or exclude commands (or
|
||||
features) at compile time. This makes it easy to customize your embedded
|
||||
systems. To create a working system, just add a kernel, a shell (such as ash),
|
||||
and an editor (such as elvis-tiny or ae).
|
||||
|
||||
As of version 0.20 there is a version number. : ) Also as of version
|
||||
0.20, BB is now modularized to easily allow you to build of only the
|
||||
BB parts you need, thereby reducing binary size. To turn off unwanted
|
||||
Busybox components, simply edit the file busybox.def.h and comment out
|
||||
the parts you do not need using C++ style (//) comments.
|
||||
Busybox was originally written to support the Debian Rescue/Install disks, but
|
||||
it also makes an excellent environment for any small or embedded system.
|
||||
|
||||
After the build is complete a busybox.links file is generated which is
|
||||
then used by 'make install' to create symlinks to the busybox binary
|
||||
for all compiled in functions. By default, 'make install' will place
|
||||
the symlink forest into `pwd`/_install unless you have defined the
|
||||
PREFIX environment variable.
|
||||
As of version 0.20 there is a version number. : ) Also as of version 0.20,
|
||||
BusyBox is now modularized to easily allow you to build only the components you
|
||||
need, thereby reducing binary size. To turn off unwanted Busybox components,
|
||||
simply edit the file busybox.def.h and comment out the components you do not
|
||||
need using C++ style (//) comments.
|
||||
|
||||
After the build is complete a busybox.links file is generated which is then
|
||||
used by 'make install' to create symlinks to the busybox binary for all
|
||||
compiled in functions. By default, 'make install' will place the symlink
|
||||
forest into `pwd`/_install unless you have defined the PREFIX environment
|
||||
variable (i.e. make PREFIX="/tmp/foo" install)
|
||||
|
||||
----------------
|
||||
Getting help:
|
||||
When you find you need help, you can check out the BusyBox mailing list
|
||||
archives at http://opensource.lineo.com/lists/busybox/ or even join
|
||||
the mailing list if you are interested.
|
||||
|
||||
----------------
|
||||
Bugs:
|
||||
If you find bugs, follow the instructions at http://bugs.lineo.com/Reporting.html
|
||||
and submit a bug report. This way, we can be sure nothing falls through the
|
||||
cracks...
|
||||
|
||||
----------------
|
||||
FTP:
|
||||
Source for the latest released version can always be downloaded from
|
||||
ftp://ftp.lineo.com/pub/busybox.
|
||||
|
||||
----------------
|
||||
CVS:
|
||||
BusyBox now has its own publically browsable CVS tree at:
|
||||
http://opensource.lineo.com/cgi-bin/cvsweb/busybox/
|
||||
|
||||
Anonymous CVS access is available. For instructions, check out:
|
||||
http://opensource.lineo.com/cvs_anon.html
|
||||
|
||||
For those that are actively contributing there is even CVS write access:
|
||||
http://opensource.lineo.com/cvs_write.html
|
||||
|
||||
|
||||
----------------
|
||||
|
||||
Please feed suggestions, bug reports, insults, and bribes back to:
|
||||
Erik Andersen
|
||||
|
||||
@@ -4,66 +4,408 @@ or that doing so is even a good idea. It just means that I _might_ get
|
||||
around to it some time. If you have any good ideas, please let me know.
|
||||
|
||||
* login/sulogin/passwd/getty/etc are part of tinylogin, and so are not
|
||||
needed or wanted in busybox (or else I'd have to link in libcrypt).
|
||||
needed or wanted in busybox (or else I'd have to link to libcrypt).
|
||||
|
||||
* Networking apps are probably going to be split out some time soon into a
|
||||
separate package (named perhaps tiny-netkit?). This currently includes
|
||||
hostid, hostname, mnc, and ping.
|
||||
|
||||
separate package (named perhaps netkit-tiny?). This would remove the
|
||||
following items from BusyBox: hostid, hostname, nc, nslookup, telnet,
|
||||
and ping. nfs mounting and syslogd (when it supports network logging)
|
||||
will remain in BusyBox.
|
||||
|
||||
-Erik
|
||||
|
||||
-----------
|
||||
|
||||
* Allow tar to create archives with sockets, devices, and other special files
|
||||
* Make insmod actually work
|
||||
* dnsdomainname
|
||||
* traceroute/netstat
|
||||
* rdate
|
||||
* hwclock
|
||||
* killall
|
||||
* stty
|
||||
* tr
|
||||
* expr (maybe?) (ash builtin?)
|
||||
* expr
|
||||
* wget (or whatever I call it)
|
||||
* tftp
|
||||
* ftp
|
||||
* group/commonize strings, remove dups (for i18n, l10n)
|
||||
* consider making a unified option parser (if it can be done
|
||||
modular, small, etc.)
|
||||
|
||||
-----------------------
|
||||
|
||||
Running the following:
|
||||
|
||||
rm -f busybox && make LDFLAGS+=-nostdlib 2>&1 | \
|
||||
sed -ne 's/.*undefined reference to `\(.*\)..*/\1/gp' | sort | uniq
|
||||
|
||||
Some known bugs, todo items, etc...
|
||||
reveals the list of all external (i.e. libc) things that BusyBox depends on.
|
||||
It would be a very nice thing to reduce this list to an absolute minimum, and
|
||||
then create a microLibc to provide these functions. There is no good reason
|
||||
for GNU libc to be so big. I'm sure it can be a lot better.
|
||||
|
||||
(BTW, this is more informative if BB_FEATURE_NFSMOUNT is turned off...)
|
||||
|
||||
Most wanted list:
|
||||
|
||||
[andersen@slag busybox]$ grep -l getgroups *.[ch]
|
||||
test.c
|
||||
|
||||
Policy violation. getgroups uses libc nss, which is unlikely
|
||||
to be present in an embedded system.
|
||||
|
||||
-----------------------
|
||||
|
||||
Compile with debugging on, run 'nm --size-sort ./busybox'
|
||||
and then start with the biggest things and make them smaller...
|
||||
|
||||
-----------------------
|
||||
|
||||
|
||||
[andersen@slag busybox]$ ./busybox du /bin
|
||||
6213 /bin
|
||||
[andersen@slag busybox]$ du /bin
|
||||
2971 /bin
|
||||
[andersen@slag busybox]$ du --block-size=512 /bin
|
||||
5943 /bin
|
||||
|
||||
-----------------------
|
||||
|
||||
-rw-r--r-- 1000/1000 4398 2000-01-06 21:55 uniq.c
|
||||
-rw-r--r-- 1000/1000 1568 1999-10-20 18:08 update.c
|
||||
-rw-r----- 0/1000 1168 2000-01-29 21:03 update.o
|
||||
-rw-r--r-- 1000/1000 22820 2000-01-05 11:36 utility.c
|
||||
-rw-r----- 0/1000 7372 2000-01-29 21:03 utility.o
|
||||
tar: Skipping to next file header
|
||||
tar: Skipping to next file header
|
||||
tar: Archive - EOF not on block boundary
|
||||
tar: Error is not recoverable: exiting now
|
||||
I think that the add_inode &c in utility.c needs to also stow the
|
||||
st_dev field, and that du.c should NOT call `reset_inode_list'
|
||||
because there can be hard links from inside one argv/ to inside
|
||||
another argv/. du.c probably ought to have an -x switch like GNU du
|
||||
does also...
|
||||
|
||||
|
||||
#1 You are storing by id instead of name like normal tar. Did you realize this?
|
||||
(or am I missing some compile option? )ctar did not do this, and I don't think
|
||||
it's a good idea for LRP.
|
||||
------------------------------------------------------------------
|
||||
|
||||
#2
|
||||
ctar did not produce the EOF error like your tar does. I believe you need to
|
||||
pad the end of the archive with at least 2 tarsized (512byte) blocks. (I
|
||||
think???)
|
||||
An interesting email listing some apps that use /proc. BusyBox
|
||||
tries to avoid /proc as mush as is possible, so this stuff is
|
||||
interesting (to me at least):
|
||||
|
||||
#3
|
||||
There is no exclude file(s) option to tar. LRP's packaging system can not
|
||||
function without this. Will you have the time to add this soon?
|
||||
|
||||
Date: Fri, 25 Feb 2000 08:23:12 +0000 (GMT)
|
||||
From: Riley Williams <rhw@MemAlpha.CX>
|
||||
X-Sender: rhw@moo.cus.org.uk
|
||||
To: almesber@lrc.di.epfl.ch
|
||||
Cc: "Albert D. Cahalan" <acahalan@cs.uml.edu>,
|
||||
Linux Kernel <linux-kernel@vger.rutgers.edu>
|
||||
Subject: Re: What /proc should contain [was: /proc/driver/microcode]
|
||||
In-Reply-To: <20000224165245.A29790@lrc.di.epfl.ch>
|
||||
Message-ID: <Pine.LNX.4.21.0002250806220.8741-100000@moo.cus.org.uk>
|
||||
Sender: owner-linux-kernel@vger.rutgers.edu
|
||||
Precedence: bulk
|
||||
|
||||
Hi there.
|
||||
|
||||
>> Nope, most /proc access is does via programs written in C.
|
||||
|
||||
> That varies a lot from file to file. E.g. I haven't seen any
|
||||
> programs that are specificly designed to read /proc/atm/* yet,
|
||||
> and I know of only one (fuser) that reads /proc/mounts,
|
||||
> extracting only partial information (just to pick two examples
|
||||
> that I'm quite familiar with).
|
||||
|
||||
As a point of reference, here's a slightly tweaked analysis of the
|
||||
programs on the system I'm reading your mail on. Basically, I ran the
|
||||
following script...
|
||||
|
||||
Q> #!/bin/bash
|
||||
Q> function use() {
|
||||
Q> for Z in $* ; do
|
||||
Q> strings $Z | grep /proc | sed "s=^=$Z ="
|
||||
Q> done
|
||||
Q> }
|
||||
Q> use /{,s}bin/* /usr/{,s}bin/* | sort -u | tee proc-usage
|
||||
|
||||
...and then went through it removing comments and print format
|
||||
strings. Replace /proc with /dev and you'd soon have an equivalent
|
||||
list for that - although I can report that such is MUCH larger...
|
||||
|
||||
There are three programs therein that refer to /proc/mounts ...
|
||||
|
||||
/bin/mount
|
||||
/bin/umount
|
||||
/usr/bin/eject
|
||||
|
||||
...and, as you stated, none that refer to /proc/atm on this system.
|
||||
However, as this is a RedHat Linux 5.0 based system, that's not
|
||||
necessarily an up to date reference thereto...
|
||||
|
||||
Here's the list anyway...
|
||||
|
||||
/bin/kill /proc/%d/cmdline
|
||||
/bin/kill /proc/%d/stat
|
||||
|
||||
/bin/mount /proc/devices
|
||||
/bin/mount /proc/filesystems
|
||||
/bin/mount /proc/mounts
|
||||
|
||||
/bin/netstat /proc/net
|
||||
/bin/netstat /proc/net/appletalk
|
||||
/bin/netstat /proc/net/ax25
|
||||
/bin/netstat /proc/net/ax25_route
|
||||
/bin/netstat /proc/net/dev
|
||||
/bin/netstat /proc/net/ip_masquerade
|
||||
/bin/netstat /proc/net/ipx
|
||||
/bin/netstat /proc/net/ipx_route
|
||||
/bin/netstat /proc/net/netstat
|
||||
/bin/netstat /proc/net/nr
|
||||
/bin/netstat /proc/net/nr_neigh
|
||||
/bin/netstat /proc/net/nr_nodes
|
||||
/bin/netstat /proc/net/raw
|
||||
/bin/netstat /proc/net/route
|
||||
/bin/netstat /proc/net/rt_cache
|
||||
/bin/netstat /proc/net/snmp
|
||||
/bin/netstat /proc/net/tcp
|
||||
/bin/netstat /proc/net/udp
|
||||
/bin/netstat /proc/net/unix
|
||||
|
||||
/bin/umount /proc/devices
|
||||
/bin/umount /proc/mounts
|
||||
|
||||
/sbin/arp /proc/net/appletalk
|
||||
/sbin/arp /proc/net/arp
|
||||
/sbin/arp /proc/net/ax25
|
||||
/sbin/arp /proc/net/ipx
|
||||
/sbin/arp /proc/net/nr
|
||||
/sbin/arp /proc/net/unix
|
||||
|
||||
/sbin/cardctl /proc/devices
|
||||
|
||||
/sbin/cardmgr /proc/devices
|
||||
|
||||
/sbin/fdisk /proc/ide/%s/media
|
||||
/sbin/fdisk /proc/scsi/scsi
|
||||
|
||||
/sbin/getty /proc/version
|
||||
|
||||
/sbin/ifconfig /proc/net
|
||||
/sbin/ifconfig /proc/net/appletalk
|
||||
/sbin/ifconfig /proc/net/ax25
|
||||
/sbin/ifconfig /proc/net/dev
|
||||
/sbin/ifconfig /proc/net/ipx
|
||||
/sbin/ifconfig /proc/net/nr
|
||||
/sbin/ifconfig /proc/net/unix
|
||||
|
||||
/sbin/ifup /proc/sys/kernel/modprobe
|
||||
|
||||
/sbin/ipchains /proc/net/ip_fwchains
|
||||
/sbin/ipchains /proc/net/ip_fwnames
|
||||
/sbin/ipchains /proc/net/ip_masquerade
|
||||
/sbin/ipchains /proc/sys/net/ipv4/ip_forward
|
||||
|
||||
/sbin/ipmaddr /proc/net/dev_mcast
|
||||
/sbin/ipmaddr /proc/net/igmp
|
||||
/sbin/ipmaddr /proc/net/igmp6
|
||||
|
||||
/sbin/iptunnel /proc/net/dev
|
||||
|
||||
/sbin/killall5 /proc/%s/cmdline
|
||||
/sbin/killall5 /proc/%s/exe
|
||||
/sbin/killall5 /proc/%s/stat
|
||||
/sbin/killall5 /proc/version
|
||||
|
||||
/sbin/klogd /proc/kmsg
|
||||
|
||||
/sbin/lsmod /proc/modules
|
||||
|
||||
/sbin/modprobe /proc/modules
|
||||
|
||||
/sbin/pidof /proc/%s/cmdline
|
||||
/sbin/pidof /proc/%s/exe
|
||||
/sbin/pidof /proc/%s/stat
|
||||
/sbin/pidof /proc/version
|
||||
|
||||
/sbin/probe /proc/pci
|
||||
|
||||
/sbin/rarp /proc/net/ax25
|
||||
/sbin/rarp /proc/net/nr
|
||||
/sbin/rarp /proc/net/rarp
|
||||
|
||||
/sbin/rmmod /proc/modules
|
||||
|
||||
/sbin/rmmod.static /proc/modules
|
||||
|
||||
/sbin/route /proc/net/appletalk
|
||||
/sbin/route /proc/net/ax25
|
||||
/sbin/route /proc/net/ax25_route
|
||||
/sbin/route /proc/net/ipx
|
||||
/sbin/route /proc/net/ipx_route
|
||||
/sbin/route /proc/net/nr
|
||||
/sbin/route /proc/net/nr_neigh
|
||||
/sbin/route /proc/net/nr_nodes
|
||||
/sbin/route /proc/net/route
|
||||
/sbin/route /proc/net/rt_cache
|
||||
/sbin/route /proc/net/unix
|
||||
|
||||
/sbin/scsi_info /proc/scsi
|
||||
/sbin/scsi_info /proc/scsi/%s
|
||||
/sbin/scsi_info /proc/scsi/scsi
|
||||
|
||||
/sbin/slattach /proc/net/ax25
|
||||
/sbin/slattach /proc/net/nr
|
||||
|
||||
/sbin/swapoff /proc/swaps
|
||||
|
||||
/sbin/swapon /proc/swaps
|
||||
|
||||
/sbin/uugetty /proc/version
|
||||
|
||||
/usr/bin/dig /proc/
|
||||
/usr/bin/dig /proc/interrupts
|
||||
/usr/bin/dig /proc/meminfo
|
||||
/usr/bin/dig /proc/rtc
|
||||
/usr/bin/dig /proc/self/status
|
||||
/usr/bin/dig /proc/stat
|
||||
|
||||
/usr/bin/dnsquery /proc/
|
||||
/usr/bin/dnsquery /proc/interrupts
|
||||
/usr/bin/dnsquery /proc/meminfo
|
||||
/usr/bin/dnsquery /proc/rtc
|
||||
/usr/bin/dnsquery /proc/self/status
|
||||
/usr/bin/dnsquery /proc/stat
|
||||
|
||||
/usr/bin/eject /proc/mounts
|
||||
|
||||
/usr/bin/emacs /proc/loadavg
|
||||
|
||||
/usr/bin/fetchmail /proc/net/dev
|
||||
|
||||
/usr/bin/free /proc/meminfo
|
||||
|
||||
/usr/bin/gmake /proc/loadavg
|
||||
|
||||
/usr/bin/gpm-root /proc/loadavg
|
||||
/usr/bin/gpm-root /proc/meminfo
|
||||
|
||||
/usr/bin/host /proc/
|
||||
/usr/bin/host /proc/interrupts
|
||||
/usr/bin/host /proc/meminfo
|
||||
/usr/bin/host /proc/rtc
|
||||
/usr/bin/host /proc/self/status
|
||||
/usr/bin/host /proc/stat
|
||||
|
||||
/usr/bin/hoststat /proc/loadavg
|
||||
|
||||
/usr/bin/hwdiag /proc/cpuinfo
|
||||
/usr/bin/hwdiag /proc/pci
|
||||
/usr/bin/hwdiag /proc/scsi/scsi
|
||||
/usr/bin/hwdiag /proc/version
|
||||
|
||||
/usr/bin/lsdev /proc/dma
|
||||
/usr/bin/lsdev /proc/interrupts
|
||||
/usr/bin/lsdev /proc/ioports
|
||||
|
||||
/usr/bin/mailq /proc/loadavg
|
||||
|
||||
/usr/bin/make /proc/loadavg
|
||||
|
||||
/usr/bin/mcookie /proc/loadavg
|
||||
/usr/bin/mcookie /proc/stat
|
||||
|
||||
/usr/bin/newaliases /proc/loadavg
|
||||
|
||||
/usr/bin/nslookup /proc/
|
||||
/usr/bin/nslookup /proc/interrupts
|
||||
/usr/bin/nslookup /proc/meminfo
|
||||
/usr/bin/nslookup /proc/rtc
|
||||
/usr/bin/nslookup /proc/self/status
|
||||
/usr/bin/nslookup /proc/stat
|
||||
|
||||
/usr/bin/nsupdate /proc/
|
||||
/usr/bin/nsupdate /proc/interrupts
|
||||
/usr/bin/nsupdate /proc/meminfo
|
||||
/usr/bin/nsupdate /proc/rtc
|
||||
/usr/bin/nsupdate /proc/self/status
|
||||
/usr/bin/nsupdate /proc/stat
|
||||
|
||||
/usr/bin/pgp /proc/version
|
||||
/usr/bin/pgpe /proc/version
|
||||
/usr/bin/pgpk /proc/version
|
||||
/usr/bin/pgps /proc/version
|
||||
/usr/bin/pgpv /proc/version
|
||||
|
||||
/usr/bin/procinfo /proc/cmdline
|
||||
/usr/bin/procinfo /proc/devices
|
||||
/usr/bin/procinfo /proc/dma
|
||||
/usr/bin/procinfo /proc/filesystems
|
||||
/usr/bin/procinfo /proc/interrupts
|
||||
/usr/bin/procinfo /proc/loadavg
|
||||
/usr/bin/procinfo /proc/meminfo
|
||||
/usr/bin/procinfo /proc/modules
|
||||
/usr/bin/procinfo /proc/stat
|
||||
/usr/bin/procinfo /proc/uptime
|
||||
/usr/bin/procinfo /proc/version
|
||||
|
||||
/usr/bin/purgestat /proc/loadavg
|
||||
|
||||
/usr/bin/screen /proc/loadavg
|
||||
|
||||
/usr/bin/strace /proc/%d/stat
|
||||
|
||||
/usr/bin/top /proc/cpuinfo
|
||||
/usr/bin/top /proc/meminfo
|
||||
/usr/bin/top /proc/stat
|
||||
|
||||
/usr/bin/vmstat /proc/%s/stat
|
||||
/usr/bin/vmstat /proc/meminfo
|
||||
/usr/bin/vmstat /proc/stat
|
||||
|
||||
/usr/sbin/atd /proc/loadavg
|
||||
|
||||
/usr/sbin/dnskeygen /proc/
|
||||
/usr/sbin/dnskeygen /proc/interrupts
|
||||
/usr/sbin/dnskeygen /proc/meminfo
|
||||
/usr/sbin/dnskeygen /proc/rtc
|
||||
/usr/sbin/dnskeygen /proc/self/status
|
||||
/usr/sbin/dnskeygen /proc/stat
|
||||
|
||||
/usr/sbin/fuser /proc/%d/stat
|
||||
/usr/sbin/fuser /proc/net/%s
|
||||
/usr/sbin/fuser /proc/net/unix
|
||||
|
||||
/usr/sbin/in.identd /proc/net/tcp
|
||||
|
||||
/usr/sbin/irpd /proc/
|
||||
/usr/sbin/irpd /proc/interrupts
|
||||
/usr/sbin/irpd /proc/meminfo
|
||||
/usr/sbin/irpd /proc/rtc
|
||||
/usr/sbin/irpd /proc/self/status
|
||||
/usr/sbin/irpd /proc/stat
|
||||
|
||||
/usr/sbin/named /proc/
|
||||
/usr/sbin/named /proc/interrupts
|
||||
/usr/sbin/named /proc/meminfo
|
||||
/usr/sbin/named /proc/rtc
|
||||
/usr/sbin/named /proc/self/status
|
||||
/usr/sbin/named /proc/stat
|
||||
|
||||
/usr/sbin/named-xfer /proc/
|
||||
/usr/sbin/named-xfer /proc/interrupts
|
||||
/usr/sbin/named-xfer /proc/meminfo
|
||||
/usr/sbin/named-xfer /proc/rtc
|
||||
/usr/sbin/named-xfer /proc/self/status
|
||||
/usr/sbin/named-xfer /proc/stat
|
||||
|
||||
/usr/sbin/readprofile /proc/profile
|
||||
|
||||
/usr/sbin/rwhod /proc/loadavg
|
||||
/usr/sbin/rwhod /proc/uptime
|
||||
|
||||
/usr/sbin/sendmail /proc/loadavg
|
||||
|
||||
/usr/sbin/setconsole /proc/openprom/options
|
||||
/usr/sbin/setconsole /proc/openprom/options/${console}-mode
|
||||
/usr/sbin/setconsole /proc/openprom/options/input-device
|
||||
/usr/sbin/setconsole /proc/openprom/options/output-device
|
||||
|
||||
Best wishes from Riley.
|
||||
|
||||
* Copyright (C) 1999, Memory Alpha Systems.
|
||||
* All rights and wrongs reserved.
|
||||
|
||||
+----------------------------------------------------------------------+
|
||||
| There is something frustrating about the quality and speed of Linux |
|
||||
| development, ie., the quality is too high and the speed is too high, |
|
||||
| in other words, I can implement this XXXX feature, but I bet someone |
|
||||
| else has already done so and is just about to release their patch. |
|
||||
+----------------------------------------------------------------------+
|
||||
* http://www.memalpha.cx/Linux/Kernel/
|
||||
|
||||
|
||||
-
|
||||
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
|
||||
the body of a message to majordomo@vger.rutgers.edu
|
||||
Please read the FAQ at http://www.tux.org/lkml/
|
||||
|
||||
+381
-201
@@ -4,10 +4,6 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef BB_INIT
|
||||
#undef BB_FEATURE_LINUXRC
|
||||
#endif
|
||||
|
||||
static int been_there_done_that = 0;
|
||||
|
||||
/* It has been alledged that doing such things can
|
||||
@@ -34,289 +30,466 @@ int atexit(void (*__func) (void))
|
||||
void *__libc_stack_end;
|
||||
#endif
|
||||
|
||||
const struct BB_applet applets[] = {
|
||||
|
||||
static const struct Applet applets[] = {
|
||||
|
||||
#ifdef BB_BUSYBOX //bin
|
||||
{"busybox", busybox_main},
|
||||
#ifdef BB_AR
|
||||
{"ar", ar_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_BLOCK_DEVICE //sbin
|
||||
{"block_device", block_device_main},
|
||||
#ifdef BB_BASENAME
|
||||
{"basename", basename_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CAT //bin
|
||||
{"cat", cat_main},
|
||||
{"busybox", busybox_main, _BB_DIR_BIN},
|
||||
#ifdef BB_CAT
|
||||
{"cat", cat_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP //bin
|
||||
{"chmod", chmod_chown_chgrp_main},
|
||||
{"chown", chmod_chown_chgrp_main},
|
||||
{"chgrp", chmod_chown_chgrp_main},
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CHROOT //sbin
|
||||
{"chroot", chroot_main},
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CLEAR //usr/bin
|
||||
{"clear", clear_main},
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chown", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CHVT //usr/bin
|
||||
{"chvt", chvt_main},
|
||||
#ifdef BB_CHROOT
|
||||
{"chroot", chroot_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_CP_MV //bin
|
||||
{"cp", cp_mv_main},
|
||||
{"mv", cp_mv_main},
|
||||
#ifdef BB_CLEAR
|
||||
{"clear", clear_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DATE //bin
|
||||
{"date", date_main},
|
||||
#ifdef BB_CHVT
|
||||
{"chvt", chvt_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DD //bin
|
||||
{"dd", dd_main},
|
||||
#ifdef BB_CP_MV
|
||||
{"cp", cp_mv_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DF //bin
|
||||
{"df", df_main},
|
||||
#ifdef BB_CUT
|
||||
{"cut", cut_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DMESG //bin
|
||||
{"dmesg", dmesg_main},
|
||||
#ifdef BB_DATE
|
||||
{"date", date_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DU //bin
|
||||
{"du", du_main},
|
||||
#ifdef BB_DC
|
||||
{"dc", dc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DUTMP //usr/sbin
|
||||
{"dutmp", dutmp_main},
|
||||
#ifdef BB_DD
|
||||
{"dd", dd_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FBSET //usr/sbin
|
||||
{"fbset", fbset_main},
|
||||
#ifdef BB_DF
|
||||
{"df", df_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FDFLUSH //bin
|
||||
{"fdflush", fdflush_main},
|
||||
#ifdef BB_DIRNAME
|
||||
{"dirname", dirname_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FIND //usr/bin
|
||||
{"find", find_main},
|
||||
#ifdef BB_DMESG
|
||||
{"dmesg", dmesg_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FREE //usr/bin
|
||||
{"free", free_main},
|
||||
#ifdef BB_DU
|
||||
{"du", du_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DEALLOCVT //usr/bin
|
||||
{"deallocvt", deallocvt_main},
|
||||
#ifdef BB_DUMPKMAP
|
||||
{"dumpkmap", dumpkmap_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FSCK_MINIX //sbin
|
||||
{"fsck.minix", fsck_minix_main},
|
||||
#ifdef BB_DUTMP
|
||||
{"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_MKFS_MINIX //sbin
|
||||
{"mkfs.minix", mkfs_minix_main},
|
||||
#ifdef BB_ECHO
|
||||
{"echo", echo_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_GREP //bin
|
||||
{"grep", grep_main},
|
||||
#ifdef BB_TRUE_FALSE
|
||||
{"false", false_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_HALT //sbin
|
||||
{"halt", halt_main},
|
||||
#ifdef BB_FBSET
|
||||
{"fbset", fbset_main, _BB_DIR_USR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_HEAD //bin
|
||||
{"head", head_main},
|
||||
#ifdef BB_FDFLUSH
|
||||
{"fdflush", fdflush_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_HOSTID //usr/bin
|
||||
{"hostid", hostid_main},
|
||||
#ifdef BB_FIND
|
||||
{"find", find_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_HOSTNAME //bin
|
||||
{"hostname", hostname_main},
|
||||
#ifdef BB_FREE
|
||||
{"free", free_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_INIT //sbin
|
||||
{"init", init_main},
|
||||
#ifdef BB_FREERAMDISK
|
||||
{"freeramdisk", freeramdisk_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_INSMOD //sbin
|
||||
{"insmod", insmod_main},
|
||||
#ifdef BB_DEALLOCVT
|
||||
{"deallocvt", deallocvt_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LINUXRC //
|
||||
{"linuxrc", init_main},
|
||||
#ifdef BB_FSCK_MINIX
|
||||
{"fsck.minix", fsck_minix_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_KILL //bin
|
||||
{"kill", kill_main},
|
||||
#ifdef BB_GREP
|
||||
{"grep", grep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LENGTH //usr/bin
|
||||
{"length", length_main},
|
||||
#ifdef BB_GUNZIP
|
||||
{"gunzip", gunzip_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LN //bin
|
||||
{"ln", ln_main},
|
||||
#ifdef BB_GZIP
|
||||
{"gzip", gzip_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOADACM //usr/bin
|
||||
{"loadacm", loadacm_main},
|
||||
#ifdef BB_HALT
|
||||
{"halt", halt_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_LOADFONT //usr/bin
|
||||
{"loadfont", loadfont_main},
|
||||
#ifdef BB_HEAD
|
||||
{"head", head_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOADKMAP //sbin
|
||||
{"loadkmap", loadkmap_main},
|
||||
#ifdef BB_HOSTID
|
||||
{"hostid", hostid_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LS //bin
|
||||
{"ls", ls_main},
|
||||
#ifdef BB_HOSTNAME
|
||||
{"hostname", hostname_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LSMOD //sbin
|
||||
{"lsmod", lsmod_main},
|
||||
#ifdef BB_ID
|
||||
{"id", id_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MAKEDEVS //sbin
|
||||
{"makedevs", makedevs_main},
|
||||
#ifdef BB_INIT
|
||||
{"init", init_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_MATH //usr/bin
|
||||
{"math", math_main},
|
||||
#ifdef BB_INSMOD
|
||||
{"insmod", insmod_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_MKDIR //bin
|
||||
{"mkdir", mkdir_main},
|
||||
#ifdef BB_KILL
|
||||
{"kill", kill_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKFIFO //usr/bin
|
||||
{"mkfifo", mkfifo_main},
|
||||
#ifdef BB_KILLALL
|
||||
{"killall", kill_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKNOD //bin
|
||||
{"mknod", mknod_main},
|
||||
#ifdef BB_LENGTH
|
||||
{"length", length_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKSWAP //sbin
|
||||
{"mkswap", mkswap_main},
|
||||
#ifdef BB_LINUXRC
|
||||
{"linuxrc", init_main, _BB_DIR_ROOT},
|
||||
#endif
|
||||
#ifdef BB_MNC //usr/bin
|
||||
{"mnc", mnc_main},
|
||||
#ifdef BB_LN
|
||||
{"ln", ln_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MORE //bin
|
||||
{"more", more_main},
|
||||
#ifdef BB_LOADACM
|
||||
{"loadacm", loadacm_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MOUNT //bin
|
||||
{"mount", mount_main},
|
||||
#ifdef BB_LOADFONT
|
||||
{"loadfont", loadfont_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MT //bin
|
||||
{"mt", mt_main},
|
||||
#ifdef BB_LOADKMAP
|
||||
{"loadkmap", loadkmap_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_NSLOOKUP //usr/bin
|
||||
{"nslookup", nslookup_main},
|
||||
#ifdef BB_LOGGER
|
||||
{"logger", logger_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_PING //bin
|
||||
{"ping", ping_main},
|
||||
#ifdef BB_LOGNAME
|
||||
{"logname", logname_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_POWEROFF //sbin
|
||||
{"poweroff", poweroff_main},
|
||||
#ifdef BB_LS
|
||||
{"ls", ls_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_PRINTF //usr/bin
|
||||
{"printf", printf_main},
|
||||
#ifdef BB_LSMOD
|
||||
{"lsmod", lsmod_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_PS //bin
|
||||
{"ps", ps_main},
|
||||
#ifdef BB_MAKEDEVS
|
||||
{"makedevs", makedevs_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_PWD //bin
|
||||
{"pwd", pwd_main},
|
||||
#ifdef BB_MD5SUM
|
||||
{"md5sum", md5sum_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_REBOOT //sbin
|
||||
{"reboot", reboot_main},
|
||||
#ifdef BB_MKDIR
|
||||
{"mkdir", mkdir_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_RM //bin
|
||||
{"rm", rm_main},
|
||||
#ifdef BB_MKFIFO
|
||||
{"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_RMDIR //bin
|
||||
{"rmdir", rmdir_main},
|
||||
#ifdef BB_MKFS_MINIX
|
||||
{"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_RMMOD //sbin
|
||||
{"rmmod", rmmod_main},
|
||||
#ifdef BB_MKNOD
|
||||
{"mknod", mknod_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SFDISK //sbin
|
||||
{"fdisk", sfdisk_main},
|
||||
{"sfdisk", sfdisk_main},
|
||||
#ifdef BB_MKSWAP
|
||||
{"mkswap", mkswap_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_SED //bin
|
||||
{"sed", sed_main},
|
||||
#ifdef BB_MKTEMP
|
||||
{"mktemp", mktemp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SLEEP //bin
|
||||
{"sleep", sleep_main},
|
||||
#ifdef BB_NC
|
||||
{"nc", nc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SORT //bin
|
||||
{"sort", sort_main},
|
||||
#ifdef BB_MORE
|
||||
{"more", more_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SYNC //bin
|
||||
{"sync", sync_main},
|
||||
#ifdef BB_MOUNT
|
||||
{"mount", mount_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SYSLOGD //sbin
|
||||
{"syslogd", syslogd_main},
|
||||
#ifdef BB_MT
|
||||
{"mt", mt_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOGGER //usr/bin
|
||||
{"logger", logger_main},
|
||||
#ifdef BB_CP_MV
|
||||
{"mv", cp_mv_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOGNAME //usr/bin
|
||||
{"logname", logname_main},
|
||||
#ifdef BB_NSLOOKUP
|
||||
{"nslookup", nslookup_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF //sbin
|
||||
{"swapon", swap_on_off_main},
|
||||
{"swapoff", swap_on_off_main},
|
||||
#ifdef BB_PING
|
||||
{"ping", ping_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TAIL //usr/bin
|
||||
{"tail", tail_main},
|
||||
#ifdef BB_POWEROFF
|
||||
{"poweroff", poweroff_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_TAR //bin
|
||||
{"tar", tar_main},
|
||||
#ifdef BB_PRINTF
|
||||
{"printf", printf_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEE //bin
|
||||
{"tee", tee_main},
|
||||
#ifdef BB_PS
|
||||
{"ps", ps_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TOUCH //usr/bin
|
||||
{"touch", touch_main},
|
||||
#ifdef BB_PWD
|
||||
{"pwd", pwd_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE //bin
|
||||
{"true", true_main},
|
||||
{"false", false_main},
|
||||
#ifdef BB_REBOOT
|
||||
{"reboot", reboot_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_TTY //usr/bin
|
||||
{"tty", tty_main},
|
||||
#ifdef BB_RM
|
||||
{"rm", rm_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNAME //bin
|
||||
{"uname", uname_main},
|
||||
#ifdef BB_RMDIR
|
||||
{"rmdir", rmdir_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UMOUNT //bin
|
||||
{"umount", umount_main},
|
||||
#ifdef BB_RMMOD
|
||||
{"rmmod", rmmod_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_UNIQ //bin
|
||||
{"uniq", uniq_main},
|
||||
#ifdef BB_SED
|
||||
{"sed", sed_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UPDATE //sbin
|
||||
{"update", update_main},
|
||||
#ifdef BB_SETKEYCODES
|
||||
{"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WC //usr/bin
|
||||
{"wc", wc_main},
|
||||
#ifdef BB_SH
|
||||
{"sh", shell_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WHOAMI //usr/bin
|
||||
{"whoami", whoami_main},
|
||||
#ifdef BB_SLEEP
|
||||
{"sleep", sleep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_YES //usr/bin
|
||||
{"yes", yes_main},
|
||||
#ifdef BB_SORT
|
||||
{"sort", sort_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_GUNZIP //bin
|
||||
{"zcat", gunzip_main},
|
||||
{"gunzip", gunzip_main},
|
||||
#ifdef BB_SYNC
|
||||
{"sync", sync_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_GZIP //bin
|
||||
{"gzip", gzip_main},
|
||||
#ifdef BB_SYSLOGD
|
||||
{"syslogd", syslogd_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF
|
||||
{"swapon", swap_on_off_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF
|
||||
{"swapoff", swap_on_off_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_TAIL
|
||||
{"tail", tail_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TAR
|
||||
{"tar", tar_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TELNET
|
||||
{"telnet", telnet_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEST
|
||||
{"test", test_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEE
|
||||
{"tee", tee_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TOUCH
|
||||
{"touch", touch_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TR
|
||||
{"tr", tr_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE
|
||||
{"true", true_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TTY
|
||||
{"tty", tty_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UMOUNT
|
||||
{"umount", umount_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNAME
|
||||
{"uname", uname_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNIQ
|
||||
{"uniq", uniq_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UPDATE
|
||||
{"update", update_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_UPTIME
|
||||
{"uptime", uptime_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UUENCODE
|
||||
{"uuencode", uuencode_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UUDECODE
|
||||
{"uudecode", uudecode_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_USLEEP
|
||||
{"usleep", usleep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WC
|
||||
{"wc", wc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WHICH
|
||||
{"which", which_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WHOAMI
|
||||
{"whoami", whoami_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_YES
|
||||
{"yes", yes_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_GUNZIP
|
||||
{"zcat", gunzip_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEST
|
||||
{"[", test_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
{0}
|
||||
};
|
||||
|
||||
|
||||
#ifdef BB_FEATURE_INSTALLER
|
||||
/*
|
||||
* directory table
|
||||
* this should be consistent w/ the enum, internal.h::Location,
|
||||
* or else...
|
||||
*/
|
||||
static char* install_dir[] = {
|
||||
"/",
|
||||
"/bin",
|
||||
"/sbin",
|
||||
"/usr/bin",
|
||||
"/usr/sbin",
|
||||
};
|
||||
|
||||
/* abstract link() */
|
||||
typedef int (*__link_f)(const char *, const char *);
|
||||
|
||||
/*
|
||||
* Where in the filesystem is this busybox?
|
||||
* [return]
|
||||
* malloc'd string w/ full pathname of busybox's location
|
||||
* NULL on failure
|
||||
*/
|
||||
static char *busybox_fullpath()
|
||||
{
|
||||
pid_t pid;
|
||||
char path[256];
|
||||
char proc[256];
|
||||
int len;
|
||||
|
||||
pid = getpid();
|
||||
sprintf(proc, "/proc/%d/exe", pid);
|
||||
len = readlink(proc, path, 256);
|
||||
if (len != -1) {
|
||||
path[len] = 0;
|
||||
} else {
|
||||
fprintf(stderr, "busybox : %s : %s\n", proc, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
return strdup(path);
|
||||
}
|
||||
|
||||
/* create (sym)links for each applet */
|
||||
static int install_links(const char *busybox, int use_symbolic_links)
|
||||
{
|
||||
__link_f Link = link;
|
||||
|
||||
char command[256];
|
||||
int i;
|
||||
int rc = 0;
|
||||
|
||||
if (use_symbolic_links) Link = symlink;
|
||||
|
||||
for (i = 0; applets[i].name != NULL; i++) {
|
||||
sprintf (
|
||||
command,
|
||||
"%s/%s",
|
||||
install_dir[applets[i].location],
|
||||
applets[i].name
|
||||
);
|
||||
#if 1
|
||||
rc |= Link(busybox, command);
|
||||
#else
|
||||
puts(command);
|
||||
#endif
|
||||
if (rc) {
|
||||
fprintf(stderr,"busybox : %s : %s\n", command, strerror(errno));
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int uninstall_links() ?
|
||||
#endif
|
||||
#endif /* BB_FEATURE_INSTALLER */
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *s = argv[0];
|
||||
char *name = argv[0];
|
||||
const struct Applet *a = applets;
|
||||
char *s;
|
||||
char *name;
|
||||
const struct BB_applet *a = applets;
|
||||
|
||||
while (*s != '\0') {
|
||||
#ifdef BB_FEATURE_INSTALLER
|
||||
/*
|
||||
* This style of argument parsing doesn't scale well
|
||||
* in the event that busybox starts wanting more --options.
|
||||
* If someone has a cleaner approach, by all means implement it.
|
||||
*/
|
||||
if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
|
||||
int use_symbolic_links = 0;
|
||||
int rc = 0;
|
||||
char *busybox;
|
||||
|
||||
/* to use symlinks, or not to use symlinks... */
|
||||
if (argc > 2) {
|
||||
if ((strcmp(argv[2], "-s") == 0)) {
|
||||
use_symbolic_links = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* link */
|
||||
busybox = busybox_fullpath();
|
||||
if (busybox) {
|
||||
install_links(busybox, use_symbolic_links);
|
||||
free(busybox);
|
||||
} else {
|
||||
rc = 1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif /* BB_FEATURE_INSTALLER */
|
||||
|
||||
for (s = name = argv[0]; *s != '\0';) {
|
||||
if (*s++ == '/')
|
||||
name = s;
|
||||
}
|
||||
|
||||
*argv = name;
|
||||
|
||||
#ifdef BB_SH
|
||||
/* Add in a special case hack -- whenever **argv == '-'
|
||||
* (i.e. '-su' or '-sh') always invoke the shell */
|
||||
if (**argv == '-')
|
||||
exit(((*(shell_main)) (argc, argv)));
|
||||
#endif
|
||||
|
||||
while (a->name != 0) {
|
||||
if (strcmp(name, a->name) == 0) {
|
||||
int status;
|
||||
|
||||
status = ((*(a->main)) (argc, argv));
|
||||
if (status < 0) {
|
||||
fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
exit(status);
|
||||
exit(((*(a->main)) (argc, argv)));
|
||||
}
|
||||
a++;
|
||||
}
|
||||
exit(busybox_main(argc, argv));
|
||||
return(busybox_main(argc, argv));
|
||||
}
|
||||
|
||||
|
||||
@@ -328,16 +501,16 @@ int busybox_main(int argc, char **argv)
|
||||
argv++;
|
||||
|
||||
if (been_there_done_that == 1 || argc < 1) {
|
||||
const struct Applet *a = applets;
|
||||
const struct BB_applet *a = applets;
|
||||
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
|
||||
BB_VER, BB_BT);
|
||||
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
|
||||
fprintf(stderr, " or: [function] [arguments]...\n\n");
|
||||
fprintf(stderr,
|
||||
"\tMost people will create a symlink to busybox for each\n"
|
||||
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
|
||||
fprintf(stderr, "\nCurrently defined functions:\n");
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n"
|
||||
"Usage: busybox [function] [arguments]...\n"
|
||||
" or: [function] [arguments]...\n\n"
|
||||
"\tBusyBox is a multi-call binary that combines many common Unix\n"
|
||||
"\tutilities into a single executable. Most people will create a\n"
|
||||
"\tlink to busybox for each function they wish to use, and BusyBox\n"
|
||||
"\twill act like whatever it was invoked as.\n"
|
||||
"\nCurrently defined functions:\n", BB_VER, BB_BT);
|
||||
|
||||
while (a->name != 0) {
|
||||
col +=
|
||||
@@ -350,9 +523,16 @@ int busybox_main(int argc, char **argv)
|
||||
}
|
||||
fprintf(stderr, "\n\n");
|
||||
exit(-1);
|
||||
} else {
|
||||
/* If we've already been here once, exit now */
|
||||
been_there_done_that = 1;
|
||||
return (main(argc, argv));
|
||||
}
|
||||
/* If we've already been here once, exit now */
|
||||
been_there_done_that = 1;
|
||||
return (main(argc, argv));
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+10
-6
@@ -4,12 +4,16 @@
|
||||
DF="busybox.def.h"
|
||||
MF="busybox.c"
|
||||
|
||||
LIST="$(sed -n '/^#define/{s/^#define //p;}' $DF)"
|
||||
LIST="$(gcc -E -dM $DF | sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/BB_\1/gp;' | sort)"
|
||||
|
||||
for def in ${LIST}; do
|
||||
i=`sed -n 's/^#ifdef \<'$def'\>.*\/\/\(.*$\)/\/\1\//gp' $MF`
|
||||
j=`sed -n '/^#ifdef \<'$def'\>.*/,/^#endif/{ s/.*\"\(.*\)\".*/\1/gp; }' $MF`
|
||||
for k in $j; do
|
||||
echo $i$k
|
||||
done
|
||||
i=`sed -n '/^#ifdef \<'$def'\>.*/,/^#endif/{ s/.*\"\(.*\)\".*\(_BB_DIR_[A-Z_]*\).*$/\2\/\1/gp; }' $MF`
|
||||
for j in $i; do
|
||||
if [ -z $j ] ; then
|
||||
continue;
|
||||
fi;
|
||||
echo $j | sed -e 's/_BB_DIR_ROOT//g;s/_BB_DIR_BIN/\/bin/g;' \
|
||||
-e 's/_BB_DIR_SBIN/\/sbin/g;s/_BB_DIR_USR_BIN/\/usr\/bin/g;' \
|
||||
-e 's/_BB_DIR_USR_SBIN/\/usr\/sbin/g;'
|
||||
done;
|
||||
done
|
||||
+8
-2
@@ -1,4 +1,10 @@
|
||||
#!/bin/sh
|
||||
ls -1 `sed -n '/^#define/{s/.*BB_// ; s/$/.c/p; }' busybox.def.h | \
|
||||
tr [:upper:] [:lower:]` 2> /dev/null | sed -e 's/\.c$/\.o/g'
|
||||
|
||||
# I added in the extra "ls" so only source files that
|
||||
# actually exist will show up in the compile list.
|
||||
ls -1 ` \
|
||||
gcc -E -dM busybox.def.h | \
|
||||
sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/\1.c/gp;' \
|
||||
| tr [:upper:] [:lower:] | sort
|
||||
` 2>/dev/null | sed -e 's/\.c$/\.o/g'
|
||||
|
||||
@@ -15,6 +15,7 @@ for i in $h ; do
|
||||
ln -fs /bin/busybox $1$i
|
||||
done
|
||||
rm -f $1/bin/busybox
|
||||
mkdir -p $1/bin
|
||||
install -m 755 busybox $1/bin/busybox
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,332 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini ar implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 by Glenn McGrath
|
||||
* Written by Glenn McGrath <bug1@netconnect.com.au> 1 June 2000
|
||||
*
|
||||
* Based in part on BusyBox tar, Debian dpkg-deb and GNU ar.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Last modified 10 June 2000
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <sys/types.h>
|
||||
#include "internal.h"
|
||||
|
||||
#define AR_BLOCK_SIZE 60
|
||||
#define AR_PRESERVE_DATE 1 /* preserve original dates */
|
||||
#define AR_VERBOSE 2 /* be verbose */
|
||||
#define AR_DISPLAY 4 /* display contents */
|
||||
#define AR_EXT_TO_FILE 8 /* extract contents of archive */
|
||||
#define AR_EXT_TO_STDOUT 16 /* extract to stdout */
|
||||
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_io_error
|
||||
#include "messages.c"
|
||||
|
||||
struct ArHeader { /* Byte Offset */
|
||||
char ar_name[16]; /* 0-15 */
|
||||
char ar_date[12]; /* 16-27 */
|
||||
char ar_uid[6], ar_gid[6]; /* 28-39 */
|
||||
char ar_mode[8]; /* 40-47 */
|
||||
char ar_size[10]; /* 48-57 */
|
||||
char ar_fmag[2]; /* 58-59 */
|
||||
};
|
||||
typedef struct ArHeader ArHeader;
|
||||
|
||||
struct ArInfo {
|
||||
char name[17]; /* File name */
|
||||
time_t date; /* long int, No of seconds since epoch */
|
||||
uid_t uid; /* unsigned int, Numeric UID */
|
||||
gid_t gid; /* unsigned int, Numeric GID */
|
||||
mode_t mode; /* unsigned int, Unix mode */
|
||||
size_t size; /* int, Size of the file */
|
||||
};
|
||||
typedef struct ArInfo ArInfo;
|
||||
|
||||
static const char ar_usage[] = "ar [optxvV] archive [filenames] \n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nExtract or list files from an ar archive.\n\n"
|
||||
"Options:\n"
|
||||
"\to\t\tpreserve original dates\n"
|
||||
"\tp\t\textract to stdout\n"
|
||||
"\tt\t\tlist\n"
|
||||
"\tx\t\textract\n"
|
||||
"\tv\t\tverbosely list files processed\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
/*
|
||||
* Display details of a file, verbosly if funct=2
|
||||
*/
|
||||
static void displayEntry(struct ArInfo *entry, int funct)
|
||||
{
|
||||
/* TODO convert mode to string */
|
||||
if ((funct & AR_VERBOSE) == AR_VERBOSE)
|
||||
printf("%i %i/%i %8i %s ", entry->mode, entry->uid, entry->gid,
|
||||
entry->size, timeString(entry->date));
|
||||
printf("%s\n", entry->name);
|
||||
}
|
||||
|
||||
/* this is from tar.c remove later*/
|
||||
static long getOctal(const char *cp, int size)
|
||||
{
|
||||
long val = 0;
|
||||
|
||||
for(;(size > 0) && (*cp == ' '); cp++, size--);
|
||||
if ((size == 0) || !isOctal(*cp))
|
||||
return -1;
|
||||
for(; (size > 0) && isOctal(*cp); size--) {
|
||||
val = val * 8 + *cp++ - '0';
|
||||
}
|
||||
for (;(size > 0) && (*cp == ' '); cp++, size--);
|
||||
if ((size > 0) && *cp)
|
||||
return -1;
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts from the char based struct to a new struct with stricter types
|
||||
*/
|
||||
static int processArHeader(struct ArHeader *rawHeader, struct ArInfo *header)
|
||||
{
|
||||
int count2;
|
||||
int count;
|
||||
|
||||
/* check end of header marker is valid */
|
||||
if ((rawHeader->ar_fmag[0]!='`') || (rawHeader->ar_fmag[1]!='\n'))
|
||||
return(FALSE);
|
||||
|
||||
/* convert filename */
|
||||
for (count = 0; count < 16; count++) {
|
||||
/* allow spaces in filename except at the end */
|
||||
if (rawHeader->ar_name[count] == ' ') {
|
||||
for (count2 = count; count2 < 16; count2++)
|
||||
if (!isspace(rawHeader->ar_name[count2]))
|
||||
break;
|
||||
if (count2 >= 16)
|
||||
break;
|
||||
}
|
||||
/* GNU ar uses '/' as an end of filename marker */
|
||||
if (rawHeader->ar_name[count] == '/')
|
||||
break;
|
||||
header->name[count] = rawHeader->ar_name[count];
|
||||
}
|
||||
header->name[count] = '\0';
|
||||
header->date = atoi(rawHeader->ar_date);
|
||||
header->uid = atoi(rawHeader->ar_uid);
|
||||
header->gid = atoi(rawHeader->ar_gid);
|
||||
header->mode = getOctal(rawHeader->ar_mode, sizeof(rawHeader->ar_mode));
|
||||
header->size = atoi(rawHeader->ar_size);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy size bytes from current position if srcFd to current position in dstFd
|
||||
* taken from tarExtractRegularFile in tar.c, remove later
|
||||
*/
|
||||
static int copySubFile(int srcFd, int dstFd, int copySize)
|
||||
{
|
||||
int readSize, writeSize, doneSize;
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
while (copySize > 0) {
|
||||
if (copySize > BUFSIZ)
|
||||
readSize = BUFSIZ;
|
||||
else
|
||||
readSize = copySize;
|
||||
writeSize = fullRead(srcFd, buffer, readSize);
|
||||
if (writeSize <= 0) {
|
||||
errorMsg(io_error, "copySubFile :", strerror(errno));
|
||||
return (FALSE);
|
||||
}
|
||||
doneSize = fullWrite(dstFd, buffer, writeSize);
|
||||
if (doneSize <= 0) {
|
||||
errorMsg(io_error, "copySubFile :", strerror(errno));
|
||||
return (FALSE);
|
||||
}
|
||||
copySize -= doneSize;
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract the file described in ArInfo to the specified path
|
||||
* set the new files uid, gid and mode
|
||||
*/
|
||||
static int extractToFile(struct ArInfo *file, int funct, int srcFd, const char *path)
|
||||
{
|
||||
int dstFd, temp;
|
||||
struct stat tmpStat;
|
||||
char *pathname = NULL;
|
||||
struct utimbuf newtime;
|
||||
|
||||
if ((temp = isDirectory(path, TRUE, &tmpStat)) != TRUE) {
|
||||
if (!createPath(path, 0777)) {
|
||||
fatalError("Cannot extract to specified path");
|
||||
return (FALSE);
|
||||
}
|
||||
}
|
||||
temp = (strlen(path) + 16);
|
||||
pathname = (char *) xmalloc(temp);
|
||||
pathname = strcpy(pathname, path);
|
||||
pathname = strcat(pathname, file->name);
|
||||
dstFd = device_open(pathname, O_WRONLY | O_CREAT);
|
||||
temp = copySubFile(srcFd, dstFd, file->size);
|
||||
fchown(dstFd, file->uid, file->gid);
|
||||
fchmod(dstFd, file->mode);
|
||||
close(dstFd);
|
||||
if ((funct&AR_PRESERVE_DATE)==AR_PRESERVE_DATE)
|
||||
newtime.modtime=file->date;
|
||||
else
|
||||
newtime.modtime=time(0);
|
||||
newtime.actime=time(0);
|
||||
temp = utime(pathname, &newtime);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a file descriptor for the specified file and do error checks
|
||||
*/
|
||||
static int getArFd(char *filename)
|
||||
{
|
||||
int arFd;
|
||||
char arVersion[8];
|
||||
|
||||
arFd = open(filename, O_RDONLY);
|
||||
if (arFd < 0) {
|
||||
errorMsg("Error opening '%s': %s\n", filename, strerror(errno));
|
||||
return (FALSE);
|
||||
}
|
||||
if (fullRead(arFd, arVersion, 8) <= 0) {
|
||||
errorMsg( "ar: Unexpected EOF in archive\n");
|
||||
return (FALSE);
|
||||
}
|
||||
if (strncmp(arVersion,"!<arch>",7) != 0) {
|
||||
errorMsg("ar header fails check ");
|
||||
return(FALSE);
|
||||
}
|
||||
return arFd;
|
||||
}
|
||||
|
||||
/*
|
||||
* Step through the ar file and process it one entry at a time
|
||||
* fileList[0] is the name of the ar archive
|
||||
* fileList[1] and up are filenames to extract from the archive
|
||||
* funct contains flags to specify the actions to be performed
|
||||
*/
|
||||
static int readArFile(char *fileList[16], int fileListSize, int funct)
|
||||
{
|
||||
int arFd, status, extFileFlag, i, lastOffset=0;
|
||||
ArHeader rawArHeader;
|
||||
ArInfo arEntry;
|
||||
|
||||
/* open the ar archive */
|
||||
arFd=getArFd(fileList[0]);
|
||||
|
||||
/* read the first header, then loop until ono more headers */
|
||||
while ((status = fullRead(arFd, (char *) &rawArHeader, AR_BLOCK_SIZE))
|
||||
== AR_BLOCK_SIZE) {
|
||||
|
||||
/* check the header is valid, if not try reading the header
|
||||
agian with an offset of 1, needed as some ar archive end
|
||||
with a '\n' which isnt counted in specified file size */
|
||||
if ((status=processArHeader(&rawArHeader, &arEntry))==FALSE ) {
|
||||
if ((i=lseek(arFd, 0, SEEK_CUR))==(lastOffset+60))
|
||||
lseek(arFd, lastOffset+1, SEEK_SET);
|
||||
else
|
||||
return(FALSE);
|
||||
}
|
||||
else {
|
||||
extFileFlag=0;
|
||||
|
||||
if (funct&AR_DISPLAY)
|
||||
displayEntry(&arEntry, funct);
|
||||
|
||||
/* check file was specified to be extracted only if
|
||||
some file were specified */
|
||||
if ((funct&AR_EXT_TO_FILE) || (funct&AR_EXT_TO_STDOUT)){
|
||||
if (fileListSize==1)
|
||||
extFileFlag=1;
|
||||
else {
|
||||
for( i=1; i<=fileListSize; i++)
|
||||
if ((status=(strcmp(fileList[i],arEntry.name)))==0)
|
||||
extFileFlag=1;
|
||||
}
|
||||
}
|
||||
if (extFileFlag==1) {
|
||||
if (funct&AR_EXT_TO_FILE)
|
||||
extractToFile(&arEntry, funct, arFd, "./");
|
||||
else
|
||||
copySubFile(arFd,fileno(stdout),arEntry.size);
|
||||
}
|
||||
else
|
||||
lseek(arFd, arEntry.size, SEEK_CUR);
|
||||
lastOffset=lseek(arFd, 0, SEEK_CUR);
|
||||
} /* if processArHeader */
|
||||
} /* while */
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
extern int ar_main(int argc, char **argv)
|
||||
{
|
||||
int funct = 0, ret=0, i=0;
|
||||
char *fileList[16], c, *opt_ptr;
|
||||
|
||||
if (argc < 2)
|
||||
usage(ar_usage);
|
||||
|
||||
opt_ptr = argv[1];
|
||||
if (*opt_ptr == '-')
|
||||
++opt_ptr;
|
||||
while ((c = *opt_ptr++) != '\0') {
|
||||
switch (c) {
|
||||
case 'o':
|
||||
funct = funct | AR_PRESERVE_DATE;
|
||||
break;
|
||||
case 'v':
|
||||
funct = funct | AR_VERBOSE;
|
||||
break;
|
||||
case 't':
|
||||
funct = funct | AR_DISPLAY;
|
||||
break;
|
||||
case 'x':
|
||||
funct = funct | AR_EXT_TO_FILE;
|
||||
break;
|
||||
case 'p':
|
||||
funct = funct | AR_EXT_TO_STDOUT;
|
||||
break;
|
||||
default:
|
||||
usage(ar_usage);
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0; i<(argc-2); i++)
|
||||
fileList[i]=argv[i+2];
|
||||
|
||||
if (funct > 3)
|
||||
ret = readArFile(fileList, (argc-2), funct);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
+332
@@ -0,0 +1,332 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini ar implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 by Glenn McGrath
|
||||
* Written by Glenn McGrath <bug1@netconnect.com.au> 1 June 2000
|
||||
*
|
||||
* Based in part on BusyBox tar, Debian dpkg-deb and GNU ar.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Last modified 10 June 2000
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <sys/types.h>
|
||||
#include "internal.h"
|
||||
|
||||
#define AR_BLOCK_SIZE 60
|
||||
#define AR_PRESERVE_DATE 1 /* preserve original dates */
|
||||
#define AR_VERBOSE 2 /* be verbose */
|
||||
#define AR_DISPLAY 4 /* display contents */
|
||||
#define AR_EXT_TO_FILE 8 /* extract contents of archive */
|
||||
#define AR_EXT_TO_STDOUT 16 /* extract to stdout */
|
||||
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_io_error
|
||||
#include "messages.c"
|
||||
|
||||
struct ArHeader { /* Byte Offset */
|
||||
char ar_name[16]; /* 0-15 */
|
||||
char ar_date[12]; /* 16-27 */
|
||||
char ar_uid[6], ar_gid[6]; /* 28-39 */
|
||||
char ar_mode[8]; /* 40-47 */
|
||||
char ar_size[10]; /* 48-57 */
|
||||
char ar_fmag[2]; /* 58-59 */
|
||||
};
|
||||
typedef struct ArHeader ArHeader;
|
||||
|
||||
struct ArInfo {
|
||||
char name[17]; /* File name */
|
||||
time_t date; /* long int, No of seconds since epoch */
|
||||
uid_t uid; /* unsigned int, Numeric UID */
|
||||
gid_t gid; /* unsigned int, Numeric GID */
|
||||
mode_t mode; /* unsigned int, Unix mode */
|
||||
size_t size; /* int, Size of the file */
|
||||
};
|
||||
typedef struct ArInfo ArInfo;
|
||||
|
||||
static const char ar_usage[] = "ar [optxvV] archive [filenames] \n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nExtract or list files from an ar archive.\n\n"
|
||||
"Options:\n"
|
||||
"\to\t\tpreserve original dates\n"
|
||||
"\tp\t\textract to stdout\n"
|
||||
"\tt\t\tlist\n"
|
||||
"\tx\t\textract\n"
|
||||
"\tv\t\tverbosely list files processed\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
/*
|
||||
* Display details of a file, verbosly if funct=2
|
||||
*/
|
||||
static void displayEntry(struct ArInfo *entry, int funct)
|
||||
{
|
||||
/* TODO convert mode to string */
|
||||
if ((funct & AR_VERBOSE) == AR_VERBOSE)
|
||||
printf("%i %i/%i %8i %s ", entry->mode, entry->uid, entry->gid,
|
||||
entry->size, timeString(entry->date));
|
||||
printf("%s\n", entry->name);
|
||||
}
|
||||
|
||||
/* this is from tar.c remove later*/
|
||||
static long getOctal(const char *cp, int size)
|
||||
{
|
||||
long val = 0;
|
||||
|
||||
for(;(size > 0) && (*cp == ' '); cp++, size--);
|
||||
if ((size == 0) || !isOctal(*cp))
|
||||
return -1;
|
||||
for(; (size > 0) && isOctal(*cp); size--) {
|
||||
val = val * 8 + *cp++ - '0';
|
||||
}
|
||||
for (;(size > 0) && (*cp == ' '); cp++, size--);
|
||||
if ((size > 0) && *cp)
|
||||
return -1;
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts from the char based struct to a new struct with stricter types
|
||||
*/
|
||||
static int processArHeader(struct ArHeader *rawHeader, struct ArInfo *header)
|
||||
{
|
||||
int count2;
|
||||
int count;
|
||||
|
||||
/* check end of header marker is valid */
|
||||
if ((rawHeader->ar_fmag[0]!='`') || (rawHeader->ar_fmag[1]!='\n'))
|
||||
return(FALSE);
|
||||
|
||||
/* convert filename */
|
||||
for (count = 0; count < 16; count++) {
|
||||
/* allow spaces in filename except at the end */
|
||||
if (rawHeader->ar_name[count] == ' ') {
|
||||
for (count2 = count; count2 < 16; count2++)
|
||||
if (!isspace(rawHeader->ar_name[count2]))
|
||||
break;
|
||||
if (count2 >= 16)
|
||||
break;
|
||||
}
|
||||
/* GNU ar uses '/' as an end of filename marker */
|
||||
if (rawHeader->ar_name[count] == '/')
|
||||
break;
|
||||
header->name[count] = rawHeader->ar_name[count];
|
||||
}
|
||||
header->name[count] = '\0';
|
||||
header->date = atoi(rawHeader->ar_date);
|
||||
header->uid = atoi(rawHeader->ar_uid);
|
||||
header->gid = atoi(rawHeader->ar_gid);
|
||||
header->mode = getOctal(rawHeader->ar_mode, sizeof(rawHeader->ar_mode));
|
||||
header->size = atoi(rawHeader->ar_size);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy size bytes from current position if srcFd to current position in dstFd
|
||||
* taken from tarExtractRegularFile in tar.c, remove later
|
||||
*/
|
||||
static int copySubFile(int srcFd, int dstFd, int copySize)
|
||||
{
|
||||
int readSize, writeSize, doneSize;
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
while (copySize > 0) {
|
||||
if (copySize > BUFSIZ)
|
||||
readSize = BUFSIZ;
|
||||
else
|
||||
readSize = copySize;
|
||||
writeSize = fullRead(srcFd, buffer, readSize);
|
||||
if (writeSize <= 0) {
|
||||
errorMsg(io_error, "copySubFile :", strerror(errno));
|
||||
return (FALSE);
|
||||
}
|
||||
doneSize = fullWrite(dstFd, buffer, writeSize);
|
||||
if (doneSize <= 0) {
|
||||
errorMsg(io_error, "copySubFile :", strerror(errno));
|
||||
return (FALSE);
|
||||
}
|
||||
copySize -= doneSize;
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract the file described in ArInfo to the specified path
|
||||
* set the new files uid, gid and mode
|
||||
*/
|
||||
static int extractToFile(struct ArInfo *file, int funct, int srcFd, const char *path)
|
||||
{
|
||||
int dstFd, temp;
|
||||
struct stat tmpStat;
|
||||
char *pathname = NULL;
|
||||
struct utimbuf newtime;
|
||||
|
||||
if ((temp = isDirectory(path, TRUE, &tmpStat)) != TRUE) {
|
||||
if (!createPath(path, 0777)) {
|
||||
fatalError("Cannot extract to specified path");
|
||||
return (FALSE);
|
||||
}
|
||||
}
|
||||
temp = (strlen(path) + 16);
|
||||
pathname = (char *) xmalloc(temp);
|
||||
pathname = strcpy(pathname, path);
|
||||
pathname = strcat(pathname, file->name);
|
||||
dstFd = device_open(pathname, O_WRONLY | O_CREAT);
|
||||
temp = copySubFile(srcFd, dstFd, file->size);
|
||||
fchown(dstFd, file->uid, file->gid);
|
||||
fchmod(dstFd, file->mode);
|
||||
close(dstFd);
|
||||
if ((funct&AR_PRESERVE_DATE)==AR_PRESERVE_DATE)
|
||||
newtime.modtime=file->date;
|
||||
else
|
||||
newtime.modtime=time(0);
|
||||
newtime.actime=time(0);
|
||||
temp = utime(pathname, &newtime);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a file descriptor for the specified file and do error checks
|
||||
*/
|
||||
static int getArFd(char *filename)
|
||||
{
|
||||
int arFd;
|
||||
char arVersion[8];
|
||||
|
||||
arFd = open(filename, O_RDONLY);
|
||||
if (arFd < 0) {
|
||||
errorMsg("Error opening '%s': %s\n", filename, strerror(errno));
|
||||
return (FALSE);
|
||||
}
|
||||
if (fullRead(arFd, arVersion, 8) <= 0) {
|
||||
errorMsg( "ar: Unexpected EOF in archive\n");
|
||||
return (FALSE);
|
||||
}
|
||||
if (strncmp(arVersion,"!<arch>",7) != 0) {
|
||||
errorMsg("ar header fails check ");
|
||||
return(FALSE);
|
||||
}
|
||||
return arFd;
|
||||
}
|
||||
|
||||
/*
|
||||
* Step through the ar file and process it one entry at a time
|
||||
* fileList[0] is the name of the ar archive
|
||||
* fileList[1] and up are filenames to extract from the archive
|
||||
* funct contains flags to specify the actions to be performed
|
||||
*/
|
||||
static int readArFile(char *fileList[16], int fileListSize, int funct)
|
||||
{
|
||||
int arFd, status, extFileFlag, i, lastOffset=0;
|
||||
ArHeader rawArHeader;
|
||||
ArInfo arEntry;
|
||||
|
||||
/* open the ar archive */
|
||||
arFd=getArFd(fileList[0]);
|
||||
|
||||
/* read the first header, then loop until ono more headers */
|
||||
while ((status = fullRead(arFd, (char *) &rawArHeader, AR_BLOCK_SIZE))
|
||||
== AR_BLOCK_SIZE) {
|
||||
|
||||
/* check the header is valid, if not try reading the header
|
||||
agian with an offset of 1, needed as some ar archive end
|
||||
with a '\n' which isnt counted in specified file size */
|
||||
if ((status=processArHeader(&rawArHeader, &arEntry))==FALSE ) {
|
||||
if ((i=lseek(arFd, 0, SEEK_CUR))==(lastOffset+60))
|
||||
lseek(arFd, lastOffset+1, SEEK_SET);
|
||||
else
|
||||
return(FALSE);
|
||||
}
|
||||
else {
|
||||
extFileFlag=0;
|
||||
|
||||
if (funct&AR_DISPLAY)
|
||||
displayEntry(&arEntry, funct);
|
||||
|
||||
/* check file was specified to be extracted only if
|
||||
some file were specified */
|
||||
if ((funct&AR_EXT_TO_FILE) || (funct&AR_EXT_TO_STDOUT)){
|
||||
if (fileListSize==1)
|
||||
extFileFlag=1;
|
||||
else {
|
||||
for( i=1; i<=fileListSize; i++)
|
||||
if ((status=(strcmp(fileList[i],arEntry.name)))==0)
|
||||
extFileFlag=1;
|
||||
}
|
||||
}
|
||||
if (extFileFlag==1) {
|
||||
if (funct&AR_EXT_TO_FILE)
|
||||
extractToFile(&arEntry, funct, arFd, "./");
|
||||
else
|
||||
copySubFile(arFd,fileno(stdout),arEntry.size);
|
||||
}
|
||||
else
|
||||
lseek(arFd, arEntry.size, SEEK_CUR);
|
||||
lastOffset=lseek(arFd, 0, SEEK_CUR);
|
||||
} /* if processArHeader */
|
||||
} /* while */
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
extern int ar_main(int argc, char **argv)
|
||||
{
|
||||
int funct = 0, ret=0, i=0;
|
||||
char *fileList[16], c, *opt_ptr;
|
||||
|
||||
if (argc < 2)
|
||||
usage(ar_usage);
|
||||
|
||||
opt_ptr = argv[1];
|
||||
if (*opt_ptr == '-')
|
||||
++opt_ptr;
|
||||
while ((c = *opt_ptr++) != '\0') {
|
||||
switch (c) {
|
||||
case 'o':
|
||||
funct = funct | AR_PRESERVE_DATE;
|
||||
break;
|
||||
case 'v':
|
||||
funct = funct | AR_VERBOSE;
|
||||
break;
|
||||
case 't':
|
||||
funct = funct | AR_DISPLAY;
|
||||
break;
|
||||
case 'x':
|
||||
funct = funct | AR_EXT_TO_FILE;
|
||||
break;
|
||||
case 'p':
|
||||
funct = funct | AR_EXT_TO_STDOUT;
|
||||
break;
|
||||
default:
|
||||
usage(ar_usage);
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0; i<(argc-2); i++)
|
||||
fileList[i]=argv[i+2];
|
||||
|
||||
if (funct > 3)
|
||||
ret = readArFile(fileList, (argc-2), funct);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
+110
-229
@@ -1,20 +1,58 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* zcat : stripped version based on gzip sources
|
||||
Sven Rudolph <sr1@inf.tu-dresden.de>
|
||||
*/
|
||||
/*
|
||||
* Gzip implementation for busybox
|
||||
*
|
||||
* Based on GNU gzip Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
*
|
||||
* Originally adjusted for busybox by Sven Rudolph <sr1@inf.tu-dresden.de>
|
||||
* based on gzip sources
|
||||
*
|
||||
* Adjusted further by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* to support files as well as stdin/stdout, and to generally behave itself wrt
|
||||
* command line handling.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#define bb_need_name_too_long
|
||||
#define BB_DECLARE_EXTERN
|
||||
#include "messages.c"
|
||||
#include <getopt.h>
|
||||
|
||||
static const char gunzip_usage[] =
|
||||
"gunzip [OPTION]... FILE\n\n"
|
||||
"Uncompress FILE (or standard input if FILE is '-').\n\n"
|
||||
"gunzip [OPTION]... FILE\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nUncompress FILE (or standard input if FILE is '-').\n\n"
|
||||
"Options:\n"
|
||||
|
||||
"\t-c\tWrite output to standard output\n"
|
||||
"\t-t\tTest compressed file integrity\n";
|
||||
"\t-t\tTest compressed file integrity\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
/* These defines are very important for BusyBox. Without these,
|
||||
* huge chunks of ram are pre-allocated making the BusyBox bss
|
||||
* size Freaking Huge(tm), which is a bad thing.*/
|
||||
#define SMALL_MEM
|
||||
#define DYN_ALLOC
|
||||
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_memory_exhausted
|
||||
#define bb_need_name_too_long
|
||||
#include "messages.c"
|
||||
|
||||
|
||||
/* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly
|
||||
@@ -70,7 +108,6 @@ static char *license_msg[] = {
|
||||
#include <signal.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <sys/param.h> /* for PATH_MAX */
|
||||
|
||||
/* #include "tailor.h" */
|
||||
|
||||
@@ -89,25 +126,6 @@ static char *license_msg[] = {
|
||||
#define get_char() get_byte()
|
||||
#define put_char(c) put_byte(c)
|
||||
|
||||
/* #include "gzip.h" */
|
||||
|
||||
/* gzip.h -- common declarations for all gzip modules
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
* This is free software; you can redistribute it and/or modify it under the
|
||||
* terms of the GNU General Public License, see the file COPYING.
|
||||
*/
|
||||
|
||||
#if defined(__STDC__) || defined(PROTO)
|
||||
# define OF(args) args
|
||||
#else
|
||||
# define OF(args) ()
|
||||
#endif
|
||||
|
||||
#ifdef __STDC__
|
||||
typedef void *voidp;
|
||||
#else
|
||||
typedef char *voidp;
|
||||
#endif
|
||||
|
||||
/* I don't like nested includes, but the string and io functions are used
|
||||
* too often
|
||||
@@ -118,7 +136,7 @@ typedef char *voidp;
|
||||
# if !defined(STDC_HEADERS) && !defined(NO_MEMORY_H) && !defined(__GNUC__)
|
||||
# include <memory.h>
|
||||
# endif
|
||||
# define memzero(s, n) memset ((voidp)(s), 0, (n))
|
||||
# define memzero(s, n) memset ((void *)(s), 0, (n))
|
||||
#else
|
||||
# include <strings.h>
|
||||
# define strchr index
|
||||
@@ -194,7 +212,7 @@ extern int method; /* compression method */
|
||||
# define DECLARE(type, array, size) type * array
|
||||
# define ALLOC(type, array, size) { \
|
||||
array = (type*)calloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
|
||||
if (array == NULL) errorMsg("insufficient memory"); \
|
||||
if (array == NULL) errorMsg(memory_exhausted, "gunzip"); \
|
||||
}
|
||||
# define FREE(array) {if (array != NULL) free(array), array=NULL;}
|
||||
#else
|
||||
@@ -329,49 +347,44 @@ extern int save_orig_name; /* set if original name must be saved */
|
||||
#define WARN(msg) {fprintf msg ; \
|
||||
if (exit_code == OK) exit_code = WARNING;}
|
||||
|
||||
#define do_exit(c) exit(c)
|
||||
|
||||
|
||||
/* in unzip.c */
|
||||
extern int unzip OF((int in, int out));
|
||||
extern int unzip (int in, int out);
|
||||
|
||||
/* in gzip.c */
|
||||
RETSIGTYPE abort_gzip OF((void));
|
||||
RETSIGTYPE abort_gzip (void);
|
||||
|
||||
/* in deflate.c */
|
||||
void lm_init OF((int pack_level, ush * flags));
|
||||
ulg deflate OF((void));
|
||||
void lm_init (int pack_level, ush * flags);
|
||||
ulg deflate (void);
|
||||
|
||||
/* in trees.c */
|
||||
void ct_init OF((ush * attr, int *method));
|
||||
int ct_tally OF((int dist, int lc));
|
||||
ulg flush_block OF((char *buf, ulg stored_len, int eof));
|
||||
void ct_init (ush * attr, int *method);
|
||||
int ct_tally (int dist, int lc);
|
||||
ulg flush_block (char *buf, ulg stored_len, int eof);
|
||||
|
||||
/* in bits.c */
|
||||
void bi_init OF((file_t zipfile));
|
||||
void send_bits OF((int value, int length));
|
||||
unsigned bi_reverse OF((unsigned value, int length));
|
||||
void bi_windup OF((void));
|
||||
void copy_block OF((char *buf, unsigned len, int header));
|
||||
extern int (*read_buf) OF((char *buf, unsigned size));
|
||||
void bi_init (file_t zipfile);
|
||||
void send_bits (int value, int length);
|
||||
unsigned bi_reverse (unsigned value, int length);
|
||||
void bi_windup (void);
|
||||
void copy_block (char *buf, unsigned len, int header);
|
||||
|
||||
/* in util.c: */
|
||||
extern int copy OF((int in, int out));
|
||||
extern ulg updcrc OF((uch * s, unsigned n));
|
||||
extern void clear_bufs OF((void));
|
||||
extern int fill_inbuf OF((int eof_ok));
|
||||
extern void flush_outbuf OF((void));
|
||||
extern void flush_window OF((void));
|
||||
extern void write_buf OF((int fd, voidp buf, unsigned cnt));
|
||||
extern ulg updcrc (uch * s, unsigned n);
|
||||
extern void clear_bufs (void);
|
||||
static int fill_inbuf (int eof_ok);
|
||||
extern void flush_outbuf (void);
|
||||
static void flush_window (void);
|
||||
extern void write_buf (int fd, void * buf, unsigned cnt);
|
||||
|
||||
#ifndef __linux__
|
||||
extern char *basename OF((char *fname));
|
||||
static char *basename (char *fname);
|
||||
#endif /* not __linux__ */
|
||||
extern void read_error OF((void));
|
||||
extern void write_error OF((void));
|
||||
void read_error_msg (void);
|
||||
void write_error_msg (void);
|
||||
|
||||
/* in inflate.c */
|
||||
extern int inflate OF((void));
|
||||
static int inflate (void);
|
||||
|
||||
/* #include "lzw.h" */
|
||||
|
||||
@@ -415,8 +428,8 @@ extern int inflate OF((void));
|
||||
extern int maxbits; /* max bits per code for LZW */
|
||||
extern int block_mode; /* block compress mode -C compatible with 2.0 */
|
||||
|
||||
extern int lzw OF((int in, int out));
|
||||
extern int unlzw OF((int in, int out));
|
||||
extern int lzw (int in, int out);
|
||||
extern int unlzw (int in, int out);
|
||||
|
||||
|
||||
/* #include "revision.h" */
|
||||
@@ -436,133 +449,6 @@ extern int unlzw OF((int in, int out));
|
||||
# undef LZW
|
||||
#endif
|
||||
|
||||
/* #include "getopt.h" */
|
||||
|
||||
/* Declarations for getopt.
|
||||
Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2, or (at your option) any
|
||||
later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
|
||||
#ifndef _GETOPT_H
|
||||
#define _GETOPT_H 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* For communication from `getopt' to the caller.
|
||||
When `getopt' finds an option that takes an argument,
|
||||
the argument value is returned here.
|
||||
Also, when `ordering' is RETURN_IN_ORDER,
|
||||
each non-option ARGV-element is returned here. */
|
||||
extern char *optarg;
|
||||
|
||||
/* Index in ARGV of the next element to be scanned.
|
||||
This is used for communication to and from the caller
|
||||
and for communication between successive calls to `getopt'.
|
||||
|
||||
On entry to `getopt', zero means this is the first call; initialize.
|
||||
|
||||
When `getopt' returns EOF, this is the index of the first of the
|
||||
non-option elements that the caller should itself scan.
|
||||
|
||||
Otherwise, `optind' communicates from one call to the next
|
||||
how much of ARGV has been scanned so far. */
|
||||
|
||||
extern int optind;
|
||||
|
||||
/* Callers store zero here to inhibit the error message `getopt' prints
|
||||
for unrecognized options. */
|
||||
|
||||
extern int opterr;
|
||||
|
||||
/* Set to an option character which was unrecognized. */
|
||||
|
||||
extern int optopt;
|
||||
|
||||
/* Describe the long-named options requested by the application.
|
||||
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
|
||||
of `struct option' terminated by an element containing a name which is
|
||||
zero.
|
||||
|
||||
The field `has_arg' is:
|
||||
no_argument (or 0) if the option does not take an argument,
|
||||
required_argument (or 1) if the option requires an argument,
|
||||
optional_argument (or 2) if the option takes an optional argument.
|
||||
|
||||
If the field `flag' is not NULL, it points to a variable that is set
|
||||
to the value given in the field `val' when the option is found, but
|
||||
left unchanged if the option is not found.
|
||||
|
||||
To have a long-named option do something other than set an `int' to
|
||||
a compiled-in constant, such as set a value from `optarg', set the
|
||||
option's `flag' field to zero and its `val' field to a nonzero
|
||||
value (the equivalent single-letter option character, if there is
|
||||
one). For long options that have a zero `flag' field, `getopt'
|
||||
returns the contents of the `val' field. */
|
||||
|
||||
struct option {
|
||||
#if __STDC__
|
||||
const char *name;
|
||||
#else
|
||||
char *name;
|
||||
#endif
|
||||
/* has_arg can't be an enum because some compilers complain about
|
||||
type mismatches in all the code that assumes it is an int. */
|
||||
int has_arg;
|
||||
int *flag;
|
||||
int val;
|
||||
};
|
||||
|
||||
/* Names for the values of the `has_arg' field of `struct option'. */
|
||||
|
||||
#define no_argument 0
|
||||
#define required_argument 1
|
||||
#define optional_argument 2
|
||||
|
||||
#if __STDC__ || defined(PROTO)
|
||||
#if defined(__GNU_LIBRARY__)
|
||||
/* Many other libraries have conflicting prototypes for getopt, with
|
||||
differences in the consts, in stdlib.h. To avoid compilation
|
||||
errors, only prototype getopt for the GNU C library. */
|
||||
extern int getopt(int argc, char *const *argv, const char *shortopts);
|
||||
#endif /* not __GNU_LIBRARY__ */
|
||||
extern int getopt_long(int argc, char *const *argv,
|
||||
const char *shortopts,
|
||||
const struct option *longopts, int *longind);
|
||||
extern int getopt_long_only(int argc, char *const *argv,
|
||||
const char *shortopts,
|
||||
const struct option *longopts,
|
||||
int *longind);
|
||||
|
||||
/* Internal only. Users should not call this directly. */
|
||||
extern int _getopt_internal(int argc, char *const *argv,
|
||||
const char *shortopts,
|
||||
const struct option *longopts,
|
||||
int *longind, int long_only);
|
||||
#else /* not __STDC__ */
|
||||
extern int getopt();
|
||||
extern int getopt_long();
|
||||
extern int getopt_long_only();
|
||||
|
||||
extern int _getopt_internal();
|
||||
#endif /* not __STDC__ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* _GETOPT_H */
|
||||
#include <time.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
@@ -605,7 +491,7 @@ typedef struct direct dir_type;
|
||||
#if !defined(S_ISREG) && defined(S_IFREG)
|
||||
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
#endif
|
||||
typedef RETSIGTYPE(*sig_type) OF((int));
|
||||
typedef RETSIGTYPE(*sig_type) (int);
|
||||
|
||||
#ifndef O_BINARY
|
||||
# define O_BINARY 0 /* creation mode for open() */
|
||||
@@ -631,8 +517,8 @@ typedef RETSIGTYPE(*sig_type) OF((int));
|
||||
#define RW_USER (S_IRUSR | S_IWUSR) /* creation mode for open() */
|
||||
|
||||
#ifndef MAX_PATH_LEN /* max pathname length */
|
||||
# ifdef PATH_MAX
|
||||
# define MAX_PATH_LEN PATH_MAX
|
||||
# ifdef BUFSIZ
|
||||
# define MAX_PATH_LEN BUFSIZ
|
||||
# else
|
||||
# define MAX_PATH_LEN 1024
|
||||
# endif
|
||||
@@ -644,7 +530,7 @@ typedef RETSIGTYPE(*sig_type) OF((int));
|
||||
|
||||
#ifdef NO_OFF_T
|
||||
typedef long off_t;
|
||||
off_t lseek OF((int fd, off_t offset, int whence));
|
||||
off_t lseek (int fd, off_t offset, int whence);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -687,7 +573,7 @@ long header_bytes; /* number of bytes in gzip header */
|
||||
|
||||
/* local functions */
|
||||
|
||||
local int get_method OF((int in));
|
||||
local int get_method (int in);
|
||||
|
||||
#define strequ(s1, s2) (strcmp((s1),(s2)) == 0)
|
||||
|
||||
@@ -706,11 +592,12 @@ int gunzip_main(int argc, char **argv)
|
||||
char ifname[MAX_PATH_LEN + 1]; /* input file name */
|
||||
char ofname[MAX_PATH_LEN + 1]; /* output file name */
|
||||
|
||||
if (argc == 1)
|
||||
usage(gunzip_usage);
|
||||
|
||||
if (strcmp(*argv, "zcat") == 0)
|
||||
if (strcmp(*argv, "zcat") == 0) {
|
||||
to_stdout = 1;
|
||||
if (argc == 1) {
|
||||
fromstdin = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Parse any options */
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
@@ -773,7 +660,7 @@ int gunzip_main(int argc, char **argv)
|
||||
usage(gunzip_usage);
|
||||
if (strlen(*argv) > MAX_PATH_LEN) {
|
||||
fprintf(stderr, name_too_long, "gunzip");
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
strcpy(ifname, *argv);
|
||||
|
||||
@@ -781,13 +668,13 @@ int gunzip_main(int argc, char **argv)
|
||||
inFileNum = open(ifname, O_RDONLY);
|
||||
if (inFileNum < 0) {
|
||||
perror(ifname);
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
/* Get the time stamp on the input file. */
|
||||
result = stat(ifname, &statBuf);
|
||||
if (result < 0) {
|
||||
perror(ifname);
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
ifile_size = statBuf.st_size;
|
||||
}
|
||||
@@ -812,7 +699,7 @@ int gunzip_main(int argc, char **argv)
|
||||
/* And get to work */
|
||||
if (strlen(ifname) > MAX_PATH_LEN - 4) {
|
||||
fprintf(stderr, name_too_long, "gunzip");
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
strcpy(ofname, ifname);
|
||||
pos = strstr(ofname, ".gz");
|
||||
@@ -836,7 +723,7 @@ int gunzip_main(int argc, char **argv)
|
||||
#endif
|
||||
if (outFileNum < 0) {
|
||||
perror(ofname);
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
/* Set permissions on the file */
|
||||
fchmod(outFileNum, statBuf.st_mode);
|
||||
@@ -860,7 +747,7 @@ int gunzip_main(int argc, char **argv)
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
do_exit(exit_code);
|
||||
return(exit_code);
|
||||
}
|
||||
|
||||
|
||||
@@ -953,7 +840,7 @@ int in; /* input file descriptor */
|
||||
*/
|
||||
RETSIGTYPE abort_gzip()
|
||||
{
|
||||
do_exit(ERROR);
|
||||
exit(ERROR);
|
||||
}
|
||||
|
||||
/* unzip.c -- decompress files in gzip or pkzip format.
|
||||
@@ -1027,7 +914,7 @@ int in, out; /* input and output file descriptors */
|
||||
ofd = out;
|
||||
method = get_method(ifd);
|
||||
if (method < 0) {
|
||||
do_exit(exit_code); /* error message already emitted */
|
||||
exit(exit_code); /* error message already emitted */
|
||||
}
|
||||
|
||||
updcrc(NULL, 0); /* initialize crc */
|
||||
@@ -1043,7 +930,7 @@ int in, out; /* input and output file descriptors */
|
||||
int res = inflate();
|
||||
|
||||
if (res == 3) {
|
||||
errorMsg("out of memory");
|
||||
errorMsg(memory_exhausted, "gunzip");
|
||||
} else if (res != 0) {
|
||||
errorMsg("invalid compressed data--format violated");
|
||||
}
|
||||
@@ -1146,7 +1033,7 @@ unsigned n; /* number of bytes in s[] */
|
||||
/* ===========================================================================
|
||||
* Clear input and output buffers
|
||||
*/
|
||||
void clear_bufs()
|
||||
void clear_bufs(void)
|
||||
{
|
||||
outcnt = 0;
|
||||
insize = inptr = 0;
|
||||
@@ -1174,7 +1061,7 @@ int eof_ok; /* set if EOF acceptable as a result */
|
||||
if (insize == 0) {
|
||||
if (eof_ok)
|
||||
return EOF;
|
||||
read_error();
|
||||
read_error_msg();
|
||||
}
|
||||
bytes_in += (ulg) insize;
|
||||
inptr = 1;
|
||||
@@ -1218,17 +1105,17 @@ void flush_window()
|
||||
*/
|
||||
void write_buf(fd, buf, cnt)
|
||||
int fd;
|
||||
voidp buf;
|
||||
void * buf;
|
||||
unsigned cnt;
|
||||
{
|
||||
unsigned n;
|
||||
|
||||
while ((n = write(fd, buf, cnt)) != cnt) {
|
||||
if (n == (unsigned) (-1)) {
|
||||
write_error();
|
||||
write_error_msg();
|
||||
}
|
||||
cnt -= n;
|
||||
buf = (voidp) ((char *) buf + n);
|
||||
buf = (void *) ((char *) buf + n);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1240,8 +1127,8 @@ unsigned cnt;
|
||||
# define const
|
||||
# endif
|
||||
|
||||
int strspn OF((const char *s, const char *accept));
|
||||
int strcspn OF((const char *s, const char *reject));
|
||||
int strspn (const char *s, const char *accept);
|
||||
int strcspn (const char *s, const char *reject);
|
||||
|
||||
/* ========================================================================
|
||||
* Return the length of the maximum initial segment
|
||||
@@ -1291,13 +1178,7 @@ const char *reject;
|
||||
/* ========================================================================
|
||||
* Error handlers.
|
||||
*/
|
||||
void warn(a, b)
|
||||
char *a, *b; /* message strings juxtaposed in output */
|
||||
{
|
||||
WARN((stderr, "warning: %s%s\n", a, b));
|
||||
}
|
||||
|
||||
void read_error()
|
||||
void read_error_msg()
|
||||
{
|
||||
fprintf(stderr, "\n");
|
||||
if (errno != 0) {
|
||||
@@ -1308,7 +1189,7 @@ void read_error()
|
||||
abort_gzip();
|
||||
}
|
||||
|
||||
void write_error()
|
||||
void write_error_msg()
|
||||
{
|
||||
fprintf(stderr, "\n");
|
||||
perror("");
|
||||
@@ -1499,15 +1380,15 @@ struct huft {
|
||||
|
||||
|
||||
/* Function prototypes */
|
||||
int huft_build OF((unsigned *, unsigned, unsigned, ush *, ush *,
|
||||
struct huft **, int *));
|
||||
int huft_free OF((struct huft *));
|
||||
int inflate_codes OF((struct huft *, struct huft *, int, int));
|
||||
int inflate_stored OF((void));
|
||||
int inflate_fixed OF((void));
|
||||
int inflate_dynamic OF((void));
|
||||
int inflate_block OF((int *));
|
||||
int inflate OF((void));
|
||||
int huft_build (unsigned *, unsigned, unsigned, ush *, ush *,
|
||||
struct huft **, int *);
|
||||
int huft_free (struct huft *);
|
||||
int inflate_codes (struct huft *, struct huft *, int, int);
|
||||
int inflate_stored (void);
|
||||
int inflate_fixed (void);
|
||||
int inflate_dynamic (void);
|
||||
int inflate_block (int *);
|
||||
int inflate (void);
|
||||
|
||||
|
||||
/* The inflate algorithm uses a sliding 32K byte window on the uncompressed
|
||||
|
||||
+109
-116
@@ -1,62 +1,64 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* gzip.c -- this is a stripped down version of gzip I put into busybox, it does
|
||||
* only standard in to standard out with -9 compression. It also requires the
|
||||
* zcat module for some important functions.
|
||||
/*
|
||||
* Gzip implementation for busybox
|
||||
*
|
||||
* Based on GNU gzip Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
*
|
||||
* Originally adjusted for busybox by Charles P. Wright <cpw@unix.asb.com>
|
||||
* "this is a stripped down version of gzip I put into busybox, it does
|
||||
* only standard in to standard out with -9 compression. It also requires
|
||||
* the zcat module for some important functions."
|
||||
*
|
||||
* Adjusted further by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* to support files as well as stdin/stdout, and to generally behave itself wrt
|
||||
* command line handling.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Charles P. Wright <cpw@unix.asb.com>
|
||||
*/
|
||||
#include "internal.h"
|
||||
#ifdef BB_GZIP
|
||||
|
||||
//#ifndef BB_ZCAT
|
||||
//#error you need zcat to have gzip support!
|
||||
//#endif
|
||||
#include "internal.h"
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_memory_exhausted
|
||||
#include "messages.c"
|
||||
|
||||
/* These defines are very important for BusyBox. Without these,
|
||||
* huge chunks of ram are pre-allocated making the BusyBox bss
|
||||
* size Freaking Huge(tm), which is a bad thing.*/
|
||||
#define SMALL_MEM
|
||||
#define DYN_ALLOC
|
||||
|
||||
|
||||
static const char gzip_usage[] =
|
||||
"gzip [OPTION]... FILE\n\n"
|
||||
"Compress FILE with maximum compression.\n"
|
||||
"When FILE is -, reads standard input. Implies -c.\n\n"
|
||||
"gzip [OPTION]... FILE\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCompress FILE with maximum compression.\n"
|
||||
"When FILE is '-', reads standard input. Implies -c.\n\n"
|
||||
|
||||
"Options:\n"
|
||||
"\t-c\tWrite output to standard output instead of FILE.gz\n";
|
||||
|
||||
|
||||
/* gzip.h -- common declarations for all gzip modules
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
* This is free software; you can redistribute it and/or modify it under the
|
||||
* terms of the GNU General Public License, see the file COPYING.
|
||||
*/
|
||||
|
||||
#if defined(__STDC__) || defined(PROTO)
|
||||
# define OF(args) args
|
||||
#else
|
||||
# define OF(args) ()
|
||||
"\t-c\tWrite output to standard output instead of FILE.gz\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
#ifdef __STDC__
|
||||
typedef void *voidp;
|
||||
#else
|
||||
typedef char *voidp;
|
||||
#endif
|
||||
|
||||
/* I don't like nested includes, but the string and io functions are used
|
||||
* too often
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#if !defined(NO_STRING_H) || defined(STDC_HEADERS)
|
||||
# include <string.h>
|
||||
# if !defined(STDC_HEADERS) && !defined(NO_MEMORY_H) && !defined(__GNUC__)
|
||||
# include <memory.h>
|
||||
# endif
|
||||
# define memzero(s, n) memset ((voidp)(s), 0, (n))
|
||||
#else
|
||||
# include <strings.h>
|
||||
# define strchr index
|
||||
# define strrchr rindex
|
||||
# define memcpy(d, s, n) bcopy((s), (d), (n))
|
||||
# define memcmp(s1, s2, n) bcmp((s1), (s2), (n))
|
||||
# define memzero(s, n) bzero((s), (n))
|
||||
#endif
|
||||
#include <string.h>
|
||||
#define memzero(s, n) memset ((void *)(s), 0, (n))
|
||||
|
||||
#ifndef RETSIGTYPE
|
||||
# define RETSIGTYPE void
|
||||
@@ -121,13 +123,13 @@ extern int method; /* compression method */
|
||||
#endif
|
||||
|
||||
#ifdef DYN_ALLOC
|
||||
# define EXTERN(type, array) extern type * near array
|
||||
# define DECLARE(type, array, size) type * near array
|
||||
# define EXTERN(type, array) extern type * array
|
||||
# define DECLARE(type, array, size) type * array
|
||||
# define ALLOC(type, array, size) { \
|
||||
array = (type*)fcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
|
||||
if (array == NULL) errorMsg("insufficient memory"); \
|
||||
array = (type*)calloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
|
||||
if (array == NULL) errorMsg(memory_exhausted, "gzip"); \
|
||||
}
|
||||
# define FREE(array) {if (array != NULL) fcfree(array), array=NULL;}
|
||||
# define FREE(array) {if (array != NULL) free(array), array=NULL;}
|
||||
#else
|
||||
# define EXTERN(type, array) extern type array[]
|
||||
# define DECLARE(type, array, size) type array[size]
|
||||
@@ -280,59 +282,57 @@ extern int save_orig_name; /* set if original name must be saved */
|
||||
#define WARN(msg) {if (!quiet) fprintf msg ; \
|
||||
if (exit_code == OK) exit_code = WARNING;}
|
||||
|
||||
#define do_exit(c) exit(c)
|
||||
|
||||
|
||||
/* in zip.c: */
|
||||
extern int zip OF((int in, int out));
|
||||
extern int file_read OF((char *buf, unsigned size));
|
||||
extern int zip (int in, int out);
|
||||
extern int file_read (char *buf, unsigned size);
|
||||
|
||||
/* in unzip.c */
|
||||
extern int unzip OF((int in, int out));
|
||||
extern int check_zipfile OF((int in));
|
||||
extern int unzip (int in, int out);
|
||||
extern int check_zipfile (int in);
|
||||
|
||||
/* in unpack.c */
|
||||
extern int unpack OF((int in, int out));
|
||||
extern int unpack (int in, int out);
|
||||
|
||||
/* in unlzh.c */
|
||||
extern int unlzh OF((int in, int out));
|
||||
extern int unlzh (int in, int out);
|
||||
|
||||
/* in gzip.c */
|
||||
RETSIGTYPE abort_gzip OF((void));
|
||||
RETSIGTYPE abort_gzip (void);
|
||||
|
||||
/* in deflate.c */
|
||||
void lm_init OF((ush * flags));
|
||||
ulg deflate OF((void));
|
||||
void lm_init (ush * flags);
|
||||
ulg deflate (void);
|
||||
|
||||
/* in trees.c */
|
||||
void ct_init OF((ush * attr, int *method));
|
||||
int ct_tally OF((int dist, int lc));
|
||||
ulg flush_block OF((char *buf, ulg stored_len, int eof));
|
||||
void ct_init (ush * attr, int *method);
|
||||
int ct_tally (int dist, int lc);
|
||||
ulg flush_block (char *buf, ulg stored_len, int eof);
|
||||
|
||||
/* in bits.c */
|
||||
void bi_init OF((file_t zipfile));
|
||||
void send_bits OF((int value, int length));
|
||||
unsigned bi_reverse OF((unsigned value, int length));
|
||||
void bi_windup OF((void));
|
||||
void copy_block OF((char *buf, unsigned len, int header));
|
||||
extern int (*read_buf) OF((char *buf, unsigned size));
|
||||
void bi_init (file_t zipfile);
|
||||
void send_bits (int value, int length);
|
||||
unsigned bi_reverse (unsigned value, int length);
|
||||
void bi_windup (void);
|
||||
void copy_block (char *buf, unsigned len, int header);
|
||||
extern int (*read_buf) (char *buf, unsigned size);
|
||||
|
||||
/* in util.c: */
|
||||
extern int copy OF((int in, int out));
|
||||
extern ulg updcrc OF((uch * s, unsigned n));
|
||||
extern void clear_bufs OF((void));
|
||||
extern int fill_inbuf OF((int eof_ok));
|
||||
extern void flush_outbuf OF((void));
|
||||
extern void flush_window OF((void));
|
||||
extern void write_buf OF((int fd, voidp buf, unsigned cnt));
|
||||
extern char *strlwr OF((char *s));
|
||||
extern char *add_envopt OF((int *argcp, char ***argvp, char *env));
|
||||
extern void read_error OF((void));
|
||||
extern void write_error OF((void));
|
||||
extern void display_ratio OF((long num, long den, FILE * file));
|
||||
extern int copy (int in, int out);
|
||||
extern ulg updcrc (uch * s, unsigned n);
|
||||
extern void clear_bufs (void);
|
||||
extern int fill_inbuf (int eof_ok);
|
||||
extern void flush_outbuf (void);
|
||||
extern void flush_window (void);
|
||||
extern void write_buf (int fd, void * buf, unsigned cnt);
|
||||
extern char *strlwr (char *s);
|
||||
extern char *add_envopt (int *argcp, char ***argvp, char *env);
|
||||
extern void read_error_msg (void);
|
||||
extern void write_error_msg (void);
|
||||
extern void display_ratio (long num, long den, FILE * file);
|
||||
|
||||
/* in inflate.c */
|
||||
extern int inflate OF((void));
|
||||
extern int inflate (void);
|
||||
|
||||
/* lzw.h -- define the lzw functions.
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
@@ -795,7 +795,7 @@ local int bi_valid;
|
||||
* are always zero.
|
||||
*/
|
||||
|
||||
int (*read_buf) OF((char *buf, unsigned size));
|
||||
int (*read_buf) (char *buf, unsigned size);
|
||||
|
||||
/* Current input function. Set to mem_read for in-memory compression */
|
||||
|
||||
@@ -1148,16 +1148,16 @@ local config configuration_table =
|
||||
/* ===========================================================================
|
||||
* Prototypes for local functions.
|
||||
*/
|
||||
local void fill_window OF((void));
|
||||
local void fill_window (void);
|
||||
|
||||
int longest_match OF((IPos cur_match));
|
||||
int longest_match (IPos cur_match);
|
||||
|
||||
#ifdef ASMV
|
||||
void match_init OF((void)); /* asm code initialization */
|
||||
void match_init (void); /* asm code initialization */
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
local void check_match OF((IPos start, IPos match, int length));
|
||||
local void check_match (IPos start, IPos match, int length);
|
||||
#endif
|
||||
|
||||
/* ===========================================================================
|
||||
@@ -1708,7 +1708,7 @@ struct utimbuf {
|
||||
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
#endif
|
||||
|
||||
typedef RETSIGTYPE(*sig_type) OF((int));
|
||||
typedef RETSIGTYPE(*sig_type) (int);
|
||||
|
||||
#ifndef O_BINARY
|
||||
# define O_BINARY 0 /* creation mode for open() */
|
||||
@@ -1743,7 +1743,7 @@ typedef RETSIGTYPE(*sig_type) OF((int));
|
||||
|
||||
#ifdef NO_OFF_T
|
||||
typedef long off_t;
|
||||
off_t lseek OF((int fd, off_t offset, int whence));
|
||||
off_t lseek (int fd, off_t offset, int whence);
|
||||
#endif
|
||||
|
||||
/* Separator for file name parts (see shorten_name()) */
|
||||
@@ -1782,7 +1782,6 @@ int part_nb; /* number of parts in .gz file */
|
||||
long time_stamp; /* original time stamp (modification time) */
|
||||
long ifile_size; /* input file size, -1 for devices (debug only) */
|
||||
char *env; /* contents of GZIP env variable */
|
||||
char **args = NULL; /* argv pointer if GZIP env variable defined */
|
||||
char z_suffix[MAX_SUFFIX + 1]; /* default suffix (can be set with --suffix) */
|
||||
int z_len; /* strlen(z_suffix) */
|
||||
|
||||
@@ -1882,13 +1881,13 @@ int gzip_main(int argc, char **argv)
|
||||
inFileNum = open(ifname, O_RDONLY);
|
||||
if (inFileNum < 0) {
|
||||
perror(ifname);
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
/* Get the time stamp on the input file. */
|
||||
result = stat(ifname, &statBuf);
|
||||
if (result < 0) {
|
||||
perror(ifname);
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
time_stamp = statBuf.st_ctime;
|
||||
ifile_size = statBuf.st_size;
|
||||
@@ -1922,7 +1921,7 @@ int gzip_main(int argc, char **argv)
|
||||
#endif
|
||||
if (outFileNum < 0) {
|
||||
perror(ofname);
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
SET_BINARY_MODE(outFileNum);
|
||||
/* Set permissions on the file */
|
||||
@@ -1947,7 +1946,7 @@ int gzip_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
do_exit(exit_code);
|
||||
return(exit_code);
|
||||
}
|
||||
|
||||
/* trees.c -- output deflated data using Huffman coding
|
||||
@@ -2246,17 +2245,17 @@ extern unsigned near strstart; /* window offset of current string */
|
||||
* Local (static) routines in this file.
|
||||
*/
|
||||
|
||||
local void init_block OF((void));
|
||||
local void pqdownheap OF((ct_data near * tree, int k));
|
||||
local void gen_bitlen OF((tree_desc near * desc));
|
||||
local void gen_codes OF((ct_data near * tree, int max_code));
|
||||
local void build_tree OF((tree_desc near * desc));
|
||||
local void scan_tree OF((ct_data near * tree, int max_code));
|
||||
local void send_tree OF((ct_data near * tree, int max_code));
|
||||
local int build_bl_tree OF((void));
|
||||
local void send_all_trees OF((int lcodes, int dcodes, int blcodes));
|
||||
local void compress_block OF((ct_data near * ltree, ct_data near * dtree));
|
||||
local void set_file_type OF((void));
|
||||
local void init_block (void);
|
||||
local void pqdownheap (ct_data near * tree, int k);
|
||||
local void gen_bitlen (tree_desc near * desc);
|
||||
local void gen_codes (ct_data near * tree, int max_code);
|
||||
local void build_tree (tree_desc near * desc);
|
||||
local void scan_tree (ct_data near * tree, int max_code);
|
||||
local void send_tree (ct_data near * tree, int max_code);
|
||||
local int build_bl_tree (void);
|
||||
local void send_all_trees (int lcodes, int dcodes, int blcodes);
|
||||
local void compress_block (ct_data near * ltree, ct_data near * dtree);
|
||||
local void set_file_type (void);
|
||||
|
||||
|
||||
#ifndef DEBUG
|
||||
@@ -2276,7 +2275,6 @@ local void set_file_type OF((void));
|
||||
* used.
|
||||
*/
|
||||
|
||||
#define MAX(a,b) (a >= b ? a : b)
|
||||
/* the arguments must not have side effects */
|
||||
|
||||
/* ===========================================================================
|
||||
@@ -3097,7 +3095,7 @@ local void set_file_type()
|
||||
bin_freq += dyn_ltree[n++].Freq;
|
||||
*file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII;
|
||||
if (*file_type == BINARY && translate_eol) {
|
||||
errorMsg("-l used on binary file", "");
|
||||
errorMsg("-l used on binary file");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3138,7 +3136,7 @@ int in, out; /* input and output file descriptors */
|
||||
insize = read(in, (char *) inbuf, INBUFSIZ);
|
||||
}
|
||||
if ((int) insize == EOF && errno != 0) {
|
||||
read_error();
|
||||
read_error_msg();
|
||||
}
|
||||
bytes_in = bytes_out;
|
||||
return OK;
|
||||
@@ -3161,12 +3159,8 @@ char *s;
|
||||
|
||||
/* Provide missing strspn and strcspn functions. */
|
||||
|
||||
# ifndef __STDC__
|
||||
# define const
|
||||
# endif
|
||||
|
||||
int strspn OF((const char *s, const char *accept));
|
||||
int strcspn OF((const char *s, const char *reject));
|
||||
int strspn (const char *s, const char *accept);
|
||||
int strcspn (const char *s, const char *reject);
|
||||
|
||||
/* ========================================================================
|
||||
* Return the length of the maximum initial segment
|
||||
@@ -3257,7 +3251,7 @@ char *env; /* name of environment variable */
|
||||
nargv = (char **) calloc(*argcp + 1, sizeof(char *));
|
||||
|
||||
if (nargv == NULL)
|
||||
errorMsg("out of memory");
|
||||
errorMsg(memory_exhausted, "gzip");
|
||||
oargv = *argvp;
|
||||
*argvp = nargv;
|
||||
|
||||
@@ -3398,4 +3392,3 @@ unsigned size;
|
||||
isize += (ulg) len;
|
||||
return (int) len;
|
||||
}
|
||||
#endif
|
||||
+878
-1150
File diff suppressed because it is too large.
Load diff
+57
@@ -0,0 +1,57 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini basename implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
const char *basename_usage="basename FILE [SUFFIX]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nStrips directory path and suffixes from FILE.\n"
|
||||
"If specified, also removes any trailing SUFFIX.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
extern int basename_main(int argc, char **argv)
|
||||
{
|
||||
int m, n;
|
||||
char *s;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage(basename_usage);
|
||||
}
|
||||
|
||||
argv++;
|
||||
|
||||
s = get_last_path_component(*argv);
|
||||
|
||||
if (argc>2) {
|
||||
argv++;
|
||||
n = strlen(*argv);
|
||||
m = strlen(s);
|
||||
if (m>=n && strncmp(s+m-n, *argv, n)==0)
|
||||
s[m-n] = '\0';
|
||||
}
|
||||
printf("%s\n", s);
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -4,10 +4,6 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef BB_INIT
|
||||
#undef BB_FEATURE_LINUXRC
|
||||
#endif
|
||||
|
||||
static int been_there_done_that = 0;
|
||||
|
||||
/* It has been alledged that doing such things can
|
||||
@@ -34,289 +30,466 @@ int atexit(void (*__func) (void))
|
||||
void *__libc_stack_end;
|
||||
#endif
|
||||
|
||||
const struct BB_applet applets[] = {
|
||||
|
||||
static const struct Applet applets[] = {
|
||||
|
||||
#ifdef BB_BUSYBOX //bin
|
||||
{"busybox", busybox_main},
|
||||
#ifdef BB_AR
|
||||
{"ar", ar_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_BLOCK_DEVICE //sbin
|
||||
{"block_device", block_device_main},
|
||||
#ifdef BB_BASENAME
|
||||
{"basename", basename_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CAT //bin
|
||||
{"cat", cat_main},
|
||||
{"busybox", busybox_main, _BB_DIR_BIN},
|
||||
#ifdef BB_CAT
|
||||
{"cat", cat_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP //bin
|
||||
{"chmod", chmod_chown_chgrp_main},
|
||||
{"chown", chmod_chown_chgrp_main},
|
||||
{"chgrp", chmod_chown_chgrp_main},
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CHROOT //sbin
|
||||
{"chroot", chroot_main},
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CLEAR //usr/bin
|
||||
{"clear", clear_main},
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chown", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CHVT //usr/bin
|
||||
{"chvt", chvt_main},
|
||||
#ifdef BB_CHROOT
|
||||
{"chroot", chroot_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_CP_MV //bin
|
||||
{"cp", cp_mv_main},
|
||||
{"mv", cp_mv_main},
|
||||
#ifdef BB_CLEAR
|
||||
{"clear", clear_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DATE //bin
|
||||
{"date", date_main},
|
||||
#ifdef BB_CHVT
|
||||
{"chvt", chvt_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DD //bin
|
||||
{"dd", dd_main},
|
||||
#ifdef BB_CP_MV
|
||||
{"cp", cp_mv_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DF //bin
|
||||
{"df", df_main},
|
||||
#ifdef BB_CUT
|
||||
{"cut", cut_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DMESG //bin
|
||||
{"dmesg", dmesg_main},
|
||||
#ifdef BB_DATE
|
||||
{"date", date_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DU //bin
|
||||
{"du", du_main},
|
||||
#ifdef BB_DC
|
||||
{"dc", dc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DUTMP //usr/sbin
|
||||
{"dutmp", dutmp_main},
|
||||
#ifdef BB_DD
|
||||
{"dd", dd_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FBSET //usr/sbin
|
||||
{"fbset", fbset_main},
|
||||
#ifdef BB_DF
|
||||
{"df", df_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FDFLUSH //bin
|
||||
{"fdflush", fdflush_main},
|
||||
#ifdef BB_DIRNAME
|
||||
{"dirname", dirname_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FIND //usr/bin
|
||||
{"find", find_main},
|
||||
#ifdef BB_DMESG
|
||||
{"dmesg", dmesg_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FREE //usr/bin
|
||||
{"free", free_main},
|
||||
#ifdef BB_DU
|
||||
{"du", du_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DEALLOCVT //usr/bin
|
||||
{"deallocvt", deallocvt_main},
|
||||
#ifdef BB_DUMPKMAP
|
||||
{"dumpkmap", dumpkmap_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FSCK_MINIX //sbin
|
||||
{"fsck.minix", fsck_minix_main},
|
||||
#ifdef BB_DUTMP
|
||||
{"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_MKFS_MINIX //sbin
|
||||
{"mkfs.minix", mkfs_minix_main},
|
||||
#ifdef BB_ECHO
|
||||
{"echo", echo_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_GREP //bin
|
||||
{"grep", grep_main},
|
||||
#ifdef BB_TRUE_FALSE
|
||||
{"false", false_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_HALT //sbin
|
||||
{"halt", halt_main},
|
||||
#ifdef BB_FBSET
|
||||
{"fbset", fbset_main, _BB_DIR_USR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_HEAD //bin
|
||||
{"head", head_main},
|
||||
#ifdef BB_FDFLUSH
|
||||
{"fdflush", fdflush_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_HOSTID //usr/bin
|
||||
{"hostid", hostid_main},
|
||||
#ifdef BB_FIND
|
||||
{"find", find_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_HOSTNAME //bin
|
||||
{"hostname", hostname_main},
|
||||
#ifdef BB_FREE
|
||||
{"free", free_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_INIT //sbin
|
||||
{"init", init_main},
|
||||
#ifdef BB_FREERAMDISK
|
||||
{"freeramdisk", freeramdisk_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_INSMOD //sbin
|
||||
{"insmod", insmod_main},
|
||||
#ifdef BB_DEALLOCVT
|
||||
{"deallocvt", deallocvt_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LINUXRC //
|
||||
{"linuxrc", init_main},
|
||||
#ifdef BB_FSCK_MINIX
|
||||
{"fsck.minix", fsck_minix_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_KILL //bin
|
||||
{"kill", kill_main},
|
||||
#ifdef BB_GREP
|
||||
{"grep", grep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LENGTH //usr/bin
|
||||
{"length", length_main},
|
||||
#ifdef BB_GUNZIP
|
||||
{"gunzip", gunzip_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LN //bin
|
||||
{"ln", ln_main},
|
||||
#ifdef BB_GZIP
|
||||
{"gzip", gzip_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOADACM //usr/bin
|
||||
{"loadacm", loadacm_main},
|
||||
#ifdef BB_HALT
|
||||
{"halt", halt_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_LOADFONT //usr/bin
|
||||
{"loadfont", loadfont_main},
|
||||
#ifdef BB_HEAD
|
||||
{"head", head_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOADKMAP //sbin
|
||||
{"loadkmap", loadkmap_main},
|
||||
#ifdef BB_HOSTID
|
||||
{"hostid", hostid_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LS //bin
|
||||
{"ls", ls_main},
|
||||
#ifdef BB_HOSTNAME
|
||||
{"hostname", hostname_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LSMOD //sbin
|
||||
{"lsmod", lsmod_main},
|
||||
#ifdef BB_ID
|
||||
{"id", id_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MAKEDEVS //sbin
|
||||
{"makedevs", makedevs_main},
|
||||
#ifdef BB_INIT
|
||||
{"init", init_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_MATH //usr/bin
|
||||
{"math", math_main},
|
||||
#ifdef BB_INSMOD
|
||||
{"insmod", insmod_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_MKDIR //bin
|
||||
{"mkdir", mkdir_main},
|
||||
#ifdef BB_KILL
|
||||
{"kill", kill_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKFIFO //usr/bin
|
||||
{"mkfifo", mkfifo_main},
|
||||
#ifdef BB_KILLALL
|
||||
{"killall", kill_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKNOD //bin
|
||||
{"mknod", mknod_main},
|
||||
#ifdef BB_LENGTH
|
||||
{"length", length_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKSWAP //sbin
|
||||
{"mkswap", mkswap_main},
|
||||
#ifdef BB_LINUXRC
|
||||
{"linuxrc", init_main, _BB_DIR_ROOT},
|
||||
#endif
|
||||
#ifdef BB_MNC //usr/bin
|
||||
{"mnc", mnc_main},
|
||||
#ifdef BB_LN
|
||||
{"ln", ln_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MORE //bin
|
||||
{"more", more_main},
|
||||
#ifdef BB_LOADACM
|
||||
{"loadacm", loadacm_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MOUNT //bin
|
||||
{"mount", mount_main},
|
||||
#ifdef BB_LOADFONT
|
||||
{"loadfont", loadfont_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MT //bin
|
||||
{"mt", mt_main},
|
||||
#ifdef BB_LOADKMAP
|
||||
{"loadkmap", loadkmap_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_NSLOOKUP //usr/bin
|
||||
{"nslookup", nslookup_main},
|
||||
#ifdef BB_LOGGER
|
||||
{"logger", logger_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_PING //bin
|
||||
{"ping", ping_main},
|
||||
#ifdef BB_LOGNAME
|
||||
{"logname", logname_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_POWEROFF //sbin
|
||||
{"poweroff", poweroff_main},
|
||||
#ifdef BB_LS
|
||||
{"ls", ls_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_PRINTF //usr/bin
|
||||
{"printf", printf_main},
|
||||
#ifdef BB_LSMOD
|
||||
{"lsmod", lsmod_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_PS //bin
|
||||
{"ps", ps_main},
|
||||
#ifdef BB_MAKEDEVS
|
||||
{"makedevs", makedevs_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_PWD //bin
|
||||
{"pwd", pwd_main},
|
||||
#ifdef BB_MD5SUM
|
||||
{"md5sum", md5sum_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_REBOOT //sbin
|
||||
{"reboot", reboot_main},
|
||||
#ifdef BB_MKDIR
|
||||
{"mkdir", mkdir_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_RM //bin
|
||||
{"rm", rm_main},
|
||||
#ifdef BB_MKFIFO
|
||||
{"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_RMDIR //bin
|
||||
{"rmdir", rmdir_main},
|
||||
#ifdef BB_MKFS_MINIX
|
||||
{"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_RMMOD //sbin
|
||||
{"rmmod", rmmod_main},
|
||||
#ifdef BB_MKNOD
|
||||
{"mknod", mknod_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SFDISK //sbin
|
||||
{"fdisk", sfdisk_main},
|
||||
{"sfdisk", sfdisk_main},
|
||||
#ifdef BB_MKSWAP
|
||||
{"mkswap", mkswap_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_SED //bin
|
||||
{"sed", sed_main},
|
||||
#ifdef BB_MKTEMP
|
||||
{"mktemp", mktemp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SLEEP //bin
|
||||
{"sleep", sleep_main},
|
||||
#ifdef BB_NC
|
||||
{"nc", nc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SORT //bin
|
||||
{"sort", sort_main},
|
||||
#ifdef BB_MORE
|
||||
{"more", more_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SYNC //bin
|
||||
{"sync", sync_main},
|
||||
#ifdef BB_MOUNT
|
||||
{"mount", mount_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SYSLOGD //sbin
|
||||
{"syslogd", syslogd_main},
|
||||
#ifdef BB_MT
|
||||
{"mt", mt_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOGGER //usr/bin
|
||||
{"logger", logger_main},
|
||||
#ifdef BB_CP_MV
|
||||
{"mv", cp_mv_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_LOGNAME //usr/bin
|
||||
{"logname", logname_main},
|
||||
#ifdef BB_NSLOOKUP
|
||||
{"nslookup", nslookup_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF //sbin
|
||||
{"swapon", swap_on_off_main},
|
||||
{"swapoff", swap_on_off_main},
|
||||
#ifdef BB_PING
|
||||
{"ping", ping_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TAIL //usr/bin
|
||||
{"tail", tail_main},
|
||||
#ifdef BB_POWEROFF
|
||||
{"poweroff", poweroff_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_TAR //bin
|
||||
{"tar", tar_main},
|
||||
#ifdef BB_PRINTF
|
||||
{"printf", printf_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEE //bin
|
||||
{"tee", tee_main},
|
||||
#ifdef BB_PS
|
||||
{"ps", ps_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TOUCH //usr/bin
|
||||
{"touch", touch_main},
|
||||
#ifdef BB_PWD
|
||||
{"pwd", pwd_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE //bin
|
||||
{"true", true_main},
|
||||
{"false", false_main},
|
||||
#ifdef BB_REBOOT
|
||||
{"reboot", reboot_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_TTY //usr/bin
|
||||
{"tty", tty_main},
|
||||
#ifdef BB_RM
|
||||
{"rm", rm_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNAME //bin
|
||||
{"uname", uname_main},
|
||||
#ifdef BB_RMDIR
|
||||
{"rmdir", rmdir_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UMOUNT //bin
|
||||
{"umount", umount_main},
|
||||
#ifdef BB_RMMOD
|
||||
{"rmmod", rmmod_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_UNIQ //bin
|
||||
{"uniq", uniq_main},
|
||||
#ifdef BB_SED
|
||||
{"sed", sed_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UPDATE //sbin
|
||||
{"update", update_main},
|
||||
#ifdef BB_SETKEYCODES
|
||||
{"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WC //usr/bin
|
||||
{"wc", wc_main},
|
||||
#ifdef BB_SH
|
||||
{"sh", shell_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WHOAMI //usr/bin
|
||||
{"whoami", whoami_main},
|
||||
#ifdef BB_SLEEP
|
||||
{"sleep", sleep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_YES //usr/bin
|
||||
{"yes", yes_main},
|
||||
#ifdef BB_SORT
|
||||
{"sort", sort_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_GUNZIP //bin
|
||||
{"zcat", gunzip_main},
|
||||
{"gunzip", gunzip_main},
|
||||
#ifdef BB_SYNC
|
||||
{"sync", sync_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_GZIP //bin
|
||||
{"gzip", gzip_main},
|
||||
#ifdef BB_SYSLOGD
|
||||
{"syslogd", syslogd_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF
|
||||
{"swapon", swap_on_off_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF
|
||||
{"swapoff", swap_on_off_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_TAIL
|
||||
{"tail", tail_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TAR
|
||||
{"tar", tar_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TELNET
|
||||
{"telnet", telnet_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEST
|
||||
{"test", test_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEE
|
||||
{"tee", tee_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TOUCH
|
||||
{"touch", touch_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TR
|
||||
{"tr", tr_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE
|
||||
{"true", true_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TTY
|
||||
{"tty", tty_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UMOUNT
|
||||
{"umount", umount_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNAME
|
||||
{"uname", uname_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UNIQ
|
||||
{"uniq", uniq_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UPDATE
|
||||
{"update", update_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_UPTIME
|
||||
{"uptime", uptime_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UUENCODE
|
||||
{"uuencode", uuencode_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UUDECODE
|
||||
{"uudecode", uudecode_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_USLEEP
|
||||
{"usleep", usleep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WC
|
||||
{"wc", wc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WHICH
|
||||
{"which", which_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WHOAMI
|
||||
{"whoami", whoami_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_YES
|
||||
{"yes", yes_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_GUNZIP
|
||||
{"zcat", gunzip_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_TEST
|
||||
{"[", test_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
{0}
|
||||
};
|
||||
|
||||
|
||||
#ifdef BB_FEATURE_INSTALLER
|
||||
/*
|
||||
* directory table
|
||||
* this should be consistent w/ the enum, internal.h::Location,
|
||||
* or else...
|
||||
*/
|
||||
static char* install_dir[] = {
|
||||
"/",
|
||||
"/bin",
|
||||
"/sbin",
|
||||
"/usr/bin",
|
||||
"/usr/sbin",
|
||||
};
|
||||
|
||||
/* abstract link() */
|
||||
typedef int (*__link_f)(const char *, const char *);
|
||||
|
||||
/*
|
||||
* Where in the filesystem is this busybox?
|
||||
* [return]
|
||||
* malloc'd string w/ full pathname of busybox's location
|
||||
* NULL on failure
|
||||
*/
|
||||
static char *busybox_fullpath()
|
||||
{
|
||||
pid_t pid;
|
||||
char path[256];
|
||||
char proc[256];
|
||||
int len;
|
||||
|
||||
pid = getpid();
|
||||
sprintf(proc, "/proc/%d/exe", pid);
|
||||
len = readlink(proc, path, 256);
|
||||
if (len != -1) {
|
||||
path[len] = 0;
|
||||
} else {
|
||||
fprintf(stderr, "busybox : %s : %s\n", proc, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
return strdup(path);
|
||||
}
|
||||
|
||||
/* create (sym)links for each applet */
|
||||
static int install_links(const char *busybox, int use_symbolic_links)
|
||||
{
|
||||
__link_f Link = link;
|
||||
|
||||
char command[256];
|
||||
int i;
|
||||
int rc = 0;
|
||||
|
||||
if (use_symbolic_links) Link = symlink;
|
||||
|
||||
for (i = 0; applets[i].name != NULL; i++) {
|
||||
sprintf (
|
||||
command,
|
||||
"%s/%s",
|
||||
install_dir[applets[i].location],
|
||||
applets[i].name
|
||||
);
|
||||
#if 1
|
||||
rc |= Link(busybox, command);
|
||||
#else
|
||||
puts(command);
|
||||
#endif
|
||||
if (rc) {
|
||||
fprintf(stderr,"busybox : %s : %s\n", command, strerror(errno));
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int uninstall_links() ?
|
||||
#endif
|
||||
#endif /* BB_FEATURE_INSTALLER */
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *s = argv[0];
|
||||
char *name = argv[0];
|
||||
const struct Applet *a = applets;
|
||||
char *s;
|
||||
char *name;
|
||||
const struct BB_applet *a = applets;
|
||||
|
||||
while (*s != '\0') {
|
||||
#ifdef BB_FEATURE_INSTALLER
|
||||
/*
|
||||
* This style of argument parsing doesn't scale well
|
||||
* in the event that busybox starts wanting more --options.
|
||||
* If someone has a cleaner approach, by all means implement it.
|
||||
*/
|
||||
if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
|
||||
int use_symbolic_links = 0;
|
||||
int rc = 0;
|
||||
char *busybox;
|
||||
|
||||
/* to use symlinks, or not to use symlinks... */
|
||||
if (argc > 2) {
|
||||
if ((strcmp(argv[2], "-s") == 0)) {
|
||||
use_symbolic_links = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* link */
|
||||
busybox = busybox_fullpath();
|
||||
if (busybox) {
|
||||
install_links(busybox, use_symbolic_links);
|
||||
free(busybox);
|
||||
} else {
|
||||
rc = 1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
#endif /* BB_FEATURE_INSTALLER */
|
||||
|
||||
for (s = name = argv[0]; *s != '\0';) {
|
||||
if (*s++ == '/')
|
||||
name = s;
|
||||
}
|
||||
|
||||
*argv = name;
|
||||
|
||||
#ifdef BB_SH
|
||||
/* Add in a special case hack -- whenever **argv == '-'
|
||||
* (i.e. '-su' or '-sh') always invoke the shell */
|
||||
if (**argv == '-')
|
||||
exit(((*(shell_main)) (argc, argv)));
|
||||
#endif
|
||||
|
||||
while (a->name != 0) {
|
||||
if (strcmp(name, a->name) == 0) {
|
||||
int status;
|
||||
|
||||
status = ((*(a->main)) (argc, argv));
|
||||
if (status < 0) {
|
||||
fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
exit(status);
|
||||
exit(((*(a->main)) (argc, argv)));
|
||||
}
|
||||
a++;
|
||||
}
|
||||
exit(busybox_main(argc, argv));
|
||||
return(busybox_main(argc, argv));
|
||||
}
|
||||
|
||||
|
||||
@@ -328,16 +501,16 @@ int busybox_main(int argc, char **argv)
|
||||
argv++;
|
||||
|
||||
if (been_there_done_that == 1 || argc < 1) {
|
||||
const struct Applet *a = applets;
|
||||
const struct BB_applet *a = applets;
|
||||
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
|
||||
BB_VER, BB_BT);
|
||||
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
|
||||
fprintf(stderr, " or: [function] [arguments]...\n\n");
|
||||
fprintf(stderr,
|
||||
"\tMost people will create a symlink to busybox for each\n"
|
||||
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
|
||||
fprintf(stderr, "\nCurrently defined functions:\n");
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n"
|
||||
"Usage: busybox [function] [arguments]...\n"
|
||||
" or: [function] [arguments]...\n\n"
|
||||
"\tBusyBox is a multi-call binary that combines many common Unix\n"
|
||||
"\tutilities into a single executable. Most people will create a\n"
|
||||
"\tlink to busybox for each function they wish to use, and BusyBox\n"
|
||||
"\twill act like whatever it was invoked as.\n"
|
||||
"\nCurrently defined functions:\n", BB_VER, BB_BT);
|
||||
|
||||
while (a->name != 0) {
|
||||
col +=
|
||||
@@ -350,9 +523,16 @@ int busybox_main(int argc, char **argv)
|
||||
}
|
||||
fprintf(stderr, "\n\n");
|
||||
exit(-1);
|
||||
} else {
|
||||
/* If we've already been here once, exit now */
|
||||
been_there_done_that = 1;
|
||||
return (main(argc, argv));
|
||||
}
|
||||
/* If we've already been here once, exit now */
|
||||
been_there_done_that = 1;
|
||||
return (main(argc, argv));
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+194
-40
@@ -7,71 +7,78 @@
|
||||
//
|
||||
//
|
||||
// BusyBox Applications
|
||||
#define BB_BUSYBOX
|
||||
#define BB_AR
|
||||
#define BB_BASENAME
|
||||
#define BB_CAT
|
||||
#define BB_CHMOD_CHOWN_CHGRP
|
||||
#define BB_CHROOT
|
||||
#define BB_CHVT
|
||||
#define BB_CLEAR
|
||||
#define BB_CP_MV
|
||||
#define BB_CUT
|
||||
#define BB_DATE
|
||||
#define BB_DC
|
||||
#define BB_DD
|
||||
#define BB_DEALLOCVT
|
||||
#define BB_DF
|
||||
#define BB_DIRNAME
|
||||
#define BB_DMESG
|
||||
//#define BB_DUTMP
|
||||
#define BB_DUTMP
|
||||
#define BB_DU
|
||||
#define BB_DUMPKMAP
|
||||
#define BB_ECHO
|
||||
#define BB_FBSET
|
||||
//#define BB_FDFLUSH
|
||||
#define BB_FDFLUSH
|
||||
#define BB_FIND
|
||||
#define BB_FREE
|
||||
#define BB_FREERAMDISK
|
||||
#define BB_FSCK_MINIX
|
||||
#define BB_GREP
|
||||
#define BB_GUNZIP
|
||||
#define BB_GZIP
|
||||
//#define BB_HALT
|
||||
#define BB_HALT
|
||||
#define BB_HEAD
|
||||
//#define BB_HOSTID
|
||||
#define BB_HOSTID
|
||||
#define BB_HOSTNAME
|
||||
#define BB_ID
|
||||
#define BB_INIT
|
||||
// Don't turn BB_INSMOD on. It doesn't work.
|
||||
//#define BB_INSMOD
|
||||
#define BB_INSMOD
|
||||
#define BB_KILL
|
||||
#define BB_KLOGD
|
||||
//#define BB_LENGTH
|
||||
#define BB_KILLALL
|
||||
#define BB_LENGTH
|
||||
#define BB_LN
|
||||
//#define BB_LOADACM
|
||||
//#define BB_LOADFONT
|
||||
//#define BB_LOADKMAP
|
||||
//#define BB_LOGGER
|
||||
#define BB_LOADACM
|
||||
#define BB_LOADFONT
|
||||
#define BB_LOADKMAP
|
||||
#define BB_LOGGER
|
||||
#define BB_LOGNAME
|
||||
#define BB_LS
|
||||
#define BB_LSMOD
|
||||
//#define BB_MAKEDEVS
|
||||
#define BB_MKFS_MINIX
|
||||
//#define BB_MATH
|
||||
#define BB_MAKEDEVS
|
||||
#define BB_MD5SUM
|
||||
#define BB_MKDIR
|
||||
//#define BB_MKFIFO
|
||||
#define BB_MKFIFO
|
||||
#define BB_MKFS_MINIX
|
||||
#define BB_MKNOD
|
||||
#define BB_MKSWAP
|
||||
//#define BB_MNC
|
||||
#define BB_MKTEMP
|
||||
#define BB_NC
|
||||
#define BB_MORE
|
||||
#define BB_MOUNT
|
||||
#define BB_NFSMOUNT
|
||||
//#define BB_MT
|
||||
#define BB_MT
|
||||
#define BB_NSLOOKUP
|
||||
#define BB_PING
|
||||
#define BB_POWEROFF
|
||||
//#define BB_PRINTF
|
||||
#define BB_PRINTF
|
||||
#define BB_PS
|
||||
#define BB_PWD
|
||||
#define BB_REBOOT
|
||||
#define BB_REGEXP
|
||||
#define BB_RM
|
||||
#define BB_RMDIR
|
||||
//#define BB_RMMOD
|
||||
#define BB_RMMOD
|
||||
#define BB_SED
|
||||
//#define BB_SFDISK
|
||||
#define BB_SETKEYCODES
|
||||
#define BB_SH
|
||||
#define BB_SLEEP
|
||||
#define BB_SORT
|
||||
#define BB_SWAPONOFF
|
||||
@@ -80,11 +87,19 @@
|
||||
#define BB_TAIL
|
||||
#define BB_TAR
|
||||
#define BB_TEE
|
||||
#define BB_TEST
|
||||
#define BB_TELNET
|
||||
#define BB_TOUCH
|
||||
#define BB_TR
|
||||
#define BB_TRUE_FALSE
|
||||
#define BB_TTY
|
||||
#define BB_UPTIME
|
||||
#define BB_USLEEP
|
||||
#define BB_WC
|
||||
#define BB_WHICH
|
||||
#define BB_WHOAMI
|
||||
#define BB_UUENCODE
|
||||
#define BB_UUDECODE
|
||||
#define BB_UMOUNT
|
||||
#define BB_UNIQ
|
||||
#define BB_UNAME
|
||||
@@ -94,16 +109,42 @@
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------
|
||||
// This is where feature definitions go. Generally speaking,
|
||||
// turning this stuff off makes things a bit smaller (and less
|
||||
// pretty/useful).
|
||||
//
|
||||
//
|
||||
//
|
||||
// Turn this on to use Erik's very cool devps, devmtab, etc kernel drivers,
|
||||
// thereby eliminating the need for the /proc filesystem and thereby saving
|
||||
// lots and lots memory for more important things. You can not use this and
|
||||
// USE_PROCFS at the same time... NOTE: If you enable this feature, you
|
||||
// _must_ have patched the kernel to include the devps patch that is included
|
||||
// in the busybox/kernel-patches directory. You will also need to create some
|
||||
// device special files /dev on your embedded system:
|
||||
// mknod /dev/modules c 10 23
|
||||
// mknod /dev/mtab c 10 22
|
||||
// mknod /dev/ps c 10 21
|
||||
// I emailed Linus and this patch will not be going into the stock kernel.
|
||||
//#define BB_FEATURE_USE_DEVPS_PATCH
|
||||
//
|
||||
// enable features that use the /proc filesystem (apps that
|
||||
// break without this will tell you on compile)...
|
||||
// You can't use this and BB_FEATURE_USE_DEVPS_PATCH
|
||||
// at the same time...
|
||||
#define BB_FEATURE_USE_PROCFS
|
||||
//
|
||||
// Enable full regular expressions. This adds about
|
||||
// 4k. When this is off, things that would normally
|
||||
// use regualr expressions (like grep) will just use
|
||||
// normal strings.
|
||||
#define BB_FEATURE_FULL_REGULAR_EXPRESSIONS
|
||||
//
|
||||
// This compiles out everything but the most
|
||||
// trivial --help usage information (i.e. reduces binary size)
|
||||
//#define BB_FEATURE_TRIVIAL_HELP
|
||||
//
|
||||
// Use termios to manipulate the screen ('more' is prettier with this on)
|
||||
#define BB_FEATURE_USE_TERMIOS
|
||||
//
|
||||
@@ -111,23 +152,39 @@
|
||||
#define BB_FEATURE_AUTOWIDTH
|
||||
//
|
||||
// show username/groupnames (bypasses libc6 NSS) for ls
|
||||
#define BB_FEATURE_LS_USERNAME
|
||||
#define BB_FEATURE_LS_USERNAME
|
||||
//
|
||||
// show file timestamps in ls
|
||||
#define BB_FEATURE_LS_TIMESTAMPS
|
||||
//
|
||||
// enable ls -p and -F
|
||||
#define BB_FEATURE_LS_FILETYPES
|
||||
#define BB_FEATURE_LS_FILETYPES
|
||||
//
|
||||
// enable ls -R
|
||||
#define BB_FEATURE_LS_RECURSIVE
|
||||
//
|
||||
// Change ping implementation -- simplified, featureless, but really small.
|
||||
//#define BB_SIMPLE_PING
|
||||
////
|
||||
//#define BB_FEATURE_SIMPLE_PING
|
||||
//
|
||||
// Make init use a simplified /etc/inittab file (recommended).
|
||||
#define BB_FEATURE_USE_INITTAB
|
||||
//
|
||||
//Enable init being called as /linuxrc
|
||||
//#define BB_FEATURE_LINUXRC
|
||||
//
|
||||
//Have init enable core dumping for child processes (for debugging only)
|
||||
//#define BB_FEATURE_INIT_COREDUMPS
|
||||
//
|
||||
// Allow init to permenently chroot, and umount the old root fs
|
||||
// just like an initrd does. Requires a kernel patch by Werner Almesberger.
|
||||
// ftp://icaftp.epfl.ch/pub/people/almesber/misc/umount-root-*.tar.gz
|
||||
//#define BB_FEATURE_INIT_CHROOT
|
||||
//
|
||||
//Make sure nothing is printed to the console on boot
|
||||
#define BB_FEATURE_EXTRA_QUIET
|
||||
//
|
||||
//Should syslogd also provide klogd support?
|
||||
#define BB_FEATURE_KLOGD
|
||||
//
|
||||
//Simple tail implementation (2k vs 6k for the full one). Still
|
||||
//provides 'tail -f' support -- but for only one file at a time.
|
||||
@@ -137,21 +194,118 @@
|
||||
#define BB_FEATURE_MOUNT_LOOP
|
||||
//
|
||||
// Enable support for a real /etc/mtab file instead of /proc/mounts
|
||||
#ifdef BB_MOUNT
|
||||
//#define BB_MTAB
|
||||
#endif
|
||||
//#define BB_FEATURE_MOUNT_MTAB_SUPPORT
|
||||
//
|
||||
// Enable support for mounting remote NFS volumes
|
||||
// (This does not yet work with Linux 2.[34].x kernels)
|
||||
#define BB_FEATURE_NFSMOUNT
|
||||
//
|
||||
// Enable support for remounting filesystems
|
||||
#define BB_FEATURE_REMOUNT
|
||||
// Enable support forced filesystem unmounting
|
||||
// (i.e. in case of an unreachable NFS system).
|
||||
#define BB_FEATURE_MOUNT_FORCE
|
||||
//
|
||||
// Enable support for creation of tar files.
|
||||
//#define BB_FEATURE_TAR_CREATE
|
||||
#define BB_FEATURE_TAR_CREATE
|
||||
//
|
||||
// Allow init to permenently chroot, and umount the old root fs
|
||||
// just like an initrd does. Requires a kernel patch by Werner Almesberger.
|
||||
// ftp://icaftp.epfl.ch/pub/people/almesber/misc/umount-root-*.tar.gz
|
||||
#ifdef BB_MOUNT
|
||||
#define BB_FEATURE_INIT_CHROOT
|
||||
// Enable support for "--exclude" for excluding files
|
||||
#define BB_FEATURE_TAR_EXCLUDE
|
||||
//
|
||||
//// Enable reverse sort
|
||||
#define BB_FEATURE_SORT_REVERSE
|
||||
//
|
||||
// Enable command line editing in the shell
|
||||
#define BB_FEATURE_SH_COMMAND_EDITING
|
||||
//
|
||||
//Allow the shell to invoke all the compiled in BusyBox commands as if they
|
||||
//were shell builtins. Nice for staticly linking an emergency rescue shell
|
||||
//amoung other thing.
|
||||
#define BB_FEATURE_SH_STANDALONE_SHELL
|
||||
//
|
||||
// Enable tab completion in the shell (not yet
|
||||
// working very well -- so don't turn this on)
|
||||
//#define BB_FEATURE_SH_TAB_COMPLETION
|
||||
//
|
||||
//Turn on extra fbset options
|
||||
//#define BB_FEATURE_FBSET_FANCY
|
||||
//
|
||||
//Turn on fbset readmode support
|
||||
//#define BB_FEATURE_FBSET_READMODE
|
||||
//
|
||||
// You must enable one or both of these features
|
||||
// Support installing modules from pre 2.1 kernels
|
||||
//#define BB_FEATURE_INSMOD_OLD_KERNEL
|
||||
// Support installing modules from kernel versions after 2.1.18
|
||||
#define BB_FEATURE_INSMOD_NEW_KERNEL
|
||||
//
|
||||
// Support module version checking
|
||||
//#define BB_FEATURE_INSMOD_VERSION_CHECKING
|
||||
//
|
||||
//
|
||||
// Enable busybox --install [-s]
|
||||
// to create links (or symlinks) for all the commands that are
|
||||
// compiled into the binary. (needs /proc filesystem)
|
||||
// #define BB_FEATURE_INSTALLER
|
||||
//
|
||||
// End of Features List
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------
|
||||
// Nothing beyond this point should ever be touched by
|
||||
// mere mortals so leave this stuff alone.
|
||||
//
|
||||
#ifdef BB_FEATURE_MOUNT_MTAB_SUPPORT
|
||||
#define BB_MTAB
|
||||
#endif
|
||||
//
|
||||
#if defined BB_FEATURE_FULL_REGULAR_EXPRESSIONS && (defined BB_SED || defined BB_GREP )
|
||||
#define BB_REGEXP
|
||||
#endif
|
||||
//
|
||||
#if defined BB_FEATURE_SH_COMMAND_EDITING && defined BB_SH
|
||||
#define BB_CMDEDIT
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_KILLALL
|
||||
#ifndef BB_KILL
|
||||
#define BB_KILL
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_FEATURE_LINUXRC
|
||||
#ifndef BB_INIT
|
||||
#define BB_INIT
|
||||
#define BB_LINUXRC
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_GZIP
|
||||
#ifndef BB_GUNZIP
|
||||
#define BB_GUNZIP
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#if defined BB_MOUNT && defined BB_FEATURE_NFSMOUNT
|
||||
#define BB_NFSMOUNT
|
||||
#endif
|
||||
//
|
||||
#if defined BB_FEATURE_SH_COMMAND_EDITING
|
||||
#ifndef BB_FEATURE_USE_TERMIOS
|
||||
#define BB_FEATURE_USE_TERMIOS
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#if defined BB_FEATURE_AUTOWIDTH
|
||||
#ifndef BB_FEATURE_USE_TERMIOS
|
||||
#define BB_FEATURE_USE_TERMIOS
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#if defined BB_INSMOD
|
||||
#ifndef BB_FEATURE_INSMOD_OLD_KERNEL
|
||||
#define BB_FEATURE_INSMOD_NEW_KERNEL
|
||||
#endif
|
||||
#endif
|
||||
+10
-6
@@ -4,12 +4,16 @@
|
||||
DF="busybox.def.h"
|
||||
MF="busybox.c"
|
||||
|
||||
LIST="$(sed -n '/^#define/{s/^#define //p;}' $DF)"
|
||||
LIST="$(gcc -E -dM $DF | sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/BB_\1/gp;' | sort)"
|
||||
|
||||
for def in ${LIST}; do
|
||||
i=`sed -n 's/^#ifdef \<'$def'\>.*\/\/\(.*$\)/\/\1\//gp' $MF`
|
||||
j=`sed -n '/^#ifdef \<'$def'\>.*/,/^#endif/{ s/.*\"\(.*\)\".*/\1/gp; }' $MF`
|
||||
for k in $j; do
|
||||
echo $i$k
|
||||
done
|
||||
i=`sed -n '/^#ifdef \<'$def'\>.*/,/^#endif/{ s/.*\"\(.*\)\".*\(_BB_DIR_[A-Z_]*\).*$/\2\/\1/gp; }' $MF`
|
||||
for j in $i; do
|
||||
if [ -z $j ] ; then
|
||||
continue;
|
||||
fi;
|
||||
echo $j | sed -e 's/_BB_DIR_ROOT//g;s/_BB_DIR_BIN/\/bin/g;' \
|
||||
-e 's/_BB_DIR_SBIN/\/sbin/g;s/_BB_DIR_USR_BIN/\/usr\/bin/g;' \
|
||||
-e 's/_BB_DIR_USR_SBIN/\/usr\/sbin/g;'
|
||||
done;
|
||||
done
|
||||
+8
-2
@@ -1,4 +1,10 @@
|
||||
#!/bin/sh
|
||||
ls -1 `sed -n '/^#define/{s/.*BB_// ; s/$/.c/p; }' busybox.def.h | \
|
||||
tr [:upper:] [:lower:]` 2> /dev/null | sed -e 's/\.c$/\.o/g'
|
||||
|
||||
# I added in the extra "ls" so only source files that
|
||||
# actually exist will show up in the compile list.
|
||||
ls -1 ` \
|
||||
gcc -E -dM busybox.def.h | \
|
||||
sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/\1.c/gp;' \
|
||||
| tr [:upper:] [:lower:] | sort
|
||||
` 2>/dev/null | sed -e 's/\.c$/\.o/g'
|
||||
|
||||
+8
-7
@@ -1,5 +1,5 @@
|
||||
Name: busybox
|
||||
Version: 0.42
|
||||
Version: 0.46
|
||||
Release: 1
|
||||
Group: System/Utilities
|
||||
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
||||
@@ -10,12 +10,13 @@ Buildroot: /tmp/%{Name}-%{Version}
|
||||
Source: %{Name}-%{Version}.tar.gz
|
||||
|
||||
%Description
|
||||
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
|
||||
provides a pretty complete POSIX environment in a very small package.
|
||||
Just add a kernel, "ash" (Keith Almquists tiny Bourne shell clone), and
|
||||
an editor such as "elvis-tiny" or "ae", and you have a full system. This
|
||||
is makes an excellent environment for a "rescue" disk or any small or
|
||||
embedded system.
|
||||
BusyBox combines tiny versions of many common UNIX utilities into a single
|
||||
small executable. It provides minimalist replacements for most of the utilities
|
||||
you usually find in fileutils, shellutils, findutils, textutils, grep, gzip,
|
||||
tar, etc. BusyBox provides a fairly complete POSIX environment for any small
|
||||
or emdedded system. The utilities in BusyBox generally have fewer options then
|
||||
their full featured GNU cousins; however, the options that are provided behave
|
||||
very much like their GNU counterparts.
|
||||
|
||||
%Prep
|
||||
%setup -q -n %{Name}-%{Version}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini Cat implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -45,7 +45,11 @@ extern int cat_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (**(argv + 1) == '-') {
|
||||
usage("cat [file ...]\n");
|
||||
usage("cat [FILE ...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nConcatenates FILE(s) and prints them to the standard output.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
argc--;
|
||||
|
||||
@@ -57,5 +61,13 @@ extern int cat_main(int argc, char **argv)
|
||||
}
|
||||
print_file(file);
|
||||
}
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+53
-35
@@ -3,7 +3,7 @@
|
||||
* Mini chown/chmod/chgrp implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "internal.h"
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_invalid_option
|
||||
#define bb_need_too_few_args
|
||||
#include "messages.c"
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -32,8 +33,8 @@
|
||||
#include <pwd.h>
|
||||
|
||||
|
||||
static uid_t uid = -1;
|
||||
static gid_t gid = -1;
|
||||
static unsigned long uid = -1;
|
||||
static unsigned long gid = -1;
|
||||
static int whichApp;
|
||||
static char *invocationName = NULL;
|
||||
static char *theMode = NULL;
|
||||
@@ -43,24 +44,30 @@ static char *theMode = NULL;
|
||||
#define CHOWN_APP 2
|
||||
#define CHMOD_APP 3
|
||||
|
||||
static const char chgrp_usage[] = "chgrp [OPTION]... GROUP FILE...\n\n"
|
||||
"Change the group membership of each FILE to GROUP.\n"
|
||||
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively\n";
|
||||
static const char chgrp_usage[] = "chgrp [OPTION]... GROUP FILE...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nChange the group membership of each FILE to GROUP.\n"
|
||||
"\nOptions:\n\t-R\tChanges files and directories recursively.\n"
|
||||
#endif
|
||||
;
|
||||
static const char chown_usage[] =
|
||||
"chown [OPTION]... OWNER[.[GROUP] FILE...\n\n"
|
||||
"Change the owner and/or group of each FILE to OWNER and/or GROUP.\n"
|
||||
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively\n";
|
||||
"chown [OPTION]... OWNER[<.|:>[GROUP] FILE...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nChange the owner and/or group of each FILE to OWNER and/or GROUP.\n"
|
||||
"\nOptions:\n\t-R\tChanges files and directories recursively.\n"
|
||||
#endif
|
||||
;
|
||||
static const char chmod_usage[] =
|
||||
"chmod [-R] MODE[,MODE]... FILE...\n\n"
|
||||
"Each MODE is one or more of the letters ugoa, one of the symbols +-= and\n"
|
||||
|
||||
"chmod [-R] MODE[,MODE]... FILE...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nEach MODE is one or more of the letters ugoa, one of the symbols +-= and\n"
|
||||
"one or more of the letters rwxst.\n\n"
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively.\n";
|
||||
"\nOptions:\n\t-R\tChanges files and directories recursively.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
static int fileAction(const char *fileName, struct stat *statbuf)
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
switch (whichApp) {
|
||||
case CHGRP_APP:
|
||||
@@ -94,40 +101,42 @@ static int fileAction(const char *fileName, struct stat *statbuf)
|
||||
int chmod_chown_chgrp_main(int argc, char **argv)
|
||||
{
|
||||
int recursiveFlag = FALSE;
|
||||
char *groupName;
|
||||
char *p;
|
||||
char *groupName=NULL;
|
||||
char *p=NULL;
|
||||
const char *appUsage;
|
||||
|
||||
whichApp =
|
||||
(strcmp(*argv, "chown") == 0)?
|
||||
whichApp = (strcmp(*argv, "chown") == 0)?
|
||||
CHOWN_APP : (strcmp(*argv, "chmod") == 0)?
|
||||
CHMOD_APP : CHGRP_APP;
|
||||
|
||||
appUsage =
|
||||
(whichApp == CHOWN_APP)?
|
||||
appUsage = (whichApp == CHOWN_APP)?
|
||||
chown_usage : (whichApp == CHMOD_APP) ? chmod_usage : chgrp_usage;
|
||||
|
||||
if (argc < 2)
|
||||
usage(appUsage);
|
||||
invocationName = *argv;
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
while (--argc >= 0 && *argv && (**argv == '-')) {
|
||||
while (*++(*argv)) {
|
||||
switch (**argv) {
|
||||
case 'R':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, invalid_option, invocationName, **argv);
|
||||
usage(appUsage);
|
||||
case 'R':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, invalid_option, invocationName, **argv);
|
||||
usage(appUsage);
|
||||
}
|
||||
argc--;
|
||||
}
|
||||
argv++;
|
||||
}
|
||||
|
||||
if (argc == 0 || *argv == NULL) {
|
||||
fprintf(stderr, too_few_args, invocationName);
|
||||
usage(appUsage);
|
||||
}
|
||||
|
||||
if (whichApp == CHMOD_APP) {
|
||||
theMode = *argv;
|
||||
} else {
|
||||
@@ -142,6 +151,8 @@ int chmod_chown_chgrp_main(int argc, char **argv)
|
||||
goto bad_group;
|
||||
} else {
|
||||
groupName = strchr(*argv, '.');
|
||||
if (groupName == NULL)
|
||||
groupName = strchr(*argv, ':');
|
||||
if (groupName) {
|
||||
*groupName++ = '\0';
|
||||
gid = strtoul(groupName, &p, 10);
|
||||
@@ -171,9 +182,8 @@ int chmod_chown_chgrp_main(int argc, char **argv)
|
||||
fatalError( "%s: too few arguments\n", invocationName);
|
||||
}
|
||||
while (argc-- > 1) {
|
||||
if (recursiveAction
|
||||
(*(++argv), recursiveFlag, TRUE, FALSE, fileAction,
|
||||
fileAction) == FALSE)
|
||||
if (recursiveAction (*(++argv), recursiveFlag, FALSE, FALSE,
|
||||
fileAction, fileAction, NULL) == FALSE)
|
||||
exit(FALSE);
|
||||
}
|
||||
exit(TRUE);
|
||||
@@ -181,3 +191,11 @@ int chmod_chown_chgrp_main(int argc, char **argv)
|
||||
bad_group:
|
||||
fatalError( "%s: unknown group name: %s\n", invocationName, groupName);
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -3,7 +3,7 @@
|
||||
* Mini chroot implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -28,14 +28,18 @@
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n\n"
|
||||
|
||||
"Run COMMAND with root directory set to NEWROOT.\n";
|
||||
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nRun COMMAND with root directory set to NEWROOT.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
int chroot_main(int argc, char **argv)
|
||||
{
|
||||
char *prog;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage(chroot_usage);
|
||||
}
|
||||
@@ -43,25 +47,31 @@ int chroot_main(int argc, char **argv)
|
||||
argv++;
|
||||
|
||||
if (chroot(*argv) || (chdir("/"))) {
|
||||
fprintf(stderr, "chroot: cannot change root directory to %s: %s\n",
|
||||
fatalError("chroot: cannot change root directory to %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc >= 1) {
|
||||
fprintf(stderr, "command: %s\n", *argv);
|
||||
prog = *argv;
|
||||
execvp(*argv, argv);
|
||||
} else {
|
||||
char *prog;
|
||||
|
||||
prog = getenv("SHELL");
|
||||
if (!prog)
|
||||
prog = "/bin/sh";
|
||||
execlp(prog, prog, NULL);
|
||||
}
|
||||
fprintf(stderr, "chroot: cannot execute %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit(FALSE);
|
||||
fatalError("chroot: cannot execute %s: %s\n",
|
||||
prog, strerror(errno));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -5,22 +5,27 @@
|
||||
* busyboxed by Erik Andersen
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/vt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
/* From <linux/vt.h> */
|
||||
#define VT_ACTIVATE 0x5606 /* make vt active */
|
||||
#define VT_WAITACTIVE 0x5607 /* wait for vt active */
|
||||
|
||||
extern int getfd(void);
|
||||
|
||||
int chvt_main(int argc, char **argv)
|
||||
{
|
||||
int fd, num;
|
||||
|
||||
if ((argc != 2) || (**(argv + 1) == '-')) {
|
||||
usage
|
||||
("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
|
||||
usage ("chvt N\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nChanges the foreground virtual terminal to /dev/ttyN\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
fd = get_console_fd("/dev/console");
|
||||
num = atoi(argv[1]);
|
||||
@@ -32,5 +37,14 @@ int chvt_main(int argc, char **argv)
|
||||
perror("VT_WAITACTIVE");
|
||||
exit(FALSE);
|
||||
}
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -3,7 +3,7 @@
|
||||
* Mini clear implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -29,5 +29,5 @@
|
||||
extern int clear_main(int argc, char **argv)
|
||||
{
|
||||
printf("\033[H\033[J");
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -0,0 +1,700 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Termios command line History and Editting, originally
|
||||
* intended for NetBSD sh (ash)
|
||||
* Copyright (c) 1999
|
||||
* Main code: Adam Rogoyski <rogoyski@cs.utexas.edu>
|
||||
* Etc: Dave Cinege <dcinege@psychosis.com>
|
||||
* Majorly adjusted/re-written for busybox:
|
||||
* Erik Andersen <andersee@debian.org>
|
||||
*
|
||||
* You may use this code as you wish, so long as the original author(s)
|
||||
* are attributed in any redistributions of the source code.
|
||||
* This code is 'as is' with no warranty.
|
||||
* This code may safely be consumed by a BSD or GPL license.
|
||||
*
|
||||
* v 0.5 19990328 Initial release
|
||||
*
|
||||
* Future plans: Simple file and path name completion. (like BASH)
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Usage and Known bugs:
|
||||
Terminal key codes are not extensive, and more will probably
|
||||
need to be added. This version was created on Debian GNU/Linux 2.x.
|
||||
Delete, Backspace, Home, End, and the arrow keys were tested
|
||||
to work in an Xterm and console. Ctrl-A also works as Home.
|
||||
Ctrl-E also works as End. The binary size increase is <3K.
|
||||
|
||||
Editting will not display correctly for lines greater then the
|
||||
terminal width. (more then one line.) However, history will.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#ifdef BB_FEATURE_SH_COMMAND_EDITING
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <ctype.h>
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
#define MAX_HISTORY 15 /* Maximum length of the linked list for the command line history */
|
||||
|
||||
#define ESC 27
|
||||
#define DEL 127
|
||||
#define member(c, s) ((c) ? ((char *)strchr ((s), (c)) != (char *)NULL) : 0)
|
||||
#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
|
||||
|
||||
static struct history *his_front = NULL; /* First element in command line list */
|
||||
static struct history *his_end = NULL; /* Last element in command line list */
|
||||
|
||||
/* ED: sparc termios is broken: revert back to old termio handling. */
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
|
||||
#if #cpu(sparc)
|
||||
# include <termio.h>
|
||||
# define termios termio
|
||||
# define setTermSettings(fd,argp) ioctl(fd,TCSETAF,argp)
|
||||
# define getTermSettings(fd,argp) ioctl(fd,TCGETA,argp)
|
||||
#else
|
||||
# include <termios.h>
|
||||
# define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp)
|
||||
# define getTermSettings(fd,argp) tcgetattr(fd, argp);
|
||||
#endif
|
||||
|
||||
/* Current termio and the previous termio before starting sh */
|
||||
struct termios initial_settings, new_settings;
|
||||
|
||||
|
||||
#ifndef _POSIX_VDISABLE
|
||||
#define _POSIX_VDISABLE '\0'
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
static int cmdedit_termw = 80; /* actual terminal width */
|
||||
static int cmdedit_scroll = 27; /* width of EOL scrolling region */
|
||||
static int history_counter = 0; /* Number of commands in history list */
|
||||
static int reset_term = 0; /* Set to true if the terminal needs to be reset upon exit */
|
||||
|
||||
struct history {
|
||||
char *s;
|
||||
struct history *p;
|
||||
struct history *n;
|
||||
};
|
||||
|
||||
#define xwrite write
|
||||
|
||||
void
|
||||
cmdedit_setwidth(int w)
|
||||
{
|
||||
if (w > 20) {
|
||||
cmdedit_termw = w;
|
||||
cmdedit_scroll = w / 3;
|
||||
} else {
|
||||
errorMsg("\n*** Error: minimum screen width is 21\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void cmdedit_reset_term(void)
|
||||
{
|
||||
if (reset_term)
|
||||
/* sparc and other have broken termios support: use old termio handling. */
|
||||
setTermSettings(fileno(stdin), (void*) &initial_settings);
|
||||
}
|
||||
|
||||
void clean_up_and_die(int sig)
|
||||
{
|
||||
cmdedit_reset_term();
|
||||
fprintf(stdout, "\n");
|
||||
if (sig!=SIGINT)
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/* Go to HOME position */
|
||||
void input_home(int outputFd, int *cursor)
|
||||
{
|
||||
while (*cursor > 0) {
|
||||
xwrite(outputFd, "\b", 1);
|
||||
--*cursor;
|
||||
}
|
||||
}
|
||||
|
||||
/* Go to END position */
|
||||
void input_end(int outputFd, int *cursor, int len)
|
||||
{
|
||||
while (*cursor < len) {
|
||||
xwrite(outputFd, "\033[C", 3);
|
||||
++*cursor;
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete the char in back of the cursor */
|
||||
void input_backspace(char* command, int outputFd, int *cursor, int *len)
|
||||
{
|
||||
int j = 0;
|
||||
|
||||
/* Debug crap */
|
||||
//fprintf(stderr, "\nerik: len=%d, cursor=%d, strlen(command)='%d'\n", *len, *cursor, strlen(command));
|
||||
//xwrite(outputFd, command, *len);
|
||||
//*cursor = *len;
|
||||
|
||||
|
||||
if (*cursor > 0) {
|
||||
xwrite(outputFd, "\b \b", 3);
|
||||
--*cursor;
|
||||
memmove(command + *cursor, command + *cursor + 1,
|
||||
BUFSIZ - *cursor + 1);
|
||||
|
||||
for (j = *cursor; j < (BUFSIZ - 1); j++) {
|
||||
if (!*(command + j))
|
||||
break;
|
||||
else
|
||||
xwrite(outputFd, (command + j), 1);
|
||||
}
|
||||
|
||||
xwrite(outputFd, " \b", 2);
|
||||
|
||||
while (j-- > *cursor)
|
||||
xwrite(outputFd, "\b", 1);
|
||||
|
||||
--*len;
|
||||
}
|
||||
}
|
||||
|
||||
/* Delete the char in front of the cursor */
|
||||
void input_delete(char* command, int outputFd, int cursor, int *len)
|
||||
{
|
||||
int j = 0;
|
||||
|
||||
if (cursor == *len)
|
||||
return;
|
||||
|
||||
memmove(command + cursor, command + cursor + 1,
|
||||
BUFSIZ - cursor - 1);
|
||||
for (j = cursor; j < (BUFSIZ - 1); j++) {
|
||||
if (!*(command + j))
|
||||
break;
|
||||
else
|
||||
xwrite(outputFd, (command + j), 1);
|
||||
}
|
||||
|
||||
xwrite(outputFd, " \b", 2);
|
||||
|
||||
while (j-- > cursor)
|
||||
xwrite(outputFd, "\b", 1);
|
||||
--*len;
|
||||
}
|
||||
|
||||
/* Move forward one charactor */
|
||||
void input_forward(int outputFd, int *cursor, int len)
|
||||
{
|
||||
if (*cursor < len) {
|
||||
xwrite(outputFd, "\033[C", 3);
|
||||
++*cursor;
|
||||
}
|
||||
}
|
||||
|
||||
/* Move back one charactor */
|
||||
void input_backward(int outputFd, int *cursor)
|
||||
{
|
||||
if (*cursor > 0) {
|
||||
xwrite(outputFd, "\033[D", 3);
|
||||
--*cursor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef BB_FEATURE_SH_TAB_COMPLETION
|
||||
char** username_tab_completion(char* command, int *num_matches)
|
||||
{
|
||||
char **matches = (char **) NULL;
|
||||
*num_matches=0;
|
||||
fprintf(stderr, "\nin username_tab_completion\n");
|
||||
return (matches);
|
||||
}
|
||||
|
||||
#include <dirent.h>
|
||||
char** exe_n_cwd_tab_completion(char* command, int *num_matches)
|
||||
{
|
||||
char *dirName;
|
||||
char **matches = (char **) NULL;
|
||||
DIR *dir;
|
||||
struct dirent *next;
|
||||
|
||||
matches = malloc( sizeof(char*)*50);
|
||||
|
||||
/* Stick a wildcard onto the command, for later use */
|
||||
strcat( command, "*");
|
||||
|
||||
/* Now wall the current directory */
|
||||
dirName = get_current_dir_name();
|
||||
dir = opendir(dirName);
|
||||
if (!dir) {
|
||||
/* Don't print an error, just shut up and return */
|
||||
*num_matches=0;
|
||||
return (matches);
|
||||
}
|
||||
while ((next = readdir(dir)) != NULL) {
|
||||
|
||||
/* Some quick sanity checks */
|
||||
if ((strcmp(next->d_name, "..") == 0)
|
||||
|| (strcmp(next->d_name, ".") == 0)) {
|
||||
continue;
|
||||
}
|
||||
/* See if this matches */
|
||||
if (check_wildcard_match(next->d_name, command) == TRUE) {
|
||||
/* Cool, found a match. Add it to the list */
|
||||
matches[*num_matches] = malloc(strlen(next->d_name)+1);
|
||||
strcpy( matches[*num_matches], next->d_name);
|
||||
++*num_matches;
|
||||
//matches = realloc( matches, sizeof(char*)*(*num_matches));
|
||||
}
|
||||
}
|
||||
|
||||
return (matches);
|
||||
}
|
||||
|
||||
void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len)
|
||||
{
|
||||
/* Do TAB completion */
|
||||
static int num_matches=0;
|
||||
static char **matches = (char **) NULL;
|
||||
int pos = cursor;
|
||||
|
||||
|
||||
if (lastWasTab == FALSE) {
|
||||
char *tmp, *tmp1, *matchBuf;
|
||||
|
||||
/* For now, we will not bother with trying to distinguish
|
||||
* whether the cursor is in/at a command extression -- we
|
||||
* will always try all possible matches. If you don't like
|
||||
* that then feel free to fix it.
|
||||
*/
|
||||
|
||||
/* Make a local copy of the string -- up
|
||||
* to the position of the cursor */
|
||||
matchBuf = (char *) calloc(BUFSIZ, sizeof(char));
|
||||
strncpy(matchBuf, command, cursor);
|
||||
tmp=matchBuf;
|
||||
|
||||
/* skip past any command seperator tokens */
|
||||
while (*tmp && (tmp1=strpbrk(tmp, ";|&{(`")) != NULL) {
|
||||
tmp=++tmp1;
|
||||
/* skip any leading white space */
|
||||
while (*tmp && isspace(*tmp))
|
||||
++tmp;
|
||||
}
|
||||
|
||||
/* skip any leading white space */
|
||||
while (*tmp && isspace(*tmp))
|
||||
++tmp;
|
||||
|
||||
/* Free up any memory already allocated */
|
||||
if (matches) {
|
||||
free(matches);
|
||||
matches = (char **) NULL;
|
||||
}
|
||||
|
||||
/* If the word starts with `~' and there is no slash in the word,
|
||||
* then try completing this word as a username. */
|
||||
|
||||
/* FIXME -- this check is broken! */
|
||||
if (*tmp == '~' && !strchr(tmp, '/'))
|
||||
matches = username_tab_completion(tmp, &num_matches);
|
||||
|
||||
/* Try to match any executable in our path and everything
|
||||
* in the current working directory that matches. */
|
||||
if (!matches)
|
||||
matches = exe_n_cwd_tab_completion(tmp, &num_matches);
|
||||
|
||||
/* Don't leak memory */
|
||||
free( matchBuf);
|
||||
|
||||
/* Did we find exactly one match? */
|
||||
if (matches && num_matches==1) {
|
||||
/* write out the matched command */
|
||||
strncpy(command+pos, matches[0]+pos, strlen(matches[0])-pos);
|
||||
len=strlen(command);
|
||||
cursor=len;
|
||||
xwrite(outputFd, matches[0]+pos, strlen(matches[0])-pos);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* Ok -- the last char was a TAB. Since they
|
||||
* just hit TAB again, print a list of all the
|
||||
* available choices... */
|
||||
if ( matches && num_matches>0 ) {
|
||||
int i, col;
|
||||
|
||||
/* Go to the next line */
|
||||
xwrite(outputFd, "\n", 1);
|
||||
/* Print the list of matches */
|
||||
for (i=0,col=0; i<num_matches; i++) {
|
||||
char foo[17];
|
||||
sprintf(foo, "%-14s ", matches[i]);
|
||||
col += xwrite(outputFd, foo, strlen(foo));
|
||||
if (col > 60 && matches[i+1] != NULL) {
|
||||
xwrite(outputFd, "\n", 1);
|
||||
col = 0;
|
||||
}
|
||||
}
|
||||
/* Go to the next line */
|
||||
xwrite(outputFd, "\n", 1);
|
||||
/* Rewrite the prompt */
|
||||
xwrite(outputFd, prompt, strlen(prompt));
|
||||
/* Rewrite the command */
|
||||
xwrite(outputFd, command, len);
|
||||
/* Put the cursor back to where it used to be */
|
||||
for (cursor=len; cursor > pos; cursor--)
|
||||
xwrite(outputFd, "\b", 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void get_previous_history(struct history **hp, char* command)
|
||||
{
|
||||
free((*hp)->s);
|
||||
(*hp)->s = strdup(command);
|
||||
*hp = (*hp)->p;
|
||||
}
|
||||
|
||||
void get_next_history(struct history **hp, char* command)
|
||||
{
|
||||
free((*hp)->s);
|
||||
(*hp)->s = strdup(command);
|
||||
*hp = (*hp)->n;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is used to grab a character buffer
|
||||
* from the input file descriptor and allows you to
|
||||
* a string with full command editing (sortof like
|
||||
* a mini readline).
|
||||
*
|
||||
* The following standard commands are not implemented:
|
||||
* ESC-b -- Move back one word
|
||||
* ESC-f -- Move forward one word
|
||||
* ESC-d -- Delete back one word
|
||||
* ESC-h -- Delete forward one word
|
||||
* CTL-t -- Transpose two characters
|
||||
*
|
||||
* Furthermore, the "vi" command editing keys are not implemented.
|
||||
*
|
||||
* TODO: implement TAB command completion. :)
|
||||
*/
|
||||
extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
|
||||
{
|
||||
|
||||
int inputFd=fileno(stdin);
|
||||
int outputFd=fileno(stdout);
|
||||
int nr = 0;
|
||||
int len = 0;
|
||||
int j = 0;
|
||||
int cursor = 0;
|
||||
int break_out = 0;
|
||||
int ret = 0;
|
||||
int lastWasTab = FALSE;
|
||||
char c = 0;
|
||||
struct history *hp = his_end;
|
||||
|
||||
memset(command, 0, sizeof(command));
|
||||
if (!reset_term) {
|
||||
|
||||
getTermSettings(inputFd, (void*) &initial_settings);
|
||||
memcpy(&new_settings, &initial_settings, sizeof(struct termios));
|
||||
new_settings.c_cc[VMIN] = 1;
|
||||
new_settings.c_cc[VTIME] = 0;
|
||||
new_settings.c_cc[VINTR] = _POSIX_VDISABLE; /* Turn off CTRL-C, so we can trap it */
|
||||
new_settings.c_lflag &= ~ICANON; /* unbuffered input */
|
||||
new_settings.c_lflag &= ~(ECHO|ECHOCTL|ECHONL); /* Turn off echoing */
|
||||
reset_term = 1;
|
||||
}
|
||||
setTermSettings(inputFd, (void*) &new_settings);
|
||||
|
||||
memset(command, 0, BUFSIZ);
|
||||
|
||||
while (1) {
|
||||
|
||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||
return;
|
||||
//fprintf(stderr, "got a '%c' (%d)\n", c, c);
|
||||
|
||||
switch (c) {
|
||||
case '\n':
|
||||
case '\r':
|
||||
/* Enter */
|
||||
*(command + len++ + 1) = c;
|
||||
xwrite(outputFd, &c, 1);
|
||||
break_out = 1;
|
||||
break;
|
||||
case 1:
|
||||
/* Control-a -- Beginning of line */
|
||||
input_home(outputFd, &cursor);
|
||||
case 2:
|
||||
/* Control-b -- Move back one character */
|
||||
input_backward(outputFd, &cursor);
|
||||
break;
|
||||
case 3:
|
||||
/* Control-c -- leave the current line,
|
||||
* and start over on the next line */
|
||||
|
||||
/* Go to the next line */
|
||||
xwrite(outputFd, "\n", 1);
|
||||
|
||||
/* Rewrite the prompt */
|
||||
xwrite(outputFd, prompt, strlen(prompt));
|
||||
|
||||
/* Reset the command string */
|
||||
memset(command, 0, sizeof(command));
|
||||
len = cursor = 0;
|
||||
|
||||
break;
|
||||
case 4:
|
||||
/* Control-d -- Delete one character, or exit
|
||||
* if the len=0 and no chars to delete */
|
||||
if (len == 0) {
|
||||
xwrite(outputFd, "exit", 4);
|
||||
clean_up_and_die(0);
|
||||
} else {
|
||||
input_delete(command, outputFd, cursor, &len);
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
/* Control-e -- End of line */
|
||||
input_end(outputFd, &cursor, len);
|
||||
break;
|
||||
case 6:
|
||||
/* Control-f -- Move forward one character */
|
||||
input_forward(outputFd, &cursor, len);
|
||||
break;
|
||||
case '\b':
|
||||
case DEL:
|
||||
/* Control-h and DEL */
|
||||
input_backspace(command, outputFd, &cursor, &len);
|
||||
break;
|
||||
case '\t':
|
||||
#ifdef BB_FEATURE_SH_TAB_COMPLETION
|
||||
input_tab(command, prompt, outputFd, &cursor, &len);
|
||||
#endif
|
||||
break;
|
||||
case 14:
|
||||
/* Control-n -- Get next command in history */
|
||||
if (hp && hp->n && hp->n->s) {
|
||||
get_next_history(&hp, command);
|
||||
goto rewrite_line;
|
||||
} else {
|
||||
xwrite(outputFd, "\007", 1);
|
||||
}
|
||||
break;
|
||||
case 16:
|
||||
/* Control-p -- Get previous command from history */
|
||||
if (hp && hp->p) {
|
||||
get_previous_history(&hp, command);
|
||||
goto rewrite_line;
|
||||
} else {
|
||||
xwrite(outputFd, "\007", 1);
|
||||
}
|
||||
break;
|
||||
case ESC:{
|
||||
/* escape sequence follows */
|
||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||
return;
|
||||
|
||||
if (c == '[') { /* 91 */
|
||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||
return;
|
||||
|
||||
switch (c) {
|
||||
case 'A':
|
||||
/* Up Arrow -- Get previous command from history */
|
||||
if (hp && hp->p) {
|
||||
get_previous_history(&hp, command);
|
||||
goto rewrite_line;
|
||||
} else {
|
||||
xwrite(outputFd, "\007", 1);
|
||||
}
|
||||
break;
|
||||
case 'B':
|
||||
/* Down Arrow -- Get next command in history */
|
||||
if (hp && hp->n && hp->n->s) {
|
||||
get_next_history(&hp, command);
|
||||
goto rewrite_line;
|
||||
} else {
|
||||
xwrite(outputFd, "\007", 1);
|
||||
}
|
||||
break;
|
||||
|
||||
/* Rewrite the line with the selected history item */
|
||||
rewrite_line:
|
||||
/* erase old command from command line */
|
||||
len = strlen(command)-strlen(hp->s);
|
||||
|
||||
while (len>cursor)
|
||||
input_delete(command, outputFd, cursor, &len);
|
||||
while (cursor>0)
|
||||
input_backspace(command, outputFd, &cursor, &len);
|
||||
input_home(outputFd, &cursor);
|
||||
|
||||
/* write new command */
|
||||
strcpy(command, hp->s);
|
||||
len = strlen(hp->s);
|
||||
xwrite(outputFd, command, len);
|
||||
cursor = len;
|
||||
break;
|
||||
case 'C':
|
||||
/* Right Arrow -- Move forward one character */
|
||||
input_forward(outputFd, &cursor, len);
|
||||
break;
|
||||
case 'D':
|
||||
/* Left Arrow -- Move back one character */
|
||||
input_backward(outputFd, &cursor);
|
||||
break;
|
||||
case '3':
|
||||
/* Delete */
|
||||
input_delete(command, outputFd, cursor, &len);
|
||||
break;
|
||||
case '1':
|
||||
/* Home (Ctrl-A) */
|
||||
input_home(outputFd, &cursor);
|
||||
break;
|
||||
case '4':
|
||||
/* End (Ctrl-E) */
|
||||
input_end(outputFd, &cursor, len);
|
||||
break;
|
||||
default:
|
||||
xwrite(outputFd, "\007", 1);
|
||||
}
|
||||
if (c == '1' || c == '3' || c == '4')
|
||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||
return; /* read 126 (~) */
|
||||
}
|
||||
if (c == 'O') {
|
||||
/* 79 */
|
||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||
return;
|
||||
switch (c) {
|
||||
case 'H':
|
||||
/* Home (xterm) */
|
||||
input_home(outputFd, &cursor);
|
||||
break;
|
||||
case 'F':
|
||||
/* End (xterm) */
|
||||
input_end(outputFd, &cursor, len);
|
||||
break;
|
||||
default:
|
||||
xwrite(outputFd, "\007", 1);
|
||||
}
|
||||
}
|
||||
c = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
default: /* If it's regular input, do the normal thing */
|
||||
|
||||
if (!isprint(c)) { /* Skip non-printable characters */
|
||||
break;
|
||||
}
|
||||
|
||||
if (len >= (BUFSIZ - 2)) /* Need to leave space for enter */
|
||||
break;
|
||||
|
||||
len++;
|
||||
|
||||
if (cursor == (len - 1)) { /* Append if at the end of the line */
|
||||
*(command + cursor) = c;
|
||||
} else { /* Insert otherwise */
|
||||
memmove(command + cursor + 1, command + cursor,
|
||||
len - cursor - 1);
|
||||
|
||||
*(command + cursor) = c;
|
||||
|
||||
for (j = cursor; j < len; j++)
|
||||
xwrite(outputFd, command + j, 1);
|
||||
for (; j > cursor; j--)
|
||||
xwrite(outputFd, "\033[D", 3);
|
||||
}
|
||||
|
||||
cursor++;
|
||||
xwrite(outputFd, &c, 1);
|
||||
break;
|
||||
}
|
||||
if (c == '\t')
|
||||
lastWasTab = TRUE;
|
||||
else
|
||||
lastWasTab = FALSE;
|
||||
|
||||
if (break_out) /* Enter is the command terminator, no more input. */
|
||||
break;
|
||||
}
|
||||
|
||||
nr = len + 1;
|
||||
setTermSettings(inputFd, (void *) &initial_settings);
|
||||
reset_term = 0;
|
||||
|
||||
|
||||
/* Handle command history log */
|
||||
if (*(command)) {
|
||||
|
||||
struct history *h = his_end;
|
||||
|
||||
if (!h) {
|
||||
/* No previous history */
|
||||
h = his_front = malloc(sizeof(struct history));
|
||||
h->n = malloc(sizeof(struct history));
|
||||
|
||||
h->p = NULL;
|
||||
h->s = strdup(command);
|
||||
h->n->p = h;
|
||||
h->n->n = NULL;
|
||||
h->n->s = NULL;
|
||||
his_end = h->n;
|
||||
history_counter++;
|
||||
} else {
|
||||
/* Add a new history command */
|
||||
h->n = malloc(sizeof(struct history));
|
||||
|
||||
h->n->p = h;
|
||||
h->n->n = NULL;
|
||||
h->n->s = NULL;
|
||||
h->s = strdup(command);
|
||||
his_end = h->n;
|
||||
|
||||
/* After max history, remove the oldest command */
|
||||
if (history_counter >= MAX_HISTORY) {
|
||||
|
||||
struct history *p = his_front->n;
|
||||
|
||||
p->p = NULL;
|
||||
free(his_front->s);
|
||||
free(his_front);
|
||||
his_front = p;
|
||||
} else {
|
||||
history_counter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
extern void cmdedit_init(void)
|
||||
{
|
||||
atexit(cmdedit_reset_term);
|
||||
signal(SIGKILL, clean_up_and_die);
|
||||
signal(SIGINT, clean_up_and_die);
|
||||
signal(SIGQUIT, clean_up_and_die);
|
||||
signal(SIGTERM, clean_up_and_die);
|
||||
}
|
||||
#endif /* BB_FEATURE_SH_COMMAND_EDITING */
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef CMDEDIT_H
|
||||
#define CMDEDIT_H
|
||||
|
||||
/* unix systems can #define POSIX to use termios, otherwise
|
||||
* the bsd or sysv interface will be used
|
||||
*/
|
||||
|
||||
#ifdef __STDC__
|
||||
#include <stddef.h>
|
||||
|
||||
typedef size_t (*cmdedit_strwidth_proc)(char *);
|
||||
|
||||
void cmdedit_init(void);
|
||||
void cmdedit_read_input(char* promptStr, char* command); /* read a line of input */
|
||||
void cmdedit_setwidth(int); /* specify width of screen */
|
||||
void cmdedit_histadd(char *); /* adds entries to hist */
|
||||
void cmdedit_strwidth(cmdedit_strwidth_proc); /* to bind cmdedit_strlen */
|
||||
|
||||
extern int (*cmdedit_in_hook)(char *);
|
||||
extern int (*cmdedit_out_hook)(char *);
|
||||
extern int (*cmdedit_tab_hook)(char *, int, int *);
|
||||
|
||||
#else /* not __STDC__ */
|
||||
|
||||
void cmdedit_init(void);
|
||||
void cmdedit_read_input(char* promptStr, char* command);
|
||||
void cmdedit_setwidth();
|
||||
void cmdedit_histadd();
|
||||
void cmdedit_strwidth();
|
||||
|
||||
extern int (*cmdedit_in_hook)();
|
||||
extern int (*cmdedit_out_hook)();
|
||||
extern int (*cmdedit_tab_hook)();
|
||||
|
||||
#endif /* __STDC__ */
|
||||
|
||||
#endif /* CMDEDIT_H */
|
||||
+21
-7
@@ -5,22 +5,27 @@
|
||||
* busyboxed by Erik Andersen
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/vt.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
/* From <linux/vt.h> */
|
||||
#define VT_ACTIVATE 0x5606 /* make vt active */
|
||||
#define VT_WAITACTIVE 0x5607 /* wait for vt active */
|
||||
|
||||
extern int getfd(void);
|
||||
|
||||
int chvt_main(int argc, char **argv)
|
||||
{
|
||||
int fd, num;
|
||||
|
||||
if ((argc != 2) || (**(argv + 1) == '-')) {
|
||||
usage
|
||||
("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
|
||||
usage ("chvt N\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nChanges the foreground virtual terminal to /dev/ttyN\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
fd = get_console_fd("/dev/console");
|
||||
num = atoi(argv[1]);
|
||||
@@ -32,5 +37,14 @@ int chvt_main(int argc, char **argv)
|
||||
perror("VT_WAITACTIVE");
|
||||
exit(FALSE);
|
||||
}
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -3,7 +3,7 @@
|
||||
* Mini clear implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -29,5 +29,5 @@
|
||||
extern int clear_main(int argc, char **argv)
|
||||
{
|
||||
printf("\033[H\033[J");
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -5,13 +5,15 @@
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/vt.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern int getfd(void);
|
||||
/* From <linux/vt.h> */
|
||||
#define VT_DISALLOCATE 0x5608 /* free memory associated to vt */
|
||||
|
||||
|
||||
char *progname;
|
||||
|
||||
int deallocvt_main(int argc, char *argv[])
|
||||
@@ -20,7 +22,11 @@ int deallocvt_main(int argc, char *argv[])
|
||||
|
||||
if ((argc != 2) || (**(argv + 1) == '-')) {
|
||||
usage
|
||||
("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
|
||||
("deallocvt N\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nDeallocate unused virtual terminal /dev/ttyN\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
progname = argv[0];
|
||||
@@ -31,7 +37,7 @@ int deallocvt_main(int argc, char *argv[])
|
||||
/* deallocate all unused consoles */
|
||||
if (ioctl(fd, VT_DISALLOCATE, 0)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
exit(1);
|
||||
exit( FALSE);
|
||||
}
|
||||
} else
|
||||
for (i = 1; i < argc; i++) {
|
||||
@@ -45,8 +51,8 @@ int deallocvt_main(int argc, char *argv[])
|
||||
perror("VT_DISALLOCATE");
|
||||
fprintf(stderr, "%s: could not deallocate console %d\n",
|
||||
progname, num);
|
||||
exit(1);
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
return( TRUE);
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini dumpkmap implementation for busybox
|
||||
*
|
||||
* Copyright (C) Arne Bernin <arne@matrix.loopback.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
/* From <linux/kd.h> */
|
||||
struct kbentry {
|
||||
unsigned char kb_table;
|
||||
unsigned char kb_index;
|
||||
unsigned short kb_value;
|
||||
};
|
||||
#define KDGKBENT 0x4B46 /* gets one entry in translation table */
|
||||
|
||||
/* From <linux/keyboard.h> */
|
||||
#define NR_KEYS 128
|
||||
#define MAX_NR_KEYMAPS 256
|
||||
|
||||
|
||||
static const char dumpkmap_usage[] = "dumpkmap\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrints out a binary keyboard translation table to standard input.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
int dumpkmap_main(int argc, char **argv)
|
||||
{
|
||||
struct kbentry ke;
|
||||
int i, j, fd;
|
||||
char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap";
|
||||
|
||||
if (argc>=2 && *argv[1]=='-') {
|
||||
usage(dumpkmap_usage);
|
||||
}
|
||||
|
||||
fd = open("/dev/tty0", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
write(1, magic, 7);
|
||||
|
||||
for (i=0; i < MAX_NR_KEYMAPS; i++) flags[i]=0;
|
||||
flags[0]=1;
|
||||
flags[1]=1;
|
||||
flags[2]=1;
|
||||
flags[4]=1;
|
||||
flags[5]=1;
|
||||
flags[6]=1;
|
||||
flags[8]=1;
|
||||
flags[9]=1;
|
||||
flags[10]=1;
|
||||
flags[12]=1;
|
||||
|
||||
/* dump flags */
|
||||
for (i=0; i < MAX_NR_KEYMAPS; i++) write(1,&flags[i],1);
|
||||
|
||||
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
||||
if (flags[i] == 1) {
|
||||
for (j = 0; j < NR_KEYS; j++) {
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
if (ioctl(fd, KDGKBENT, &ke) < 0) {
|
||||
|
||||
fprintf(stderr, "ioctl returned: %s, %s, %s, %xqq\n",strerror(errno),(char *)&ke.kb_index,(char *)&ke.kb_table,(int)&ke.kb_value);
|
||||
}
|
||||
else {
|
||||
write(1,&ke.kb_value,2);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
+19
-9
@@ -7,6 +7,7 @@
|
||||
* Peter Novodvorsky <petya@logic.ru>
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
@@ -21,6 +22,12 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/kd.h>
|
||||
|
||||
static const char loadacm_usage[] = "loadacm\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nLoads an acm from standard input.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
typedef unsigned short unicode;
|
||||
|
||||
static long int ctoi(unsigned char *s, int *is_unicode);
|
||||
@@ -33,20 +40,24 @@ int loadacm_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (argc>=2 && *argv[1]=='-') {
|
||||
usage(loadacm_usage);
|
||||
}
|
||||
|
||||
fd = open("/dev/tty", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty1: %s\n", strerror(errno));
|
||||
return 1;
|
||||
return( FALSE);
|
||||
}
|
||||
|
||||
if (screen_map_load(fd, stdin)) {
|
||||
fprintf(stderr, "Error loading acm: %s\n", strerror(errno));
|
||||
return 1;
|
||||
return( FALSE);
|
||||
}
|
||||
|
||||
write(fd, "\033(K", 3);
|
||||
|
||||
return 0;
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
int screen_map_load(int fd, FILE * fp)
|
||||
@@ -57,7 +68,7 @@ int screen_map_load(int fd, FILE * fp)
|
||||
int parse_failed = 0;
|
||||
int is_unicode;
|
||||
|
||||
if (fstat(fp->_fileno, &stbuf))
|
||||
if (fstat(fileno(fp), &stbuf))
|
||||
perror("Cannot stat map file"), exit(1);
|
||||
|
||||
/* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */
|
||||
@@ -129,10 +140,9 @@ int screen_map_load(int fd, FILE * fp)
|
||||
perror("PIO_SCRNMAP ioctl"), exit(1);
|
||||
else
|
||||
return 0;
|
||||
} else {
|
||||
fprintf(stderr, "Error parsing symbolic map\n");
|
||||
exit(1);
|
||||
}
|
||||
fprintf(stderr, "Error parsing symbolic map\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -353,8 +363,8 @@ void saveoldmap(int fd, char *omfil)
|
||||
unicode utf8_to_ucs2(char *buf)
|
||||
{
|
||||
int utf_count = 0;
|
||||
long utf_char;
|
||||
unicode tc;
|
||||
long utf_char = 0;
|
||||
unicode tc = 0;
|
||||
unsigned char c;
|
||||
|
||||
do {
|
||||
|
||||
@@ -31,7 +31,10 @@
|
||||
#define PSF_SEPARATOR 0xFFFF
|
||||
|
||||
static const char loadfont_usage[] = "loadfont\n"
|
||||
"\n" "\tLoad a console font from standard input.\n" "\n";
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"Loads a console font from standard input.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
struct psf_header {
|
||||
unsigned char magic1, magic2; /* Magic number */
|
||||
@@ -47,14 +50,18 @@ extern int loadfont_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (argc>=2 && *argv[1]=='-') {
|
||||
usage(loadfont_usage);
|
||||
}
|
||||
|
||||
fd = open("/dev/tty0", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
|
||||
return 1;
|
||||
return( FALSE);
|
||||
}
|
||||
loadnewfont(fd);
|
||||
|
||||
return 0;
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
static void do_loadfont(int fd, char *inbuf, int unit, int fontsize)
|
||||
|
||||
+29
-13
@@ -24,16 +24,26 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <linux/kd.h>
|
||||
#include <linux/keyboard.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
/* From <linux/kd.h> */
|
||||
struct kbentry {
|
||||
unsigned char kb_table;
|
||||
unsigned char kb_index;
|
||||
unsigned short kb_value;
|
||||
};
|
||||
#define KDSKBENT 0x4B47 /* sets one entry in translation table */
|
||||
|
||||
/* From <linux/keyboard.h> */
|
||||
#define NR_KEYS 128
|
||||
#define MAX_NR_KEYMAPS 256
|
||||
|
||||
|
||||
static const char loadkmap_usage[] = "loadkmap\n"
|
||||
"\n"
|
||||
|
||||
"\tLoad a binary keyboard translation table from standard input.\n"
|
||||
"\n";
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nLoads a binary keyboard translation table from standard input.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
int loadkmap_main(int argc, char **argv)
|
||||
@@ -43,28 +53,32 @@ int loadkmap_main(int argc, char **argv)
|
||||
int i, j, fd, readsz, pos, ibuffsz = NR_KEYS * sizeof(u_short);
|
||||
char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap", buff[7];
|
||||
|
||||
if (argc>=2 && *argv[1]=='-') {
|
||||
usage(loadkmap_usage);
|
||||
}
|
||||
|
||||
fd = open("/dev/tty0", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
|
||||
return 1;
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
read(0, buff, 7);
|
||||
if (0 != strncmp(buff, magic, 7)) {
|
||||
fprintf(stderr, "This is not a valid binary keymap.\n");
|
||||
return 1;
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS)) {
|
||||
fprintf(stderr, "Error reading keymap flags: %s\n",
|
||||
strerror(errno));
|
||||
return 1;
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
ibuff = (u_short *) malloc(ibuffsz);
|
||||
if (!ibuff) {
|
||||
fprintf(stderr, "Out of memory.\n");
|
||||
return 1;
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
||||
@@ -75,7 +89,7 @@ int loadkmap_main(int argc, char **argv)
|
||||
< 0) {
|
||||
fprintf(stderr, "Error reading keymap: %s\n",
|
||||
strerror(errno));
|
||||
return 1;
|
||||
exit(FALSE);
|
||||
}
|
||||
pos += readsz;
|
||||
}
|
||||
@@ -87,6 +101,8 @@ int loadkmap_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
return 0;
|
||||
/* Don't bother to close files. Exit does that
|
||||
* automagically, so we can save a few bytes */
|
||||
/* close(fd); */
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* setkeycodes
|
||||
*
|
||||
* Copyright (C) 1994-1998 Andries E. Brouwer <aeb@cwi.nl>
|
||||
*
|
||||
* Adjusted for BusyBox by Erik Andersen <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
|
||||
/* From <linux/kd.h> */
|
||||
struct kbkeycode {
|
||||
unsigned int scancode, keycode;
|
||||
};
|
||||
#define KDSETKEYCODE 0x4B4D /* write kernel keycode table entry */
|
||||
|
||||
|
||||
static const char setkeycodes_usage[] =
|
||||
"setkeycodes SCANCODE KEYCODE ...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nSet entries into the kernel's scancode-to-keycode map,\n"
|
||||
"allowing unusual keyboards to generate usable keycodes.\n\n"
|
||||
"SCANCODE may be either xx or e0xx (hexadecimal),\n"
|
||||
"and KEYCODE is given in decimal\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int
|
||||
setkeycodes_main(int argc, char** argv)
|
||||
{
|
||||
char *ep;
|
||||
int fd, sc;
|
||||
struct kbkeycode a;
|
||||
|
||||
if (argc % 2 != 1 || argc < 2) {
|
||||
usage(setkeycodes_usage);
|
||||
}
|
||||
|
||||
fd = get_console_fd("/dev/console");
|
||||
|
||||
while (argc > 2) {
|
||||
a.keycode = atoi(argv[2]);
|
||||
a.scancode = sc = strtol(argv[1], &ep, 16);
|
||||
if (*ep) {
|
||||
fatalError("error reading SCANCODE: '%s'\n", argv[1]);
|
||||
}
|
||||
if (a.scancode > 127) {
|
||||
a.scancode -= 0xe000;
|
||||
a.scancode += 128;
|
||||
}
|
||||
if (a.scancode > 255 || a.keycode > 127) {
|
||||
fatalError("SCANCODE or KEYCODE outside bounds\n");
|
||||
}
|
||||
if (ioctl(fd,KDSETKEYCODE,&a)) {
|
||||
perror("KDSETKEYCODE");
|
||||
fatalError("failed to set SCANCODE %x to KEYCODE %d\n", sc, a.keycode);
|
||||
}
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
}
|
||||
return( TRUE);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini basename implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
const char *basename_usage="basename FILE [SUFFIX]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nStrips directory path and suffixes from FILE.\n"
|
||||
"If specified, also removes any trailing SUFFIX.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
extern int basename_main(int argc, char **argv)
|
||||
{
|
||||
int m, n;
|
||||
char *s;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage(basename_usage);
|
||||
}
|
||||
|
||||
argv++;
|
||||
|
||||
s = get_last_path_component(*argv);
|
||||
|
||||
if (argc>2) {
|
||||
argv++;
|
||||
n = strlen(*argv);
|
||||
m = strlen(s);
|
||||
if (m>=n && strncmp(s+m-n, *argv, n)==0)
|
||||
s[m-n] = '\0';
|
||||
}
|
||||
printf("%s\n", s);
|
||||
return(TRUE);
|
||||
}
|
||||
+15
-3
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini Cat implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -45,7 +45,11 @@ extern int cat_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (**(argv + 1) == '-') {
|
||||
usage("cat [file ...]\n");
|
||||
usage("cat [FILE ...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nConcatenates FILE(s) and prints them to the standard output.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
argc--;
|
||||
|
||||
@@ -57,5 +61,13 @@ extern int cat_main(int argc, char **argv)
|
||||
}
|
||||
print_file(file);
|
||||
}
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+22
-12
@@ -3,7 +3,7 @@
|
||||
* Mini chroot implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -28,14 +28,18 @@
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n\n"
|
||||
|
||||
"Run COMMAND with root directory set to NEWROOT.\n";
|
||||
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nRun COMMAND with root directory set to NEWROOT.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
int chroot_main(int argc, char **argv)
|
||||
{
|
||||
char *prog;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage(chroot_usage);
|
||||
}
|
||||
@@ -43,25 +47,31 @@ int chroot_main(int argc, char **argv)
|
||||
argv++;
|
||||
|
||||
if (chroot(*argv) || (chdir("/"))) {
|
||||
fprintf(stderr, "chroot: cannot change root directory to %s: %s\n",
|
||||
fatalError("chroot: cannot change root directory to %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc >= 1) {
|
||||
fprintf(stderr, "command: %s\n", *argv);
|
||||
prog = *argv;
|
||||
execvp(*argv, argv);
|
||||
} else {
|
||||
char *prog;
|
||||
|
||||
prog = getenv("SHELL");
|
||||
if (!prog)
|
||||
prog = "/bin/sh";
|
||||
execlp(prog, prog, NULL);
|
||||
}
|
||||
fprintf(stderr, "chroot: cannot execute %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit(FALSE);
|
||||
fatalError("chroot: cannot execute %s: %s\n",
|
||||
prog, strerror(errno));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+388
@@ -0,0 +1,388 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* cut implementation for busybox
|
||||
*
|
||||
* Copyright (c) Michael J. Holme
|
||||
*
|
||||
* This version of cut is adapted from Minix cut and was modified
|
||||
* by Erik Andersen <andersee@debian.org> to be used in busybox.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Original copyright notice is retained at the end of this file.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <sys/types.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_help
|
||||
#include "messages.c"
|
||||
|
||||
#define MAX_FIELD 80 /* Pointers to the beginning of each field
|
||||
* are stored in columns[], if a line holds
|
||||
* more than MAX_FIELD columns the array
|
||||
* boundary is exceed. But unlikely at 80 */
|
||||
|
||||
#define MAX_ARGS 32 /* Maximum number of fields following -f or
|
||||
* -c switches */
|
||||
int args[MAX_ARGS * 2];
|
||||
int num_args;
|
||||
|
||||
/* Lots of new defines, should easen maintainance... */
|
||||
#define DUMP_STDIN 0 /* define for mode: no options */
|
||||
#define OPTIONF 1 /* define for mode: option -f */
|
||||
#define OPTIONC 2 /* define for mode: option -c */
|
||||
#define OPTIONB 3 /* define for mode: option -b */
|
||||
#define NOTSET 0 /* option not selected */
|
||||
#define SET 1 /* option selected */
|
||||
#define OPTIONS 1 /*define option -s */
|
||||
/* Defines for the warnings */
|
||||
#define DELIMITER_NOT_APPLICABLE 0
|
||||
#define OVERRIDING_PREVIOUS_MODE 1
|
||||
#define OPTION_NOT_APPLICABLE 2
|
||||
#define UNKNOWN_OPTION 3
|
||||
#define FILE_NOT_READABLE 4
|
||||
/* Defines for the fatal errors */
|
||||
#define SYNTAX_ERROR 101
|
||||
#define POSITION_ERROR 102
|
||||
#define LINE_TO_LONG_ERROR 103
|
||||
#define RANGE_ERROR 104
|
||||
#define MAX_FIELDS_EXEEDED_ERROR 105
|
||||
#define MAX_ARGS_EXEEDED_ERROR 106
|
||||
|
||||
|
||||
int mode; /* 0 = dump stdin to stdout, 1=-f, 2=-c */
|
||||
char delim = '\t'; /* default delimiting character */
|
||||
FILE *fd;
|
||||
char *name;
|
||||
char line[BUFSIZ];
|
||||
int exit_status;
|
||||
int option = 0; /* for -s option */
|
||||
|
||||
int cut_main(int argc, char **argv);
|
||||
void warn(int warn_number, char *option);
|
||||
void cuterror(int err);
|
||||
void get_args(void);
|
||||
void cut(void);
|
||||
|
||||
void warn(int warn_number, char *option)
|
||||
{
|
||||
static char *warn_msg[] = {
|
||||
"%s: Option -%s allowed only with -f\n",
|
||||
"%s: -%s overrides earlier option\n",
|
||||
"%s: -%s not allowed in current mode\n",
|
||||
"%s: Cannot open %s\n"
|
||||
};
|
||||
|
||||
fprintf(stderr, warn_msg[warn_number], name, option);
|
||||
exit_status = warn_number + 1;
|
||||
|
||||
}
|
||||
|
||||
void cuterror(int err)
|
||||
{
|
||||
static char *err_mes[] = {
|
||||
"%s: syntax error\n",
|
||||
"%s: position must be >0\n",
|
||||
"%s: line longer than BUFSIZ\n",
|
||||
"%s: range must not decrease from left to right\n",
|
||||
"%s: MAX_FIELD exceeded\n",
|
||||
"%s: MAX_ARGS exceeded\n"
|
||||
};
|
||||
|
||||
fprintf(stderr, err_mes[err - 101], name);
|
||||
exit(err);
|
||||
}
|
||||
|
||||
|
||||
void get_args()
|
||||
{
|
||||
int i = 0;
|
||||
int arg_ptr = 0;
|
||||
int flag;
|
||||
|
||||
num_args = 0;
|
||||
do {
|
||||
if (num_args == MAX_ARGS)
|
||||
cuterror(MAX_ARGS_EXEEDED_ERROR);
|
||||
if (!isdigit(line[i]) && line[i] != '-')
|
||||
cuterror(SYNTAX_ERROR);
|
||||
|
||||
args[arg_ptr] = 1;
|
||||
args[arg_ptr + 1] = BUFSIZ;
|
||||
flag = 1;
|
||||
|
||||
while (line[i] != ',' && line[i] != 0) {
|
||||
if (isdigit(line[i])) {
|
||||
args[arg_ptr] = 0;
|
||||
while (isdigit(line[i]))
|
||||
args[arg_ptr] = 10 * args[arg_ptr] + line[i++] - '0';
|
||||
if (!args[arg_ptr])
|
||||
cuterror(POSITION_ERROR);
|
||||
arg_ptr++;
|
||||
}
|
||||
if (line[i] == '-') {
|
||||
arg_ptr |= 1;
|
||||
i++;
|
||||
flag = 0;
|
||||
}
|
||||
}
|
||||
if (flag && arg_ptr & 1)
|
||||
args[arg_ptr] = args[arg_ptr - 1];
|
||||
if (args[num_args * 2] > args[num_args * 2 + 1])
|
||||
cuterror(RANGE_ERROR);
|
||||
num_args++;
|
||||
arg_ptr = num_args * 2;
|
||||
}
|
||||
while (line[i++]);
|
||||
}
|
||||
|
||||
|
||||
void cut()
|
||||
{
|
||||
int i, j, length, maxcol=0;
|
||||
char *columns[MAX_FIELD];
|
||||
|
||||
while (fgets(line, BUFSIZ, fd)) {
|
||||
maxcol=0;
|
||||
length = strlen(line) - 1;
|
||||
*(line + length) = 0;
|
||||
switch (mode) {
|
||||
case DUMP_STDIN:
|
||||
printf("%s", line);
|
||||
break;
|
||||
case OPTIONF:
|
||||
columns[maxcol++] = line;
|
||||
for (i = 0; i < length; i++) {
|
||||
if (*(line + i) == delim) {
|
||||
*(line + i) = 0;
|
||||
if (maxcol == MAX_FIELD)
|
||||
cuterror(MAX_FIELDS_EXEEDED_ERROR);
|
||||
columns[maxcol] = line + i + 1;
|
||||
maxcol++;
|
||||
}
|
||||
}
|
||||
if (maxcol != 1) {
|
||||
for (i = 0; i < num_args; i++) {
|
||||
for (j = args[i * 2]; j <= args[i * 2 + 1]; j++)
|
||||
if (j <= maxcol) {
|
||||
|
||||
printf("%s", columns[j - 1]);
|
||||
|
||||
if (i != num_args - 1 || j != args[i * 2 + 1])
|
||||
putchar(delim);
|
||||
}
|
||||
}
|
||||
} else if (option != OPTIONS) {
|
||||
printf("%s",line);
|
||||
}
|
||||
break;
|
||||
case OPTIONC:
|
||||
for (i = 0; i < num_args; i++) {
|
||||
for (j = args[i * 2];
|
||||
j <= (args[i * 2 + 1] >
|
||||
length ? length : args[i * 2 + 1]); j++)
|
||||
putchar(*(line + j - 1));
|
||||
}
|
||||
}
|
||||
if (maxcol != 1)
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int cut_main(int argc, char **argv)
|
||||
{
|
||||
int i = 1;
|
||||
int numberFilenames = 0;
|
||||
|
||||
name = argv[0];
|
||||
|
||||
if (argc == 1 || strcmp(argv[1], dash_dash_help)==0)
|
||||
usage( "cut [OPTION]... [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrints selected fields from each input FILE to standard output.\n\n"
|
||||
"Options:\n"
|
||||
"\t-b LIST\tOutput only bytes from LIST\n"
|
||||
"\t-c LIST\tOutput only characters from LIST\n"
|
||||
"\t-d CHAR\tUse CHAR instead of tab as the field delimiter\n"
|
||||
"\t-s\tOnly output Lines if the include DELIM\n"
|
||||
"\t-f N\tPrint only these fields\n"
|
||||
"\t-n\tIgnored\n"
|
||||
#endif
|
||||
);
|
||||
|
||||
while (i < argc) {
|
||||
if (argv[i][0] == '-') {
|
||||
switch (argv[i++][1]) {
|
||||
case 'd':
|
||||
if (mode == OPTIONC || mode == OPTIONB)
|
||||
warn(DELIMITER_NOT_APPLICABLE, "d");
|
||||
if (argc > i)
|
||||
delim = argv[i++][0];
|
||||
else
|
||||
cuterror(SYNTAX_ERROR);
|
||||
break;
|
||||
case 'f':
|
||||
sprintf(line, "%s", argv[i++]);
|
||||
if (mode == OPTIONC || mode == OPTIONB)
|
||||
warn(OVERRIDING_PREVIOUS_MODE, "f");
|
||||
mode = OPTIONF;
|
||||
break;
|
||||
case 'b':
|
||||
sprintf(line, "%s", argv[i++]);
|
||||
if (mode == OPTIONF || mode == OPTIONC)
|
||||
warn(OVERRIDING_PREVIOUS_MODE, "b");
|
||||
mode = OPTIONB;
|
||||
break;
|
||||
case 'c':
|
||||
sprintf(line, "%s", argv[i++]);
|
||||
if (mode == OPTIONF || mode == OPTIONB)
|
||||
warn(OVERRIDING_PREVIOUS_MODE, "c");
|
||||
mode = OPTIONC;
|
||||
break;
|
||||
case 's':
|
||||
option = OPTIONS;
|
||||
|
||||
break;
|
||||
case '\0': /* - means: read from stdin */
|
||||
numberFilenames++;
|
||||
break;
|
||||
case 'n': /* needed for Posix, but no effect here */
|
||||
if (mode != OPTIONB)
|
||||
warn(OPTION_NOT_APPLICABLE, "n");
|
||||
break;
|
||||
default:
|
||||
warn(UNKNOWN_OPTION, &(argv[i - 1][1]));
|
||||
}
|
||||
} else {
|
||||
i++;
|
||||
numberFilenames++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Here follow the checks, if the selected options are reasonable. */
|
||||
if (mode == OPTIONB) /* since in Minix char := byte */
|
||||
mode = OPTIONC;
|
||||
|
||||
if (mode != OPTIONF && option == OPTIONS)
|
||||
warn(DELIMITER_NOT_APPLICABLE,"s");
|
||||
get_args();
|
||||
if (numberFilenames != 0) {
|
||||
i = 1;
|
||||
while (i < argc) {
|
||||
if (argv[i][0] == '-') {
|
||||
switch (argv[i][1]) {
|
||||
case 'f':
|
||||
case 'c':
|
||||
case 'b':
|
||||
case 'd':
|
||||
i += 2;
|
||||
break;
|
||||
case 'n':
|
||||
case 'i':
|
||||
case 's':
|
||||
i++;
|
||||
break;
|
||||
case '\0':
|
||||
fd = stdin;
|
||||
i++;
|
||||
cut();
|
||||
break;
|
||||
default:
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
if ((fd = fopen(argv[i++], "r")) == NULL) {
|
||||
warn(FILE_NOT_READABLE, argv[i - 1]);
|
||||
} else {
|
||||
cut();
|
||||
fclose(fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fd = stdin;
|
||||
cut();
|
||||
}
|
||||
|
||||
return(exit_status);
|
||||
}
|
||||
|
||||
/* cut - extract columns from a file or stdin. Author: Michael J. Holme
|
||||
*
|
||||
* Copyright 1989, Michael John Holme, All rights reserved.
|
||||
* This code may be freely distributed, provided that this notice
|
||||
* remains intact.
|
||||
*
|
||||
* V1.1: 6th September 1989
|
||||
*
|
||||
* Bugs, criticisms, etc,
|
||||
* c/o Mark Powell
|
||||
* JANET sq79@uk.ac.liv
|
||||
* ARPA sq79%liv.ac.uk@nsfnet-relay.ac.uk
|
||||
* UUCP ...!mcvax!ukc!liv.ac.uk!sq79
|
||||
*-------------------------------------------------------------------------
|
||||
* Changed for POSIX1003.2/Draft10 conformance
|
||||
* Thomas Brupbacher (tobr@mw.lpc.ethz.ch), September 1990.
|
||||
* Changes:
|
||||
* - separation of error messages ( stderr) and output (stdout).
|
||||
* - support for -b and -n (no effect, -b acts as -c)
|
||||
* - support for -s
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987,1997, Prentice Hall
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use of the MINIX operating system in source and
|
||||
* binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of Prentice Hall nor the names of the software
|
||||
* authors or contributors may be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND
|
||||
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL PRENTICE HALL OR ANY AUTHORS OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
+22
-30
@@ -40,12 +40,14 @@
|
||||
mail commands */
|
||||
|
||||
static const char date_usage[] = "date [OPTION]... [+FORMAT]\n"
|
||||
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n\n"
|
||||
"Display the current time in the given FORMAT, or set the system date.\n"
|
||||
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
|
||||
"\t-s\t\tset time described by STRING\n"
|
||||
|
||||
"\t-u\t\tprint or set Coordinated Universal Time\n";
|
||||
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nDisplays the current time in the given FORMAT, or sets the system date.\n"
|
||||
"\nOptions:\n\t-R\tOutputs RFC-822 compliant date string\n"
|
||||
"\t-s\tSets time described by STRING\n"
|
||||
"\t-u\tPrints or sets Coordinated Universal Time\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
/* Input parsing code is always bulky - used heavy duty libc stuff as
|
||||
@@ -64,8 +66,7 @@ struct tm *date_conv_time(struct tm *tm_time, const char *t_string)
|
||||
&(tm_time->tm_min), &(tm_time->tm_year));
|
||||
|
||||
if (nr < 4 || nr > 5) {
|
||||
fprintf(stderr, invalid_date, "date", t_string);
|
||||
exit(FALSE);
|
||||
fatalError(invalid_date, "date", t_string);
|
||||
}
|
||||
|
||||
/* correct for century - minor Y2K problem here? */
|
||||
@@ -149,10 +150,7 @@ struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
|
||||
|
||||
}
|
||||
|
||||
fprintf(stderr, invalid_date, "date", t_string);
|
||||
|
||||
exit(FALSE);
|
||||
|
||||
fatalError(invalid_date, "date", t_string);
|
||||
}
|
||||
|
||||
|
||||
@@ -183,27 +181,25 @@ int date_main(int argc, char **argv)
|
||||
set_time = 1;
|
||||
if (date_str != NULL)
|
||||
usage(date_usage);
|
||||
date_str = optarg;
|
||||
date_str = *argv;
|
||||
break;
|
||||
case 'u':
|
||||
utc = 1;
|
||||
if (putenv("TZ=UTC0") != 0) {
|
||||
fprintf(stderr, memory_exhausted, "date");
|
||||
exit(FALSE);
|
||||
}
|
||||
/* Look ma, no break. Don't fix it either. */
|
||||
if (putenv("TZ=UTC0") != 0)
|
||||
fatalError(memory_exhausted, "date");
|
||||
break;
|
||||
case 'd':
|
||||
use_arg = 1;
|
||||
if (date_str != NULL)
|
||||
usage(date_usage);
|
||||
date_str = optarg;
|
||||
date_str = *argv;
|
||||
break;
|
||||
case '-':
|
||||
usage(date_usage);
|
||||
}
|
||||
} else {
|
||||
if ((date_fmt == NULL) && (strcmp(*argv, "+") == 0))
|
||||
date_fmt = *argv;
|
||||
if ((date_fmt == NULL) && (**argv == '+'))
|
||||
date_fmt = *argv + 1; /* Skip over the '+' */
|
||||
else if (date_str == NULL) {
|
||||
set_time = 1;
|
||||
date_str = *argv;
|
||||
@@ -239,16 +235,13 @@ int date_main(int argc, char **argv)
|
||||
|
||||
/* Correct any day of week and day of year etc fields */
|
||||
tm = mktime(&tm_time);
|
||||
if (tm < 0) {
|
||||
fprintf(stderr, invalid_date, "date", date_str);
|
||||
exit(FALSE);
|
||||
}
|
||||
if (tm < 0)
|
||||
fatalError(invalid_date, "date", date_str);
|
||||
|
||||
/* if setting time, set it */
|
||||
if (set_time) {
|
||||
if (stime(&tm) < 0) {
|
||||
fprintf(stderr, "date: can't set date.\n");
|
||||
exit(FALSE);
|
||||
fatalError("date: can't set date.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -276,10 +269,9 @@ int date_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* Print OUTPUT (after ALL that!) */
|
||||
t_buff = malloc(201);
|
||||
t_buff = xmalloc(201);
|
||||
strftime(t_buff, 200, date_fmt, &tm_time);
|
||||
printf("%s\n", t_buff);
|
||||
|
||||
exit(TRUE);
|
||||
|
||||
return(TRUE);
|
||||
}
|
||||
+35
-27
@@ -2,13 +2,13 @@
|
||||
/*
|
||||
* Mini dd implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999, 2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* based in part on code taken from sash.
|
||||
*
|
||||
* Copyright (c) 1999 by David I. Bell
|
||||
* Permission is granted to use, distribute, or modify this source,
|
||||
* provided that this copyright notice remains intact.
|
||||
* Based in part on code taken from sash.
|
||||
* Copyright (c) 1999 by David I. Bell
|
||||
* Permission is granted to use, distribute, or modify this source,
|
||||
* provided that this copyright notice remains intact.
|
||||
*
|
||||
* Permission to distribute this code under the GPL has been granted.
|
||||
*
|
||||
@@ -41,24 +41,26 @@ typedef unsigned long long int uintmax_t;
|
||||
#endif
|
||||
|
||||
static const char dd_usage[] =
|
||||
"dd [if=name] [of=name] [bs=n] [count=n] [skip=n] [seek=n]\n\n"
|
||||
"Copy a file, converting and formatting according to options\n\n"
|
||||
"dd [if=FILE] [of=FILE] [bs=N] [count=N] [skip=N] [seek=N]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCopy a file, converting and formatting according to options\n\n"
|
||||
"\tif=FILE\tread from FILE instead of stdin\n"
|
||||
"\tof=FILE\twrite to FILE instead of stdout\n"
|
||||
"\tbs=n\tread and write n bytes at a time\n"
|
||||
"\tcount=n\tcopy only n input blocks\n"
|
||||
"\tskip=n\tskip n input blocks\n"
|
||||
"\tseek=n\tskip n output blocks\n"
|
||||
|
||||
"\tbs=N\tread and write N bytes at a time\n"
|
||||
"\tcount=N\tcopy only N input blocks\n"
|
||||
"\tskip=N\tskip N input blocks\n"
|
||||
"\tseek=N\tskip N output blocks\n"
|
||||
"\n"
|
||||
"Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n";
|
||||
"Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
extern int dd_main(int argc, char **argv)
|
||||
{
|
||||
const char *inFile = NULL;
|
||||
const char *outFile = NULL;
|
||||
char *inFile = NULL;
|
||||
char *outFile = NULL;
|
||||
char *cp;
|
||||
int inFd;
|
||||
int outFd;
|
||||
@@ -114,11 +116,7 @@ extern int dd_main(int argc, char **argv)
|
||||
argv++;
|
||||
}
|
||||
|
||||
buf = malloc(blockSize);
|
||||
if (buf == NULL) {
|
||||
fprintf(stderr, "Cannot allocate buffer\n");
|
||||
exit(FALSE);
|
||||
}
|
||||
buf = xmalloc(blockSize);
|
||||
|
||||
intotal = 0;
|
||||
outTotal = 0;
|
||||
@@ -129,9 +127,12 @@ extern int dd_main(int argc, char **argv)
|
||||
inFd = open(inFile, 0);
|
||||
|
||||
if (inFd < 0) {
|
||||
perror(inFile);
|
||||
free(buf);
|
||||
exit(FALSE);
|
||||
/* Note that we are not freeing buf or closing
|
||||
* files here to save a few bytes. This exits
|
||||
* here anyways... */
|
||||
|
||||
/* free(buf); */
|
||||
fatalError( inFile);
|
||||
}
|
||||
|
||||
if (outFile == NULL)
|
||||
@@ -140,10 +141,13 @@ extern int dd_main(int argc, char **argv)
|
||||
outFd = open(outFile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
|
||||
if (outFd < 0) {
|
||||
perror(outFile);
|
||||
close(inFd);
|
||||
free(buf);
|
||||
exit(FALSE);
|
||||
/* Note that we are not freeing buf or closing
|
||||
* files here to save a few bytes. This exits
|
||||
* here anyways... */
|
||||
|
||||
/* close(inFd);
|
||||
free(buf); */
|
||||
fatalError( outFile);
|
||||
}
|
||||
|
||||
lseek(inFd, skipBlocks * blockSize, SEEK_SET);
|
||||
@@ -184,9 +188,13 @@ extern int dd_main(int argc, char **argv)
|
||||
perror(inFile);
|
||||
|
||||
cleanup:
|
||||
/* Note that we are not freeing memory or closing
|
||||
* files here, to save a few bytes. */
|
||||
#if 0
|
||||
close(inFd);
|
||||
close(outFd);
|
||||
free(buf);
|
||||
#endif
|
||||
|
||||
printf("%ld+%d records in\n", (long) (intotal / blockSize),
|
||||
(intotal % blockSize) != 0);
|
||||
|
||||
+20
-10
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini df implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* based on original code by (I think) Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
@@ -27,11 +27,12 @@
|
||||
#include <mntent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/vfs.h>
|
||||
#include <fstab.h>
|
||||
|
||||
static const char df_usage[] = "df [filesystem ...]\n"
|
||||
|
||||
"\n" "\tPrint the filesystem space used and space available.\n";
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint the filesystem space used and space available.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern const char mtab_file[]; /* Defined in utility.c */
|
||||
|
||||
@@ -40,7 +41,6 @@ static int df(char *device, const char *mountPoint)
|
||||
struct statfs s;
|
||||
long blocks_used;
|
||||
long blocks_percent_used;
|
||||
struct fstab *fstabItem;
|
||||
|
||||
if (statfs(mountPoint, &s) != 0) {
|
||||
perror(mountPoint);
|
||||
@@ -51,11 +51,10 @@ static int df(char *device, const char *mountPoint)
|
||||
blocks_used = s.f_blocks - s.f_bfree;
|
||||
blocks_percent_used = (long)
|
||||
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
|
||||
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
|
||||
if (strcmp(device, "/dev/root") == 0) {
|
||||
fstabItem = getfsfile("/");
|
||||
if (fstabItem != NULL)
|
||||
device = fstabItem->fs_spec;
|
||||
/* Adjusts device to be the real root device,
|
||||
* or leaves device alone if it can't find it */
|
||||
find_real_root_device_name( device);
|
||||
}
|
||||
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
|
||||
device,
|
||||
@@ -78,6 +77,9 @@ extern int df_main(int argc, char **argv)
|
||||
struct mntent *mountEntry;
|
||||
int status;
|
||||
|
||||
if (**(argv + 1) == '-') {
|
||||
usage(df_usage);
|
||||
}
|
||||
while (argc > 1) {
|
||||
if ((mountEntry = findMountPoint(argv[1], mtab_file)) == 0) {
|
||||
fprintf(stderr, "%s: can't find mount point.\n", argv[1]);
|
||||
@@ -106,5 +108,13 @@ extern int df_main(int argc, char **argv)
|
||||
endmntent(mountTable);
|
||||
}
|
||||
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -0,0 +1,49 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini dirname implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern int dirname_main(int argc, char **argv)
|
||||
{
|
||||
char* s;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage("dirname [FILENAME ...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nStrips non-directory suffix from FILENAME\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
argv++;
|
||||
|
||||
s=*argv+strlen(*argv)-1;
|
||||
while (s && *s == '/') {
|
||||
*s = '\0';
|
||||
s=*argv+strlen(*argv)-1;
|
||||
}
|
||||
s = strrchr(*argv, '/');
|
||||
if (s && *s)
|
||||
*s = '\0';
|
||||
printf("%s\n", (s)? *argv : ".");
|
||||
return(TRUE);
|
||||
}
|
||||
+54
-16
@@ -3,7 +3,7 @@
|
||||
* Mini du implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -32,22 +32,28 @@
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/param.h> /* for PATH_MAX */
|
||||
|
||||
typedef void (Display) (long, char *);
|
||||
|
||||
static const char du_usage[] =
|
||||
|
||||
"du [OPTION]... [FILE]...\n\n"
|
||||
"\t-s\tdisplay only a total for each argument\n";
|
||||
"du [OPTION]... [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nSummarizes disk space used for each FILE and/or directory.\n"
|
||||
"Disk space is printed in units of 1024 bytes.\n\n"
|
||||
"Options:\n"
|
||||
"\t-l\tcount sizes many times if hard linked\n"
|
||||
"\t-s\tdisplay only a total for each argument\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
static int du_depth = 0;
|
||||
static int count_hardlinks = 0;
|
||||
|
||||
static Display *print;
|
||||
|
||||
static void print_normal(long size, char *filename)
|
||||
{
|
||||
fprintf(stdout, "%-7ld %s\n", size, filename);
|
||||
fprintf(stdout, "%ld\t%s\n", size, filename);
|
||||
}
|
||||
|
||||
static void print_summary(long size, char *filename)
|
||||
@@ -57,24 +63,26 @@ static void print_summary(long size, char *filename)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* tiny recursive du */
|
||||
static long du(char *filename)
|
||||
{
|
||||
struct stat statbuf;
|
||||
long sum;
|
||||
int len;
|
||||
|
||||
if ((lstat(filename, &statbuf)) != 0) {
|
||||
fprintf(stdout, "du: %s: %s\n", filename, strerror(errno));
|
||||
printf("du: %s: %s\n", filename, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
du_depth++;
|
||||
sum = statbuf.st_blocks;
|
||||
sum = (statbuf.st_blocks >> 1);
|
||||
|
||||
/* Don't add in stuff pointed to by links */
|
||||
/* Don't add in stuff pointed to by symbolic links */
|
||||
if (S_ISLNK(statbuf.st_mode)) {
|
||||
return 0;
|
||||
sum = 0L;
|
||||
if (du_depth == 1)
|
||||
print(sum, filename);
|
||||
}
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
DIR *dir;
|
||||
@@ -82,10 +90,16 @@ static long du(char *filename)
|
||||
|
||||
dir = opendir(filename);
|
||||
if (!dir) {
|
||||
du_depth--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = strlen(filename);
|
||||
if (filename[len - 1] == '/')
|
||||
filename[--len] = '\0';
|
||||
|
||||
while ((entry = readdir(dir))) {
|
||||
char newfile[PATH_MAX + 1];
|
||||
char newfile[BUFSIZ + 1];
|
||||
char *name = entry->d_name;
|
||||
|
||||
if ((strcmp(name, "..") == 0)
|
||||
@@ -93,8 +107,9 @@ static long du(char *filename)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (strlen(filename) + strlen(name) + 1 > PATH_MAX) {
|
||||
if (len + strlen(name) + 1 > BUFSIZ) {
|
||||
fprintf(stderr, name_too_long, "du");
|
||||
du_depth--;
|
||||
return 0;
|
||||
}
|
||||
sprintf(newfile, "%s/%s", filename, name);
|
||||
@@ -104,6 +119,17 @@ static long du(char *filename)
|
||||
closedir(dir);
|
||||
print(sum, filename);
|
||||
}
|
||||
else if (statbuf.st_nlink > 1 && !count_hardlinks) {
|
||||
/* Add files with hard links only once */
|
||||
if (is_in_ino_dev_hashtable(&statbuf, NULL)) {
|
||||
sum = 0L;
|
||||
if (du_depth == 1)
|
||||
print(sum, filename);
|
||||
}
|
||||
else {
|
||||
add_to_ino_dev_hashtable(&statbuf, NULL);
|
||||
}
|
||||
}
|
||||
du_depth--;
|
||||
return sum;
|
||||
}
|
||||
@@ -124,7 +150,11 @@ int du_main(int argc, char **argv)
|
||||
case 's':
|
||||
print = print_summary;
|
||||
break;
|
||||
case 'l':
|
||||
count_hardlinks = 1;
|
||||
break;
|
||||
case 'h':
|
||||
case '-':
|
||||
usage(du_usage);
|
||||
break;
|
||||
default:
|
||||
@@ -144,13 +174,21 @@ int du_main(int argc, char **argv)
|
||||
|
||||
for (; i < argc; i++) {
|
||||
sum = du(argv[i]);
|
||||
if ((sum) && (isDirectory(argv[i], FALSE, NULL))) {
|
||||
if (sum && isDirectory(argv[i], FALSE, NULL)) {
|
||||
print_normal(sum, argv[i]);
|
||||
}
|
||||
reset_ino_dev_hashtable();
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* $Id: du.c,v 1.12 2000/02/11 21:55:04 erik Exp $ */
|
||||
/* $Id: du.c,v 1.20 2000/06/19 17:25:39 andersen Exp $ */
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -0,0 +1,122 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* echo implementation for busybox
|
||||
*
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Original copyright notice is retained at the end of this file.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static const char uname_usage[] =
|
||||
"echo [-neE] [ARG ...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrints the specified ARGs to stdout\n\n"
|
||||
"Options:\n"
|
||||
"\t-n\tsuppress trailing newline\n"
|
||||
"\t-e\tinterpret backslash-escaped characters (i.e. \\t=tab etc)\n"
|
||||
"\t-E\tdisable interpretation of backslash-escaped characters\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int
|
||||
echo_main(int argc, char** argv)
|
||||
{
|
||||
register char **ap;
|
||||
char *p;
|
||||
register char c;
|
||||
int nflag = 0;
|
||||
int eflag = 0;
|
||||
|
||||
ap = argv;
|
||||
if (argc)
|
||||
ap++;
|
||||
while ((p = *ap) != NULL && *p == '-') {
|
||||
if (strcmp(p, "-n")==0) {
|
||||
nflag = 1;
|
||||
} else if (strcmp(p, "-e")==0) {
|
||||
eflag = 1;
|
||||
} else if (strcmp(p, "-E")==0) {
|
||||
eflag = 0;
|
||||
}
|
||||
else if (strncmp(p, "--", 2)==0) {
|
||||
usage( uname_usage);
|
||||
}
|
||||
else break;
|
||||
ap++;
|
||||
}
|
||||
while ((p = *ap++) != NULL) {
|
||||
while ((c = *p++) != '\0') {
|
||||
if (c == '\\' && eflag) {
|
||||
if (*p == 'c')
|
||||
exit(0);
|
||||
else
|
||||
c = process_escape_sequence(&p);
|
||||
}
|
||||
putchar(c);
|
||||
}
|
||||
if (*ap)
|
||||
putchar(' ');
|
||||
}
|
||||
if (! nflag)
|
||||
putchar('\n');
|
||||
fflush(stdout);
|
||||
return( 0);
|
||||
}
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Kenneth Almquist.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)echo.c 8.1 (Berkeley) 5/31/93
|
||||
*/
|
||||
|
||||
|
||||
+9
-6
@@ -3,7 +3,7 @@
|
||||
* Mini head implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -27,12 +27,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
const char head_usage[] =
|
||||
"head [OPTION] [FILE]...\n\n"
|
||||
"Print first 10 lines of each FILE to standard output.\n"
|
||||
"head [OPTION] [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint first 10 lines of each FILE to standard output.\n"
|
||||
"With more than one FILE, precede each with a header giving the\n"
|
||||
"file name. With no FILE, or when FILE is -, read standard input.\n\n"
|
||||
|
||||
"Options:\n" "\t-n NUM\t\tPrint first NUM lines instead of first 10\n";
|
||||
"Options:\n" "\t-n NUM\t\tPrint first NUM lines instead of first 10\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
int head(int len, FILE * src)
|
||||
{
|
||||
@@ -106,7 +109,7 @@ int head_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* $Id: head.c,v 1.8 2000/02/08 19:58:47 erik Exp $ */
|
||||
/* $Id: head.c,v 1.11 2000/06/19 17:25:39 andersen Exp $ */
|
||||
+1
-1
@@ -26,5 +26,5 @@
|
||||
extern int hostid_main(int argc, char **argv)
|
||||
{
|
||||
printf("%lx\n", gethostid());
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini id implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2000 by Randolph Chung <tausq@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
static const char id_usage[] =
|
||||
"id [OPTIONS]... [USERNAME]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint information for USERNAME or the current user\n\n"
|
||||
"Options:\n"
|
||||
"\t-g\tprints only the group ID\n"
|
||||
"\t-u\tprints only the user ID\n"
|
||||
"\t-r\tprints the real user ID instead of the effective ID (with -ug)\n\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int id_main(int argc, char **argv)
|
||||
{
|
||||
int no_user = 0, no_group = 0, print_real = 0;
|
||||
char *cp, *user, *group;
|
||||
unsigned long gid;
|
||||
|
||||
cp = user = group = NULL;
|
||||
|
||||
argc--; argv++;
|
||||
|
||||
while (argc > 0) {
|
||||
cp = *argv;
|
||||
if (*cp == '-') {
|
||||
switch (*++cp) {
|
||||
case 'u': no_group = 1; break;
|
||||
case 'g': no_user = 1; break;
|
||||
case 'r': print_real = 1; break;
|
||||
default: usage(id_usage);
|
||||
}
|
||||
} else {
|
||||
user = cp;
|
||||
}
|
||||
argc--; argv++;
|
||||
}
|
||||
|
||||
if (no_user && no_group) usage(id_usage);
|
||||
|
||||
if (user == NULL) {
|
||||
user = xmalloc(9);
|
||||
group = xmalloc(9);
|
||||
if (print_real) {
|
||||
my_getpwuid(user, getuid());
|
||||
my_getgrgid(group, getgid());
|
||||
} else {
|
||||
my_getpwuid(user, geteuid());
|
||||
my_getgrgid(group, getegid());
|
||||
}
|
||||
} else {
|
||||
group = xmalloc(9);
|
||||
gid = my_getpwnamegid(user);
|
||||
my_getgrgid(group, gid);
|
||||
}
|
||||
|
||||
if (no_group) printf("%lu\n", my_getpwnam(user));
|
||||
else if (no_user) printf("%lu\n", my_getgrnam(group));
|
||||
else
|
||||
printf("uid=%lu(%s) gid=%lu(%s)\n",
|
||||
my_getpwnam(user), user, my_getgrnam(group), group);
|
||||
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
/* END CODE */
|
||||
+6
-2
@@ -7,8 +7,12 @@
|
||||
extern int length_main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 2 || **(argv + 1) == '-') {
|
||||
usage("length string\n");
|
||||
usage("length STRING\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrints out the length of the specified STRING.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
printf("%d\n", strlen(argv[1]));
|
||||
printf("%lu\n", (long)strlen(argv[1]));
|
||||
return (TRUE);
|
||||
}
|
||||
+65
-50
@@ -2,8 +2,7 @@
|
||||
/*
|
||||
* Mini ln implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -31,16 +30,19 @@
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <sys/param.h> /* for PATH_MAX */
|
||||
|
||||
static const char ln_usage[] =
|
||||
"ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n"
|
||||
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n"
|
||||
"ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCreate a link named LINK_NAME or DIRECTORY to the specified TARGET\n"
|
||||
"\nYou may use '--' to indicate that all following arguments are non-options.\n\n"
|
||||
"Options:\n"
|
||||
"\t-s\tmake symbolic links instead of hard links\n"
|
||||
|
||||
"\t-f\tremove existing destination files\n"
|
||||
"\t-n\tno dereference symlinks - treat like normal file\n";
|
||||
"\t-n\tno dereference symlinks - treat like normal file\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
static int symlinkFlag = FALSE;
|
||||
static int removeoldFlag = FALSE;
|
||||
@@ -48,65 +50,65 @@ static int followLinks = TRUE;
|
||||
|
||||
extern int ln_main(int argc, char **argv)
|
||||
{
|
||||
char *linkName;
|
||||
char *linkName, *dirName=NULL;
|
||||
int linkIntoDirFlag;
|
||||
int stopIt = FALSE;
|
||||
|
||||
if (argc < 3) {
|
||||
usage(ln_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 's':
|
||||
symlinkFlag = TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
removeoldFlag = TRUE;
|
||||
break;
|
||||
case 'n':
|
||||
followLinks = FALSE;
|
||||
break;
|
||||
default:
|
||||
usage(ln_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
while (argc > 0 && stopIt == FALSE) {
|
||||
if (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 's':
|
||||
symlinkFlag = TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
removeoldFlag = TRUE;
|
||||
break;
|
||||
case 'n':
|
||||
followLinks = FALSE;
|
||||
break;
|
||||
case '-':
|
||||
stopIt = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage(ln_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (argc < 2) {
|
||||
usage(ln_usage);
|
||||
}
|
||||
|
||||
linkName = argv[argc - 1];
|
||||
|
||||
if (strlen(linkName) > PATH_MAX) {
|
||||
fprintf(stderr, name_too_long, "ln");
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
linkIntoDirFlag = isDirectory(linkName, TRUE, NULL);
|
||||
|
||||
if ((argc > 3) && !linkIntoDirFlag) {
|
||||
linkIntoDirFlag = isDirectory(linkName, followLinks, NULL);
|
||||
if ((argc >= 3) && linkIntoDirFlag == FALSE) {
|
||||
fprintf(stderr, not_a_directory, "ln", linkName);
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
if (linkIntoDirFlag == TRUE)
|
||||
dirName = linkName;
|
||||
|
||||
while (argc-- >= 2) {
|
||||
char srcName[PATH_MAX + 1];
|
||||
int nChars, status;
|
||||
int status;
|
||||
|
||||
if (strlen(*argv) > PATH_MAX) {
|
||||
fprintf(stderr, name_too_long, "ln");
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
if (followLinks == FALSE) {
|
||||
strcpy(srcName, *argv);
|
||||
} else {
|
||||
/* Warning! This can silently truncate if > PATH_MAX, but
|
||||
I don't think that there can be one > PATH_MAX anyway. */
|
||||
nChars = readlink(*argv, srcName, PATH_MAX);
|
||||
srcName[nChars] = '\0';
|
||||
if (linkIntoDirFlag == TRUE) {
|
||||
char *baseName = get_last_path_component(*argv);
|
||||
linkName = (char *)malloc(strlen(dirName)+strlen(baseName)+2);
|
||||
strcpy(linkName, dirName);
|
||||
if(dirName[strlen(dirName)-1] != '/')
|
||||
strcat(linkName, "/");
|
||||
strcat(linkName,baseName);
|
||||
}
|
||||
|
||||
if (removeoldFlag == TRUE) {
|
||||
@@ -125,6 +127,19 @@ extern int ln_main(int argc, char **argv)
|
||||
perror(linkName);
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
if (linkIntoDirFlag == TRUE)
|
||||
free(linkName);
|
||||
|
||||
argv++;
|
||||
}
|
||||
exit TRUE;
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+11
-9
@@ -23,22 +23,24 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static const char logname_usage[] = "logname\n\n"
|
||||
|
||||
"Print the name of the current user.\n";
|
||||
static const char logname_usage[] = "logname\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint the name of the current user.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int logname_main(int argc, char **argv)
|
||||
{
|
||||
char *cp;
|
||||
char *user = xmalloc(9);
|
||||
|
||||
if (argc > 1)
|
||||
usage(logname_usage);
|
||||
|
||||
cp = getlogin();
|
||||
if (cp) {
|
||||
puts(cp);
|
||||
my_getpwuid(user, geteuid());
|
||||
if (user) {
|
||||
puts(user);
|
||||
exit(TRUE);
|
||||
}
|
||||
fprintf(stderr, "%s: no login name\n", argv[0]);
|
||||
exit(FALSE);
|
||||
fprintf(stderr, "no login name\n");
|
||||
return(FALSE);
|
||||
}
|
||||
+81
-26
@@ -49,11 +49,7 @@
|
||||
/************************************************************************/
|
||||
|
||||
#include "internal.h"
|
||||
#if !defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||
# include <linux/types.h>
|
||||
#else
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@@ -70,11 +66,6 @@
|
||||
#define APPCHAR(mode) ("\0|\0\0/\0\0\0\0\0@\0=\0\0\0" [TYPEINDEX(mode)])
|
||||
#endif
|
||||
|
||||
#ifndef MAJOR
|
||||
#define MAJOR(dev) (((dev)>>8)&0xff)
|
||||
#define MINOR(dev) ((dev)&0xff)
|
||||
#endif
|
||||
|
||||
#define FMT_AUTO 0
|
||||
#define FMT_LONG 1 /* one record per line, extended info */
|
||||
#define FMT_SINGLE 2 /* one record per line */
|
||||
@@ -91,9 +82,14 @@
|
||||
#define DISP_DOT 8 /* show . and .. */
|
||||
#define DISP_NUMERIC 16 /* numeric uid and gid */
|
||||
#define DISP_FULLTIME 32 /* show extended time display */
|
||||
#define DIR_NOLIST 64 /* show directory as itself, not contents */
|
||||
#define DIR_NOLIST 64 /* show directory as itself, not contents */
|
||||
#define DISP_DIRNAME 128 /* show directory name (for internal use) */
|
||||
#define DIR_RECURSE 256 /* -R (not yet implemented) */
|
||||
#define DISP_RECURSIVE 256 /* Do a recursive listing */
|
||||
|
||||
#ifndef MAJOR
|
||||
#define MAJOR(dev) (((dev)>>8)&0xff)
|
||||
#define MINOR(dev) ((dev)&0xff)
|
||||
#endif
|
||||
|
||||
static unsigned char display_fmt = FMT_AUTO;
|
||||
static unsigned short opts = 0;
|
||||
@@ -184,7 +180,7 @@ static char append_char(mode_t mode)
|
||||
static void list_single(const char *name, struct stat *info,
|
||||
const char *fullname)
|
||||
{
|
||||
char scratch[PATH_MAX + 1];
|
||||
char scratch[BUFSIZ + 1];
|
||||
short len = strlen(name);
|
||||
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
@@ -345,7 +341,7 @@ static int list_item(const char *name)
|
||||
struct stat info;
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
char fullname[MAXNAMLEN + 1], *fnend;
|
||||
char fullname[BUFSIZ + 1], *fnend;
|
||||
|
||||
if (lstat(name, &info))
|
||||
goto listerr;
|
||||
@@ -450,10 +446,54 @@ static const char ls_usage[] = "ls [-1a"
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
"F"
|
||||
#endif
|
||||
#ifdef FEATURE_RECURSIVE
|
||||
#ifdef BB_FEATURE_LS_RECURSIVE
|
||||
"R"
|
||||
#endif
|
||||
"] [filenames...]\n";
|
||||
"] [filenames...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nList directory contents\n\n"
|
||||
"Options:\n"
|
||||
"\t-a\tdo not hide entries starting with .\n"
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
"\t-c\twith -l: show ctime (the time of last\n"
|
||||
"\t\tmodification of file status information)\n"
|
||||
#endif
|
||||
"\t-d\tlist directory entries instead of contents\n"
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
"\t-e\tlist both full date and full time\n"
|
||||
#endif
|
||||
"\t-l\tuse a long listing format\n"
|
||||
"\t-n\tlist numeric UIDs and GIDs instead of names\n"
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
"\t-p\tappend indicator (one of /=@|) to entries\n"
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
"\t-u\twith -l: show access time (the time of last\n"
|
||||
"\t\taccess of the file)\n"
|
||||
#endif
|
||||
"\t-x\tlist entries by lines instead of by columns\n"
|
||||
"\t-A\tdo not list implied . and ..\n"
|
||||
"\t-C\tlist entries by columns\n"
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
"\t-F\tappend indicator (one of */=@|) to entries\n"
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LS_RECURSIVE
|
||||
"\t-R\tlist subdirectories recursively\n"
|
||||
#endif
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
#ifdef BB_FEATURE_LS_RECURSIVE
|
||||
static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
int i;
|
||||
fprintf(stdout, "\n%s:\n", fileName);
|
||||
i = list_item(fileName);
|
||||
newline();
|
||||
return (i);
|
||||
}
|
||||
#endif
|
||||
|
||||
extern int ls_main(int argc, char **argv)
|
||||
{
|
||||
@@ -508,11 +548,6 @@ extern int ls_main(int argc, char **argv)
|
||||
case 'd':
|
||||
opts |= DIR_NOLIST;
|
||||
break;
|
||||
#ifdef FEATURE_RECURSIVE
|
||||
case 'R':
|
||||
opts |= DIR_RECURSE;
|
||||
break;
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
case 'u':
|
||||
time_fmt = TIME_ACCESS;
|
||||
@@ -524,6 +559,13 @@ extern int ls_main(int argc, char **argv)
|
||||
opts |= DISP_FULLTIME;
|
||||
break;
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LS_RECURSIVE
|
||||
case 'R':
|
||||
opts |= DISP_RECURSIVE;
|
||||
break;
|
||||
#endif
|
||||
case 'g': /* ignore -- for ftp servers */
|
||||
break;
|
||||
default:
|
||||
goto print_usage_message;
|
||||
}
|
||||
@@ -550,12 +592,25 @@ extern int ls_main(int argc, char **argv)
|
||||
#endif
|
||||
|
||||
/* process files specified, or current directory if none */
|
||||
i = 0;
|
||||
if (argi == argc)
|
||||
i = list_item(".");
|
||||
while (argi < argc)
|
||||
i |= list_item(argv[argi++]);
|
||||
newline();
|
||||
#ifdef BB_FEATURE_LS_RECURSIVE
|
||||
if (opts & DISP_RECURSIVE) {
|
||||
i = 0;
|
||||
if (argi == argc) {
|
||||
i = recursiveAction(".", TRUE, FALSE, FALSE, NULL, dirAction, NULL);
|
||||
}
|
||||
while (argi < argc) {
|
||||
i |= recursiveAction(argv[argi++], TRUE, FALSE, FALSE, NULL, dirAction, NULL);
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
i = 0;
|
||||
if (argi == argc)
|
||||
i = list_item(".");
|
||||
while (argi < argc)
|
||||
i |= list_item(argv[argi++]);
|
||||
newline();
|
||||
}
|
||||
exit(i);
|
||||
|
||||
print_usage_message:
|
||||
|
||||
+1021
File diff suppressed because it is too large.
Load diff
+10
-9
@@ -2,8 +2,7 @@
|
||||
/*
|
||||
* Mini mkdir implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -29,15 +28,17 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/param.h> /* for PATH_MAX */
|
||||
|
||||
static const char mkdir_usage[] =
|
||||
"mkdir [OPTION] DIRECTORY...\n\n"
|
||||
"Create the DIRECTORY(ies), if they do not already exist\n\n"
|
||||
"mkdir [OPTION] DIRECTORY...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCreate the DIRECTORY(ies), if they do not already exist\n\n"
|
||||
"Options:\n"
|
||||
|
||||
"\t-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
|
||||
"\t-p\tno error if existing, make parent directories as needed\n";
|
||||
"\t-p\tno error if existing, make parent directories as needed\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
static int parentFlag = FALSE;
|
||||
@@ -87,9 +88,9 @@ extern int mkdir_main(int argc, char **argv)
|
||||
while (argc > 0) {
|
||||
int status;
|
||||
struct stat statBuf;
|
||||
char buf[PATH_MAX + 1];
|
||||
char buf[BUFSIZ + 1];
|
||||
|
||||
if (strlen(*argv) > PATH_MAX - 1) {
|
||||
if (strlen(*argv) > BUFSIZ - 1) {
|
||||
fprintf(stderr, name_too_long, "mkdir");
|
||||
exit FALSE;
|
||||
}
|
||||
@@ -111,5 +112,5 @@ extern int mkdir_main(int argc, char **argv)
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
exit TRUE;
|
||||
return( TRUE);
|
||||
}
|
||||
+8
-7
@@ -26,11 +26,13 @@
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char mkfifo_usage[] = "mkfifo [OPTIONS] name\n\n"
|
||||
"Create the named fifo\n\n"
|
||||
|
||||
static const char mkfifo_usage[] = "mkfifo [OPTIONS] name\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCreates a named pipe (identical to 'mknod name p')\n\n"
|
||||
"Options:\n"
|
||||
"\t-m\tcreate the fifo with the specified mode; default = a=rw-umask\n";
|
||||
"\t-m\tcreate the pipe using the specified mode (default a=rw)\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int mkfifo_main(int argc, char **argv)
|
||||
{
|
||||
@@ -58,12 +60,11 @@ extern int mkfifo_main(int argc, char **argv)
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
if (argc < 1)
|
||||
if (argc < 1 || *argv[0] == '-')
|
||||
usage(mkfifo_usage);
|
||||
if (mkfifo(*argv, mode) < 0) {
|
||||
perror("mkfifo");
|
||||
exit(255);
|
||||
} else {
|
||||
exit(TRUE);
|
||||
}
|
||||
return(TRUE);
|
||||
}
|
||||
+42
-15
@@ -28,23 +28,51 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static const char mknod_usage[] = "mknod NAME TYPE MAJOR MINOR\n\n"
|
||||
"Make block or character special files.\n\n"
|
||||
static const char mknod_usage[] = "mknod [OPTIONS] NAME TYPE MAJOR MINOR\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCreate a special file (block, character, or pipe).\n\n"
|
||||
"Options:\n"
|
||||
"\t-m\tcreate the special file using the specified mode (default a=rw)\n\n"
|
||||
"TYPEs include:\n"
|
||||
"\tb:\tMake a block (buffered) device.\n"
|
||||
|
||||
"\tc or u:\tMake a character (un-buffered) device.\n"
|
||||
"\tp:\tMake a named pipe. Major and minor are ignored for named pipes.\n";
|
||||
"\tp:\tMake a named pipe. MAJOR and MINOR are ignored for named pipes.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
int mknod_main(int argc, char **argv)
|
||||
{
|
||||
char *thisarg;
|
||||
mode_t mode = 0;
|
||||
mode_t perm = 0666;
|
||||
dev_t dev = 0;
|
||||
|
||||
if (argc != 5 || **(argv + 1) == '-') {
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (argc > 1) {
|
||||
if (**argv != '-')
|
||||
break;
|
||||
thisarg = *argv;
|
||||
thisarg++;
|
||||
switch (*thisarg) {
|
||||
case 'm':
|
||||
argc--;
|
||||
argv++;
|
||||
parse_mode(*argv, &perm);
|
||||
umask(0);
|
||||
break;
|
||||
default:
|
||||
usage(mknod_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
if (argc != 4 && argc != 2) {
|
||||
usage(mknod_usage);
|
||||
}
|
||||
switch (argv[2][0]) {
|
||||
switch (argv[1][0]) {
|
||||
case 'c':
|
||||
case 'u':
|
||||
mode = S_IFCHR;
|
||||
@@ -54,23 +82,22 @@ int mknod_main(int argc, char **argv)
|
||||
break;
|
||||
case 'p':
|
||||
mode = S_IFIFO;
|
||||
if (argc!=2) {
|
||||
usage(mknod_usage);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
usage(mknod_usage);
|
||||
}
|
||||
|
||||
if (mode == S_IFCHR || mode == S_IFBLK) {
|
||||
dev = (atoi(argv[3]) << 8) | atoi(argv[4]);
|
||||
if (argc != 5) {
|
||||
usage(mknod_usage);
|
||||
}
|
||||
dev = (atoi(argv[2]) << 8) | atoi(argv[3]);
|
||||
}
|
||||
|
||||
mode |= 0666;
|
||||
mode |= perm;
|
||||
|
||||
if (mknod(argv[1], mode, dev) != 0) {
|
||||
perror(argv[1]);
|
||||
return (FALSE);
|
||||
}
|
||||
if (mknod(argv[0], mode, dev) != 0)
|
||||
fatalError("%s: %s\n", argv[0], strerror(errno));
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
+7
-4
@@ -51,14 +51,12 @@
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <libintl.h>
|
||||
|
||||
|
||||
#ifndef S_IFMT
|
||||
@@ -139,7 +137,12 @@ static void verify __P((char *s, char *end));
|
||||
/* The value to return to the calling program. */
|
||||
static int exit_status;
|
||||
|
||||
static const char printf_usage[] = "printf format [argument...]\n";
|
||||
static const char printf_usage[] = "printf FORMAT [ARGUMENT...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nFormats and prints ARGUMENT(s) according to FORMAT,\n"
|
||||
"Where FORMAT controls the output exactly as in C printf.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
int printf_main(int argc, char **argv)
|
||||
{
|
||||
@@ -167,7 +170,7 @@ int printf_main(int argc, char **argv)
|
||||
fprintf(stderr, "excess args ignored");
|
||||
*/
|
||||
|
||||
exit(exit_status);
|
||||
return(exit_status);
|
||||
}
|
||||
|
||||
/* Print the text in FORMAT, using ARGV (with ARGC elements) for
|
||||
|
||||
+5
-7
@@ -24,17 +24,15 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/param.h>
|
||||
#include <errno.h>
|
||||
|
||||
extern int pwd_main(int argc, char **argv)
|
||||
{
|
||||
char buf[PATH_MAX + 1];
|
||||
char buf[BUFSIZ + 1];
|
||||
|
||||
if (getcwd(buf, sizeof(buf)) == NULL) {
|
||||
perror("get working directory");
|
||||
exit(FALSE);
|
||||
}
|
||||
if (getcwd(buf, sizeof(buf)) == NULL)
|
||||
fatalError("pwd: %s\n", strerror(errno));
|
||||
|
||||
printf("%s\n", buf);
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
+39
-27
@@ -3,7 +3,7 @@
|
||||
* Mini rm implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -29,12 +29,15 @@
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char *rm_usage = "rm [OPTION]... FILE...\n\n"
|
||||
"Remove (unlink) the FILE(s).\n\n"
|
||||
static const char *rm_usage = "rm [OPTION]... FILE...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nRemove (unlink) the FILE(s). You may use '--' to\n"
|
||||
"indicate that all following arguments are non-options.\n\n"
|
||||
"Options:\n"
|
||||
|
||||
"\t-f\t\tremove existing destinations, never prompt\n"
|
||||
"\t-r or -R\tremove the contents of directories recursively\n";
|
||||
"\t-r or -R\tremove the contents of directories recursively\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
static int recursiveFlag = FALSE;
|
||||
@@ -42,7 +45,7 @@ static int forceFlag = FALSE;
|
||||
static const char *srcName;
|
||||
|
||||
|
||||
static int fileAction(const char *fileName, struct stat *statbuf)
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
if (unlink(fileName) < 0) {
|
||||
perror(fileName);
|
||||
@@ -51,7 +54,7 @@ static int fileAction(const char *fileName, struct stat *statbuf)
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
static int dirAction(const char *fileName, struct stat *statbuf)
|
||||
static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
if (rmdir(fileName) < 0) {
|
||||
perror(fileName);
|
||||
@@ -62,30 +65,39 @@ static int dirAction(const char *fileName, struct stat *statbuf)
|
||||
|
||||
extern int rm_main(int argc, char **argv)
|
||||
{
|
||||
int stopIt=FALSE;
|
||||
struct stat statbuf;
|
||||
|
||||
if (argc < 2) {
|
||||
usage(rm_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 'R':
|
||||
case 'r':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
forceFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage(rm_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
while (argc > 0 && stopIt == FALSE) {
|
||||
if (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 'R':
|
||||
case 'r':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
forceFlag = TRUE;
|
||||
break;
|
||||
case '-':
|
||||
stopIt = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage(rm_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (argc < 1 && forceFlag == FALSE) {
|
||||
usage(rm_usage);
|
||||
}
|
||||
|
||||
while (argc-- > 0) {
|
||||
@@ -95,10 +107,10 @@ extern int rm_main(int argc, char **argv)
|
||||
/* do not reports errors for non-existent files if -f, just skip them */
|
||||
} else {
|
||||
if (recursiveAction(srcName, recursiveFlag, FALSE,
|
||||
TRUE, fileAction, dirAction) == FALSE) {
|
||||
TRUE, fileAction, dirAction, NULL) == FALSE) {
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
+7
-3
@@ -3,7 +3,7 @@
|
||||
* Mini rmdir implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -31,7 +31,11 @@ extern int rmdir_main(int argc, char **argv)
|
||||
{
|
||||
if (argc == 1 || **(argv + 1) == '-') {
|
||||
usage
|
||||
("rmdir [OPTION]... DIRECTORY...\n\nRemove the DIRECTORY(ies), if they are empty.\n");
|
||||
("rmdir [OPTION]... DIRECTORY...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nRemove the DIRECTORY(ies), if they are empty.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
while (--argc > 0) {
|
||||
@@ -40,5 +44,5 @@ extern int rmdir_main(int argc, char **argv)
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
+7
-3
@@ -24,7 +24,11 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
const char sleep_usage[] = "sleep N\n\n" "Pause for N seconds.\n";
|
||||
const char sleep_usage[] = "sleep N\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPause for N seconds.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int sleep_main(int argc, char **argv)
|
||||
{
|
||||
@@ -35,6 +39,6 @@ extern int sleep_main(int argc, char **argv)
|
||||
if (sleep(atoi(*(++argv))) != 0) {
|
||||
perror("sleep");
|
||||
exit(FALSE);
|
||||
} else
|
||||
exit(TRUE);
|
||||
}
|
||||
return(TRUE);
|
||||
}
|
||||
+30
-36
@@ -3,7 +3,7 @@
|
||||
* Mini sort implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -29,7 +29,22 @@
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char sort_usage[] = "sort [OPTION]... [FILE]...\n\n";
|
||||
static const char sort_usage[] = "sort [-n]"
|
||||
#ifdef BB_FEATURE_SORT_REVERSE
|
||||
" [-r]"
|
||||
#endif
|
||||
" [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nSorts lines of text in the specified files\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
#ifdef BB_FEATURE_SORT_REVERSE
|
||||
#define APPLY_REVERSE(x) (reverse ? -(x) : (x))
|
||||
static int reverse = 0;
|
||||
#else
|
||||
#define APPLY_REVERSE(x) (x)
|
||||
#endif
|
||||
|
||||
/* typedefs _______________________________________________________________ */
|
||||
|
||||
@@ -43,7 +58,6 @@ typedef struct Line {
|
||||
typedef struct {
|
||||
int len; /* number of Lines */
|
||||
Line **sorted; /* array fed to qsort */
|
||||
|
||||
Line *head; /* head of List */
|
||||
Line *current; /* current Line */
|
||||
} List;
|
||||
@@ -60,36 +74,23 @@ static const int max = 1024;
|
||||
static Line *line_alloc()
|
||||
{
|
||||
Line *self;
|
||||
|
||||
self = malloc(1 * sizeof(Line));
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Initialize Line with string */
|
||||
static Line *line_init(Line * self, const char *string)
|
||||
{
|
||||
self->data = malloc((strlen(string) + 1) * sizeof(char));
|
||||
|
||||
if (self->data == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
strcpy(self->data, string);
|
||||
self->next = NULL;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Construct Line from FILE* */
|
||||
static Line *line_newFromFile(FILE * src)
|
||||
{
|
||||
char buffer[max];
|
||||
Line *self;
|
||||
char *cstring = NULL;
|
||||
|
||||
if (fgets(buffer, max, src)) {
|
||||
if ((cstring = get_line_from_file(src))) {
|
||||
self = line_alloc();
|
||||
if (self == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
line_init(self, buffer);
|
||||
self->data = cstring;
|
||||
self->next = NULL;
|
||||
return self;
|
||||
}
|
||||
return NULL;
|
||||
@@ -120,7 +121,7 @@ static int compare_ascii(const void *a, const void *b)
|
||||
y = *doh;
|
||||
|
||||
// fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data);
|
||||
return strcmp(x->data, y->data);
|
||||
return APPLY_REVERSE(strcmp(x->data, y->data));
|
||||
}
|
||||
|
||||
/* numeric order */
|
||||
@@ -138,7 +139,7 @@ static int compare_numeric(const void *a, const void *b)
|
||||
xint = strtoul(x->data, NULL, 10);
|
||||
yint = strtoul(y->data, NULL, 10);
|
||||
|
||||
return (xint - yint);
|
||||
return APPLY_REVERSE(xint - yint);
|
||||
}
|
||||
|
||||
|
||||
@@ -166,7 +167,7 @@ static List *list_insert(List * self, Line * line)
|
||||
self->head = line;
|
||||
self->current = line;
|
||||
|
||||
/* all subsequent insertions */
|
||||
/* all subsequent insertions */
|
||||
} else {
|
||||
self->current->next = line;
|
||||
self->current = line;
|
||||
@@ -230,12 +231,6 @@ static void list_release(List * self)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* I need a list
|
||||
* to insert lines into
|
||||
* then I need to sort this list
|
||||
* and finally print it
|
||||
*/
|
||||
|
||||
int sort_main(int argc, char **argv)
|
||||
{
|
||||
@@ -254,20 +249,19 @@ int sort_main(int argc, char **argv)
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 'g':
|
||||
/* what's the diff between -g && -n? */
|
||||
compare = compare_numeric;
|
||||
break;
|
||||
case 'h':
|
||||
usage(sort_usage);
|
||||
break;
|
||||
case 'n':
|
||||
/* what's the diff between -g && -n? */
|
||||
/* numeric comparison */
|
||||
compare = compare_numeric;
|
||||
break;
|
||||
#ifdef BB_FEATURE_SORT_REVERSE
|
||||
case 'r':
|
||||
/* reverse */
|
||||
reverse = 1;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
fprintf(stderr, "sort: invalid option -- %c\n", opt);
|
||||
usage(sort_usage);
|
||||
@@ -307,7 +301,7 @@ int sort_main(int argc, char **argv)
|
||||
list_release(&list);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* $Id: sort.c,v 1.11 2000/02/08 19:58:47 erik Exp $ */
|
||||
/* $Id: sort.c,v 1.18 2000/06/28 22:15:26 markw Exp $ */
|
||||
+6
-2
@@ -27,7 +27,11 @@
|
||||
extern int sync_main(int argc, char **argv)
|
||||
{
|
||||
if (argc > 1 && **(argv + 1) == '-') {
|
||||
usage("sync\n\nWrite all buffered filesystem blocks to disk.\n");
|
||||
usage("sync\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nWrite all buffered filesystem blocks to disk.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
exit(sync());
|
||||
return(sync());
|
||||
}
|
||||
+23
-12
@@ -47,6 +47,9 @@
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_help
|
||||
#include "messages.c"
|
||||
|
||||
|
||||
#define XWRITE(fd, buffer, n_bytes) \
|
||||
@@ -70,15 +73,18 @@ static int forever;
|
||||
static int print_headers;
|
||||
|
||||
const char tail_usage[] =
|
||||
"tail [OPTION] [FILE]...\n\n"
|
||||
"Print last 10 lines of each FILE to standard output.\n"
|
||||
"tail [OPTION] [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint last 10 lines of each FILE to standard output.\n"
|
||||
"With more than one FILE, precede each with a header giving the\n"
|
||||
"file name. With no FILE, or when FILE is -, read standard input.\n\n"
|
||||
"Options:\n"
|
||||
"\t-n NUM\t\tPrint last NUM lines instead of first 10\n"
|
||||
|
||||
"\t-f\t\tOutput data as the file grows. This version\n"
|
||||
"\t\t\tof 'tail -f' supports only one file at a time.\n";
|
||||
"\t\t\tof 'tail -f' supports only one file at a time.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
static void write_header(const char *filename)
|
||||
@@ -330,7 +336,7 @@ static int tail_file(const char *filename, off_t n_units)
|
||||
/* Not standard input. */
|
||||
fd = open(filename, O_RDONLY);
|
||||
if (fd == -1)
|
||||
errorMsg("open error");
|
||||
perror(filename);
|
||||
|
||||
errors = tail_lines(filename, fd, (long) n_units);
|
||||
close(fd);
|
||||
@@ -368,8 +374,10 @@ extern int tail_main(int argc, char **argv)
|
||||
case 'h':
|
||||
usage(tail_usage);
|
||||
default:
|
||||
fprintf(stderr, "tail: invalid option -- %c\n", opt);
|
||||
usage(tail_usage);
|
||||
if ((n_units = atoi(&argv[i][1])) < 1) {
|
||||
fprintf(stderr, "tail: invalid option -- %c\n", opt);
|
||||
usage(tail_usage);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
@@ -392,7 +400,7 @@ extern int tail_main(int argc, char **argv)
|
||||
exit_status |= tail_file(argv[i], n_units);
|
||||
}
|
||||
|
||||
exit(exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
return(exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
@@ -444,6 +452,8 @@ extern int tail_main(int argc, char **argv)
|
||||
#define NDEBUG 1
|
||||
|
||||
|
||||
static void detailed_error(int i, int errnum, char *fmt, ...)
|
||||
__attribute__ ((format (printf, 3, 4)));
|
||||
static void detailed_error(int i, int errnum, char *fmt, ...)
|
||||
{
|
||||
va_list arguments;
|
||||
@@ -508,9 +518,9 @@ char *program_name;
|
||||
static int have_read_stdin;
|
||||
|
||||
|
||||
static const char tail_usage[] = "tail [OPTION]... [FILE]...\n\
|
||||
\n\
|
||||
Print last 10 lines of each FILE to standard output.\n\
|
||||
static const char tail_usage[] = "tail [OPTION]... [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint last 10 lines of each FILE to standard output.\n\
|
||||
With more than one FILE, precede each with a header giving the file name.\n\
|
||||
With no FILE, or when FILE is -, read standard input.\n\
|
||||
\n\
|
||||
@@ -519,11 +529,12 @@ With no FILE, or when FILE is -, read standard input.\n\
|
||||
-n=N output the last N lines, instead of last 10\n\
|
||||
-q never output headers giving file names\n\
|
||||
-v always output headers giving file names\n\
|
||||
--help display this help and exit\n\
|
||||
\n\
|
||||
If the first character of N (bytes or lines) is a `+', output begins with \n\
|
||||
the Nth item from the start of each file, otherwise, print the last N items\n\
|
||||
in the file. N bytes may be suffixed by k (x1024), b (x512), or m (1024^2).\n\n";
|
||||
in the file. N bytes may be suffixed by k (x1024), b (x512), or m (1024^2).\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
static void write_header(const char *filename, const char *comment)
|
||||
{
|
||||
|
||||
+17
-6
@@ -3,7 +3,7 @@
|
||||
* Mini tee implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -23,22 +23,25 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static const char tee_usage[] =
|
||||
"tee [OPTION]... [FILE]...\n\n"
|
||||
"Copy standard input to each FILE, and also to standard output.\n\n"
|
||||
"tee [OPTION]... [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCopy standard input to each FILE, and also to standard output.\n\n"
|
||||
"Options:\n" "\t-a\tappend to the given FILEs, do not overwrite\n"
|
||||
#if 0
|
||||
"\t-i\tignore interrupt signals\n"
|
||||
#endif
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
/* FileList _______________________________________________________________ */
|
||||
|
||||
#define FL_MAX 1024
|
||||
static FILE *FileList[FL_MAX];
|
||||
static FILE **FileList;
|
||||
static int FL_end;
|
||||
|
||||
typedef void (FL_Function) (FILE * file, char c);
|
||||
@@ -99,6 +102,11 @@ int tee_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* init FILE pointers */
|
||||
FileList = calloc(FL_MAX, sizeof(FILE*));
|
||||
if (!FileList) {
|
||||
fprintf(stderr, "tee: %s\n", strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
FL_end = 0;
|
||||
FileList[0] = stdout;
|
||||
for (; i < argc; i++) {
|
||||
@@ -119,7 +127,10 @@ int tee_main(int argc, char **argv)
|
||||
|
||||
/* clean up */
|
||||
FL_apply(tee_fclose, 0);
|
||||
exit(0);
|
||||
/* Don't bother to close files Exit does that
|
||||
* automagically, so we can save a few bytes */
|
||||
/* free(FileList); */
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* $Id: tee.c,v 1.6 2000/02/08 19:58:47 erik Exp $ */
|
||||
/* $Id: tee.c,v 1.11 2000/06/19 17:25:40 andersen Exp $ */
|
||||
@@ -0,0 +1,595 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* test implementation for busybox
|
||||
*
|
||||
* Copyright (c) by a whole pile of folks:
|
||||
*
|
||||
* test(1); version 7-like -- author Erik Baalbergen
|
||||
* modified by Eric Gisin to be used as built-in.
|
||||
* modified by Arnold Robbins to add SVR3 compatibility
|
||||
* (-x -c -b -p -u -g -k) plus Korn's -L -nt -ot -ef and new -S (socket).
|
||||
* modified by J.T. Conklin for NetBSD.
|
||||
* modified by Herbert Xu to be used as built-in in ash.
|
||||
* modified by Erik Andersen <andersee@debian.org> to be used
|
||||
* in busybox.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Original copyright notice states:
|
||||
* "This program is in the Public Domain."
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_help
|
||||
#include "messages.c"
|
||||
|
||||
/* test(1) accepts the following grammar:
|
||||
oexpr ::= aexpr | aexpr "-o" oexpr ;
|
||||
aexpr ::= nexpr | nexpr "-a" aexpr ;
|
||||
nexpr ::= primary | "!" primary
|
||||
primary ::= unary-operator operand
|
||||
| operand binary-operator operand
|
||||
| operand
|
||||
| "(" oexpr ")"
|
||||
;
|
||||
unary-operator ::= "-r"|"-w"|"-x"|"-f"|"-d"|"-c"|"-b"|"-p"|
|
||||
"-u"|"-g"|"-k"|"-s"|"-t"|"-z"|"-n"|"-o"|"-O"|"-G"|"-L"|"-S";
|
||||
|
||||
binary-operator ::= "="|"!="|"-eq"|"-ne"|"-ge"|"-gt"|"-le"|"-lt"|
|
||||
"-nt"|"-ot"|"-ef";
|
||||
operand ::= <any legal UNIX file name>
|
||||
*/
|
||||
|
||||
enum token {
|
||||
EOI,
|
||||
FILRD,
|
||||
FILWR,
|
||||
FILEX,
|
||||
FILEXIST,
|
||||
FILREG,
|
||||
FILDIR,
|
||||
FILCDEV,
|
||||
FILBDEV,
|
||||
FILFIFO,
|
||||
FILSOCK,
|
||||
FILSYM,
|
||||
FILGZ,
|
||||
FILTT,
|
||||
FILSUID,
|
||||
FILSGID,
|
||||
FILSTCK,
|
||||
FILNT,
|
||||
FILOT,
|
||||
FILEQ,
|
||||
FILUID,
|
||||
FILGID,
|
||||
STREZ,
|
||||
STRNZ,
|
||||
STREQ,
|
||||
STRNE,
|
||||
STRLT,
|
||||
STRGT,
|
||||
INTEQ,
|
||||
INTNE,
|
||||
INTGE,
|
||||
INTGT,
|
||||
INTLE,
|
||||
INTLT,
|
||||
UNOT,
|
||||
BAND,
|
||||
BOR,
|
||||
LPAREN,
|
||||
RPAREN,
|
||||
OPERAND
|
||||
};
|
||||
|
||||
enum token_types {
|
||||
UNOP,
|
||||
BINOP,
|
||||
BUNOP,
|
||||
BBINOP,
|
||||
PAREN
|
||||
};
|
||||
|
||||
struct t_op {
|
||||
const char *op_text;
|
||||
short op_num, op_type;
|
||||
} const 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 */
|
||||
{"-O", FILUID, UNOP},
|
||||
{"-G", FILGID, UNOP},
|
||||
{"-L", FILSYM, UNOP},
|
||||
{"-S", FILSOCK,UNOP},
|
||||
{"=", 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},
|
||||
{0, 0, 0}
|
||||
};
|
||||
|
||||
char **t_wp;
|
||||
struct t_op const *t_wp_op;
|
||||
static gid_t *group_array = NULL;
|
||||
static int ngroups;
|
||||
|
||||
static enum token t_lex();
|
||||
static int oexpr();
|
||||
static int aexpr();
|
||||
static int nexpr();
|
||||
static int binop();
|
||||
static int primary();
|
||||
static int filstat();
|
||||
static int getn();
|
||||
static int newerf();
|
||||
static int olderf();
|
||||
static int equalf();
|
||||
static void syntax();
|
||||
static int test_eaccess();
|
||||
static int is_a_group_member();
|
||||
static void initialize_group_array();
|
||||
|
||||
extern int
|
||||
test_main(int argc, char** argv)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (strcmp(argv[0], "[") == 0) {
|
||||
if (strcmp(argv[--argc], "]"))
|
||||
fatalError("missing ]\n");
|
||||
argv[argc] = NULL;
|
||||
}
|
||||
if (strcmp(argv[1], dash_dash_help) == 0) {
|
||||
usage("test EXPRESSION\n"
|
||||
"or [ EXPRESSION ]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nChecks file types and compares values returning an exit\n"
|
||||
"code determined by the value of EXPRESSION.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
/* Implement special cases from POSIX.2, section 4.62.4 */
|
||||
switch (argc) {
|
||||
case 1:
|
||||
exit( 1);
|
||||
case 2:
|
||||
exit (*argv[1] == '\0');
|
||||
case 3:
|
||||
if (argv[1][0] == '!' && argv[1][1] == '\0') {
|
||||
exit (!(*argv[2] == '\0'));
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (argv[1][0] != '!' || argv[1][1] != '\0') {
|
||||
if (t_lex(argv[2]),
|
||||
t_wp_op && t_wp_op->op_type == BINOP) {
|
||||
t_wp = &argv[1];
|
||||
exit (binop() == 0);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if (argv[1][0] == '!' && argv[1][1] == '\0') {
|
||||
if (t_lex(argv[3]),
|
||||
t_wp_op && t_wp_op->op_type == BINOP) {
|
||||
t_wp = &argv[2];
|
||||
exit (!(binop() == 0));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
t_wp = &argv[1];
|
||||
res = !oexpr(t_lex(*t_wp));
|
||||
|
||||
if (*t_wp != NULL && *++t_wp != NULL)
|
||||
syntax(*t_wp, "unknown operand");
|
||||
|
||||
return( res);
|
||||
}
|
||||
|
||||
static void
|
||||
syntax(op, msg)
|
||||
char *op;
|
||||
char *msg;
|
||||
{
|
||||
if (op && *op)
|
||||
fatalError("%s: %s\n", op, msg);
|
||||
else
|
||||
fatalError("%s\n", msg);
|
||||
}
|
||||
|
||||
static int
|
||||
oexpr(n)
|
||||
enum token n;
|
||||
{
|
||||
int res;
|
||||
|
||||
res = aexpr(n);
|
||||
if (t_lex(*++t_wp) == BOR)
|
||||
return oexpr(t_lex(*++t_wp)) || res;
|
||||
t_wp--;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int
|
||||
aexpr(n)
|
||||
enum token n;
|
||||
{
|
||||
int res;
|
||||
|
||||
res = nexpr(n);
|
||||
if (t_lex(*++t_wp) == BAND)
|
||||
return aexpr(t_lex(*++t_wp)) && res;
|
||||
t_wp--;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int
|
||||
nexpr(n)
|
||||
enum token n; /* token */
|
||||
{
|
||||
if (n == UNOT)
|
||||
return !nexpr(t_lex(*++t_wp));
|
||||
return primary(n);
|
||||
}
|
||||
|
||||
static int
|
||||
primary(n)
|
||||
enum token n;
|
||||
{
|
||||
int res;
|
||||
|
||||
if (n == EOI)
|
||||
syntax(NULL, "argument expected");
|
||||
if (n == LPAREN) {
|
||||
res = oexpr(t_lex(*++t_wp));
|
||||
if (t_lex(*++t_wp) != RPAREN)
|
||||
syntax(NULL, "closing paren expected");
|
||||
return res;
|
||||
}
|
||||
if (t_wp_op && t_wp_op->op_type == UNOP) {
|
||||
/* unary expression */
|
||||
if (*++t_wp == NULL)
|
||||
syntax(t_wp_op->op_text, "argument expected");
|
||||
switch (n) {
|
||||
case STREZ:
|
||||
return strlen(*t_wp) == 0;
|
||||
case STRNZ:
|
||||
return strlen(*t_wp) != 0;
|
||||
case FILTT:
|
||||
return isatty(getn(*t_wp));
|
||||
default:
|
||||
return filstat(*t_wp, n);
|
||||
}
|
||||
}
|
||||
|
||||
if (t_lex(t_wp[1]), t_wp_op && t_wp_op->op_type == BINOP) {
|
||||
return binop();
|
||||
}
|
||||
|
||||
return strlen(*t_wp) > 0;
|
||||
}
|
||||
|
||||
static int
|
||||
binop()
|
||||
{
|
||||
const char *opnd1, *opnd2;
|
||||
struct t_op const *op;
|
||||
|
||||
opnd1 = *t_wp;
|
||||
(void) t_lex(*++t_wp);
|
||||
op = t_wp_op;
|
||||
|
||||
if ((opnd2 = *++t_wp) == (char *)0)
|
||||
syntax(op->op_text, "argument expected");
|
||||
|
||||
switch (op->op_num) {
|
||||
case STREQ:
|
||||
return strcmp(opnd1, opnd2) == 0;
|
||||
case STRNE:
|
||||
return strcmp(opnd1, opnd2) != 0;
|
||||
case STRLT:
|
||||
return strcmp(opnd1, opnd2) < 0;
|
||||
case STRGT:
|
||||
return strcmp(opnd1, opnd2) > 0;
|
||||
case INTEQ:
|
||||
return getn(opnd1) == getn(opnd2);
|
||||
case INTNE:
|
||||
return getn(opnd1) != getn(opnd2);
|
||||
case INTGE:
|
||||
return getn(opnd1) >= getn(opnd2);
|
||||
case INTGT:
|
||||
return getn(opnd1) > getn(opnd2);
|
||||
case INTLE:
|
||||
return getn(opnd1) <= getn(opnd2);
|
||||
case INTLT:
|
||||
return getn(opnd1) < getn(opnd2);
|
||||
case FILNT:
|
||||
return newerf (opnd1, opnd2);
|
||||
case FILOT:
|
||||
return olderf (opnd1, opnd2);
|
||||
case FILEQ:
|
||||
return equalf (opnd1, opnd2);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
filstat(nm, mode)
|
||||
char *nm;
|
||||
enum token mode;
|
||||
{
|
||||
struct stat s;
|
||||
int i;
|
||||
|
||||
if (mode == FILSYM) {
|
||||
#ifdef S_IFLNK
|
||||
if (lstat(nm, &s) == 0) {
|
||||
i = S_IFLNK;
|
||||
goto filetype;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (stat(nm, &s) != 0)
|
||||
return 0;
|
||||
|
||||
switch (mode) {
|
||||
case FILRD:
|
||||
return test_eaccess(nm, R_OK) == 0;
|
||||
case FILWR:
|
||||
return test_eaccess(nm, W_OK) == 0;
|
||||
case FILEX:
|
||||
return test_eaccess(nm, X_OK) == 0;
|
||||
case FILEXIST:
|
||||
return 1;
|
||||
case FILREG:
|
||||
i = S_IFREG;
|
||||
goto filetype;
|
||||
case FILDIR:
|
||||
i = S_IFDIR;
|
||||
goto filetype;
|
||||
case FILCDEV:
|
||||
i = S_IFCHR;
|
||||
goto filetype;
|
||||
case FILBDEV:
|
||||
i = S_IFBLK;
|
||||
goto filetype;
|
||||
case FILFIFO:
|
||||
#ifdef S_IFIFO
|
||||
i = S_IFIFO;
|
||||
goto filetype;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
case FILSOCK:
|
||||
#ifdef S_IFSOCK
|
||||
i = S_IFSOCK;
|
||||
goto filetype;
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
case FILSUID:
|
||||
i = S_ISUID;
|
||||
goto filebit;
|
||||
case FILSGID:
|
||||
i = S_ISGID;
|
||||
goto filebit;
|
||||
case FILSTCK:
|
||||
i = S_ISVTX;
|
||||
goto filebit;
|
||||
case FILGZ:
|
||||
return s.st_size > 0L;
|
||||
case FILUID:
|
||||
return s.st_uid == geteuid();
|
||||
case FILGID:
|
||||
return s.st_gid == getegid();
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
|
||||
filetype:
|
||||
return ((s.st_mode & S_IFMT) == i);
|
||||
|
||||
filebit:
|
||||
return ((s.st_mode & i) != 0);
|
||||
}
|
||||
|
||||
static enum token
|
||||
t_lex(s)
|
||||
char *s;
|
||||
{
|
||||
struct t_op const *op = ops;
|
||||
|
||||
if (s == 0) {
|
||||
t_wp_op = (struct t_op *)0;
|
||||
return EOI;
|
||||
}
|
||||
while (op->op_text) {
|
||||
if (strcmp(s, op->op_text) == 0) {
|
||||
t_wp_op = op;
|
||||
return op->op_num;
|
||||
}
|
||||
op++;
|
||||
}
|
||||
t_wp_op = (struct t_op *)0;
|
||||
return OPERAND;
|
||||
}
|
||||
|
||||
/* atoi with error detection */
|
||||
static int
|
||||
getn(s)
|
||||
char *s;
|
||||
{
|
||||
char *p;
|
||||
long r;
|
||||
|
||||
errno = 0;
|
||||
r = strtol(s, &p, 10);
|
||||
|
||||
if (errno != 0)
|
||||
fatalError("%s: out of range\n", s);
|
||||
|
||||
while (isspace(*p))
|
||||
p++;
|
||||
|
||||
if (*p)
|
||||
fatalError("%s: bad number\n", s);
|
||||
|
||||
return (int) r;
|
||||
}
|
||||
|
||||
static int
|
||||
newerf (f1, f2)
|
||||
char *f1, *f2;
|
||||
{
|
||||
struct stat b1, b2;
|
||||
|
||||
return (stat (f1, &b1) == 0 &&
|
||||
stat (f2, &b2) == 0 &&
|
||||
b1.st_mtime > b2.st_mtime);
|
||||
}
|
||||
|
||||
static int
|
||||
olderf (f1, f2)
|
||||
char *f1, *f2;
|
||||
{
|
||||
struct stat b1, b2;
|
||||
|
||||
return (stat (f1, &b1) == 0 &&
|
||||
stat (f2, &b2) == 0 &&
|
||||
b1.st_mtime < b2.st_mtime);
|
||||
}
|
||||
|
||||
static int
|
||||
equalf (f1, f2)
|
||||
char *f1, *f2;
|
||||
{
|
||||
struct stat b1, b2;
|
||||
|
||||
return (stat (f1, &b1) == 0 &&
|
||||
stat (f2, &b2) == 0 &&
|
||||
b1.st_dev == b2.st_dev &&
|
||||
b1.st_ino == b2.st_ino);
|
||||
}
|
||||
|
||||
/* Do the same thing access(2) does, but use the effective uid and gid,
|
||||
and don't make the mistake of telling root that any file is
|
||||
executable. */
|
||||
static int
|
||||
test_eaccess (path, mode)
|
||||
char *path;
|
||||
int mode;
|
||||
{
|
||||
struct stat st;
|
||||
int euid = geteuid();
|
||||
|
||||
if (stat (path, &st) < 0)
|
||||
return (-1);
|
||||
|
||||
if (euid == 0) {
|
||||
/* Root can read or write any file. */
|
||||
if (mode != X_OK)
|
||||
return (0);
|
||||
|
||||
/* Root can execute any file that has any one of the execute
|
||||
bits set. */
|
||||
if (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (st.st_uid == euid) /* owner */
|
||||
mode <<= 6;
|
||||
else if (is_a_group_member (st.st_gid))
|
||||
mode <<= 3;
|
||||
|
||||
if (st.st_mode & mode)
|
||||
return (0);
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
static void
|
||||
initialize_group_array ()
|
||||
{
|
||||
ngroups = getgroups(0, NULL);
|
||||
if ((group_array = realloc(group_array, ngroups * sizeof(gid_t))) == NULL)
|
||||
fatalError("Out of space\n");
|
||||
|
||||
getgroups(ngroups, group_array);
|
||||
}
|
||||
|
||||
/* Return non-zero if GID is one that we have in our groups list. */
|
||||
static int
|
||||
is_a_group_member (gid)
|
||||
gid_t gid;
|
||||
{
|
||||
register int i;
|
||||
|
||||
/* Short-circuit if possible, maybe saving a call to getgroups(). */
|
||||
if (gid == getgid() || gid == getegid())
|
||||
return (1);
|
||||
|
||||
if (ngroups == 0)
|
||||
initialize_group_array ();
|
||||
|
||||
/* Search through the list looking for GID. */
|
||||
for (i = 0; i < ngroups; i++)
|
||||
if (gid == group_array[i])
|
||||
return (1);
|
||||
|
||||
return (0);
|
||||
}
|
||||
+32
-28
@@ -3,7 +3,7 @@
|
||||
* Mini touch implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -31,10 +31,13 @@
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
static const char touch_usage[] = "touch [-c] file [file ...]\n\n"
|
||||
|
||||
"Update the last-modified date on the given file[s].\n";
|
||||
|
||||
static const char touch_usage[] = "touch [-c] file [file ...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nUpdate the last-modified date on the given file[s].\n\n"
|
||||
"Options:\n"
|
||||
"\t-c\tDo not create any files\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
extern int touch_main(int argc, char **argv)
|
||||
@@ -42,15 +45,9 @@ extern int touch_main(int argc, char **argv)
|
||||
int fd;
|
||||
int create = TRUE;
|
||||
|
||||
if (argc < 2) {
|
||||
usage(touch_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
while (*(++(*argv))) {
|
||||
switch (**argv) {
|
||||
case 'c':
|
||||
create = FALSE;
|
||||
@@ -59,23 +56,30 @@ extern int touch_main(int argc, char **argv)
|
||||
usage(touch_usage);
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argc < 1) {
|
||||
usage(touch_usage);
|
||||
}
|
||||
|
||||
while (argc > 0) {
|
||||
fd = open(*argv, (create == FALSE) ? O_RDWR : O_RDWR | O_CREAT,
|
||||
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||
if (fd < 0) {
|
||||
if (create == FALSE && errno == ENOENT)
|
||||
exit(TRUE);
|
||||
else {
|
||||
fatalError("touch: %s", strerror(errno));
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
if (utime(*argv, NULL)) {
|
||||
fatalError("touch: %s", strerror(errno));
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
fd = open(*argv, (create == FALSE) ? O_RDWR : O_RDWR | O_CREAT, 0644);
|
||||
if (fd < 0) {
|
||||
if (create == FALSE && errno == ENOENT)
|
||||
exit(TRUE);
|
||||
else {
|
||||
perror("touch");
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
if (utime(*argv, NULL)) {
|
||||
perror("touch");
|
||||
exit(FALSE);
|
||||
} else
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
+240
@@ -0,0 +1,240 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini tr implementation for busybox
|
||||
*
|
||||
* Copyright (c) Michiel Huisjes
|
||||
*
|
||||
* This version of tr is adapted from Minix tr and was modified
|
||||
* by Erik Andersen <andersee@debian.org> to be used in busybox.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Original copyright notice is retained at the end of this file.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_write_error
|
||||
#include "messages.c"
|
||||
|
||||
const char *tr_usage="tr [-cds] STRING1 [STRING2]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nTranslate, squeeze, and/or delete characters from\n"
|
||||
"standard input, writing to standard output.\n\n"
|
||||
"Options:\n"
|
||||
"\t-c\ttake complement of STRING1\n"
|
||||
"\t-d\tdelete input characters coded STRING1\n"
|
||||
"\t-s\tsqueeze multiple output characters of STRING2 into one character\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
#ifdef TRUE
|
||||
#undef TRUE
|
||||
#undef FALSE
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
#define ASCII 0377
|
||||
|
||||
/* some glabals shared across this file */
|
||||
static char com_fl, del_fl, sq_fl;
|
||||
static unsigned char output[BUFSIZ], input[BUFSIZ];
|
||||
static unsigned char vector[ASCII + 1];
|
||||
static char invec[ASCII + 1], outvec[ASCII + 1];
|
||||
static short in_index, out_index;
|
||||
|
||||
|
||||
static void convert()
|
||||
{
|
||||
short read_chars = 0;
|
||||
short c, coded;
|
||||
short last = -1;
|
||||
|
||||
for (;;) {
|
||||
if (in_index == read_chars) {
|
||||
if ((read_chars = read(0, (char *) input, BUFSIZ)) <= 0) {
|
||||
if (write(1, (char *) output, out_index) != out_index)
|
||||
write(2, write_error, strlen(write_error));
|
||||
exit(0);
|
||||
}
|
||||
in_index = 0;
|
||||
}
|
||||
c = input[in_index++];
|
||||
coded = vector[c];
|
||||
if (del_fl && invec[c])
|
||||
continue;
|
||||
if (sq_fl && last == coded && outvec[coded])
|
||||
continue;
|
||||
output[out_index++] = last = coded;
|
||||
if (out_index == BUFSIZ) {
|
||||
if (write(1, (char *) output, out_index) != out_index) {
|
||||
write(2, write_error, strlen(write_error));
|
||||
exit(1);
|
||||
}
|
||||
out_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
static void map(register unsigned char *string1, register unsigned char *string2)
|
||||
{
|
||||
unsigned char last = '0';
|
||||
|
||||
while (*string1) {
|
||||
if (*string2 == '\0')
|
||||
vector[*string1] = last;
|
||||
else
|
||||
vector[*string1] = last = *string2++;
|
||||
string1++;
|
||||
}
|
||||
}
|
||||
|
||||
static void expand(char *arg, register unsigned char *buffer)
|
||||
{
|
||||
int i, ac;
|
||||
|
||||
while (*arg) {
|
||||
if (*arg == '\\') {
|
||||
arg++;
|
||||
*buffer++ = process_escape_sequence(&arg);
|
||||
} else if (*arg == '[') {
|
||||
arg++;
|
||||
i = *arg++;
|
||||
if (*arg++ != '-') {
|
||||
*buffer++ = '[';
|
||||
arg -= 2;
|
||||
continue;
|
||||
}
|
||||
ac = *arg++;
|
||||
while (i <= ac)
|
||||
*buffer++ = i++;
|
||||
arg++; /* Skip ']' */
|
||||
} else
|
||||
*buffer++ = *arg++;
|
||||
}
|
||||
}
|
||||
|
||||
static void complement(unsigned char *buffer)
|
||||
{
|
||||
register unsigned char *ptr;
|
||||
register short i, index;
|
||||
unsigned char conv[ASCII + 2];
|
||||
|
||||
index = 0;
|
||||
for (i = 1; i <= ASCII; i++) {
|
||||
for (ptr = buffer; *ptr; ptr++)
|
||||
if (*ptr == i)
|
||||
break;
|
||||
if (*ptr == '\0')
|
||||
conv[index++] = i & ASCII;
|
||||
}
|
||||
conv[index] = '\0';
|
||||
strcpy((char *) buffer, (char *) conv);
|
||||
}
|
||||
|
||||
extern int tr_main(int argc, char **argv)
|
||||
{
|
||||
register unsigned char *ptr;
|
||||
int index = 1;
|
||||
short i;
|
||||
|
||||
if (argc > 1 && argv[index][0] == '-') {
|
||||
for (ptr = (unsigned char *) &argv[index][1]; *ptr; ptr++) {
|
||||
switch (*ptr) {
|
||||
case 'c':
|
||||
com_fl = TRUE;
|
||||
break;
|
||||
case 'd':
|
||||
del_fl = TRUE;
|
||||
break;
|
||||
case 's':
|
||||
sq_fl = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage(tr_usage);
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
for (i = 0; i <= ASCII; i++) {
|
||||
vector[i] = i;
|
||||
invec[i] = outvec[i] = FALSE;
|
||||
}
|
||||
|
||||
if (argv[index] != NULL) {
|
||||
expand(argv[index++], input);
|
||||
if (com_fl)
|
||||
complement(input);
|
||||
if (argv[index] != NULL) {
|
||||
if (*argv[index] == '\0')
|
||||
fatalError("tr: STRING2 cannot be empty\n");
|
||||
expand(argv[index], output);
|
||||
map(input, output);
|
||||
}
|
||||
for (ptr = input; *ptr; ptr++)
|
||||
invec[*ptr] = TRUE;
|
||||
for (ptr = output; *ptr; ptr++)
|
||||
outvec[*ptr] = TRUE;
|
||||
}
|
||||
convert();
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987,1997, Prentice Hall
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use of the MINIX operating system in source and
|
||||
* binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of Prentice Hall nor the names of the software
|
||||
* authors or contributors may be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND
|
||||
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL PRENTICE HALL OR ANY AUTHORS OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
+8
-5
@@ -24,10 +24,13 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
static const char tty_usage[] = "tty\n\n"
|
||||
"Print the file name of the terminal connected to standard input.\n"
|
||||
|
||||
"\t-s\tprint nothing, only return an exit status\n";
|
||||
static const char tty_usage[] = "tty\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint the file name of the terminal connected to standard input.\n\n"
|
||||
"Options:\n"
|
||||
"\t-s\tprint nothing, only return an exit status\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int tty_main(int argc, char **argv)
|
||||
{
|
||||
@@ -43,5 +46,5 @@ extern int tty_main(int argc, char **argv)
|
||||
else
|
||||
puts("not a tty");
|
||||
}
|
||||
exit(isatty(0) ? TRUE : FALSE);
|
||||
return(isatty(0) ? TRUE : FALSE);
|
||||
}
|
||||
+7
-4
@@ -42,8 +42,9 @@
|
||||
|
||||
|
||||
static const char uname_usage[] =
|
||||
"uname [OPTION]...\n\n"
|
||||
"Print certain system information. With no OPTION, same as -s.\n\n"
|
||||
"uname [OPTION]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint certain system information. With no OPTION, same as -s.\n\n"
|
||||
"Options:\n"
|
||||
"\t-a\tprint all information\n"
|
||||
"\t-m\tthe machine (hardware) type\n"
|
||||
@@ -52,7 +53,9 @@ static const char uname_usage[] =
|
||||
"\t-s\tprint the operating system name\n"
|
||||
|
||||
"\t-p\tprint the host processor type\n"
|
||||
"\t-v\tprint the operating system version\n";
|
||||
"\t-v\tprint the operating system version\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
static void print_element(unsigned int mask, char *element);
|
||||
@@ -153,7 +156,7 @@ int uname_main(int argc, char **argv)
|
||||
print_element(PRINT_MACHINE, name.machine);
|
||||
print_element(PRINT_PROCESSOR, processor);
|
||||
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
/* If the name element set in MASK is selected for printing in `toprint',
|
||||
|
||||
+8
-11
@@ -3,7 +3,7 @@
|
||||
* Mini uniq implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -29,14 +29,11 @@
|
||||
|
||||
static const char uniq_usage[] =
|
||||
"uniq [OPTION]... [INPUT [OUTPUT]]\n"
|
||||
"Discard all but one of successive identical lines from INPUT (or\n"
|
||||
"standard input), writing to OUTPUT (or standard output).\n"
|
||||
"\n"
|
||||
"\t-h\tdisplay this help and exit\n"
|
||||
|
||||
"\n"
|
||||
"A field is a run of whitespace, then non-whitespace characters.\n"
|
||||
"Fields are skipped before chars.\n";
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nDiscard all but one of successive identical lines from INPUT\n"
|
||||
"(or standard input), writing to OUTPUT (or standard output).\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
/* max chars in line */
|
||||
#define UNIQ_MAX 4096
|
||||
@@ -187,7 +184,7 @@ int uniq_main(int argc, char **argv)
|
||||
subject_last(&s);
|
||||
subject_study(&s);
|
||||
|
||||
exit(0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* $Id: uniq.c,v 1.7 2000/02/08 19:58:47 erik Exp $ */
|
||||
/* $Id: uniq.c,v 1.11 2000/06/19 17:25:40 andersen Exp $ */
|
||||
@@ -0,0 +1,42 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini usleep implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
const char usleep_usage[] = "usleep N\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPause for N microseconds.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int usleep_main(int argc, char **argv)
|
||||
{
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage(usleep_usage);
|
||||
}
|
||||
|
||||
usleep(atoi(*(++argv))); /* return void */
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -0,0 +1,351 @@
|
||||
/* uudecode.c -- uudecode utility.
|
||||
* Copyright (C) 1994, 1995 Free Software Foundation, Inc.
|
||||
*
|
||||
* This product is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This product is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this product; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* Reworked to GNU style by Ian Lance Taylor, ian@airs.com, August 93. */
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <pwd.h>
|
||||
|
||||
/*struct passwd *getpwnam();*/
|
||||
|
||||
/* Single character decode. */
|
||||
#define DEC(Char) (((Char) - ' ') & 077)
|
||||
|
||||
static int read_stduu (const char *inname)
|
||||
{
|
||||
char buf[2 * BUFSIZ];
|
||||
|
||||
while (1) {
|
||||
int n;
|
||||
char *p;
|
||||
|
||||
if (fgets (buf, sizeof(buf), stdin) == NULL) {
|
||||
errorMsg("%s: Short file\n", inname);
|
||||
return FALSE;
|
||||
}
|
||||
p = buf;
|
||||
|
||||
/* N is used to avoid writing out all the characters at the end of
|
||||
the file. */
|
||||
n = DEC (*p);
|
||||
if (n <= 0)
|
||||
break;
|
||||
for (++p; n > 0; p += 4, n -= 3) {
|
||||
char ch;
|
||||
|
||||
if (n >= 3) {
|
||||
ch = DEC (p[0]) << 2 | DEC (p[1]) >> 4;
|
||||
putchar (ch);
|
||||
ch = DEC (p[1]) << 4 | DEC (p[2]) >> 2;
|
||||
putchar (ch);
|
||||
ch = DEC (p[2]) << 6 | DEC (p[3]);
|
||||
putchar (ch);
|
||||
} else {
|
||||
if (n >= 1) {
|
||||
ch = DEC (p[0]) << 2 | DEC (p[1]) >> 4;
|
||||
putchar (ch);
|
||||
}
|
||||
if (n >= 2) {
|
||||
ch = DEC (p[1]) << 4 | DEC (p[2]) >> 2;
|
||||
putchar (ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fgets (buf, sizeof(buf), stdin) == NULL
|
||||
|| strcmp (buf, "end\n")) {
|
||||
errorMsg("%s: No `end' line\n", inname);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int read_base64 (const char *inname)
|
||||
{
|
||||
static const char b64_tab[256] = {
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*000-007*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*010-017*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*020-027*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*030-037*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*040-047*/
|
||||
'\177', '\177', '\177', '\76', '\177', '\177', '\177', '\77', /*050-057*/
|
||||
'\64', '\65', '\66', '\67', '\70', '\71', '\72', '\73', /*060-067*/
|
||||
'\74', '\75', '\177', '\177', '\177', '\100', '\177', '\177', /*070-077*/
|
||||
'\177', '\0', '\1', '\2', '\3', '\4', '\5', '\6', /*100-107*/
|
||||
'\7', '\10', '\11', '\12', '\13', '\14', '\15', '\16', /*110-117*/
|
||||
'\17', '\20', '\21', '\22', '\23', '\24', '\25', '\26', /*120-127*/
|
||||
'\27', '\30', '\31', '\177', '\177', '\177', '\177', '\177', /*130-137*/
|
||||
'\177', '\32', '\33', '\34', '\35', '\36', '\37', '\40', /*140-147*/
|
||||
'\41', '\42', '\43', '\44', '\45', '\46', '\47', '\50', /*150-157*/
|
||||
'\51', '\52', '\53', '\54', '\55', '\56', '\57', '\60', /*160-167*/
|
||||
'\61', '\62', '\63', '\177', '\177', '\177', '\177', '\177', /*170-177*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*200-207*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*210-217*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*220-227*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*230-237*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*240-247*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*250-257*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*260-267*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*270-277*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*300-307*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*310-317*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*320-327*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*330-337*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*340-347*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*350-357*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*360-367*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*370-377*/
|
||||
};
|
||||
unsigned char buf[2 * BUFSIZ];
|
||||
|
||||
while (1) {
|
||||
int last_data = 0;
|
||||
unsigned char *p;
|
||||
|
||||
if (fgets (buf, sizeof(buf), stdin) == NULL) {
|
||||
errorMsg("%s: Short file\n", inname);
|
||||
return FALSE;
|
||||
}
|
||||
p = buf;
|
||||
|
||||
if (memcmp (buf, "====", 4) == 0)
|
||||
break;
|
||||
if (last_data != 0) {
|
||||
errorMsg("%s: data following `=' padding character\n", inname);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* The following implementation of the base64 decoding might look
|
||||
a bit clumsy but I only try to follow the POSIX standard:
|
||||
``All line breaks or other characters not found in the table
|
||||
[with base64 characters] shall be ignored by decoding
|
||||
software.'' */
|
||||
while (*p != '\n') {
|
||||
char c1, c2, c3;
|
||||
|
||||
while ((b64_tab[*p] & '\100') != 0)
|
||||
if (*p == '\n' || *p++ == '=')
|
||||
break;
|
||||
if (*p == '\n')
|
||||
/* This leaves the loop. */
|
||||
continue;
|
||||
c1 = b64_tab[*p++];
|
||||
|
||||
while ((b64_tab[*p] & '\100') != 0)
|
||||
if (*p == '\n' || *p++ == '=') {
|
||||
errorMsg("%s: illegal line\n", inname);
|
||||
return FALSE;
|
||||
}
|
||||
c2 = b64_tab[*p++];
|
||||
|
||||
while (b64_tab[*p] == '\177')
|
||||
if (*p++ == '\n') {
|
||||
errorMsg("%s: illegal line\n", inname);
|
||||
return FALSE;
|
||||
}
|
||||
if (*p == '=') {
|
||||
putchar (c1 << 2 | c2 >> 4);
|
||||
last_data = 1;
|
||||
break;
|
||||
}
|
||||
c3 = b64_tab[*p++];
|
||||
|
||||
while (b64_tab[*p] == '\177')
|
||||
if (*p++ == '\n') {
|
||||
errorMsg("%s: illegal line\n", inname);
|
||||
return FALSE;
|
||||
}
|
||||
putchar (c1 << 2 | c2 >> 4);
|
||||
putchar (c2 << 4 | c3 >> 2);
|
||||
if (*p == '=') {
|
||||
last_data = 1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
putchar (c3 << 6 | b64_tab[*p++]);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int decode (const char *inname,
|
||||
const char *forced_outname)
|
||||
{
|
||||
struct passwd *pw;
|
||||
register int n;
|
||||
register char *p;
|
||||
int mode, n1;
|
||||
char buf[2 * BUFSIZ];
|
||||
char *outname;
|
||||
int do_base64 = 0;
|
||||
|
||||
/* Search for header line. */
|
||||
|
||||
while (1) {
|
||||
if (fgets (buf, sizeof (buf), stdin) == NULL) {
|
||||
errorMsg("%s: No `begin' line\n", inname);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (strncmp (buf, "begin", 5) == 0) {
|
||||
if (sscanf (buf, "begin-base64 %o %s", &mode, buf) == 2) {
|
||||
do_base64 = 1;
|
||||
break;
|
||||
} else if (sscanf (buf, "begin %o %s", &mode, buf) == 2)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* If the output file name is given on the command line this rules. */
|
||||
if (forced_outname != NULL)
|
||||
outname = (char *) forced_outname;
|
||||
else {
|
||||
/* Handle ~user/file format. */
|
||||
if (buf[0] != '~')
|
||||
outname = buf;
|
||||
else {
|
||||
p = buf + 1;
|
||||
while (*p != '/')
|
||||
++p;
|
||||
if (*p == '\0') {
|
||||
errorMsg("%s: Illegal ~user\n", inname);
|
||||
return FALSE;
|
||||
}
|
||||
*p++ = '\0';
|
||||
pw = getpwnam (buf + 1);
|
||||
if (pw == NULL) {
|
||||
errorMsg("%s: No user `%s'\n", inname, buf + 1);
|
||||
return FALSE;
|
||||
}
|
||||
n = strlen (pw->pw_dir);
|
||||
n1 = strlen (p);
|
||||
outname = (char *) alloca ((size_t) (n + n1 + 2));
|
||||
memcpy (outname + n + 1, p, (size_t) (n1 + 1));
|
||||
memcpy (outname, pw->pw_dir, (size_t) n);
|
||||
outname[n] = '/';
|
||||
}
|
||||
}
|
||||
|
||||
/* Create output file and set mode. */
|
||||
if (strcmp (outname, "/dev/stdout") != 0 && strcmp (outname, "-") != 0
|
||||
&& (freopen (outname, "w", stdout) == NULL
|
||||
|| chmod (outname, mode & (S_IRWXU | S_IRWXG | S_IRWXO))
|
||||
)) {
|
||||
errorMsg("uudeoce %s: %s %s\n", outname, inname, strerror(errno)); /* */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* We differenciate decoding standard UU encoding and base64. A
|
||||
common function would only slow down the program. */
|
||||
|
||||
/* For each input line: */
|
||||
if (do_base64)
|
||||
return read_base64 (inname);
|
||||
else
|
||||
return read_stduu (inname);
|
||||
}
|
||||
|
||||
static const char uudecode_usage[] =
|
||||
"uudecode [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nUudecode a file that is uuencoded.\n\n"
|
||||
"Options:\n"
|
||||
"\t-o FILE\tdirect output to FILE\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
int uudecode_main (int argc,
|
||||
char **argv)
|
||||
{
|
||||
int opt;
|
||||
int exit_status;
|
||||
const char *outname;
|
||||
outname = NULL;
|
||||
|
||||
while ((opt = getopt(argc, argv, "o:")) != EOF) {
|
||||
switch (opt) {
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
outname = optarg;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(uudecode_usage);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind == argc)
|
||||
exit_status = decode ("stdin", outname) == 0 ? TRUE : FALSE;
|
||||
else {
|
||||
exit_status = TRUE;
|
||||
do {
|
||||
if (freopen (argv[optind], "r", stdin) != NULL) {
|
||||
if (decode (argv[optind], outname) != 0)
|
||||
exit_status = FALSE;
|
||||
} else {
|
||||
errorMsg("uudecode: %s: %s\n", argv[optind], strerror(errno));
|
||||
exit_status = FALSE;
|
||||
}
|
||||
optind++;
|
||||
}
|
||||
while (optind < argc);
|
||||
}
|
||||
return(exit_status);
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
/* uuencode.c -- uuencode utility.
|
||||
* Copyright (C) 1994, 1995 Free Software Foundation, Inc.
|
||||
*
|
||||
* This product is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This product is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this product; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* Reworked to GNU style by Ian Lance Taylor, ian@airs.com, August 93. */
|
||||
/* Hacked to work with BusyBox by Alfred M. Szmidt */
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#define RW (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
|
||||
|
||||
static void encode __P ((void));
|
||||
|
||||
/* Pointer to the translation table we currently use. */
|
||||
const char *trans_ptr;
|
||||
|
||||
/* The two currently defined translation tables. The first is the
|
||||
standard uuencoding, the second is base64 encoding. */
|
||||
const char uu_std[64] = {
|
||||
'`', '!', '"', '#', '$', '%', '&', '\'',
|
||||
'(', ')', '*', '+', ',', '-', '.', '/',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', ':', ';', '<', '=', '>', '?',
|
||||
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
|
||||
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
||||
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
||||
'X', 'Y', 'Z', '[', '\\', ']', '^', '_'
|
||||
};
|
||||
|
||||
const char uu_base64[64] = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
||||
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
|
||||
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
||||
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
||||
'w', 'x', 'y', 'z', '0', '1', '2', '3',
|
||||
'4', '5', '6', '7', '8', '9', '+', '/'
|
||||
};
|
||||
|
||||
/* ENC is the basic 1 character encoding function to make a char printing. */
|
||||
#define ENC(Char) (trans_ptr[(Char) & 077])
|
||||
|
||||
/* Copy from IN to OUT, encoding as you go along. */
|
||||
static void encode()
|
||||
{
|
||||
register int ch, n;
|
||||
char *p = NULL;
|
||||
char buf[80];
|
||||
|
||||
while (1) {
|
||||
n = 0;
|
||||
do {
|
||||
register int m = fread (buf, 1, 45 - n, stdin);
|
||||
if (m == 0)
|
||||
break;
|
||||
n += m;
|
||||
}
|
||||
while (n < 45);
|
||||
|
||||
if (n == 0)
|
||||
break;
|
||||
|
||||
if (trans_ptr == uu_std)
|
||||
if (putchar (ENC (n)) == EOF)
|
||||
break;
|
||||
for (p = buf; n > 2; n -= 3, p += 3) {
|
||||
ch = *p >> 2;
|
||||
ch = ENC (ch);
|
||||
if (putchar (ch) == EOF)
|
||||
break;
|
||||
ch = ((*p << 4) & 060) | ((p[1] >> 4) & 017);
|
||||
ch = ENC (ch);
|
||||
if (putchar (ch) == EOF)
|
||||
break;
|
||||
ch = ((p[1] << 2) & 074) | ((p[2] >> 6) & 03);
|
||||
ch = ENC (ch);
|
||||
if (putchar (ch) == EOF)
|
||||
break;
|
||||
ch = p[2] & 077;
|
||||
ch = ENC (ch);
|
||||
if (putchar (ch) == EOF)
|
||||
break;
|
||||
}
|
||||
|
||||
if (n != 0)
|
||||
break;
|
||||
|
||||
if (putchar ('\n') == EOF)
|
||||
break;
|
||||
}
|
||||
|
||||
while (n != 0) {
|
||||
char c1 = *p;
|
||||
char c2 = n == 1 ? 0 : p[1];
|
||||
|
||||
ch = c1 >> 2;
|
||||
ch = ENC (ch);
|
||||
if (putchar (ch) == EOF)
|
||||
break;
|
||||
|
||||
ch = ((c1 << 4) & 060) | ((c2 >> 4) & 017);
|
||||
ch = ENC (ch);
|
||||
if (putchar (ch) == EOF)
|
||||
break;
|
||||
|
||||
if (n == 1)
|
||||
ch = trans_ptr == uu_std ? ENC ('\0') : '=';
|
||||
else {
|
||||
ch = (c2 << 2) & 074;
|
||||
ch = ENC (ch);
|
||||
}
|
||||
if (putchar (ch) == EOF)
|
||||
break;
|
||||
ch = trans_ptr == uu_std ? ENC ('\0') : '=';
|
||||
if (putchar (ch) == EOF)
|
||||
break;
|
||||
putchar ('\n');
|
||||
break;
|
||||
}
|
||||
|
||||
if (ferror (stdin))
|
||||
errorMsg("Read error\n");
|
||||
|
||||
if (trans_ptr == uu_std) {
|
||||
putchar (ENC ('\0'));
|
||||
putchar ('\n');
|
||||
}
|
||||
}
|
||||
|
||||
static const char uuencode_usage[] =
|
||||
"uuencode [OPTION] [INFILE] REMOTEFILE\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nUuencode a file.\n\n"
|
||||
"Options:\n"
|
||||
"\t-m\tuse base64 encoding as of RFC1521\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
int uuencode_main (int argc,
|
||||
char **argv)
|
||||
{
|
||||
int opt;
|
||||
struct stat sb;
|
||||
int mode;
|
||||
|
||||
trans_ptr = uu_std; /* Standard encoding is old uu format */
|
||||
|
||||
/* Parse any options */
|
||||
while ((opt = getopt (argc, argv, "m")) != EOF) {
|
||||
switch (opt) {
|
||||
case 'm':
|
||||
trans_ptr = uu_base64;
|
||||
break;
|
||||
|
||||
case 0:
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(uuencode_usage);
|
||||
}
|
||||
}
|
||||
|
||||
switch (argc - optind) {
|
||||
case 2:
|
||||
/* Optional first argument is input file. */
|
||||
if (!freopen (argv[optind], "r", stdin) || fstat (fileno (stdin), &sb)) {
|
||||
errorMsg("uuencode: %s: %s\n", argv[optind], strerror(errno));
|
||||
exit FALSE;
|
||||
}
|
||||
mode = sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
optind++;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
mode = RW & ~umask (RW);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
default:
|
||||
usage(uuencode_usage);
|
||||
}
|
||||
|
||||
printf("begin%s %o %s\n", trans_ptr == uu_std ? "" : "-base64",
|
||||
mode, argv[optind]);
|
||||
encode();
|
||||
printf(trans_ptr == uu_std ? "end\n" : "====\n");
|
||||
if (ferror (stdout)) {
|
||||
errorMsg("Write error\n");
|
||||
exit FALSE;
|
||||
}
|
||||
return( TRUE);
|
||||
}
|
||||
+9
-5
@@ -23,14 +23,18 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static const char wc_usage[] = "wc [OPTION]... [FILE]...\n\n"
|
||||
"Print line, word, and byte counts for each FILE, and a total line if\n"
|
||||
"more than one FILE is specified. With no FILE, read standard input.\n"
|
||||
static const char wc_usage[] = "wc [OPTION]... [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint line, word, and byte counts for each FILE, and a total line if\n"
|
||||
"more than one FILE is specified. With no FILE, read standard input.\n\n"
|
||||
"Options:\n"
|
||||
"\t-c\tprint the byte counts\n"
|
||||
"\t-l\tprint the newline counts\n"
|
||||
|
||||
"\t-L\tprint the length of the longest line\n"
|
||||
"\t-w\tprint the word counts\n";
|
||||
"\t-w\tprint the word counts\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
static int total_lines, total_words, total_chars, max_length;
|
||||
static int print_lines, print_words, print_chars, print_length;
|
||||
@@ -162,5 +166,5 @@ int wc_main(int argc, char **argv)
|
||||
print_counts(total_lines, total_words, total_chars,
|
||||
max_length, "total");
|
||||
}
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
+11
-11
@@ -24,26 +24,26 @@
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
|
||||
static const char whoami_usage[] = "whoami\n\n"
|
||||
"Print the user name associated with the current effective user id.\n"
|
||||
|
||||
"Same as id -un.\n";
|
||||
static const char whoami_usage[] = "whoami\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrints the user name associated with the current effective user id.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int whoami_main(int argc, char **argv)
|
||||
{
|
||||
struct passwd *pw;
|
||||
uid_t uid;
|
||||
char *user = xmalloc(9);
|
||||
uid_t uid = geteuid();
|
||||
|
||||
if (argc > 1)
|
||||
usage(whoami_usage);
|
||||
|
||||
uid = geteuid();
|
||||
pw = getpwuid(uid);
|
||||
if (pw) {
|
||||
puts(pw->pw_name);
|
||||
my_getpwuid(user, uid);
|
||||
if (user) {
|
||||
puts(user);
|
||||
exit(TRUE);
|
||||
}
|
||||
fprintf(stderr, "%s: cannot find username for UID %u\n", argv[0],
|
||||
(unsigned) uid);
|
||||
exit(FALSE);
|
||||
return(FALSE);
|
||||
}
|
||||
+10
-1
@@ -27,12 +27,21 @@ extern int yes_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (argc == 1)
|
||||
if (argc >= 2 && *argv[1] == '-') {
|
||||
usage("yes [OPTION]... [STRING]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nRepeatedly outputs a line with all specified STRING(s), or `y'.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
if (argc == 1) {
|
||||
while (1)
|
||||
if (puts("y") == EOF) {
|
||||
perror("yes");
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
while (1)
|
||||
for (i = 1; i < argc; i++)
|
||||
|
||||
@@ -37,110 +37,160 @@
|
||||
#include <utime.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/param.h>
|
||||
#include <setjmp.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define is_cp 0
|
||||
#define is_mv 1
|
||||
static int dz_i; /* index into cp_mv_usage */
|
||||
static const char *dz; /* dollar zero, .bss */
|
||||
static int dz_i; /* index, .bss */
|
||||
static const char *cp_mv_usage[] = /* .rodata */
|
||||
{
|
||||
"cp [OPTION]... SOURCE DEST\n"
|
||||
" or: cp [OPTION]... SOURCE... DIRECTORY\n\n"
|
||||
"Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n"
|
||||
" or: cp [OPTION]... SOURCE... DIRECTORY\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCopies SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n"
|
||||
"\n"
|
||||
"\t-a\tsame as -dpR\n"
|
||||
"\t-d\tpreserve links\n"
|
||||
"\t-p\tpreserve file attributes if possible\n"
|
||||
"\t-R\tcopy directories recursively\n",
|
||||
"\t-a\tSame as -dpR\n"
|
||||
"\t-d\tPreserves links\n"
|
||||
"\t-p\tPreserves file attributes if possible\n"
|
||||
"\t-f\tforce (implied; ignored) - always set\n"
|
||||
"\t-R\tCopies directories recursively\n"
|
||||
#endif
|
||||
,
|
||||
"mv SOURCE DEST\n"
|
||||
" or: mv SOURCE... DIRECTORY\n\n"
|
||||
"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n"
|
||||
"Warning!! This is not GNU `mv'. It does not preserve hard links.\n"
|
||||
" or: mv SOURCE... DIRECTORY\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nRename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n"
|
||||
#endif
|
||||
};
|
||||
|
||||
static int recursiveFlag;
|
||||
static int followLinks;
|
||||
static int preserveFlag;
|
||||
static int forceFlag;
|
||||
|
||||
static const char *baseSrcName;
|
||||
static int srcDirFlag;
|
||||
static struct stat srcStatBuf;
|
||||
|
||||
static char baseDestName[BUFSIZ + 1];
|
||||
static size_t baseDestLen;
|
||||
static int destDirFlag;
|
||||
static struct stat destStatBuf;
|
||||
|
||||
static jmp_buf catch;
|
||||
static volatile int mv_Action_first_time;
|
||||
|
||||
static void name_too_long__exit (void) __attribute__((noreturn));
|
||||
|
||||
static
|
||||
void name_too_long__exit (void)
|
||||
{
|
||||
fprintf(stderr, name_too_long, dz);
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
fill_baseDest_buf(char *_buf, size_t * _buflen) {
|
||||
const char *srcBasename;
|
||||
if ((srcBasename = strrchr(baseSrcName, '/')) == NULL) {
|
||||
srcBasename = baseSrcName;
|
||||
if (_buf[*_buflen - 1] != '/') {
|
||||
if (++(*_buflen) > BUFSIZ)
|
||||
name_too_long__exit();
|
||||
strcat(_buf, "/");
|
||||
}
|
||||
}
|
||||
if (*_buflen + strlen(srcBasename) > BUFSIZ)
|
||||
name_too_long__exit();
|
||||
strcat(_buf, srcBasename);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
static int
|
||||
cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
char destName[BUFSIZ + 1];
|
||||
size_t destLen;
|
||||
const char *srcBasename;
|
||||
char *name;
|
||||
|
||||
strcpy(destName, baseDestName);
|
||||
destLen = strlen(destName);
|
||||
|
||||
if (srcDirFlag == TRUE) {
|
||||
if (recursiveFlag == FALSE) {
|
||||
fprintf(stderr, omitting_directory, dz, baseSrcName);
|
||||
return TRUE;
|
||||
}
|
||||
srcBasename = (strstr(fileName, baseSrcName)
|
||||
+ strlen(baseSrcName));
|
||||
|
||||
if (destLen + strlen(srcBasename) > BUFSIZ) {
|
||||
fprintf(stderr, name_too_long, dz);
|
||||
return FALSE;
|
||||
}
|
||||
strcat(destName, srcBasename);
|
||||
}
|
||||
else if (destDirFlag == TRUE) {
|
||||
fill_baseDest_buf(&destName[0], &destLen);
|
||||
}
|
||||
else {
|
||||
srcBasename = baseSrcName;
|
||||
}
|
||||
if (mv_Action_first_time && (dz_i == is_mv)) {
|
||||
mv_Action_first_time = errno = 0;
|
||||
if (rename(fileName, destName) < 0 && errno != EXDEV) {
|
||||
fprintf(stderr, "%s: rename(%s, %s): %s\n",
|
||||
dz, fileName, destName, strerror(errno));
|
||||
goto do_copyFile; /* Try anyway... */
|
||||
}
|
||||
else if (errno == EXDEV)
|
||||
goto do_copyFile;
|
||||
else
|
||||
longjmp(catch, 1); /* succeeded with rename() */
|
||||
}
|
||||
do_copyFile:
|
||||
if (preserveFlag == TRUE && statbuf->st_nlink > 1) {
|
||||
if (is_in_ino_dev_hashtable(statbuf, &name)) {
|
||||
if (link(name, destName) < 0) {
|
||||
fprintf(stderr, "%s: link(%s, %s): %s\n",
|
||||
dz, name, destName, strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
add_to_ino_dev_hashtable(statbuf, destName);
|
||||
}
|
||||
}
|
||||
return copyFile(fileName, destName, preserveFlag, followLinks, forceFlag);
|
||||
}
|
||||
|
||||
static int
|
||||
rm_Action(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
int status = TRUE;
|
||||
|
||||
if (S_ISDIR(statbuf->st_mode)) {
|
||||
if (rmdir(fileName) < 0) {
|
||||
fprintf(stderr, "%s: rmdir(%s): %s\n", dz, fileName, strerror(errno));
|
||||
status = FALSE;
|
||||
}
|
||||
} else if (unlink(fileName) < 0) {
|
||||
fprintf(stderr, "%s: unlink(%s): %s\n", dz, fileName, strerror(errno));
|
||||
status = FALSE;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
extern int cp_mv_main(int argc, char **argv)
|
||||
{
|
||||
__label__ name_too_long__exit;
|
||||
__label__ exit_false;
|
||||
|
||||
int recursiveFlag;
|
||||
int followLinks;
|
||||
int preserveFlag;
|
||||
|
||||
const char *baseSrcName;
|
||||
int srcDirFlag;
|
||||
struct stat srcStatBuf;
|
||||
|
||||
char baseDestName[PATH_MAX + 1];
|
||||
size_t baseDestLen;
|
||||
int destDirFlag;
|
||||
struct stat destStatBuf;
|
||||
|
||||
void fill_baseDest_buf(char *_buf, size_t * _buflen) {
|
||||
const char *srcBasename;
|
||||
if ((srcBasename = strrchr(baseSrcName, '/')) == NULL) {
|
||||
srcBasename = baseSrcName;
|
||||
if (_buf[*_buflen - 1] != '/') {
|
||||
if (++(*_buflen) > PATH_MAX)
|
||||
goto name_too_long__exit;
|
||||
strcat(_buf, "/");
|
||||
}
|
||||
}
|
||||
if (*_buflen + strlen(srcBasename) > PATH_MAX)
|
||||
goto name_too_long__exit;
|
||||
strcat(_buf, srcBasename);
|
||||
return;
|
||||
}
|
||||
|
||||
int fileAction(const char *fileName, struct stat *statbuf) {
|
||||
char destName[PATH_MAX + 1];
|
||||
size_t destLen;
|
||||
const char *srcBasename;
|
||||
|
||||
strcpy(destName, baseDestName);
|
||||
destLen = strlen(destName);
|
||||
|
||||
if (srcDirFlag == TRUE) {
|
||||
if (recursiveFlag == FALSE) {
|
||||
fprintf(stderr, omitting_directory, "cp", baseSrcName);
|
||||
return TRUE;
|
||||
}
|
||||
srcBasename = (strstr(fileName, baseSrcName)
|
||||
+ strlen(baseSrcName));
|
||||
|
||||
if (destLen + strlen(srcBasename) > PATH_MAX) {
|
||||
fprintf(stderr, name_too_long, "cp");
|
||||
return FALSE;
|
||||
}
|
||||
strcat(destName, srcBasename);
|
||||
} else if (destDirFlag == TRUE) {
|
||||
fill_baseDest_buf(&destName[0], &destLen);
|
||||
} else {
|
||||
srcBasename = baseSrcName;
|
||||
}
|
||||
return copyFile(fileName, destName, preserveFlag, followLinks);
|
||||
}
|
||||
|
||||
int rmfileAction(const char *fileName, struct stat *statbuf) {
|
||||
if (unlink(fileName) < 0) {
|
||||
perror(fileName);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int rmdirAction(const char *fileName, struct stat *statbuf) {
|
||||
if (rmdir(fileName) < 0) {
|
||||
perror(fileName);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if ((dz = strrchr(*argv, '/')) == NULL)
|
||||
dz = *argv;
|
||||
else
|
||||
dz++;
|
||||
dz = *argv; /* already basename'd by busybox.c:main */
|
||||
if (*dz == 'c' && *(dz + 1) == 'p')
|
||||
dz_i = is_cp;
|
||||
else
|
||||
@@ -151,9 +201,9 @@ extern int cp_mv_main(int argc, char **argv)
|
||||
argv++;
|
||||
|
||||
if (dz_i == is_cp) {
|
||||
recursiveFlag = preserveFlag = FALSE;
|
||||
recursiveFlag = preserveFlag = forceFlag = FALSE;
|
||||
followLinks = TRUE;
|
||||
while (**argv == '-') {
|
||||
while (*argv && **argv == '-') {
|
||||
while (*++(*argv)) {
|
||||
switch (**argv) {
|
||||
case 'a':
|
||||
@@ -170,6 +220,9 @@ extern int cp_mv_main(int argc, char **argv)
|
||||
case 'R':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
forceFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage(cp_mv_usage[is_cp]);
|
||||
}
|
||||
@@ -177,12 +230,16 @@ extern int cp_mv_main(int argc, char **argv)
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
if (argc < 2) {
|
||||
usage(cp_mv_usage[dz_i]);
|
||||
}
|
||||
} else { /* (dz_i == is_mv) */
|
||||
recursiveFlag = preserveFlag = TRUE;
|
||||
followLinks = FALSE;
|
||||
}
|
||||
|
||||
|
||||
if (strlen(argv[argc - 1]) > PATH_MAX) {
|
||||
if (strlen(argv[argc - 1]) > BUFSIZ) {
|
||||
fprintf(stderr, name_too_long, "cp");
|
||||
goto exit_false;
|
||||
}
|
||||
@@ -199,53 +256,92 @@ extern int cp_mv_main(int argc, char **argv)
|
||||
|
||||
while (argc-- > 1) {
|
||||
size_t srcLen;
|
||||
int flags_memo;
|
||||
volatile int flags_memo;
|
||||
int status;
|
||||
|
||||
baseSrcName = *(argv++);
|
||||
|
||||
if ((srcLen = strlen(baseSrcName)) > PATH_MAX)
|
||||
goto name_too_long__exit;
|
||||
if ((srcLen = strlen(baseSrcName)) > BUFSIZ)
|
||||
name_too_long__exit();
|
||||
|
||||
if (srcLen == 0)
|
||||
continue;
|
||||
if (srcLen == 0) continue; /* "" */
|
||||
|
||||
srcDirFlag = isDirectory(baseSrcName, followLinks, &srcStatBuf);
|
||||
|
||||
if ((flags_memo = (recursiveFlag == TRUE &&
|
||||
srcDirFlag == TRUE && destDirFlag == TRUE))) {
|
||||
if ((destStatBuf.st_ino == srcStatBuf.st_ino) &&
|
||||
(destStatBuf.st_rdev == srcStatBuf.st_rdev)) {
|
||||
fprintf(stderr,
|
||||
"%s: Cannot %s `%s' into a subdirectory of itself, `%s/%s'\n",
|
||||
dz, dz, baseSrcName, baseDestName, baseSrcName);
|
||||
continue;
|
||||
|
||||
struct stat sb;
|
||||
int state = 0;
|
||||
char *pushd, *d, *p;
|
||||
|
||||
if ((pushd = getcwd(NULL, BUFSIZ + 1)) == NULL) {
|
||||
fprintf(stderr, "%s: getcwd(): %s\n", dz, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
if (chdir(baseDestName) < 0) {
|
||||
fprintf(stderr, "%s: chdir(%s): %s\n", dz, baseSrcName, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
if ((d = getcwd(NULL, BUFSIZ + 1)) == NULL) {
|
||||
fprintf(stderr, "%s: getcwd(): %s\n", dz, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
while (!state && *d != '\0') {
|
||||
if (stat(d, &sb) < 0) { /* stat not lstat - always dereference targets */
|
||||
fprintf(stderr, "%s: stat(%s) :%s\n", dz, d, strerror(errno));
|
||||
state = -1;
|
||||
continue;
|
||||
}
|
||||
if ((sb.st_ino == srcStatBuf.st_ino) &&
|
||||
(sb.st_dev == srcStatBuf.st_dev)) {
|
||||
fprintf(stderr,
|
||||
"%s: Cannot %s `%s' "
|
||||
"into a subdirectory of itself, `%s/%s'\n",
|
||||
dz, dz, baseSrcName, baseDestName, baseSrcName);
|
||||
state = -1;
|
||||
continue;
|
||||
}
|
||||
if ((p = strrchr(d, '/')) != NULL) {
|
||||
*p = '\0';
|
||||
}
|
||||
}
|
||||
if (chdir(pushd) < 0) {
|
||||
fprintf(stderr, "%s: chdir(%s): %s\n", dz, pushd, strerror(errno));
|
||||
free(pushd);
|
||||
free(d);
|
||||
continue;
|
||||
}
|
||||
free(pushd);
|
||||
free(d);
|
||||
if (state < 0)
|
||||
continue;
|
||||
else
|
||||
fill_baseDest_buf(baseDestName, &baseDestLen);
|
||||
}
|
||||
if (recursiveAction(baseSrcName,
|
||||
recursiveFlag, followLinks, FALSE,
|
||||
fileAction, fileAction) == FALSE)
|
||||
goto exit_false;
|
||||
|
||||
if (dz_i == is_mv &&
|
||||
recursiveAction(baseSrcName,
|
||||
recursiveFlag, followLinks, TRUE,
|
||||
rmfileAction, rmdirAction) == FALSE)
|
||||
goto exit_false;
|
||||
|
||||
status = setjmp(catch);
|
||||
if (status == 0) {
|
||||
mv_Action_first_time = 1;
|
||||
if (recursiveAction(baseSrcName,
|
||||
recursiveFlag, followLinks, FALSE,
|
||||
cp_mv_Action, cp_mv_Action, NULL) == FALSE) goto exit_false;
|
||||
if (dz_i == is_mv &&
|
||||
recursiveAction(baseSrcName,
|
||||
recursiveFlag, followLinks, TRUE,
|
||||
rm_Action, rm_Action, NULL) == FALSE) goto exit_false;
|
||||
}
|
||||
if (flags_memo)
|
||||
*(baseDestName + baseDestLen) = '\0';
|
||||
}
|
||||
|
||||
exit TRUE;
|
||||
|
||||
name_too_long__exit:
|
||||
fprintf(stderr, name_too_long, "cp");
|
||||
exit_false:
|
||||
exit FALSE;
|
||||
return( TRUE);
|
||||
exit_false:
|
||||
return( FALSE);
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
// c-file-style: "linux"
|
||||
// tab-width: 4
|
||||
// End:
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -0,0 +1,388 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* cut implementation for busybox
|
||||
*
|
||||
* Copyright (c) Michael J. Holme
|
||||
*
|
||||
* This version of cut is adapted from Minix cut and was modified
|
||||
* by Erik Andersen <andersee@debian.org> to be used in busybox.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Original copyright notice is retained at the end of this file.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <sys/types.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_help
|
||||
#include "messages.c"
|
||||
|
||||
#define MAX_FIELD 80 /* Pointers to the beginning of each field
|
||||
* are stored in columns[], if a line holds
|
||||
* more than MAX_FIELD columns the array
|
||||
* boundary is exceed. But unlikely at 80 */
|
||||
|
||||
#define MAX_ARGS 32 /* Maximum number of fields following -f or
|
||||
* -c switches */
|
||||
int args[MAX_ARGS * 2];
|
||||
int num_args;
|
||||
|
||||
/* Lots of new defines, should easen maintainance... */
|
||||
#define DUMP_STDIN 0 /* define for mode: no options */
|
||||
#define OPTIONF 1 /* define for mode: option -f */
|
||||
#define OPTIONC 2 /* define for mode: option -c */
|
||||
#define OPTIONB 3 /* define for mode: option -b */
|
||||
#define NOTSET 0 /* option not selected */
|
||||
#define SET 1 /* option selected */
|
||||
#define OPTIONS 1 /*define option -s */
|
||||
/* Defines for the warnings */
|
||||
#define DELIMITER_NOT_APPLICABLE 0
|
||||
#define OVERRIDING_PREVIOUS_MODE 1
|
||||
#define OPTION_NOT_APPLICABLE 2
|
||||
#define UNKNOWN_OPTION 3
|
||||
#define FILE_NOT_READABLE 4
|
||||
/* Defines for the fatal errors */
|
||||
#define SYNTAX_ERROR 101
|
||||
#define POSITION_ERROR 102
|
||||
#define LINE_TO_LONG_ERROR 103
|
||||
#define RANGE_ERROR 104
|
||||
#define MAX_FIELDS_EXEEDED_ERROR 105
|
||||
#define MAX_ARGS_EXEEDED_ERROR 106
|
||||
|
||||
|
||||
int mode; /* 0 = dump stdin to stdout, 1=-f, 2=-c */
|
||||
char delim = '\t'; /* default delimiting character */
|
||||
FILE *fd;
|
||||
char *name;
|
||||
char line[BUFSIZ];
|
||||
int exit_status;
|
||||
int option = 0; /* for -s option */
|
||||
|
||||
int cut_main(int argc, char **argv);
|
||||
void warn(int warn_number, char *option);
|
||||
void cuterror(int err);
|
||||
void get_args(void);
|
||||
void cut(void);
|
||||
|
||||
void warn(int warn_number, char *option)
|
||||
{
|
||||
static char *warn_msg[] = {
|
||||
"%s: Option -%s allowed only with -f\n",
|
||||
"%s: -%s overrides earlier option\n",
|
||||
"%s: -%s not allowed in current mode\n",
|
||||
"%s: Cannot open %s\n"
|
||||
};
|
||||
|
||||
fprintf(stderr, warn_msg[warn_number], name, option);
|
||||
exit_status = warn_number + 1;
|
||||
|
||||
}
|
||||
|
||||
void cuterror(int err)
|
||||
{
|
||||
static char *err_mes[] = {
|
||||
"%s: syntax error\n",
|
||||
"%s: position must be >0\n",
|
||||
"%s: line longer than BUFSIZ\n",
|
||||
"%s: range must not decrease from left to right\n",
|
||||
"%s: MAX_FIELD exceeded\n",
|
||||
"%s: MAX_ARGS exceeded\n"
|
||||
};
|
||||
|
||||
fprintf(stderr, err_mes[err - 101], name);
|
||||
exit(err);
|
||||
}
|
||||
|
||||
|
||||
void get_args()
|
||||
{
|
||||
int i = 0;
|
||||
int arg_ptr = 0;
|
||||
int flag;
|
||||
|
||||
num_args = 0;
|
||||
do {
|
||||
if (num_args == MAX_ARGS)
|
||||
cuterror(MAX_ARGS_EXEEDED_ERROR);
|
||||
if (!isdigit(line[i]) && line[i] != '-')
|
||||
cuterror(SYNTAX_ERROR);
|
||||
|
||||
args[arg_ptr] = 1;
|
||||
args[arg_ptr + 1] = BUFSIZ;
|
||||
flag = 1;
|
||||
|
||||
while (line[i] != ',' && line[i] != 0) {
|
||||
if (isdigit(line[i])) {
|
||||
args[arg_ptr] = 0;
|
||||
while (isdigit(line[i]))
|
||||
args[arg_ptr] = 10 * args[arg_ptr] + line[i++] - '0';
|
||||
if (!args[arg_ptr])
|
||||
cuterror(POSITION_ERROR);
|
||||
arg_ptr++;
|
||||
}
|
||||
if (line[i] == '-') {
|
||||
arg_ptr |= 1;
|
||||
i++;
|
||||
flag = 0;
|
||||
}
|
||||
}
|
||||
if (flag && arg_ptr & 1)
|
||||
args[arg_ptr] = args[arg_ptr - 1];
|
||||
if (args[num_args * 2] > args[num_args * 2 + 1])
|
||||
cuterror(RANGE_ERROR);
|
||||
num_args++;
|
||||
arg_ptr = num_args * 2;
|
||||
}
|
||||
while (line[i++]);
|
||||
}
|
||||
|
||||
|
||||
void cut()
|
||||
{
|
||||
int i, j, length, maxcol=0;
|
||||
char *columns[MAX_FIELD];
|
||||
|
||||
while (fgets(line, BUFSIZ, fd)) {
|
||||
maxcol=0;
|
||||
length = strlen(line) - 1;
|
||||
*(line + length) = 0;
|
||||
switch (mode) {
|
||||
case DUMP_STDIN:
|
||||
printf("%s", line);
|
||||
break;
|
||||
case OPTIONF:
|
||||
columns[maxcol++] = line;
|
||||
for (i = 0; i < length; i++) {
|
||||
if (*(line + i) == delim) {
|
||||
*(line + i) = 0;
|
||||
if (maxcol == MAX_FIELD)
|
||||
cuterror(MAX_FIELDS_EXEEDED_ERROR);
|
||||
columns[maxcol] = line + i + 1;
|
||||
maxcol++;
|
||||
}
|
||||
}
|
||||
if (maxcol != 1) {
|
||||
for (i = 0; i < num_args; i++) {
|
||||
for (j = args[i * 2]; j <= args[i * 2 + 1]; j++)
|
||||
if (j <= maxcol) {
|
||||
|
||||
printf("%s", columns[j - 1]);
|
||||
|
||||
if (i != num_args - 1 || j != args[i * 2 + 1])
|
||||
putchar(delim);
|
||||
}
|
||||
}
|
||||
} else if (option != OPTIONS) {
|
||||
printf("%s",line);
|
||||
}
|
||||
break;
|
||||
case OPTIONC:
|
||||
for (i = 0; i < num_args; i++) {
|
||||
for (j = args[i * 2];
|
||||
j <= (args[i * 2 + 1] >
|
||||
length ? length : args[i * 2 + 1]); j++)
|
||||
putchar(*(line + j - 1));
|
||||
}
|
||||
}
|
||||
if (maxcol != 1)
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int cut_main(int argc, char **argv)
|
||||
{
|
||||
int i = 1;
|
||||
int numberFilenames = 0;
|
||||
|
||||
name = argv[0];
|
||||
|
||||
if (argc == 1 || strcmp(argv[1], dash_dash_help)==0)
|
||||
usage( "cut [OPTION]... [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrints selected fields from each input FILE to standard output.\n\n"
|
||||
"Options:\n"
|
||||
"\t-b LIST\tOutput only bytes from LIST\n"
|
||||
"\t-c LIST\tOutput only characters from LIST\n"
|
||||
"\t-d CHAR\tUse CHAR instead of tab as the field delimiter\n"
|
||||
"\t-s\tOnly output Lines if the include DELIM\n"
|
||||
"\t-f N\tPrint only these fields\n"
|
||||
"\t-n\tIgnored\n"
|
||||
#endif
|
||||
);
|
||||
|
||||
while (i < argc) {
|
||||
if (argv[i][0] == '-') {
|
||||
switch (argv[i++][1]) {
|
||||
case 'd':
|
||||
if (mode == OPTIONC || mode == OPTIONB)
|
||||
warn(DELIMITER_NOT_APPLICABLE, "d");
|
||||
if (argc > i)
|
||||
delim = argv[i++][0];
|
||||
else
|
||||
cuterror(SYNTAX_ERROR);
|
||||
break;
|
||||
case 'f':
|
||||
sprintf(line, "%s", argv[i++]);
|
||||
if (mode == OPTIONC || mode == OPTIONB)
|
||||
warn(OVERRIDING_PREVIOUS_MODE, "f");
|
||||
mode = OPTIONF;
|
||||
break;
|
||||
case 'b':
|
||||
sprintf(line, "%s", argv[i++]);
|
||||
if (mode == OPTIONF || mode == OPTIONC)
|
||||
warn(OVERRIDING_PREVIOUS_MODE, "b");
|
||||
mode = OPTIONB;
|
||||
break;
|
||||
case 'c':
|
||||
sprintf(line, "%s", argv[i++]);
|
||||
if (mode == OPTIONF || mode == OPTIONB)
|
||||
warn(OVERRIDING_PREVIOUS_MODE, "c");
|
||||
mode = OPTIONC;
|
||||
break;
|
||||
case 's':
|
||||
option = OPTIONS;
|
||||
|
||||
break;
|
||||
case '\0': /* - means: read from stdin */
|
||||
numberFilenames++;
|
||||
break;
|
||||
case 'n': /* needed for Posix, but no effect here */
|
||||
if (mode != OPTIONB)
|
||||
warn(OPTION_NOT_APPLICABLE, "n");
|
||||
break;
|
||||
default:
|
||||
warn(UNKNOWN_OPTION, &(argv[i - 1][1]));
|
||||
}
|
||||
} else {
|
||||
i++;
|
||||
numberFilenames++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Here follow the checks, if the selected options are reasonable. */
|
||||
if (mode == OPTIONB) /* since in Minix char := byte */
|
||||
mode = OPTIONC;
|
||||
|
||||
if (mode != OPTIONF && option == OPTIONS)
|
||||
warn(DELIMITER_NOT_APPLICABLE,"s");
|
||||
get_args();
|
||||
if (numberFilenames != 0) {
|
||||
i = 1;
|
||||
while (i < argc) {
|
||||
if (argv[i][0] == '-') {
|
||||
switch (argv[i][1]) {
|
||||
case 'f':
|
||||
case 'c':
|
||||
case 'b':
|
||||
case 'd':
|
||||
i += 2;
|
||||
break;
|
||||
case 'n':
|
||||
case 'i':
|
||||
case 's':
|
||||
i++;
|
||||
break;
|
||||
case '\0':
|
||||
fd = stdin;
|
||||
i++;
|
||||
cut();
|
||||
break;
|
||||
default:
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
if ((fd = fopen(argv[i++], "r")) == NULL) {
|
||||
warn(FILE_NOT_READABLE, argv[i - 1]);
|
||||
} else {
|
||||
cut();
|
||||
fclose(fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fd = stdin;
|
||||
cut();
|
||||
}
|
||||
|
||||
return(exit_status);
|
||||
}
|
||||
|
||||
/* cut - extract columns from a file or stdin. Author: Michael J. Holme
|
||||
*
|
||||
* Copyright 1989, Michael John Holme, All rights reserved.
|
||||
* This code may be freely distributed, provided that this notice
|
||||
* remains intact.
|
||||
*
|
||||
* V1.1: 6th September 1989
|
||||
*
|
||||
* Bugs, criticisms, etc,
|
||||
* c/o Mark Powell
|
||||
* JANET sq79@uk.ac.liv
|
||||
* ARPA sq79%liv.ac.uk@nsfnet-relay.ac.uk
|
||||
* UUCP ...!mcvax!ukc!liv.ac.uk!sq79
|
||||
*-------------------------------------------------------------------------
|
||||
* Changed for POSIX1003.2/Draft10 conformance
|
||||
* Thomas Brupbacher (tobr@mw.lpc.ethz.ch), September 1990.
|
||||
* Changes:
|
||||
* - separation of error messages ( stderr) and output (stdout).
|
||||
* - support for -b and -n (no effect, -b acts as -c)
|
||||
* - support for -s
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987,1997, Prentice Hall
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use of the MINIX operating system in source and
|
||||
* binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of Prentice Hall nor the names of the software
|
||||
* authors or contributors may be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND
|
||||
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL PRENTICE HALL OR ANY AUTHORS OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
@@ -40,12 +40,14 @@
|
||||
mail commands */
|
||||
|
||||
static const char date_usage[] = "date [OPTION]... [+FORMAT]\n"
|
||||
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n\n"
|
||||
"Display the current time in the given FORMAT, or set the system date.\n"
|
||||
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
|
||||
"\t-s\t\tset time described by STRING\n"
|
||||
|
||||
"\t-u\t\tprint or set Coordinated Universal Time\n";
|
||||
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nDisplays the current time in the given FORMAT, or sets the system date.\n"
|
||||
"\nOptions:\n\t-R\tOutputs RFC-822 compliant date string\n"
|
||||
"\t-s\tSets time described by STRING\n"
|
||||
"\t-u\tPrints or sets Coordinated Universal Time\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
/* Input parsing code is always bulky - used heavy duty libc stuff as
|
||||
@@ -64,8 +66,7 @@ struct tm *date_conv_time(struct tm *tm_time, const char *t_string)
|
||||
&(tm_time->tm_min), &(tm_time->tm_year));
|
||||
|
||||
if (nr < 4 || nr > 5) {
|
||||
fprintf(stderr, invalid_date, "date", t_string);
|
||||
exit(FALSE);
|
||||
fatalError(invalid_date, "date", t_string);
|
||||
}
|
||||
|
||||
/* correct for century - minor Y2K problem here? */
|
||||
@@ -149,10 +150,7 @@ struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
|
||||
|
||||
}
|
||||
|
||||
fprintf(stderr, invalid_date, "date", t_string);
|
||||
|
||||
exit(FALSE);
|
||||
|
||||
fatalError(invalid_date, "date", t_string);
|
||||
}
|
||||
|
||||
|
||||
@@ -183,27 +181,25 @@ int date_main(int argc, char **argv)
|
||||
set_time = 1;
|
||||
if (date_str != NULL)
|
||||
usage(date_usage);
|
||||
date_str = optarg;
|
||||
date_str = *argv;
|
||||
break;
|
||||
case 'u':
|
||||
utc = 1;
|
||||
if (putenv("TZ=UTC0") != 0) {
|
||||
fprintf(stderr, memory_exhausted, "date");
|
||||
exit(FALSE);
|
||||
}
|
||||
/* Look ma, no break. Don't fix it either. */
|
||||
if (putenv("TZ=UTC0") != 0)
|
||||
fatalError(memory_exhausted, "date");
|
||||
break;
|
||||
case 'd':
|
||||
use_arg = 1;
|
||||
if (date_str != NULL)
|
||||
usage(date_usage);
|
||||
date_str = optarg;
|
||||
date_str = *argv;
|
||||
break;
|
||||
case '-':
|
||||
usage(date_usage);
|
||||
}
|
||||
} else {
|
||||
if ((date_fmt == NULL) && (strcmp(*argv, "+") == 0))
|
||||
date_fmt = *argv;
|
||||
if ((date_fmt == NULL) && (**argv == '+'))
|
||||
date_fmt = *argv + 1; /* Skip over the '+' */
|
||||
else if (date_str == NULL) {
|
||||
set_time = 1;
|
||||
date_str = *argv;
|
||||
@@ -239,16 +235,13 @@ int date_main(int argc, char **argv)
|
||||
|
||||
/* Correct any day of week and day of year etc fields */
|
||||
tm = mktime(&tm_time);
|
||||
if (tm < 0) {
|
||||
fprintf(stderr, invalid_date, "date", date_str);
|
||||
exit(FALSE);
|
||||
}
|
||||
if (tm < 0)
|
||||
fatalError(invalid_date, "date", date_str);
|
||||
|
||||
/* if setting time, set it */
|
||||
if (set_time) {
|
||||
if (stime(&tm) < 0) {
|
||||
fprintf(stderr, "date: can't set date.\n");
|
||||
exit(FALSE);
|
||||
fatalError("date: can't set date.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -276,10 +269,9 @@ int date_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
/* Print OUTPUT (after ALL that!) */
|
||||
t_buff = malloc(201);
|
||||
t_buff = xmalloc(201);
|
||||
strftime(t_buff, 200, date_fmt, &tm_time);
|
||||
printf("%s\n", t_buff);
|
||||
|
||||
exit(TRUE);
|
||||
|
||||
return(TRUE);
|
||||
}
|
||||
+74
-17
@@ -1,5 +1,6 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include "internal.h"
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@@ -7,7 +8,13 @@
|
||||
|
||||
/* Tiny RPN calculator, because "expr" didn't give me bitwise operations. */
|
||||
|
||||
static const char math_usage[] = "math expression ...";
|
||||
static const char dc_usage[] = "dc expression ...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nThis is a Tiny RPN calculator that understands the\n"
|
||||
"following operations: +, -, /, *, and, or, not, eor.\n"
|
||||
"i.e. 'dc 2 2 add' -> 4, and 'dc 8 8 \\* 2 2 + /' -> 16\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
static double stack[100];
|
||||
static unsigned int pointer;
|
||||
@@ -15,7 +22,7 @@ static unsigned int pointer;
|
||||
static void push(double a)
|
||||
{
|
||||
if (pointer >= (sizeof(stack) / sizeof(*stack))) {
|
||||
fprintf(stderr, "math: stack overflow\n");
|
||||
fprintf(stderr, "dc: stack overflow\n");
|
||||
exit(-1);
|
||||
} else
|
||||
stack[pointer++] = a;
|
||||
@@ -24,7 +31,7 @@ static void push(double a)
|
||||
static double pop()
|
||||
{
|
||||
if (pointer == 0) {
|
||||
fprintf(stderr, "math: stack underflow\n");
|
||||
fprintf(stderr, "dc: stack underflow\n");
|
||||
exit(-1);
|
||||
}
|
||||
return stack[--pointer];
|
||||
@@ -85,15 +92,19 @@ struct op {
|
||||
};
|
||||
|
||||
static const struct op operators[] = {
|
||||
{"+", add},
|
||||
{"add", add},
|
||||
{"and", and},
|
||||
{"div", divide},
|
||||
{"eor", eor},
|
||||
{"mul", mul},
|
||||
{"not", not},
|
||||
{"or", or},
|
||||
{"-", sub},
|
||||
{"sub", sub},
|
||||
{0, 0}
|
||||
{"*", mul},
|
||||
{"mul", mul},
|
||||
{"/", divide},
|
||||
{"div", divide},
|
||||
{"and", and},
|
||||
{"or", or},
|
||||
{"not", not},
|
||||
{"eor", eor},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
static void stack_machine(const char *argument)
|
||||
@@ -121,17 +132,63 @@ static void stack_machine(const char *argument)
|
||||
}
|
||||
o++;
|
||||
}
|
||||
fprintf(stderr, "math: %s: syntax error.\n", argument);
|
||||
fprintf(stderr, "dc: %s: syntax error.\n", argument);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
int math_main(int argc, char **argv)
|
||||
/* return pointer to next token in buffer and set *buffer to one char
|
||||
* past the end of the above mentioned token
|
||||
*/
|
||||
static char *get_token(char **buffer)
|
||||
{
|
||||
while (argc >= 2) {
|
||||
stack_machine(argv[1]);
|
||||
argv++;
|
||||
argc--;
|
||||
char *start = NULL;
|
||||
char *current = *buffer;
|
||||
|
||||
while (isspace(*current)) { current++; }
|
||||
if (*current != 0) {
|
||||
start = current;
|
||||
while (!isspace(*current) && current != 0) { current++; }
|
||||
*buffer = current;
|
||||
}
|
||||
return start;
|
||||
}
|
||||
|
||||
/* In Perl one might say, scalar m|\s*(\S+)\s*|g */
|
||||
static int number_of_tokens(char *buffer)
|
||||
{
|
||||
int i = 0;
|
||||
char *b = buffer;
|
||||
while (get_token(&b)) { i++; }
|
||||
return i;
|
||||
}
|
||||
|
||||
int dc_main(int argc, char **argv)
|
||||
{
|
||||
/* take stuff from stdin if no args are given */
|
||||
if (argc <= 1) {
|
||||
int i, len;
|
||||
char *line = NULL;
|
||||
char *cursor = NULL;
|
||||
char *token = NULL;
|
||||
while ((line = get_line_from_file(stdin))) {
|
||||
cursor = line;
|
||||
len = number_of_tokens(line);
|
||||
for (i = 0; i < len; i++) {
|
||||
token = get_token(&cursor);
|
||||
*cursor++ = 0;
|
||||
stack_machine(token);
|
||||
}
|
||||
free(line);
|
||||
}
|
||||
} else {
|
||||
if (*argv[1]=='-')
|
||||
usage(dc_usage);
|
||||
while (argc >= 2) {
|
||||
stack_machine(argv[1]);
|
||||
argv++;
|
||||
argc--;
|
||||
}
|
||||
}
|
||||
stack_machine(0);
|
||||
return 0;
|
||||
return( TRUE);
|
||||
}
|
||||
@@ -2,13 +2,13 @@
|
||||
/*
|
||||
* Mini dd implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999, 2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* based in part on code taken from sash.
|
||||
*
|
||||
* Copyright (c) 1999 by David I. Bell
|
||||
* Permission is granted to use, distribute, or modify this source,
|
||||
* provided that this copyright notice remains intact.
|
||||
* Based in part on code taken from sash.
|
||||
* Copyright (c) 1999 by David I. Bell
|
||||
* Permission is granted to use, distribute, or modify this source,
|
||||
* provided that this copyright notice remains intact.
|
||||
*
|
||||
* Permission to distribute this code under the GPL has been granted.
|
||||
*
|
||||
@@ -41,24 +41,26 @@ typedef unsigned long long int uintmax_t;
|
||||
#endif
|
||||
|
||||
static const char dd_usage[] =
|
||||
"dd [if=name] [of=name] [bs=n] [count=n] [skip=n] [seek=n]\n\n"
|
||||
"Copy a file, converting and formatting according to options\n\n"
|
||||
"dd [if=FILE] [of=FILE] [bs=N] [count=N] [skip=N] [seek=N]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCopy a file, converting and formatting according to options\n\n"
|
||||
"\tif=FILE\tread from FILE instead of stdin\n"
|
||||
"\tof=FILE\twrite to FILE instead of stdout\n"
|
||||
"\tbs=n\tread and write n bytes at a time\n"
|
||||
"\tcount=n\tcopy only n input blocks\n"
|
||||
"\tskip=n\tskip n input blocks\n"
|
||||
"\tseek=n\tskip n output blocks\n"
|
||||
|
||||
"\tbs=N\tread and write N bytes at a time\n"
|
||||
"\tcount=N\tcopy only N input blocks\n"
|
||||
"\tskip=N\tskip N input blocks\n"
|
||||
"\tseek=N\tskip N output blocks\n"
|
||||
"\n"
|
||||
"Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n";
|
||||
"Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
extern int dd_main(int argc, char **argv)
|
||||
{
|
||||
const char *inFile = NULL;
|
||||
const char *outFile = NULL;
|
||||
char *inFile = NULL;
|
||||
char *outFile = NULL;
|
||||
char *cp;
|
||||
int inFd;
|
||||
int outFd;
|
||||
@@ -114,11 +116,7 @@ extern int dd_main(int argc, char **argv)
|
||||
argv++;
|
||||
}
|
||||
|
||||
buf = malloc(blockSize);
|
||||
if (buf == NULL) {
|
||||
fprintf(stderr, "Cannot allocate buffer\n");
|
||||
exit(FALSE);
|
||||
}
|
||||
buf = xmalloc(blockSize);
|
||||
|
||||
intotal = 0;
|
||||
outTotal = 0;
|
||||
@@ -129,9 +127,12 @@ extern int dd_main(int argc, char **argv)
|
||||
inFd = open(inFile, 0);
|
||||
|
||||
if (inFd < 0) {
|
||||
perror(inFile);
|
||||
free(buf);
|
||||
exit(FALSE);
|
||||
/* Note that we are not freeing buf or closing
|
||||
* files here to save a few bytes. This exits
|
||||
* here anyways... */
|
||||
|
||||
/* free(buf); */
|
||||
fatalError( inFile);
|
||||
}
|
||||
|
||||
if (outFile == NULL)
|
||||
@@ -140,10 +141,13 @@ extern int dd_main(int argc, char **argv)
|
||||
outFd = open(outFile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
|
||||
if (outFd < 0) {
|
||||
perror(outFile);
|
||||
close(inFd);
|
||||
free(buf);
|
||||
exit(FALSE);
|
||||
/* Note that we are not freeing buf or closing
|
||||
* files here to save a few bytes. This exits
|
||||
* here anyways... */
|
||||
|
||||
/* close(inFd);
|
||||
free(buf); */
|
||||
fatalError( outFile);
|
||||
}
|
||||
|
||||
lseek(inFd, skipBlocks * blockSize, SEEK_SET);
|
||||
@@ -184,9 +188,13 @@ extern int dd_main(int argc, char **argv)
|
||||
perror(inFile);
|
||||
|
||||
cleanup:
|
||||
/* Note that we are not freeing memory or closing
|
||||
* files here, to save a few bytes. */
|
||||
#if 0
|
||||
close(inFd);
|
||||
close(outFd);
|
||||
free(buf);
|
||||
#endif
|
||||
|
||||
printf("%ld+%d records in\n", (long) (intotal / blockSize),
|
||||
(intotal % blockSize) != 0);
|
||||
|
||||
+13
-7
@@ -5,13 +5,15 @@
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/vt.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern int getfd(void);
|
||||
/* From <linux/vt.h> */
|
||||
#define VT_DISALLOCATE 0x5608 /* free memory associated to vt */
|
||||
|
||||
|
||||
char *progname;
|
||||
|
||||
int deallocvt_main(int argc, char *argv[])
|
||||
@@ -20,7 +22,11 @@ int deallocvt_main(int argc, char *argv[])
|
||||
|
||||
if ((argc != 2) || (**(argv + 1) == '-')) {
|
||||
usage
|
||||
("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
|
||||
("deallocvt N\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nDeallocate unused virtual terminal /dev/ttyN\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
progname = argv[0];
|
||||
@@ -31,7 +37,7 @@ int deallocvt_main(int argc, char *argv[])
|
||||
/* deallocate all unused consoles */
|
||||
if (ioctl(fd, VT_DISALLOCATE, 0)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
exit(1);
|
||||
exit( FALSE);
|
||||
}
|
||||
} else
|
||||
for (i = 1; i < argc; i++) {
|
||||
@@ -45,8 +51,8 @@ int deallocvt_main(int argc, char *argv[])
|
||||
perror("VT_DISALLOCATE");
|
||||
fprintf(stderr, "%s: could not deallocate console %d\n",
|
||||
progname, num);
|
||||
exit(1);
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
return( TRUE);
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
BusyBox for Debian
|
||||
----------------------
|
||||
|
||||
BusyBox is being developed and maintained by Erik Andersen
|
||||
<andersee@debian.org>.
|
||||
|
||||
If you have a problem with BusyBox, send email to the Debian bug tracking
|
||||
system that lives at <submit@bugs.lineo.com>
|
||||
|
||||
Erik Andersen <andersee@debian.org>, Sun, 18 Jun 2000 21:52:00 -0600
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
busybox (0.46-1) unstable; urgency=low
|
||||
|
||||
* New version released. See changelog for details.
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Tue, 11 Jul 2000 12:15:44 -0600
|
||||
|
||||
busybox (0.45-1) unstable; urgency=low
|
||||
|
||||
* First attempt at packaging BusyBox as a .deb. This has been in
|
||||
in the Debian boot-floppies CVS tree forever. Hopefully, having it as a
|
||||
standalone app will make life easier for me, the debian-installer team, and
|
||||
everyone else as well...
|
||||
* I have created a busybox-static that can be used as a rescue shell when you
|
||||
hose your system. Just invoke "busybox sh" to fir up the shell. This has
|
||||
every app provided by busybox staically linked in. There have been several
|
||||
times in the past that I would have loved to have this sitting on my system
|
||||
(i.e. when libc gets screwed up.)
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Tue, 27 Jun 2000 12:26:41 -0600
|
||||
|
||||
Local variables:
|
||||
mode: debian-changelog
|
||||
add-log-mailing-address: "andersee@debian.org"
|
||||
End:
|
||||
Vendored
+46
@@ -0,0 +1,46 @@
|
||||
Source: busybox
|
||||
Priority: optional
|
||||
Maintainer: Erik Andersen <andersee@debian.org>
|
||||
Build-Depends: debhelper
|
||||
Standards-Version: 3.1.1
|
||||
|
||||
Package: busybox
|
||||
Architecture: any
|
||||
Depends: ${shlibs:Depends}
|
||||
Conflicts: binutils, bsdutils, console-tools, cpio, debianutils, dnsutils, dpkg, fbset, fdflush, fileutils, grep, gzip, hostname, modutils, mount, netbase, procps, psmisc, sed, sharutils, shellutils, sysklogd, sysvinit, tar, textutils, update, util-linux
|
||||
Replaces: netbase
|
||||
Section: utils
|
||||
Description: Tiny utilities for the debian-installer and for embedded systems.
|
||||
BusyBox combines tiny versions of many common UNIX utilities into a single
|
||||
small executable. It provides minimalist replacements for the most common
|
||||
utilities you would usually find on your desktop system (i.e. ls, cp, mv,
|
||||
mount, tar, etc). The utilities in BusyBox generally have fewer options than
|
||||
their full-featured GNU cousins; however, the options that are included
|
||||
provide the expected functionality and behave very much like their GNU
|
||||
counterparts.
|
||||
.
|
||||
BusyBox is used by the debian-installer. Installing BusyBox onto your Debian
|
||||
system is not recommended, unless you are intended to make a very small
|
||||
embedded system. Chances are good that for embedded systems, you will want to
|
||||
recompile to only include the tools and utilities you wish to include.
|
||||
|
||||
Package: busybox-static
|
||||
Architecture: any
|
||||
Depends: ${shlibs:Depends}
|
||||
Section: shells
|
||||
Description: Provides a stand alone rescue shell with tons of builtin utilities.
|
||||
BusyBox combines tiny versions of many common UNIX utilities into a single
|
||||
small executable. It provides minimalist replacements for the most common
|
||||
utilities you would usually find on your desktop system (i.e. ls, cp, mv,
|
||||
mount, tar, etc). The utilities in BusyBox generally have fewer options than
|
||||
their full-featured GNU cousins; however, the options that are included
|
||||
provide the expected functionality and behave very much like their GNU
|
||||
counterparts.
|
||||
.
|
||||
BusyBox-static provides you with a statically linked simple stand alone shell
|
||||
that provides all the utilities available in BusyBox. This package is
|
||||
intended to be used as a rescue shell, in the event that you screw up your
|
||||
system. Invoke "busybox sh" and you have a standalone shell ready to save
|
||||
your system from certain destruction. Invoke "busybox", and it will list the
|
||||
available builtin commands.
|
||||
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
This package was debianized by Erik Andersen <andersee@debian.org> on
|
||||
Sun, 18 Jun 2000 23:31:02 -0600
|
||||
|
||||
It was downloaded from ftp://ftp.lineo.com/pub/busybox
|
||||
HomePage is at: http://busybox.lineo.com/
|
||||
|
||||
Copyright: GPL
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
#!/usr/bin/make -f
|
||||
|
||||
# This is a bit unusual, in that I have to completely recompile everything
|
||||
# twice. The first is the normal, dynamically linked package. The second is
|
||||
# for the statically linked package. This file has been adjusted accordingly.
|
||||
|
||||
# This is the debhelper compatability version to use.
|
||||
export DH_COMPAT=1
|
||||
|
||||
bb=debian/tmp
|
||||
bbs=debian/busybox-static
|
||||
|
||||
clean:
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
rm -f build-stamp-busybox build-stamp-busybox-static
|
||||
-$(MAKE) clean
|
||||
-rm -rf $(bb) $(bbs)
|
||||
dh_clean
|
||||
|
||||
half_clean:
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
rm -rf $(bbs) build-stamp-busybox-static
|
||||
-$(MAKE) clean
|
||||
|
||||
build: build-stamp-busybox
|
||||
build-stamp-busybox:
|
||||
dh_testdir
|
||||
$(MAKE)
|
||||
touch build-stamp-busybox
|
||||
|
||||
install: build
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_clean -k
|
||||
dh_installdirs
|
||||
$(MAKE) "PREFIX=$(bb)" install
|
||||
mkdir -p $(bb)/usr/share/man/man1
|
||||
cp docs/BusyBox.1 $(bb)/usr/share/man/man1/busybox.1
|
||||
|
||||
# Now for the statically linked stuff
|
||||
build-static: build-stamp-busybox-static
|
||||
build-stamp-busybox-static:
|
||||
dh_testdir
|
||||
$(MAKE) DOSTATIC=true
|
||||
touch build-stamp-busybox-static
|
||||
|
||||
install-static: build
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_clean -k
|
||||
dh_installdirs
|
||||
# Do not run 'make install', since we do not want all the symlinks.
|
||||
# This just installes the busybox binary...
|
||||
#$(MAKE) "PREFIX=$(bbs)" install
|
||||
mkdir -p $(bbs)/bin/
|
||||
cp busybox $(bbs)/bin/busybox
|
||||
mkdir -p $(bbs)/usr/share/man/man1/
|
||||
cp docs/BusyBox.1 $(bbs)/usr/share/man/man1/busybox.1
|
||||
|
||||
do_static: half_clean build-static install-static
|
||||
|
||||
|
||||
# Build architecture-independent files here.
|
||||
binary-indep:
|
||||
# We have nothing to do by default.
|
||||
|
||||
# Build architecture-dependent files here.
|
||||
binary-arch: busybox busybox-static
|
||||
|
||||
busybox: install
|
||||
@echo "--- Building: $@"
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_installdirs
|
||||
#
|
||||
#Note that for busybox, we do not install any docs,
|
||||
# or man apges or anything else. This is in blatent violation of every
|
||||
# Debian policy out there, since this package is intended to be used
|
||||
# _only_ by the debian-installer.
|
||||
#
|
||||
#dh_installdocs -p$@ docs/BusyBox.txt \
|
||||
# docs/BusyBox.html docs/busybox.lineo.com AUTHORS README TODO
|
||||
#rm -rf $(bb)/usr/share/doc/busybox/busybox.lineo.com/CVS \
|
||||
# $(bb)/usr/share/doc/busybox/busybox.lineo.com/.cvsignore \
|
||||
# $(bb)/usr/share/doc/busybox/busybox.lineo.com/images/CVS \
|
||||
# $(bb)/usr/share/doc/busybox/busybox.lineo.com/images/.cvsignore
|
||||
#dh_undocumented -p$@
|
||||
dh_installchangelogs -p$@ Changelog
|
||||
dh_strip -p$@
|
||||
dh_compress -p$@
|
||||
dh_fixperms -p$@
|
||||
dh_installdeb -p$@
|
||||
dh_shlibdeps -p$@
|
||||
#
|
||||
#Make _very_ sure there are no docs lurking about.
|
||||
#
|
||||
rm -rf $(bb)/usr/share/doc
|
||||
rm -rf $(bb)/usr/share/man
|
||||
dh_gencontrol -p$@
|
||||
dh_md5sums -p$@
|
||||
dh_builddeb -p$@
|
||||
|
||||
|
||||
busybox-static: do_static
|
||||
@echo "--- Building: $@"
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_installdirs
|
||||
dh_installdocs -p$@ docs/BusyBox.txt \
|
||||
docs/BusyBox.html docs/busybox.lineo.com AUTHORS README TODO
|
||||
rm -rf $(bbs)/usr/share/doc/busybox-static/busybox.lineo.com/CVS \
|
||||
$(bbs)/usr/share/doc/busybox-static/busybox.lineo.com/.cvsignore \
|
||||
$(bbs)/usr/share/doc/busybox-static/busybox.lineo.com/images/CVS \
|
||||
$(bbs)/usr/share/doc/busybox-static/busybox.lineo.com/images/.cvsignore
|
||||
dh_undocumented -p$@
|
||||
dh_installchangelogs -p$@ Changelog
|
||||
dh_strip -p$@
|
||||
dh_compress -p$@
|
||||
dh_fixperms -p$@
|
||||
dh_installdeb -p$@
|
||||
dh_shlibdeps -p$@
|
||||
dh_gencontrol -p$@
|
||||
dh_md5sums -p$@
|
||||
dh_builddeb -p$@
|
||||
|
||||
|
||||
binary: binary-indep binary-arch
|
||||
.PHONY: build clean binary-indep binary-arch binary install
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/bin/sh
|
||||
# define.sh - creates an include file full of #defines
|
||||
#
|
||||
# SYNOPSIS
|
||||
#
|
||||
# define.sh POSIX_ME_HARDER ...
|
||||
#
|
||||
# <GPL>
|
||||
|
||||
for i ; do
|
||||
case $1 in
|
||||
!!*!!)
|
||||
echo "// #define" `echo $1 | sed 's/^!!\(.*\)!!$/\1/'`
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "#define $1"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# </GPL>
|
||||
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini df implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* based on original code by (I think) Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
@@ -27,11 +27,12 @@
|
||||
#include <mntent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/vfs.h>
|
||||
#include <fstab.h>
|
||||
|
||||
static const char df_usage[] = "df [filesystem ...]\n"
|
||||
|
||||
"\n" "\tPrint the filesystem space used and space available.\n";
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint the filesystem space used and space available.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern const char mtab_file[]; /* Defined in utility.c */
|
||||
|
||||
@@ -40,7 +41,6 @@ static int df(char *device, const char *mountPoint)
|
||||
struct statfs s;
|
||||
long blocks_used;
|
||||
long blocks_percent_used;
|
||||
struct fstab *fstabItem;
|
||||
|
||||
if (statfs(mountPoint, &s) != 0) {
|
||||
perror(mountPoint);
|
||||
@@ -51,11 +51,10 @@ static int df(char *device, const char *mountPoint)
|
||||
blocks_used = s.f_blocks - s.f_bfree;
|
||||
blocks_percent_used = (long)
|
||||
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
|
||||
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
|
||||
if (strcmp(device, "/dev/root") == 0) {
|
||||
fstabItem = getfsfile("/");
|
||||
if (fstabItem != NULL)
|
||||
device = fstabItem->fs_spec;
|
||||
/* Adjusts device to be the real root device,
|
||||
* or leaves device alone if it can't find it */
|
||||
find_real_root_device_name( device);
|
||||
}
|
||||
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
|
||||
device,
|
||||
@@ -78,6 +77,9 @@ extern int df_main(int argc, char **argv)
|
||||
struct mntent *mountEntry;
|
||||
int status;
|
||||
|
||||
if (**(argv + 1) == '-') {
|
||||
usage(df_usage);
|
||||
}
|
||||
while (argc > 1) {
|
||||
if ((mountEntry = findMountPoint(argv[1], mtab_file)) == 0) {
|
||||
fprintf(stderr, "%s: can't find mount point.\n", argv[1]);
|
||||
@@ -106,5 +108,13 @@ extern int df_main(int argc, char **argv)
|
||||
endmntent(mountTable);
|
||||
}
|
||||
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -0,0 +1,49 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini dirname implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern int dirname_main(int argc, char **argv)
|
||||
{
|
||||
char* s;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage("dirname [FILENAME ...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nStrips non-directory suffix from FILENAME\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
argv++;
|
||||
|
||||
s=*argv+strlen(*argv)-1;
|
||||
while (s && *s == '/') {
|
||||
*s = '\0';
|
||||
s=*argv+strlen(*argv)-1;
|
||||
}
|
||||
s = strrchr(*argv, '/');
|
||||
if (s && *s)
|
||||
*s = '\0';
|
||||
printf("%s\n", (s)? *argv : ".");
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -16,9 +16,7 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <linux/unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if __GNU_LIBRARY__ < 5
|
||||
@@ -34,7 +32,15 @@ static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
|
||||
# include <sys/klog.h>
|
||||
#endif
|
||||
|
||||
static const char dmesg_usage[] = "dmesg [-c] [-n level] [-s bufsize]\n";
|
||||
static const char dmesg_usage[] = "dmesg [-c] [-n LEVEL] [-s SIZE]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrints or controls the kernel ring buffer\n\n"
|
||||
"Options:\n"
|
||||
"\t-c\t\tClears the ring buffer's contents after printing\n"
|
||||
"\t-n LEVEL\tSets console logging level\n"
|
||||
"\t-s SIZE\t\tUse a buffer of size SIZE\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
int dmesg_main(int argc, char **argv)
|
||||
{
|
||||
@@ -95,7 +101,7 @@ int dmesg_main(int argc, char **argv)
|
||||
|
||||
if (bufsize < 4096)
|
||||
bufsize = 4096;
|
||||
buf = (char *) malloc(bufsize);
|
||||
buf = (char *) xmalloc(bufsize);
|
||||
n = klogctl(cmd, buf, bufsize);
|
||||
if (n < 0) {
|
||||
goto klogctl_error;
|
||||
@@ -121,6 +127,5 @@ int dmesg_main(int argc, char **argv)
|
||||
exit(FALSE);
|
||||
klogctl_error:
|
||||
perror("klogctl");
|
||||
exit(FALSE);
|
||||
|
||||
return(FALSE);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
BusyBox.txt
|
||||
BusyBox.1
|
||||
BusyBox.html
|
||||
-1025
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1 @@
|
||||
BusyBox.html
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 8.8 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 8.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.1 KiB |
Loaded 100 of 251 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user