Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f8263516c2 | ||
|
|
db7f2af089 | ||
|
|
f6b7139971 | ||
|
|
d266748c76 | ||
|
|
53323695c5 | ||
|
|
67fdf5e538 | ||
|
|
ff1ed7215c | ||
|
|
d89882da16 | ||
|
|
3570a34de4 | ||
|
|
caffb6eff0 | ||
|
|
c5949f62e5 | ||
|
|
e081eae7a4 | ||
|
|
bf73909f23 | ||
|
|
944be90b21 | ||
|
|
fe4208fe93 | ||
|
|
488aac2e2a | ||
|
|
896fa4ea1d | ||
|
|
57f83fffd8 | ||
|
|
6f283c2f77 | ||
|
|
9ae3838657 | ||
|
|
1b1cfde1f8 | ||
|
|
0102a9fd48 | ||
|
|
2da90d3b58 | ||
|
|
285b446d17 | ||
|
|
32e95f988d | ||
|
|
96bdde97fb | ||
|
|
6d66817b6b | ||
|
|
82e0614101 | ||
|
|
a37d5b772b | ||
|
|
5b17693f0a | ||
|
|
ebc0dd7a8a | ||
|
|
92a61c1206 | ||
|
|
90f580ad5b | ||
|
|
d995493987 | ||
|
|
a2f2a8f8c0 | ||
|
|
810d38f850 | ||
|
|
a1b35c4512 | ||
|
|
8c185f9600 | ||
|
|
75610e18b3 | ||
|
|
2c1faecba7 | ||
|
|
c873d61008 | ||
|
|
ba35b98444 | ||
|
|
d2f5677762 | ||
|
|
d1de4a16ad | ||
|
|
f34aa4c378 | ||
|
|
8a2e56c5df | ||
|
|
350b3f9236 | ||
|
|
ae22612792 | ||
|
|
624cc771da | ||
|
|
8847b9a03a | ||
|
|
7c22b77162 | ||
|
|
cff3fe3ae9 | ||
|
|
0cccdfaf36 | ||
|
|
b938e2ff99 | ||
|
|
46a98dfb13 | ||
|
|
56f3e353da | ||
|
|
06f64b2370 | ||
|
|
0b2da467a8 | ||
|
|
721119e1db | ||
|
|
cd26ff4eac | ||
|
|
252bacc9ea | ||
|
|
fd3741d712 | ||
|
|
38c8551cf2 | ||
|
|
63dde9d4ce | ||
|
|
b2f36af157 | ||
|
|
6fc2a7d04d | ||
|
|
82cfbad216 | ||
|
|
c9db2e8665 | ||
|
|
d2d3aa39ef | ||
|
|
2aee993118 | ||
|
|
f5cf8c6c65 | ||
|
|
33bee33af0 | ||
|
|
5f84fd7066 | ||
|
|
cbe05e45db | ||
|
|
7e3bf6e339 | ||
|
|
ce40fc044b | ||
|
|
5d63884a8f | ||
|
|
31e6829bd8 | ||
|
|
131241f71c | ||
|
|
cbbe4d6bc2 | ||
|
|
56a328810b | ||
|
|
b4c3c59a45 | ||
|
|
f8e04f7113 | ||
|
|
fb6a50820c | ||
|
|
d39d120998 | ||
|
|
5d513f7256 | ||
|
|
dd450a0ded | ||
|
|
322ae93a5e | ||
|
|
b89075298e | ||
|
|
23ad7f7f06 | ||
|
|
ccb0a9ba88 | ||
|
|
fca8050f0f | ||
|
|
ac19b7e032 | ||
|
|
49352adf9c | ||
|
|
605a819a17 | ||
|
|
f0b073f55a | ||
|
|
de34e43755 | ||
|
|
cbb61c78ae | ||
|
|
73de6561ca | ||
|
|
729216cb11 | ||
|
|
18310f1ce3 | ||
|
|
0ae8e5a645 | ||
|
|
bd7c67136a | ||
|
|
1c6917d2c4 | ||
|
|
e2b345a6d8 | ||
|
|
437bf72785 | ||
|
|
6fb88e73f7 | ||
|
|
8324b9f1aa | ||
|
|
11c655295c | ||
|
|
44e3840343 | ||
|
|
17c8851813 | ||
|
|
6085c72b6e | ||
|
|
9dd79791c8 | ||
|
|
ebee301c8b | ||
|
|
d13ebff163 | ||
|
|
1eec89df4c | ||
|
|
3639c5d950 | ||
|
|
1b355ebba6 | ||
|
|
43c8c38bbf | ||
|
|
61a9d8d145 | ||
|
|
9670083818 | ||
|
|
b92223b6f5 | ||
|
|
fd50c3d2f9 | ||
|
|
cb91d69b3f | ||
|
|
73bdf13d35 | ||
|
|
3a957b9d4c | ||
|
|
18a1014c95 | ||
|
|
da542f3a0c | ||
|
|
f446297afd | ||
|
|
e99674a70f | ||
|
|
5eb5912790 | ||
|
|
4e61db2284 | ||
|
|
ad3d90f91e | ||
|
|
a3de24e85d | ||
|
|
1638488d26 | ||
|
|
ab60f6987a | ||
|
|
88cc3057fd | ||
|
|
06aeb6c417 | ||
|
|
4d5ac2f346 | ||
|
|
3a0f4baf2f | ||
|
|
8237add8d0 | ||
|
|
32f2769800 | ||
|
|
089d12d762 | ||
|
|
aaa94fb8a9 | ||
|
|
ce82c8ab77 | ||
|
|
2368a387ed | ||
|
|
e4c4d69c04 | ||
|
|
6ab22027d0 | ||
|
|
fba9c00071 | ||
|
|
acf5551099 | ||
|
|
918507edda | ||
|
|
851ce895bd | ||
|
|
a1f16bba72 | ||
|
|
e2205f093b | ||
|
|
0e4cec0be8 | ||
|
|
dc746169cf | ||
|
|
282c364148 | ||
|
|
fa405d0cb2 | ||
|
|
202995c612 | ||
|
|
c86e5e6145 | ||
|
|
be0dc0d06a | ||
|
|
b2fc5a0647 | ||
|
|
e89267c8b3 | ||
|
|
8cbac440d6 | ||
|
|
6ac18a3d83 | ||
|
|
bb39a31e33 | ||
|
|
79565b6c91 | ||
|
|
f9ca653faa | ||
|
|
88f50b6bf5 | ||
|
|
40406e6bad | ||
|
|
adbf018dc4 | ||
|
|
deb95f69b6 | ||
|
|
46ade97983 | ||
|
|
0c8e2a6580 | ||
|
|
fdd5103348 | ||
|
|
5ae166813f | ||
|
|
807f0fd637 | ||
|
|
d5fa3e3e9a | ||
|
|
080d51bf45 | ||
|
|
0f8f7b8a35 | ||
|
|
98bbd688a8 | ||
|
|
43c17b3d96 | ||
|
|
616d13bcd1 | ||
|
|
259972e565 | ||
|
|
9cf306d55e | ||
|
|
6a4c33c5c0 | ||
|
|
6150df320a | ||
|
|
d5704686b1 | ||
|
|
1428c4f136 | ||
|
|
a5716d3029 | ||
|
|
501c88b245 | ||
|
|
6a99aaf020 | ||
|
|
7ce41ad692 | ||
|
|
e92108ae6d | ||
|
|
0d49dd53cf | ||
|
|
cc10a5b42b | ||
|
|
83e85f6a08 | ||
|
|
52681b48dc | ||
|
|
fad9c1198a | ||
|
|
b040d4f3da | ||
|
|
b9ea02c04b | ||
|
|
d34595d857 | ||
|
|
e5db406690 | ||
|
|
40bfc76385 | ||
|
|
e99f7500e0 | ||
|
|
ea824fb937 | ||
|
|
bf960f58e2 | ||
|
|
7df345e149 | ||
|
|
ec8d60f0f8 | ||
|
|
0010ee45e3 | ||
|
|
c768ab490e | ||
|
|
ced2cefcca | ||
|
|
1f45b268cb | ||
|
|
1ac435c15e | ||
|
|
51154bacbe | ||
|
|
3950596e1e | ||
|
|
99e370f0c6 | ||
|
|
aa4f108338 | ||
|
|
27a804246a | ||
|
|
869057238b | ||
|
|
2f46b664b7 | ||
|
|
91a4400fd5 | ||
|
|
a16c66335e | ||
|
|
ae6eae02dd | ||
|
|
52d6fa3bb3 | ||
|
|
1d255be78d | ||
|
|
2ef880b236 | ||
|
|
a9d69fb568 | ||
|
|
8f122431f5 | ||
|
|
6efc48c1ae | ||
|
|
9c5fcc3408 | ||
|
|
cc8a66b113 | ||
|
|
97562bd9d7 | ||
|
|
21ddb38fcf | ||
|
|
a1d187a8a8 | ||
|
|
bc0aed79a8 | ||
|
|
47d4926244 | ||
|
|
bf181b9338 | ||
|
|
3bd8bd89ee | ||
|
|
464c5de00d | ||
|
|
70705d7c96 | ||
|
|
add09fd558 | ||
|
|
17ad45aace | ||
|
|
df4532bfa3 | ||
|
|
ff5a9033f9 | ||
|
|
f626dcbc84 | ||
|
|
9027bcf2f4 | ||
|
|
93c0d9f090 | ||
|
|
fad04fdd12 | ||
|
|
b870af09ae | ||
|
|
d6912c97de | ||
|
|
58361a44b5 | ||
|
|
e7413a9cde | ||
|
|
d537a95fdb | ||
|
|
4ac6cb534d | ||
|
|
ec10b9d534 | ||
|
|
34623db618 | ||
|
|
02008346c0 | ||
|
|
94074a980c | ||
|
|
496e33feeb | ||
|
|
4f7fe77d07 | ||
|
|
06f3529ada | ||
|
|
156959ea93 | ||
|
|
f4c022649b | ||
|
|
55380700d8 | ||
|
|
00143ba921 | ||
|
|
ac48461da9 | ||
|
|
37653aaf9c | ||
|
|
c41e8c840f | ||
|
|
6f96e674b9 | ||
|
|
be84cd4ef6 | ||
|
|
e58771e73c | ||
|
|
e714bce003 | ||
|
|
3ecbe9f4dc | ||
|
|
97426e082a | ||
|
|
8fbaeece53 | ||
|
|
68fda241d2 | ||
|
|
858c1adf2b | ||
|
|
7719008a85 |
No files matched your search
@@ -1,2 +1,4 @@
|
||||
busybox
|
||||
busybox.links
|
||||
_install
|
||||
loop.h
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
--blank-lines-after-declarations
|
||||
--blank-lines-after-procedures
|
||||
--break-before-boolean-operator
|
||||
--no-blank-lines-after-commas
|
||||
--braces-on-if-line
|
||||
--braces-on-struct-decl-line
|
||||
--comment-indentation25
|
||||
--declaration-comment-column25
|
||||
--no-comment-delimiters-on-blank-lines
|
||||
--cuddle-else
|
||||
--continuation-indentation4
|
||||
--case-indentation0
|
||||
--else-endif-column33
|
||||
--space-after-cast
|
||||
--line-comments-indentation0
|
||||
--declaration-indentation1
|
||||
--dont-format-first-column-comments
|
||||
--dont-format-comments
|
||||
--honour-newlines
|
||||
--indent-level4
|
||||
/* changed from 0 to 4 */
|
||||
--parameter-indentation4
|
||||
--line-length78 /* changed from 75 */
|
||||
--continue-at-parentheses
|
||||
--no-space-after-function-call-names
|
||||
--dont-break-procedure-type
|
||||
--dont-star-comments
|
||||
--leave-optional-blank-lines
|
||||
--dont-space-special-semicolon
|
||||
--tab-size4
|
||||
/* additions by Mark */
|
||||
--case-brace-indentation0
|
||||
--leave-preprocessor-space
|
||||
@@ -12,6 +12,9 @@ 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.
|
||||
|
||||
Edward Betts <edward@debian.org>
|
||||
expr, hostid, logname, tty, wc, whoami, yes
|
||||
|
||||
John Beppu <beppu@lineo.com>
|
||||
du, head, nslookup, sort, tee, uniq
|
||||
|
||||
@@ -43,12 +46,21 @@ Glenn McGrath <bug1@netconnect.com.au>
|
||||
Bruce Perens <bruce@pixar.com>
|
||||
Original author of BusyBox. His code is still in many apps.
|
||||
|
||||
Chip Rosenthal <chip@unicom.com>, <crosenth@covad.com>
|
||||
wget - Contributed by permission of Covad Communications
|
||||
|
||||
Pavel Roskin <proski@gnu.org>
|
||||
Lots of bugs fixes and patches.
|
||||
|
||||
Gyepi Sam <gyepi@praxis-sw.com>
|
||||
Remote logging feature for syslogd
|
||||
|
||||
Linus Torvalds <torvalds@transmeta.com>
|
||||
mkswap, fsck.minix, mkfs.minix
|
||||
|
||||
Mark Whitley <markw@lineo.com>
|
||||
sed remix, bug fixes, style-guide, etc.
|
||||
|
||||
Charles P. Wright <cpwright@villagenet.com>
|
||||
gzip, mini-netcat(nc)
|
||||
|
||||
|
||||
@@ -1,3 +1,47 @@
|
||||
0.47
|
||||
|
||||
* A bug in syslogd was fixed that allowed it to potentially fork-bomb
|
||||
your system. Anyone using 0.46 syslogd should upgrade.
|
||||
* Renamed busybox.defs.h to the more sensible "Config.h"
|
||||
* Improved portability between different libcs.
|
||||
* Many apps ported to use getopt()
|
||||
* Common handling of '--help'
|
||||
* All usage messages centralized.
|
||||
* Added a bunch of new commands:
|
||||
* 'rdate' contributed by Sterling Huxley <sterling@europa.com>
|
||||
* 'wget' contributed by Chip Rosenthal <chip@unicom.com>,
|
||||
<crosenth@covad.com> and Covad Communications
|
||||
* 'getopt' from "Alfred M. Szmidt" <ams@trillian.itslinux.org>
|
||||
* dos2unix, unix2dos, reset, and unrpm.c (and lots of help
|
||||
debugging) thanks to Kent Robotti <robotti@metconnect.com>.
|
||||
* 'renice' command, thanks to Dave Cinege <dcinege@psychosis.com>
|
||||
* 'xargs' (written by me)
|
||||
* 'expr' contributed by Edward Betts <edward@debian.org>, based
|
||||
on GNY expr
|
||||
* lsmod now uses the query_module syscall, rather then /proc (me)
|
||||
* syslogd can now log messages to remote hosts -- patch thanks
|
||||
to Gyepi Sam <gyepi@praxis-sw.com>
|
||||
* chroot can now call the builtin shell - Pavel Roskin <proski@gnu.org>
|
||||
* 'make install' now creates relative symlinks, and added a new
|
||||
'make install-hardlinks' target to (tada) install hardlinks.
|
||||
* Rewrite of 'tail' to make it simpler, smaller, and more robust.
|
||||
It now weighs only 2.25k (3k when full featured). The code is
|
||||
cleaner too, thanks to Allen Soard <esp-software@mail.hypermart.net>
|
||||
* Add optional ls file sorting, thanks to a patch from
|
||||
Sterling Huxley <sterling@europa.com>
|
||||
* Fixed chmod option parsing so things like 'chmod -r /tmp/file'
|
||||
now work (previously it thought -r was an option). Doh!
|
||||
* Fixed tar handling of stdin and stdout
|
||||
* Renamed "internal.h" to the more sensible "busybox.h"
|
||||
* Preliminary support for GNU HURD.
|
||||
* Updated my devps and devmtab kernel patches for the latest 2.2.x
|
||||
kernel, for those wanting to go proc-less.
|
||||
* Tons of other bugfixes.
|
||||
|
||||
|
||||
-Erik Andersen, 25 September 2000
|
||||
|
||||
|
||||
0.46
|
||||
|
||||
* Better portability. Now should compile cleanly with libc5,
|
||||
@@ -58,7 +102,7 @@
|
||||
Matt Kraai as well.
|
||||
|
||||
|
||||
-Erik Andersen
|
||||
-Erik Andersen, 11 July 2000
|
||||
|
||||
|
||||
0.45
|
||||
|
||||
+37
-19
@@ -23,16 +23,19 @@
|
||||
#define BB_DF
|
||||
#define BB_DIRNAME
|
||||
#define BB_DMESG
|
||||
#define BB_DOS2UNIX
|
||||
#define BB_DUTMP
|
||||
#define BB_DU
|
||||
#define BB_DUMPKMAP
|
||||
#define BB_ECHO
|
||||
#define BB_EXPR
|
||||
#define BB_FBSET
|
||||
#define BB_FDFLUSH
|
||||
#define BB_FIND
|
||||
#define BB_FREE
|
||||
#define BB_FREERAMDISK
|
||||
#define BB_FSCK_MINIX
|
||||
#define BB_GETOPT
|
||||
#define BB_GREP
|
||||
#define BB_GUNZIP
|
||||
#define BB_GZIP
|
||||
@@ -72,7 +75,10 @@
|
||||
#define BB_PRINTF
|
||||
#define BB_PS
|
||||
#define BB_PWD
|
||||
#define BB_RDATE
|
||||
#define BB_REBOOT
|
||||
#define BB_RENICE
|
||||
#define BB_RESET
|
||||
#define BB_RM
|
||||
#define BB_RMDIR
|
||||
#define BB_RMMOD
|
||||
@@ -93,9 +99,11 @@
|
||||
#define BB_TR
|
||||
#define BB_TRUE_FALSE
|
||||
#define BB_TTY
|
||||
#define BB_UNRPM
|
||||
#define BB_UPTIME
|
||||
#define BB_USLEEP
|
||||
#define BB_WC
|
||||
#define BB_WGET
|
||||
#define BB_WHICH
|
||||
#define BB_WHOAMI
|
||||
#define BB_UUENCODE
|
||||
@@ -103,7 +111,9 @@
|
||||
#define BB_UMOUNT
|
||||
#define BB_UNIQ
|
||||
#define BB_UNAME
|
||||
#define BB_UNIX2DOS
|
||||
#define BB_UPDATE
|
||||
#define BB_XARGS
|
||||
#define BB_YES
|
||||
// End of Applications List
|
||||
//
|
||||
@@ -116,14 +126,13 @@
|
||||
//
|
||||
//
|
||||
//
|
||||
// Turn this on to use Erik's very cool devps, devmtab, etc kernel drivers,
|
||||
// Turn this on to use Erik's very cool devps, and devmtab 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
|
||||
// device special files in /dev on your embedded system:
|
||||
// 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.
|
||||
@@ -135,12 +144,6 @@
|
||||
// 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
|
||||
@@ -160,9 +163,15 @@
|
||||
// enable ls -p and -F
|
||||
#define BB_FEATURE_LS_FILETYPES
|
||||
//
|
||||
// sort the file names (still a bit buggy)
|
||||
#define BB_FEATURE_LS_SORTFILES
|
||||
//
|
||||
// enable ls -R
|
||||
#define BB_FEATURE_LS_RECURSIVE
|
||||
//
|
||||
// enable ls -L
|
||||
#define BB_FEATURE_LS_FOLLOWLINKS
|
||||
//
|
||||
// Change ping implementation -- simplified, featureless, but really small.
|
||||
//#define BB_FEATURE_SIMPLE_PING
|
||||
//
|
||||
@@ -170,7 +179,7 @@
|
||||
#define BB_FEATURE_USE_INITTAB
|
||||
//
|
||||
//Enable init being called as /linuxrc
|
||||
//#define BB_FEATURE_LINUXRC
|
||||
#define BB_FEATURE_LINUXRC
|
||||
//
|
||||
//Have init enable core dumping for child processes (for debugging only)
|
||||
//#define BB_FEATURE_INIT_COREDUMPS
|
||||
@@ -186,8 +195,11 @@
|
||||
//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.
|
||||
// enable syslogd -R remotehost
|
||||
#define BB_FEATURE_REMOTE_LOG
|
||||
//
|
||||
//Simple tail implementation (2.34k vs 3k for the full one).
|
||||
//Both provide 'tail -f' support (only one file at a time.)
|
||||
#define BB_FEATURE_SIMPLE_TAIL
|
||||
//
|
||||
// Enable support for loop devices in mount
|
||||
@@ -197,7 +209,6 @@
|
||||
//#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 forced filesystem unmounting
|
||||
@@ -210,6 +221,9 @@
|
||||
// Enable support for "--exclude" for excluding files
|
||||
#define BB_FEATURE_TAR_EXCLUDE
|
||||
//
|
||||
// Enable support for s///p pattern matching
|
||||
#define BB_FEATURE_SED_PATTERN_SPACE
|
||||
//
|
||||
//// Enable reverse sort
|
||||
#define BB_FEATURE_SORT_REVERSE
|
||||
//
|
||||
@@ -218,7 +232,7 @@
|
||||
//
|
||||
//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.
|
||||
//among other thing.
|
||||
#define BB_FEATURE_SH_STANDALONE_SHELL
|
||||
//
|
||||
// Enable tab completion in the shell (not yet
|
||||
@@ -240,12 +254,20 @@
|
||||
// Support module version checking
|
||||
//#define BB_FEATURE_INSMOD_VERSION_CHECKING
|
||||
//
|
||||
// Support for Minix filesystem, version 2
|
||||
//#define BB_FEATURE_MINIX2
|
||||
//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// Clean up all memory before exiting -- usually not needed
|
||||
// as the OS can clean up... Don't enable this unless you
|
||||
// have a really good reason for cleaning things up manually.
|
||||
//#define BB_FEATURE_CLEAN_UP
|
||||
//
|
||||
// End of Features List
|
||||
//
|
||||
//
|
||||
@@ -261,10 +283,6 @@
|
||||
#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
|
||||
@@ -278,8 +296,8 @@
|
||||
#ifdef BB_FEATURE_LINUXRC
|
||||
#ifndef BB_INIT
|
||||
#define BB_INIT
|
||||
#define BB_LINUXRC
|
||||
#endif
|
||||
#define BB_LINUXRC
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_GZIP
|
||||
+326
@@ -0,0 +1,326 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
|
||||
// NOTE: This file only defines features usefull under the Hurd,
|
||||
// To compile for the Hurd raname this to Config.h prior to make
|
||||
|
||||
// This file defines the feature set to be compiled into busybox.
|
||||
// When you turn things off here, they won't be compiled in at all.
|
||||
//
|
||||
//// This file is parsed by sed. You MUST use single line comments.
|
||||
// i.e. //#define BB_BLAH
|
||||
//
|
||||
//
|
||||
// BusyBox Applications
|
||||
#define BB_AR
|
||||
#define BB_BASENAME
|
||||
#define BB_CAT
|
||||
#define BB_CHMOD_CHOWN_CHGRP
|
||||
#define BB_CHROOT
|
||||
//#define BB_CHVT /* not needed */
|
||||
#define BB_CLEAR
|
||||
#define BB_CP_MV
|
||||
#define BB_CUT
|
||||
#define BB_DATE
|
||||
#define BB_DC
|
||||
#define BB_DD
|
||||
//#define BB_DEALLOCVT /* inot needed */
|
||||
//#define BB_DF /* different implementation */
|
||||
#define BB_DIRNAME
|
||||
//#define BB_DMESG /* doesnt compile, different implementation */
|
||||
#define BB_DUTMP
|
||||
#define BB_DU
|
||||
//#define BB_DUMPKMAP /* not needed */
|
||||
#define BB_ECHO
|
||||
#define BB_EXPR
|
||||
//#define BB_FBSET /* not needed, doesnt compile */
|
||||
//#define BB_FDFLUSH /* is this needed? */
|
||||
#define BB_FIND
|
||||
//#define BB_FREE /* doesnt compile */
|
||||
#define BB_FREERAMDISK /* does hurd support ramdisks ? */
|
||||
#define BB_FSCK_MINIX
|
||||
#define BB_GETOPT
|
||||
#define BB_GREP
|
||||
#define BB_GUNZIP
|
||||
#define BB_GZIP
|
||||
#define BB_HALT
|
||||
#define BB_HEAD
|
||||
#define BB_HOSTID
|
||||
#define BB_HOSTNAME
|
||||
#define BB_ID
|
||||
//#define BB_INIT /* not needed?, doesnt compile */
|
||||
//#define BB_INSMOD /* not needed, doesnt compile */
|
||||
#define BB_KILL
|
||||
#define BB_KILLALL
|
||||
#define BB_LENGTH
|
||||
#define BB_LN
|
||||
//#define BB_LOADACM /* not needed, doesnt compile */
|
||||
//#define BB_LOADFONT /* not needed, doesnt compile */
|
||||
//#define BB_LOADKMAP /* not needed */
|
||||
#define BB_LOGGER
|
||||
#define BB_LOGNAME
|
||||
#define BB_LS
|
||||
//#define BB_LSMOD /* not needed, doesnt compile */
|
||||
//#define BB_MAKEDEVS /* different implementation */
|
||||
#define BB_MD5SUM
|
||||
#define BB_MKDIR
|
||||
#define BB_MKFIFO
|
||||
#define BB_MKFS_MINIX
|
||||
#define BB_MKNOD
|
||||
//#define BB_MKSWAP /* different impelementation (i think) */
|
||||
#define BB_MKTEMP
|
||||
#define BB_NC
|
||||
#define BB_MORE
|
||||
//#define BB_MOUNT /* different implementation */
|
||||
#define BB_MT
|
||||
#define BB_NSLOOKUP
|
||||
//#define BB_PING /* doesnt compile, Hurd uses BSD style ip.h */
|
||||
//#define BB_POWEROFF /* different implementation i assume */
|
||||
#define BB_PRINTF
|
||||
//#define BB_PS /* needs /proc */
|
||||
#define BB_PWD
|
||||
#define BB_RDATE
|
||||
//#define BB_REBOOT /* different implementation */
|
||||
#define BB_RENICE
|
||||
#define BB_RESET
|
||||
#define BB_RM
|
||||
#define BB_RMDIR
|
||||
//#define BB_RMMOD /* not needed, doesnt compile */
|
||||
#define BB_SED
|
||||
//#define BB_SETKEYCODES /* is this needed ? */
|
||||
#define BB_SH
|
||||
#define BB_SLEEP
|
||||
#define BB_SORT
|
||||
//#define BB_SWAPONOFF /* different implementation, doesnt compile */
|
||||
#define BB_SYNC
|
||||
//#define BB_SYSLOGD /* doesnt compile */
|
||||
#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 /* doesnt compile */
|
||||
#define BB_USLEEP
|
||||
#define BB_WC
|
||||
#define BB_WGET
|
||||
#define BB_WHICH
|
||||
#define BB_WHOAMI
|
||||
#define BB_UUENCODE
|
||||
#define BB_UUDECODE
|
||||
//#define BB_UMOUNT /* different implementation */
|
||||
#define BB_UNIQ
|
||||
//#define BB_UNAME /* doesnt compile */
|
||||
//#define BB_UPDATE /* doesnt compile */
|
||||
#define BB_YES
|
||||
// End of Applications List
|
||||
//
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------
|
||||
// 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 and devmtab 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 in /dev on your embedded system:
|
||||
// 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
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// calculate terminal & column widths (for more and ls)
|
||||
#define BB_FEATURE_AUTOWIDTH
|
||||
//
|
||||
// show username/groupnames (bypasses libc6 NSS) for ls
|
||||
#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
|
||||
//
|
||||
// sort the file names (still a bit buggy)
|
||||
#define BB_FEATURE_LS_SORTFILES
|
||||
//
|
||||
// enable ls -R
|
||||
#define BB_FEATURE_LS_RECURSIVE
|
||||
//
|
||||
// Change ping implementation -- simplified, featureless, but really small.
|
||||
#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
|
||||
//
|
||||
// enable syslogd -R remotehost
|
||||
#define BB_FEATURE_REMOTE_LOG
|
||||
//
|
||||
//Simple tail implementation (2.34k vs 3k for the full one).
|
||||
//Both provide 'tail -f' support (only one file at a time.)
|
||||
#define BB_FEATURE_SIMPLE_TAIL
|
||||
//
|
||||
// Enable support for loop devices in mount
|
||||
//#define BB_FEATURE_MOUNT_LOOP
|
||||
//
|
||||
// Enable support for a real /etc/mtab file instead of /proc/mounts
|
||||
//#define BB_FEATURE_MOUNT_MTAB_SUPPORT
|
||||
//
|
||||
// Enable support for mounting remote NFS volumes
|
||||
//#define BB_FEATURE_NFSMOUNT
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// Enable support for "--exclude" for excluding files
|
||||
#define BB_FEATURE_TAR_EXCLUDE
|
||||
//
|
||||
// Enable support for s///p pattern matching
|
||||
#define BB_FEATURE_SED_PATTERN_SPACE
|
||||
//
|
||||
//// 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
|
||||
//among 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
|
||||
//
|
||||
// Support for Minix filesystem, version 2
|
||||
//#define BB_FEATURE_MINIX2
|
||||
//
|
||||
//
|
||||
// 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
|
||||
//
|
||||
// Clean up all memory before exiting -- usually not needed
|
||||
// as the OS can clean up... Don't enable this unless you
|
||||
// have a really good reason for cleaning things up manually.
|
||||
//#define BB_FEATURE_CLEAN_UP
|
||||
//
|
||||
// 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_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
|
||||
#endif
|
||||
#define BB_LINUXRC
|
||||
#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
|
||||
@@ -19,74 +19,108 @@
|
||||
#
|
||||
|
||||
PROG := busybox
|
||||
VERSION := 0.46
|
||||
VERSION := 0.47
|
||||
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.
|
||||
DOSTATIC = false
|
||||
|
||||
# Set the following to `true' to make a debuggable build.
|
||||
# Leave this set to `false' for production use.
|
||||
# eg: `make DODEBUG=true tests'
|
||||
# Do not enable this for production builds...
|
||||
DODEBUG = false
|
||||
|
||||
# This enables compiling with dmalloc ( http://dmalloc.com/ )
|
||||
# which is an excellent public domain mem leak and malloc problem
|
||||
# detector. To enable dmalloc, before running busybox you will
|
||||
# want to first set up your environment.
|
||||
# eg: `export DMALLOC_OPTIONS=debug=0x14f47d83,inter=100,log=logfile`
|
||||
# Do not enable this for production builds...
|
||||
DODMALLOC = false
|
||||
|
||||
# If you want large file summit support, turn this on.
|
||||
# This has no effect if you don't have a kernel with lfs
|
||||
# support, and a system with libc-2.1.3 or later.
|
||||
# Some of the programs that can benefit from lfs support
|
||||
# are dd, gzip, mount, tar, and mkfs_minix.
|
||||
# LFS allows you to use the above programs for files
|
||||
# larger than 2GB!
|
||||
DOLFS = false
|
||||
|
||||
|
||||
# If you are running a cross compiler, you may want to set this
|
||||
# to something more interesting...
|
||||
CROSS = #powerpc-linux-
|
||||
CC = $(CROSS)gcc
|
||||
STRIPTOOL = $(CROSS)strip
|
||||
|
||||
# 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...
|
||||
# the following lines to meet your needs. This is how I make
|
||||
# busybox compile with uC-Libc...
|
||||
#LIBCDIR=/home/andersen/CVS/uC-libc
|
||||
#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)
|
||||
#CFLAGS+=-nostdinc -fno-builtin -I$(LIBCDIR)/include -I$(GCCINCDIR)
|
||||
#LDFLAGS+=-nostdlib
|
||||
#LIBRARIES = /home/andersen/CVS/uC-libc/libc.a
|
||||
#LIBRARIES = $(LIBCDIR)/libc.a
|
||||
|
||||
|
||||
CC = gcc
|
||||
#--------------------------------------------------------
|
||||
|
||||
# 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)
|
||||
|
||||
WARNINGS = -Wall
|
||||
|
||||
# Allow alternative stripping tools to be used...
|
||||
ifndef $(STRIPTOOL)
|
||||
STRIPTOOL = strip
|
||||
ifeq ($(DOLFS),true)
|
||||
# For large file summit support
|
||||
CFLAGS+=-D_FILE_OFFSET_BITS=64
|
||||
endif
|
||||
ifeq ($(DODMALLOC),true)
|
||||
# For testing mem leaks with dmalloc
|
||||
CFLAGS+=-DDMALLOC
|
||||
LIBRARIES = -ldmalloc
|
||||
# Force debug=true, since this is useless when not debugging...
|
||||
DODEBUG = true
|
||||
endif
|
||||
|
||||
# -D_GNU_SOURCE is needed because environ is used in init.c
|
||||
ifeq ($(DODEBUG),true)
|
||||
CFLAGS += -Wall -g -D_GNU_SOURCE
|
||||
CFLAGS += $(WARNINGS) -g -D_GNU_SOURCE
|
||||
LDFLAGS +=
|
||||
STRIP =
|
||||
else
|
||||
CFLAGS += -Wall $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE
|
||||
CFLAGS += $(WARNINGS) $(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
|
||||
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
|
||||
|
||||
ifndef $(PREFIX)
|
||||
PREFIX = `pwd`/_install
|
||||
endif
|
||||
|
||||
OBJECTS = $(shell ./busybox.sh) busybox.o messages.o utility.o
|
||||
OBJECTS = $(shell ./busybox.sh) busybox.o messages.o usage.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 doc
|
||||
|
||||
doc: olddoc
|
||||
@@ -113,7 +147,7 @@ docs/busybox.lineo.com/BusyBox.html: docs/busybox.pod
|
||||
|
||||
|
||||
# New docs based on DOCBOOK SGML
|
||||
newdoc: docs/busybox.txt docs/busybox.pdf docs/busybox/busybox.html
|
||||
newdoc: docs/busybox.txt docs/busybox.pdf docs/busybox/busyboxdocumentation.html
|
||||
|
||||
docs/busybox.txt: docs/busybox.sgml
|
||||
@echo
|
||||
@@ -130,33 +164,37 @@ docs/busybox.ps: docs/busybox.sgml
|
||||
docs/busybox.pdf: docs/busybox.ps
|
||||
(cd docs; ps2pdf busybox.ps)
|
||||
|
||||
docs/busybox/busybox.html: docs/busybox.sgml
|
||||
docs/busybox/busyboxdocumentation.html: docs/busybox.sgml
|
||||
(cd docs/busybox.lineo.com; sgmltools -b html ../busybox.sgml)
|
||||
|
||||
|
||||
|
||||
busybox: $(OBJECTS)
|
||||
busybox: $(OBJECTS)
|
||||
$(CC) $(LDFLAGS) -o $@ $^ $(LIBRARIES)
|
||||
$(STRIP)
|
||||
|
||||
busybox.links: busybox.def.h
|
||||
busybox.links: Config.h
|
||||
- ./busybox.mkll | sort >$@
|
||||
|
||||
nfsmount.o cmdedit.o: %.o: %.h
|
||||
$(OBJECTS): %.o: busybox.def.h internal.h %.c Makefile
|
||||
$(OBJECTS): %.o: Config.h busybox.h %.c Makefile
|
||||
|
||||
utility.o: loop.h
|
||||
|
||||
loop.h:
|
||||
@./mk_loop_h.sh
|
||||
|
||||
test tests:
|
||||
cd tests && $(MAKE) all
|
||||
|
||||
clean:
|
||||
- rm -f busybox.links *~ *.o core
|
||||
- rm -rf _install
|
||||
- cd tests && $(MAKE) clean
|
||||
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
|
||||
- rm -rf docs/busybox _install
|
||||
- rm -f busybox.links *~ *.o core
|
||||
|
||||
distclean: clean
|
||||
- rm -f busybox
|
||||
@@ -165,6 +203,9 @@ distclean: clean
|
||||
install: busybox busybox.links
|
||||
./install.sh $(PREFIX)
|
||||
|
||||
install-hardlinks: busybox busybox.links
|
||||
./install.sh $(PREFIX) --hardlinks
|
||||
|
||||
dist release: distclean doc
|
||||
cd ..; \
|
||||
rm -rf busybox-$(VERSION); \
|
||||
|
||||
@@ -20,7 +20,7 @@ it also makes an excellent environment for any small or embedded system.
|
||||
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
|
||||
simply edit the file "Config.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
|
||||
|
||||
@@ -8,27 +8,20 @@ around to it some time. If you have any good ideas, please let me know.
|
||||
|
||||
* Networking apps are probably going to be split out some time soon into a
|
||||
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.
|
||||
following items from BusyBox: hostid, hostname, nc, nslookup, telnet, and
|
||||
ping. nfs mounting and syslogd (network logging) will remain in BusyBox.
|
||||
|
||||
-Erik
|
||||
|
||||
-----------
|
||||
|
||||
* Make insmod actually work
|
||||
* dnsdomainname
|
||||
* traceroute/netstat
|
||||
* rdate
|
||||
* hwclock
|
||||
* stty
|
||||
* 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.)
|
||||
|
||||
-----------------------
|
||||
|
||||
@@ -59,353 +52,6 @@ and then start with the biggest things and make them smaller...
|
||||
|
||||
-----------------------
|
||||
|
||||
|
||||
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...
|
||||
|
||||
du.c probably ought to have an -x switch like GNU du does...
|
||||
|
||||
------------------------------------------------------------------
|
||||
|
||||
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):
|
||||
|
||||
|
||||
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/
|
||||
|
||||
+166
-162
@@ -1,364 +1,375 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
static int been_there_done_that = 0;
|
||||
#define bb_need_full_version
|
||||
#define BB_DECLARE_EXTERN
|
||||
#include "messages.c"
|
||||
|
||||
/* It has been alledged that doing such things can
|
||||
* help reduce binary size when staticly linking,
|
||||
* of course with glibc, this is unlikely as long
|
||||
* as we use things like printf -- perhaps a printf
|
||||
* replacement may be in order
|
||||
*/
|
||||
#if 0
|
||||
void exit(int status) __attribute__ ((noreturn));
|
||||
void exit(int status)
|
||||
{
|
||||
_exit(status);
|
||||
};
|
||||
void abort(void) __attribute__ ((__noreturn__));
|
||||
void abort(void)
|
||||
{
|
||||
_exit(0);
|
||||
};
|
||||
int atexit(void (*__func) (void))
|
||||
{
|
||||
_exit(0);
|
||||
};
|
||||
void *__libc_stack_end;
|
||||
#endif
|
||||
static int been_there_done_that = 0;
|
||||
|
||||
const struct BB_applet applets[] = {
|
||||
|
||||
#ifdef BB_AR
|
||||
{"ar", ar_main, _BB_DIR_USR_BIN},
|
||||
{"ar", ar_main, _BB_DIR_USR_BIN, ar_usage},
|
||||
#endif
|
||||
#ifdef BB_BASENAME
|
||||
{"basename", basename_main, _BB_DIR_USR_BIN},
|
||||
{"basename", basename_main, _BB_DIR_USR_BIN, basename_usage},
|
||||
#endif
|
||||
{"busybox", busybox_main, _BB_DIR_BIN},
|
||||
{"busybox", busybox_main, _BB_DIR_BIN, NULL},
|
||||
#ifdef BB_CAT
|
||||
{"cat", cat_main, _BB_DIR_BIN},
|
||||
{"cat", cat_main, _BB_DIR_BIN, cat_usage},
|
||||
#endif
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
{"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN, chgrp_usage},
|
||||
#endif
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
{"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN, chmod_usage},
|
||||
#endif
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chown", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
{"chown", chmod_chown_chgrp_main, _BB_DIR_BIN, chown_usage},
|
||||
#endif
|
||||
#ifdef BB_CHROOT
|
||||
{"chroot", chroot_main, _BB_DIR_SBIN},
|
||||
{"chroot", chroot_main, _BB_DIR_USR_SBIN, chroot_usage},
|
||||
#endif
|
||||
#ifdef BB_CLEAR
|
||||
{"clear", clear_main, _BB_DIR_USR_BIN},
|
||||
{"clear", clear_main, _BB_DIR_USR_BIN, clear_usage},
|
||||
#endif
|
||||
#ifdef BB_CHVT
|
||||
{"chvt", chvt_main, _BB_DIR_USR_BIN},
|
||||
{"chvt", chvt_main, _BB_DIR_USR_BIN, chvt_usage},
|
||||
#endif
|
||||
#ifdef BB_CP_MV
|
||||
{"cp", cp_mv_main, _BB_DIR_BIN},
|
||||
{"cp", cp_mv_main, _BB_DIR_BIN, cp_usage},
|
||||
#endif
|
||||
#ifdef BB_CUT
|
||||
{"cut", cut_main, _BB_DIR_USR_BIN},
|
||||
{"cut", cut_main, _BB_DIR_USR_BIN, cut_usage},
|
||||
#endif
|
||||
#ifdef BB_DATE
|
||||
{"date", date_main, _BB_DIR_BIN},
|
||||
{"date", date_main, _BB_DIR_BIN, date_usage},
|
||||
#endif
|
||||
#ifdef BB_DC
|
||||
{"dc", dc_main, _BB_DIR_USR_BIN},
|
||||
{"dc", dc_main, _BB_DIR_USR_BIN, dc_usage},
|
||||
#endif
|
||||
#ifdef BB_DD
|
||||
{"dd", dd_main, _BB_DIR_BIN},
|
||||
{"dd", dd_main, _BB_DIR_BIN, dd_usage},
|
||||
#endif
|
||||
#ifdef BB_DF
|
||||
{"df", df_main, _BB_DIR_BIN},
|
||||
{"df", df_main, _BB_DIR_BIN, df_usage},
|
||||
#endif
|
||||
#ifdef BB_DIRNAME
|
||||
{"dirname", dirname_main, _BB_DIR_USR_BIN},
|
||||
{"dirname", dirname_main, _BB_DIR_USR_BIN, dirname_usage},
|
||||
#endif
|
||||
#ifdef BB_DMESG
|
||||
{"dmesg", dmesg_main, _BB_DIR_BIN},
|
||||
{"dmesg", dmesg_main, _BB_DIR_BIN, dmesg_usage},
|
||||
#endif
|
||||
#ifdef BB_DOS2UNIX
|
||||
{"dos2unix", dos2unix_main, _BB_DIR_USR_BIN, dos2unix_usage},
|
||||
#endif
|
||||
#ifdef BB_DU
|
||||
{"du", du_main, _BB_DIR_BIN},
|
||||
{"du", du_main, _BB_DIR_USR_BIN, du_usage},
|
||||
#endif
|
||||
#ifdef BB_DUMPKMAP
|
||||
{"dumpkmap", dumpkmap_main, _BB_DIR_BIN},
|
||||
{"dumpkmap", dumpkmap_main, _BB_DIR_BIN, dumpkmap_usage},
|
||||
#endif
|
||||
#ifdef BB_DUTMP
|
||||
{"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
|
||||
{"dutmp", dutmp_main, _BB_DIR_USR_SBIN, dutmp_usage},
|
||||
#endif
|
||||
#ifdef BB_ECHO
|
||||
{"echo", echo_main, _BB_DIR_BIN},
|
||||
{"echo", echo_main, _BB_DIR_BIN, echo_usage},
|
||||
#endif
|
||||
#ifdef BB_EXPR
|
||||
{"expr", expr_main, _BB_DIR_USR_BIN, expr_usage},
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE
|
||||
{"false", false_main, _BB_DIR_BIN},
|
||||
{"false", false_main, _BB_DIR_BIN, false_usage},
|
||||
#endif
|
||||
#ifdef BB_FBSET
|
||||
{"fbset", fbset_main, _BB_DIR_USR_SBIN},
|
||||
{"fbset", fbset_main, _BB_DIR_USR_SBIN, NULL},
|
||||
#endif
|
||||
#ifdef BB_FDFLUSH
|
||||
{"fdflush", fdflush_main, _BB_DIR_BIN},
|
||||
{"fdflush", fdflush_main, _BB_DIR_BIN, fdflush_usage},
|
||||
#endif
|
||||
#ifdef BB_FIND
|
||||
{"find", find_main, _BB_DIR_USR_BIN},
|
||||
{"find", find_main, _BB_DIR_USR_BIN, find_usage},
|
||||
#endif
|
||||
#ifdef BB_FREE
|
||||
{"free", free_main, _BB_DIR_USR_BIN},
|
||||
{"free", free_main, _BB_DIR_USR_BIN, free_usage},
|
||||
#endif
|
||||
#ifdef BB_FREERAMDISK
|
||||
{"freeramdisk", freeramdisk_main, _BB_DIR_SBIN},
|
||||
{"freeramdisk", freeramdisk_main, _BB_DIR_SBIN, freeramdisk_usage},
|
||||
#endif
|
||||
#ifdef BB_DEALLOCVT
|
||||
{"deallocvt", deallocvt_main, _BB_DIR_USR_BIN},
|
||||
{"deallocvt", deallocvt_main, _BB_DIR_USR_BIN, deallocvt_usage},
|
||||
#endif
|
||||
#ifdef BB_FSCK_MINIX
|
||||
{"fsck.minix", fsck_minix_main, _BB_DIR_SBIN},
|
||||
{"fsck.minix", fsck_minix_main, _BB_DIR_SBIN, fsck_minix_usage},
|
||||
#endif
|
||||
#ifdef BB_GETOPT
|
||||
{"getopt", getopt_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_GREP
|
||||
{"grep", grep_main, _BB_DIR_BIN},
|
||||
{"grep", grep_main, _BB_DIR_BIN, grep_usage},
|
||||
#endif
|
||||
#ifdef BB_GUNZIP
|
||||
{"gunzip", gunzip_main, _BB_DIR_BIN},
|
||||
{"gunzip", gunzip_main, _BB_DIR_BIN, gunzip_usage},
|
||||
#endif
|
||||
#ifdef BB_GZIP
|
||||
{"gzip", gzip_main, _BB_DIR_BIN},
|
||||
{"gzip", gzip_main, _BB_DIR_BIN, gzip_usage},
|
||||
#endif
|
||||
#ifdef BB_HALT
|
||||
{"halt", halt_main, _BB_DIR_SBIN},
|
||||
{"halt", halt_main, _BB_DIR_SBIN, halt_usage},
|
||||
#endif
|
||||
#ifdef BB_HEAD
|
||||
{"head", head_main, _BB_DIR_BIN},
|
||||
{"head", head_main, _BB_DIR_USR_BIN, head_usage},
|
||||
#endif
|
||||
#ifdef BB_HOSTID
|
||||
{"hostid", hostid_main, _BB_DIR_USR_BIN},
|
||||
{"hostid", hostid_main, _BB_DIR_USR_BIN, hostid_usage},
|
||||
#endif
|
||||
#ifdef BB_HOSTNAME
|
||||
{"hostname", hostname_main, _BB_DIR_BIN},
|
||||
{"hostname", hostname_main, _BB_DIR_BIN, hostname_usage},
|
||||
#endif
|
||||
#ifdef BB_ID
|
||||
{"id", id_main, _BB_DIR_USR_BIN},
|
||||
{"id", id_main, _BB_DIR_USR_BIN, id_usage},
|
||||
#endif
|
||||
#ifdef BB_INIT
|
||||
{"init", init_main, _BB_DIR_SBIN},
|
||||
{"init", init_main, _BB_DIR_SBIN, NULL},
|
||||
#endif
|
||||
#ifdef BB_INSMOD
|
||||
{"insmod", insmod_main, _BB_DIR_SBIN},
|
||||
{"insmod", insmod_main, _BB_DIR_SBIN, insmod_usage},
|
||||
#endif
|
||||
#ifdef BB_KILL
|
||||
{"kill", kill_main, _BB_DIR_BIN},
|
||||
{"kill", kill_main, _BB_DIR_BIN, kill_usage},
|
||||
#endif
|
||||
#ifdef BB_KILLALL
|
||||
{"killall", kill_main, _BB_DIR_USR_BIN},
|
||||
{"killall", kill_main, _BB_DIR_USR_BIN, kill_usage},
|
||||
#endif
|
||||
#ifdef BB_LENGTH
|
||||
{"length", length_main, _BB_DIR_USR_BIN},
|
||||
{"length", length_main, _BB_DIR_USR_BIN, length_usage},
|
||||
#endif
|
||||
#ifdef BB_LINUXRC
|
||||
{"linuxrc", init_main, _BB_DIR_ROOT},
|
||||
{"linuxrc", init_main, _BB_DIR_ROOT, NULL},
|
||||
#endif
|
||||
#ifdef BB_LN
|
||||
{"ln", ln_main, _BB_DIR_BIN},
|
||||
{"ln", ln_main, _BB_DIR_BIN, ln_usage},
|
||||
#endif
|
||||
#ifdef BB_LOADACM
|
||||
{"loadacm", loadacm_main, _BB_DIR_USR_BIN},
|
||||
{"loadacm", loadacm_main, _BB_DIR_USR_BIN, loadacm_usage},
|
||||
#endif
|
||||
#ifdef BB_LOADFONT
|
||||
{"loadfont", loadfont_main, _BB_DIR_USR_BIN},
|
||||
{"loadfont", loadfont_main, _BB_DIR_USR_BIN, loadfont_usage},
|
||||
#endif
|
||||
#ifdef BB_LOADKMAP
|
||||
{"loadkmap", loadkmap_main, _BB_DIR_SBIN},
|
||||
{"loadkmap", loadkmap_main, _BB_DIR_SBIN, loadkmap_usage},
|
||||
#endif
|
||||
#ifdef BB_LOGGER
|
||||
{"logger", logger_main, _BB_DIR_USR_BIN},
|
||||
{"logger", logger_main, _BB_DIR_USR_BIN, logger_usage},
|
||||
#endif
|
||||
#ifdef BB_LOGNAME
|
||||
{"logname", logname_main, _BB_DIR_USR_BIN},
|
||||
{"logname", logname_main, _BB_DIR_USR_BIN, logname_usage},
|
||||
#endif
|
||||
#ifdef BB_LS
|
||||
{"ls", ls_main, _BB_DIR_BIN},
|
||||
{"ls", ls_main, _BB_DIR_BIN, ls_usage},
|
||||
#endif
|
||||
#ifdef BB_LSMOD
|
||||
{"lsmod", lsmod_main, _BB_DIR_SBIN},
|
||||
{"lsmod", lsmod_main, _BB_DIR_SBIN, lsmod_usage},
|
||||
#endif
|
||||
#ifdef BB_MAKEDEVS
|
||||
{"makedevs", makedevs_main, _BB_DIR_SBIN},
|
||||
{"makedevs", makedevs_main, _BB_DIR_SBIN, makedevs_usage},
|
||||
#endif
|
||||
#ifdef BB_MD5SUM
|
||||
{"md5sum", md5sum_main, _BB_DIR_USR_BIN},
|
||||
{"md5sum", md5sum_main, _BB_DIR_USR_BIN, md5sum_usage},
|
||||
#endif
|
||||
#ifdef BB_MKDIR
|
||||
{"mkdir", mkdir_main, _BB_DIR_BIN},
|
||||
{"mkdir", mkdir_main, _BB_DIR_BIN, mkdir_usage},
|
||||
#endif
|
||||
#ifdef BB_MKFIFO
|
||||
{"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
|
||||
{"mkfifo", mkfifo_main, _BB_DIR_USR_BIN, mkfifo_usage},
|
||||
#endif
|
||||
#ifdef BB_MKFS_MINIX
|
||||
{"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
|
||||
{"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN, mkfs_minix_usage},
|
||||
#endif
|
||||
#ifdef BB_MKNOD
|
||||
{"mknod", mknod_main, _BB_DIR_BIN},
|
||||
{"mknod", mknod_main, _BB_DIR_BIN, mknod_usage},
|
||||
#endif
|
||||
#ifdef BB_MKSWAP
|
||||
{"mkswap", mkswap_main, _BB_DIR_SBIN},
|
||||
{"mkswap", mkswap_main, _BB_DIR_SBIN, mkswap_usage},
|
||||
#endif
|
||||
#ifdef BB_MKTEMP
|
||||
{"mktemp", mktemp_main, _BB_DIR_BIN},
|
||||
{"mktemp", mktemp_main, _BB_DIR_BIN, mktemp_usage},
|
||||
#endif
|
||||
#ifdef BB_NC
|
||||
{"nc", nc_main, _BB_DIR_USR_BIN},
|
||||
{"nc", nc_main, _BB_DIR_USR_BIN, nc_usage},
|
||||
#endif
|
||||
#ifdef BB_MORE
|
||||
{"more", more_main, _BB_DIR_BIN},
|
||||
{"more", more_main, _BB_DIR_BIN, more_usage},
|
||||
#endif
|
||||
#ifdef BB_MOUNT
|
||||
{"mount", mount_main, _BB_DIR_BIN},
|
||||
{"mount", mount_main, _BB_DIR_BIN, mount_usage},
|
||||
#endif
|
||||
#ifdef BB_MT
|
||||
{"mt", mt_main, _BB_DIR_BIN},
|
||||
{"mt", mt_main, _BB_DIR_BIN, mt_usage},
|
||||
#endif
|
||||
#ifdef BB_CP_MV
|
||||
{"mv", cp_mv_main, _BB_DIR_BIN},
|
||||
{"mv", cp_mv_main, _BB_DIR_BIN, mv_usage},
|
||||
#endif
|
||||
#ifdef BB_NSLOOKUP
|
||||
{"nslookup", nslookup_main, _BB_DIR_USR_BIN},
|
||||
{"nslookup", nslookup_main, _BB_DIR_USR_BIN, nslookup_usage},
|
||||
#endif
|
||||
#ifdef BB_PING
|
||||
{"ping", ping_main, _BB_DIR_BIN},
|
||||
{"ping", ping_main, _BB_DIR_BIN, ping_usage},
|
||||
#endif
|
||||
#ifdef BB_POWEROFF
|
||||
{"poweroff", poweroff_main, _BB_DIR_SBIN},
|
||||
{"poweroff", poweroff_main, _BB_DIR_SBIN, poweroff_usage},
|
||||
#endif
|
||||
#ifdef BB_PRINTF
|
||||
{"printf", printf_main, _BB_DIR_USR_BIN},
|
||||
{"printf", printf_main, _BB_DIR_USR_BIN, printf_usage},
|
||||
#endif
|
||||
#ifdef BB_PS
|
||||
{"ps", ps_main, _BB_DIR_BIN},
|
||||
{"ps", ps_main, _BB_DIR_BIN, ps_usage},
|
||||
#endif
|
||||
#ifdef BB_PWD
|
||||
{"pwd", pwd_main, _BB_DIR_BIN},
|
||||
{"pwd", pwd_main, _BB_DIR_BIN, pwd_usage},
|
||||
#endif
|
||||
#ifdef BB_RDATE
|
||||
{"rdate", rdate_main, _BB_DIR_USR_BIN, rdate_usage},
|
||||
#endif
|
||||
#ifdef BB_REBOOT
|
||||
{"reboot", reboot_main, _BB_DIR_SBIN},
|
||||
{"reboot", reboot_main, _BB_DIR_SBIN, reboot_usage},
|
||||
#endif
|
||||
#ifdef BB_RENICE
|
||||
{"renice", renice_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_RESET
|
||||
{"reset", reset_main, _BB_DIR_USR_BIN, reset_usage},
|
||||
#endif
|
||||
#ifdef BB_RM
|
||||
{"rm", rm_main, _BB_DIR_BIN},
|
||||
{"rm", rm_main, _BB_DIR_BIN, rm_usage},
|
||||
#endif
|
||||
#ifdef BB_RMDIR
|
||||
{"rmdir", rmdir_main, _BB_DIR_BIN},
|
||||
{"rmdir", rmdir_main, _BB_DIR_BIN, rmdir_usage},
|
||||
#endif
|
||||
#ifdef BB_RMMOD
|
||||
{"rmmod", rmmod_main, _BB_DIR_SBIN},
|
||||
{"rmmod", rmmod_main, _BB_DIR_SBIN, rmmod_usage},
|
||||
#endif
|
||||
#ifdef BB_SED
|
||||
{"sed", sed_main, _BB_DIR_BIN},
|
||||
{"sed", sed_main, _BB_DIR_BIN, sed_usage},
|
||||
#endif
|
||||
#ifdef BB_SETKEYCODES
|
||||
{"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN},
|
||||
{"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN, setkeycodes_usage},
|
||||
#endif
|
||||
#ifdef BB_SH
|
||||
{"sh", shell_main, _BB_DIR_BIN},
|
||||
{"sh", shell_main, _BB_DIR_BIN, shell_usage},
|
||||
#endif
|
||||
#ifdef BB_SLEEP
|
||||
{"sleep", sleep_main, _BB_DIR_BIN},
|
||||
{"sleep", sleep_main, _BB_DIR_BIN, sleep_usage},
|
||||
#endif
|
||||
#ifdef BB_SORT
|
||||
{"sort", sort_main, _BB_DIR_BIN},
|
||||
{"sort", sort_main, _BB_DIR_USR_BIN, sort_usage},
|
||||
#endif
|
||||
#ifdef BB_SYNC
|
||||
{"sync", sync_main, _BB_DIR_BIN},
|
||||
{"sync", sync_main, _BB_DIR_BIN, sync_usage},
|
||||
#endif
|
||||
#ifdef BB_SYSLOGD
|
||||
{"syslogd", syslogd_main, _BB_DIR_SBIN},
|
||||
{"syslogd", syslogd_main, _BB_DIR_SBIN, syslogd_usage},
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF
|
||||
{"swapon", swap_on_off_main, _BB_DIR_SBIN},
|
||||
{"swapon", swap_on_off_main, _BB_DIR_SBIN, swapon_usage},
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF
|
||||
{"swapoff", swap_on_off_main, _BB_DIR_SBIN},
|
||||
{"swapoff", swap_on_off_main, _BB_DIR_SBIN, swapoff_usage},
|
||||
#endif
|
||||
#ifdef BB_TAIL
|
||||
{"tail", tail_main, _BB_DIR_USR_BIN},
|
||||
{"tail", tail_main, _BB_DIR_USR_BIN, tail_usage},
|
||||
#endif
|
||||
#ifdef BB_TAR
|
||||
{"tar", tar_main, _BB_DIR_BIN},
|
||||
{"tar", tar_main, _BB_DIR_BIN, tar_usage},
|
||||
#endif
|
||||
#ifdef BB_TELNET
|
||||
{"telnet", telnet_main, _BB_DIR_USR_BIN},
|
||||
{"telnet", telnet_main, _BB_DIR_USR_BIN, telnet_usage},
|
||||
#endif
|
||||
#ifdef BB_TEST
|
||||
{"test", test_main, _BB_DIR_USR_BIN},
|
||||
{"test", test_main, _BB_DIR_USR_BIN, test_usage},
|
||||
#endif
|
||||
#ifdef BB_TEE
|
||||
{"tee", tee_main, _BB_DIR_BIN},
|
||||
{"tee", tee_main, _BB_DIR_USR_BIN, tee_usage},
|
||||
#endif
|
||||
#ifdef BB_TOUCH
|
||||
{"touch", touch_main, _BB_DIR_USR_BIN},
|
||||
{"touch", touch_main, _BB_DIR_BIN, touch_usage},
|
||||
#endif
|
||||
#ifdef BB_TR
|
||||
{"tr", tr_main, _BB_DIR_USR_BIN},
|
||||
{"tr", tr_main, _BB_DIR_USR_BIN, tr_usage},
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE
|
||||
{"true", true_main, _BB_DIR_BIN},
|
||||
{"true", true_main, _BB_DIR_BIN, true_usage},
|
||||
#endif
|
||||
#ifdef BB_TTY
|
||||
{"tty", tty_main, _BB_DIR_USR_BIN},
|
||||
{"tty", tty_main, _BB_DIR_USR_BIN, tty_usage},
|
||||
#endif
|
||||
#ifdef BB_UMOUNT
|
||||
{"umount", umount_main, _BB_DIR_BIN},
|
||||
{"umount", umount_main, _BB_DIR_BIN, umount_usage},
|
||||
#endif
|
||||
#ifdef BB_UNAME
|
||||
{"uname", uname_main, _BB_DIR_BIN},
|
||||
{"uname", uname_main, _BB_DIR_BIN, uname_usage},
|
||||
#endif
|
||||
#ifdef BB_UNIQ
|
||||
{"uniq", uniq_main, _BB_DIR_USR_BIN},
|
||||
{"uniq", uniq_main, _BB_DIR_USR_BIN, uniq_usage},
|
||||
#endif
|
||||
#ifdef BB_UNIX2DOS
|
||||
{"unix2dos", unix2dos_main, _BB_DIR_USR_BIN, unix2dos_usage},
|
||||
#endif
|
||||
#ifdef BB_UNRPM
|
||||
{"unrpm", unrpm_main, _BB_DIR_USR_BIN, unrpm_usage},
|
||||
#endif
|
||||
#ifdef BB_UPDATE
|
||||
{"update", update_main, _BB_DIR_SBIN},
|
||||
{"update", update_main, _BB_DIR_SBIN, update_usage},
|
||||
#endif
|
||||
#ifdef BB_UPTIME
|
||||
{"uptime", uptime_main, _BB_DIR_USR_BIN},
|
||||
{"uptime", uptime_main, _BB_DIR_USR_BIN, uptime_usage},
|
||||
#endif
|
||||
#ifdef BB_UUENCODE
|
||||
{"uuencode", uuencode_main, _BB_DIR_USR_BIN},
|
||||
{"uuencode", uuencode_main, _BB_DIR_USR_BIN, uuencode_usage},
|
||||
#endif
|
||||
#ifdef BB_UUDECODE
|
||||
{"uudecode", uudecode_main, _BB_DIR_USR_BIN},
|
||||
{"uudecode", uudecode_main, _BB_DIR_USR_BIN, uudecode_usage},
|
||||
#endif
|
||||
#ifdef BB_USLEEP
|
||||
{"usleep", usleep_main, _BB_DIR_BIN},
|
||||
{"usleep", usleep_main, _BB_DIR_BIN, usleep_usage},
|
||||
#endif
|
||||
#ifdef BB_WC
|
||||
{"wc", wc_main, _BB_DIR_USR_BIN},
|
||||
{"wc", wc_main, _BB_DIR_USR_BIN, wc_usage},
|
||||
#endif
|
||||
#ifdef BB_WGET
|
||||
{"wget", wget_main, _BB_DIR_USR_BIN, wget_usage},
|
||||
#endif
|
||||
#ifdef BB_WHICH
|
||||
{"which", which_main, _BB_DIR_USR_BIN},
|
||||
{"which", which_main, _BB_DIR_USR_BIN, which_usage},
|
||||
#endif
|
||||
#ifdef BB_WHOAMI
|
||||
{"whoami", whoami_main, _BB_DIR_USR_BIN},
|
||||
{"whoami", whoami_main, _BB_DIR_USR_BIN, whoami_usage},
|
||||
#endif
|
||||
#ifdef BB_XARGS
|
||||
{"xargs", xargs_main, _BB_DIR_USR_BIN, xargs_usage},
|
||||
#endif
|
||||
#ifdef BB_YES
|
||||
{"yes", yes_main, _BB_DIR_USR_BIN},
|
||||
{"yes", yes_main, _BB_DIR_USR_BIN, yes_usage},
|
||||
#endif
|
||||
#ifdef BB_GUNZIP
|
||||
{"zcat", gunzip_main, _BB_DIR_BIN},
|
||||
{"zcat", gunzip_main, _BB_DIR_BIN, gunzip_usage},
|
||||
#endif
|
||||
#ifdef BB_TEST
|
||||
{"[", test_main, _BB_DIR_USR_BIN},
|
||||
{"[", test_main, _BB_DIR_USR_BIN, test_usage},
|
||||
#endif
|
||||
{0}
|
||||
{0,NULL,0,NULL}
|
||||
};
|
||||
|
||||
const char *applet_name;
|
||||
|
||||
#ifdef BB_FEATURE_INSTALLER
|
||||
/*
|
||||
* directory table
|
||||
* this should be consistent w/ the enum, internal.h::Location,
|
||||
* this should be consistent w/ the enum, busybox.h::Location,
|
||||
* or else...
|
||||
*/
|
||||
static char* install_dir[] = {
|
||||
@@ -391,53 +402,43 @@ static char *busybox_fullpath()
|
||||
if (len != -1) {
|
||||
path[len] = 0;
|
||||
} else {
|
||||
fprintf(stderr, "busybox : %s : %s\n", proc, strerror(errno));
|
||||
errorMsg("%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)
|
||||
static void install_links(const char *busybox, int use_symbolic_links)
|
||||
{
|
||||
__link_f Link = link;
|
||||
|
||||
char command[256];
|
||||
int i;
|
||||
int rc = 0;
|
||||
int rc;
|
||||
|
||||
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
|
||||
sprintf ( command, "%s/%s",
|
||||
install_dir[applets[i].location],
|
||||
applets[i].name);
|
||||
rc = Link(busybox, command);
|
||||
|
||||
if (rc) {
|
||||
fprintf(stderr,"busybox : %s : %s\n", command, strerror(errno));
|
||||
errorMsg("%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;
|
||||
char *name;
|
||||
const char *s;
|
||||
const struct BB_applet *a = applets;
|
||||
applet_name = "busybox";
|
||||
|
||||
#ifdef BB_FEATURE_INSTALLER
|
||||
/*
|
||||
@@ -469,22 +470,25 @@ int main(int argc, char **argv)
|
||||
}
|
||||
#endif /* BB_FEATURE_INSTALLER */
|
||||
|
||||
for (s = name = argv[0]; *s != '\0';) {
|
||||
for (s = applet_name = argv[0]; *s != '\0';) {
|
||||
if (*s++ == '/')
|
||||
name = s;
|
||||
applet_name = s;
|
||||
}
|
||||
|
||||
*argv = name;
|
||||
*argv = (char*)applet_name;
|
||||
|
||||
#ifdef BB_SH
|
||||
/* Add in a special case hack -- whenever **argv == '-'
|
||||
* (i.e. '-su' or '-sh') always invoke the shell */
|
||||
if (**argv == '-')
|
||||
if (**argv == '-' && *(*argv+1)!= '-') {
|
||||
exit(((*(shell_main)) (argc, argv)));
|
||||
}
|
||||
#endif
|
||||
|
||||
while (a->name != 0) {
|
||||
if (strcmp(name, a->name) == 0) {
|
||||
if (strcmp(applet_name, a->name) == 0) {
|
||||
if (a->usage && argv[1] && strcmp(argv[1], "--help") == 0)
|
||||
usage(a->usage);
|
||||
exit(((*(a->main)) (argc, argv)));
|
||||
}
|
||||
a++;
|
||||
@@ -503,14 +507,14 @@ int busybox_main(int argc, char **argv)
|
||||
if (been_there_done_that == 1 || argc < 1) {
|
||||
const struct BB_applet *a = applets;
|
||||
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n"
|
||||
fprintf(stderr, "%s\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);
|
||||
"\nCurrently defined functions:\n", full_version);
|
||||
|
||||
while (a->name != 0) {
|
||||
col +=
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
# Make busybox links list file.
|
||||
|
||||
DF="busybox.def.h"
|
||||
DF="Config.h"
|
||||
MF="busybox.c"
|
||||
|
||||
LIST="$(gcc -E -dM $DF | sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/BB_\1/gp;' | sort)"
|
||||
|
||||
+2
-2
@@ -3,8 +3,8 @@
|
||||
# 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 | \
|
||||
gcc -E -dM Config.h | \
|
||||
sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/\1.c/gp;' \
|
||||
| tr [:upper:] [:lower:] | sort
|
||||
| tr '[:upper:]' '[:lower:]' | sort
|
||||
` 2>/dev/null | sed -e 's/\.c$/\.o/g'
|
||||
|
||||
+38
-10
@@ -1,21 +1,49 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
if [ "$1" = "" ]; then
|
||||
prefix=$1
|
||||
if [ "$prefix" = "" ]; then
|
||||
echo "No installation directory, aborting."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ "$2" = "--hardlinks" ]; then
|
||||
linkopts="-f"
|
||||
else
|
||||
linkopts="-fs"
|
||||
fi
|
||||
h=`sort busybox.links | uniq`
|
||||
|
||||
|
||||
rm -f $prefix/bin/busybox || exit 1
|
||||
mkdir -p $prefix/bin || exit 1
|
||||
install -m 755 busybox $prefix/bin/busybox || exit 1
|
||||
|
||||
for i in $h ; do
|
||||
echo " $1$i -> /bin/busybox"
|
||||
mkdir -p $1/`echo $i | sed -e 's/\/[^\/]*$//' `
|
||||
ln -fs /bin/busybox $1$i
|
||||
appdir=`dirname $i`
|
||||
mkdir -p $prefix/$appdir || exit 1
|
||||
if [ "$2" = "--hardlinks" ]; then
|
||||
bb_path="$prefix/bin/busybox"
|
||||
else
|
||||
case "$appdir" in
|
||||
/)
|
||||
bb_path="bin/busybox"
|
||||
;;
|
||||
/bin)
|
||||
bb_path="busybox"
|
||||
;;
|
||||
/sbin)
|
||||
bb_path="../bin/busybox"
|
||||
;;
|
||||
/usr/bin|/usr/sbin)
|
||||
bb_path="../../bin/busybox"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown installation directory: $appdir"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
echo " $prefix$i -> $bb_path"
|
||||
ln $linkopts $bb_path $prefix$i || exit 1
|
||||
done
|
||||
rm -f $1/bin/busybox
|
||||
mkdir -p $1/bin
|
||||
install -m 755 busybox $1/bin/busybox
|
||||
|
||||
exit 0
|
||||
+1458
File diff suppressed because it is too large.
Load diff
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* 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
|
||||
@@ -21,312 +21,371 @@
|
||||
* 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
|
||||
* Last modified 20 September 2000
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include "internal.h"
|
||||
#include <sys/stat.h>
|
||||
#include <malloc.h>
|
||||
#include "busybox.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 BLOCK_SIZE 60
|
||||
#define PRESERVE_DATE 1 /* preserve original dates */
|
||||
#define VERBOSE 2 /* be verbose */
|
||||
#define DISPLAY 4 /* display contents */
|
||||
#define EXT_TO_FILE 8 /* extract contents of archive */
|
||||
#define EXT_TO_STDOUT 16 /* extract to stdout */
|
||||
#define RECURSIVE 32
|
||||
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_io_error
|
||||
#include "messages.c"
|
||||
#define MAX_NAME_LENGTH 100
|
||||
|
||||
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;
|
||||
//#define BB_DECLARE_EXTERN
|
||||
//#define bb_need_io_error
|
||||
//#include "messages.c"
|
||||
|
||||
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;
|
||||
//#define BB_AR_EXPERIMENTAL_UNTAR
|
||||
|
||||
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"
|
||||
#if defined BB_AR_EXPERIMENTAL_UNTAR
|
||||
typedef struct rawTarHeader {
|
||||
char name[100]; /* 0-99 */
|
||||
char mode[8]; /* 100-107 */
|
||||
char uid[8]; /* 108-115 */
|
||||
char gid[8]; /* 116-123 */
|
||||
char size[12]; /* 124-135 */
|
||||
char mtime[12]; /* 136-147 */
|
||||
char chksum[8]; /* 148-155 */
|
||||
char typeflag; /* 156-156 */
|
||||
char linkname[100]; /* 157-256 */
|
||||
char magic[6]; /* 257-262 */
|
||||
char version[2]; /* 263-264 */
|
||||
char uname[32]; /* 265-296 */
|
||||
char gname[32]; /* 297-328 */
|
||||
char devmajor[8]; /* 329-336 */
|
||||
char devminor[8]; /* 337-344 */
|
||||
char prefix[155]; /* 345-499 */
|
||||
char padding[12]; /* 500-512 */
|
||||
} rawTarHeader_t;
|
||||
#endif
|
||||
;
|
||||
|
||||
typedef struct rawArHeader { /* Byte Offset */
|
||||
char name[16]; /* 0-15 */
|
||||
char date[12]; /* 16-27 */
|
||||
char uid[6], gid[6]; /* 28-39 */
|
||||
char mode[8]; /* 40-47 */
|
||||
char size[10]; /* 48-57 */
|
||||
char fmag[2]; /* 58-59 */
|
||||
} rawArHeader_t;
|
||||
|
||||
typedef struct headerL {
|
||||
char name[MAX_NAME_LENGTH];
|
||||
size_t size;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
mode_t mode;
|
||||
time_t mtime;
|
||||
off_t offset;
|
||||
struct headerL *next;
|
||||
} headerL_t;
|
||||
|
||||
#if defined BB_AR_EXPERIMENTAL_UNTAR
|
||||
/*
|
||||
* Display details of a file, verbosly if funct=2
|
||||
* identify Tar header (magic field) and reset srcFd to entry position
|
||||
*/
|
||||
static void displayEntry(struct ArInfo *entry, int funct)
|
||||
static int checkTarMagic(int srcFd)
|
||||
{
|
||||
/* 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);
|
||||
off_t headerStart;
|
||||
char magic[6];
|
||||
|
||||
headerStart = lseek(srcFd, 0, SEEK_CUR);
|
||||
lseek(srcFd, (off_t) 257, SEEK_CUR);
|
||||
fullRead(srcFd, magic, 6);
|
||||
lseek(srcFd, headerStart, SEEK_SET);
|
||||
if (strncmp(magic, "ustar", 5)!=0)
|
||||
return(FALSE);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
/* this is from tar.c remove later*/
|
||||
static long getOctal(const char *cp, int size)
|
||||
|
||||
static int readTarHeader(int srcFd, headerL_t *current)
|
||||
{
|
||||
long val = 0;
|
||||
rawTarHeader_t rawTarHeader;
|
||||
unsigned char *temp = (unsigned char *) &rawTarHeader;
|
||||
long sum = 0;
|
||||
int i;
|
||||
off_t initialOffset;
|
||||
|
||||
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 ");
|
||||
initialOffset = lseek(srcFd, 0, SEEK_CUR);
|
||||
if (fullRead(srcFd, (char *) &rawTarHeader, 512) != 512) {
|
||||
lseek(srcFd, initialOffset, SEEK_SET);
|
||||
return(FALSE);
|
||||
}
|
||||
return arFd;
|
||||
for (i = 0; i < 148 ; i++)
|
||||
sum += temp[i];
|
||||
sum += ' ' * 8;
|
||||
for (i = 156; i < 512 ; i++)
|
||||
sum += temp[i];
|
||||
if (sum!= strtol(rawTarHeader.chksum, NULL, 8))
|
||||
return(FALSE);
|
||||
sscanf(rawTarHeader.name, "%s", current->name);
|
||||
current->size = strtol(rawTarHeader.size, NULL, 8);
|
||||
current->uid = strtol(rawTarHeader.uid, NULL, 8);
|
||||
current->gid = strtol(rawTarHeader.gid, NULL, 8);
|
||||
current->mode = strtol(rawTarHeader.mode, NULL, 8);
|
||||
current->mtime = strtol(rawTarHeader.mtime, NULL, 8);
|
||||
current->offset = lseek(srcFd, 0 , SEEK_CUR);
|
||||
|
||||
current->next = (headerL_t *) xmalloc(sizeof(headerL_t));
|
||||
current = current->next;
|
||||
return(TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* identify Ar header (magic) and reset srcFd to entry position
|
||||
*/
|
||||
static int checkArMagic(int srcFd)
|
||||
{
|
||||
off_t headerStart;
|
||||
char arMagic[8];
|
||||
|
||||
headerStart = lseek(srcFd, 0, SEEK_CUR);
|
||||
if (fullRead(srcFd, arMagic, 8) != 8) {
|
||||
errorMsg("fatal error\n");
|
||||
return (FALSE);
|
||||
}
|
||||
lseek(srcFd, headerStart, SEEK_SET);
|
||||
|
||||
if (strncmp(arMagic,"!<arch>",7) != 0)
|
||||
return(FALSE);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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)
|
||||
* get, check and correct the converted header
|
||||
*/
|
||||
static int readArEntry(int srcFd, headerL_t *entry)
|
||||
{
|
||||
int arFd, status, extFileFlag, i, lastOffset=0;
|
||||
ArHeader rawArHeader;
|
||||
ArInfo arEntry;
|
||||
size_t nameLength;
|
||||
rawArHeader_t rawArHeader;
|
||||
off_t initialOffset;
|
||||
|
||||
/* open the ar archive */
|
||||
arFd=getArFd(fileList[0]);
|
||||
initialOffset = lseek(srcFd, 0, SEEK_CUR);
|
||||
if (fullRead(srcFd, (char *) &rawArHeader, 60) != 60) {
|
||||
lseek(srcFd, initialOffset, SEEK_SET);
|
||||
return(FALSE);
|
||||
}
|
||||
if ((rawArHeader.fmag[0]!='`') || (rawArHeader.fmag[1]!='\n')) {
|
||||
lseek(srcFd, initialOffset, SEEK_SET);
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
/* read the first header, then loop until ono more headers */
|
||||
while ((status = fullRead(arFd, (char *) &rawArHeader, AR_BLOCK_SIZE))
|
||||
== AR_BLOCK_SIZE) {
|
||||
strncpy(entry->name, rawArHeader.name, 16);
|
||||
nameLength=strcspn(entry->name, " \\");
|
||||
entry->name[nameLength]='\0';
|
||||
parse_mode(rawArHeader.mode, &entry->mode);
|
||||
entry->mtime = atoi(rawArHeader.date);
|
||||
entry->uid = atoi(rawArHeader.uid);
|
||||
entry->gid = atoi(rawArHeader.gid);
|
||||
entry->size = (size_t) atoi(rawArHeader.size);
|
||||
entry->offset = initialOffset + (off_t) 60;
|
||||
|
||||
/* 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;
|
||||
nameLength = strcspn(entry->name, "/");
|
||||
|
||||
/* handle GNU style short filenames, strip trailing '/' */
|
||||
if (nameLength > 0)
|
||||
entry->name[nameLength]='\0';
|
||||
|
||||
/* handle GNU style long filenames */
|
||||
if (nameLength == 0) {
|
||||
/* escape from recursive call */
|
||||
if (entry->name[1]=='0')
|
||||
return(TRUE);
|
||||
|
||||
/* the data section contains the real filename */
|
||||
if (entry->name[1]=='/') {
|
||||
char tempName[MAX_NAME_LENGTH];
|
||||
|
||||
if (entry->size > MAX_NAME_LENGTH)
|
||||
entry->size = MAX_NAME_LENGTH;
|
||||
fullRead(srcFd, tempName, entry->size);
|
||||
tempName[entry->size-3]='\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;
|
||||
}
|
||||
/* read the second header for this entry */
|
||||
/* be carefull, this is recursive */
|
||||
if (readArEntry(srcFd, entry)==FALSE)
|
||||
return(FALSE);
|
||||
|
||||
if ((entry->name[0]='/') && (entry->name[1]='0'))
|
||||
strcpy(entry->name, tempName);
|
||||
else {
|
||||
errorMsg("Invalid long filename\n");
|
||||
return(FALSE);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* return the headerL_t struct for the specified filename
|
||||
*/
|
||||
static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
|
||||
{
|
||||
#if defined BB_AR_EXPERIMENTAL_UNTAR
|
||||
int tar=FALSE;
|
||||
#endif
|
||||
int ar=FALSE;
|
||||
headerL_t *list;
|
||||
off_t initialOffset;
|
||||
|
||||
list = (headerL_t *) xmalloc(sizeof(headerL_t));
|
||||
initialOffset=lseek(srcFd, 0, SEEK_CUR);
|
||||
if (checkArMagic(srcFd)==TRUE)
|
||||
ar=TRUE;
|
||||
|
||||
#if defined BB_AR_EXPERIMENTAL_UNTAR
|
||||
if (checkTarMagic(srcFd)==TRUE)
|
||||
tar=TRUE;
|
||||
|
||||
if (tar==TRUE) {
|
||||
while(readTarHeader(srcFd, list)==TRUE) {
|
||||
off_t tarOffset;
|
||||
list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
|
||||
*list->next = *head;
|
||||
*head = *list;
|
||||
|
||||
/* recursive check for sub-archives */
|
||||
if ((funct & RECURSIVE) == RECURSIVE)
|
||||
head = getHeaders(srcFd, head, funct);
|
||||
tarOffset = (off_t) head->size/512;
|
||||
if ( head->size % 512 > 0)
|
||||
tarOffset++;
|
||||
tarOffset=tarOffset*512;
|
||||
lseek(srcFd, head->offset + tarOffset, SEEK_SET);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ar==TRUE) {
|
||||
lseek(srcFd, 8, SEEK_CUR);
|
||||
while(1) {
|
||||
if (readArEntry(srcFd, list) == FALSE) {
|
||||
lseek(srcFd, ++initialOffset, SEEK_CUR);
|
||||
if (readArEntry(srcFd, list) == FALSE)
|
||||
return(head);
|
||||
}
|
||||
list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
|
||||
*list->next = *head;
|
||||
*head = *list;
|
||||
/* recursive check for sub-archives */
|
||||
if (funct & RECURSIVE)
|
||||
head = getHeaders(srcFd, head, funct);
|
||||
lseek(srcFd, head->offset + head->size, SEEK_SET);
|
||||
}
|
||||
}
|
||||
return(head);
|
||||
}
|
||||
|
||||
/*
|
||||
* find an entry in the linked list matching the filename
|
||||
*/
|
||||
static headerL_t *findEntry(headerL_t *head, const char *filename)
|
||||
{
|
||||
while(head->next != NULL) {
|
||||
if (strcmp(filename, head->name)==0)
|
||||
return(head);
|
||||
head=head->next;
|
||||
}
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
extern int ar_main(int argc, char **argv)
|
||||
{
|
||||
int funct = 0, ret=0, i=0;
|
||||
char *fileList[16], c, *opt_ptr;
|
||||
int funct = 0, opt=0;
|
||||
int srcFd=0, dstFd=0;
|
||||
headerL_t *header, *entry, *extractList;
|
||||
|
||||
if (argc < 2)
|
||||
usage(ar_usage);
|
||||
|
||||
opt_ptr = argv[1];
|
||||
if (*opt_ptr == '-')
|
||||
++opt_ptr;
|
||||
while ((c = *opt_ptr++) != '\0') {
|
||||
switch (c) {
|
||||
while ((opt = getopt(argc, argv, "ovtpxR")) != -1) {
|
||||
switch (opt) {
|
||||
case 'o':
|
||||
funct = funct | AR_PRESERVE_DATE;
|
||||
funct |= PRESERVE_DATE;
|
||||
break;
|
||||
case 'v':
|
||||
funct = funct | AR_VERBOSE;
|
||||
funct |= VERBOSE;
|
||||
break;
|
||||
case 't':
|
||||
funct = funct | AR_DISPLAY;
|
||||
funct |= DISPLAY;
|
||||
break;
|
||||
case 'x':
|
||||
funct = funct | AR_EXT_TO_FILE;
|
||||
funct |= EXT_TO_FILE;
|
||||
break;
|
||||
case 'p':
|
||||
funct = funct | AR_EXT_TO_STDOUT;
|
||||
funct |= EXT_TO_STDOUT;
|
||||
break;
|
||||
case 'R':
|
||||
funct |= RECURSIVE;
|
||||
break;
|
||||
default:
|
||||
usage(ar_usage);
|
||||
}
|
||||
}
|
||||
|
||||
/* check the src filename was specified */
|
||||
if (optind == argc)
|
||||
usage(ar_usage);
|
||||
|
||||
if ( (srcFd = open(argv[optind], O_RDONLY)) < 0)
|
||||
fatalError("Cannot read %s\n", argv[optind]);
|
||||
|
||||
for(i=0; i<(argc-2); i++)
|
||||
fileList[i]=argv[i+2];
|
||||
optind++;
|
||||
entry = (headerL_t *) xmalloc(sizeof(headerL_t));
|
||||
header = (headerL_t *) xmalloc(sizeof(headerL_t));
|
||||
extractList = (headerL_t *) xmalloc(sizeof(headerL_t));
|
||||
|
||||
header = getHeaders(srcFd, header, funct);
|
||||
/* find files to extract or display */
|
||||
if (optind<argc) {
|
||||
/* only handle specified files */
|
||||
while(optind < argc) {
|
||||
if ( (entry = findEntry(header, argv[optind])) != NULL) {
|
||||
entry->next = (headerL_t *) xmalloc(sizeof(headerL_t));
|
||||
*entry->next = *extractList;
|
||||
*extractList = *entry;
|
||||
}
|
||||
optind++;
|
||||
}
|
||||
}
|
||||
else
|
||||
extractList = header;
|
||||
|
||||
if (funct > 3)
|
||||
ret = readArFile(fileList, (argc-2), funct);
|
||||
|
||||
return (ret);
|
||||
while(extractList->next != NULL) {
|
||||
if (funct & EXT_TO_FILE) {
|
||||
if (isDirectory(extractList->name, TRUE, NULL)==FALSE)
|
||||
createPath(extractList->name, 0666);
|
||||
dstFd = open(extractList->name, O_WRONLY | O_CREAT, extractList->mode);
|
||||
lseek(srcFd, extractList->offset, SEEK_SET);
|
||||
copySubFile(srcFd, dstFd, (size_t) extractList->size);
|
||||
}
|
||||
if (funct & EXT_TO_STDOUT) {
|
||||
lseek(srcFd, extractList->offset, SEEK_SET);
|
||||
copySubFile(srcFd, fileno(stdout), (size_t) extractList->size);
|
||||
}
|
||||
if ( (funct & DISPLAY) || (funct & VERBOSE)) {
|
||||
if (funct & VERBOSE)
|
||||
printf("%s %d/%d %8d %s ", modeString(extractList->mode),
|
||||
extractList->uid, extractList->gid,
|
||||
extractList->size, timeString(extractList->mtime));
|
||||
printf("%s\n", extractList->name);
|
||||
}
|
||||
extractList=extractList->next;
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
+314
-255
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* 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
|
||||
@@ -21,312 +21,371 @@
|
||||
* 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
|
||||
* Last modified 20 September 2000
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include "internal.h"
|
||||
#include <sys/stat.h>
|
||||
#include <malloc.h>
|
||||
#include "busybox.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 BLOCK_SIZE 60
|
||||
#define PRESERVE_DATE 1 /* preserve original dates */
|
||||
#define VERBOSE 2 /* be verbose */
|
||||
#define DISPLAY 4 /* display contents */
|
||||
#define EXT_TO_FILE 8 /* extract contents of archive */
|
||||
#define EXT_TO_STDOUT 16 /* extract to stdout */
|
||||
#define RECURSIVE 32
|
||||
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_io_error
|
||||
#include "messages.c"
|
||||
#define MAX_NAME_LENGTH 100
|
||||
|
||||
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;
|
||||
//#define BB_DECLARE_EXTERN
|
||||
//#define bb_need_io_error
|
||||
//#include "messages.c"
|
||||
|
||||
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;
|
||||
//#define BB_AR_EXPERIMENTAL_UNTAR
|
||||
|
||||
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"
|
||||
#if defined BB_AR_EXPERIMENTAL_UNTAR
|
||||
typedef struct rawTarHeader {
|
||||
char name[100]; /* 0-99 */
|
||||
char mode[8]; /* 100-107 */
|
||||
char uid[8]; /* 108-115 */
|
||||
char gid[8]; /* 116-123 */
|
||||
char size[12]; /* 124-135 */
|
||||
char mtime[12]; /* 136-147 */
|
||||
char chksum[8]; /* 148-155 */
|
||||
char typeflag; /* 156-156 */
|
||||
char linkname[100]; /* 157-256 */
|
||||
char magic[6]; /* 257-262 */
|
||||
char version[2]; /* 263-264 */
|
||||
char uname[32]; /* 265-296 */
|
||||
char gname[32]; /* 297-328 */
|
||||
char devmajor[8]; /* 329-336 */
|
||||
char devminor[8]; /* 337-344 */
|
||||
char prefix[155]; /* 345-499 */
|
||||
char padding[12]; /* 500-512 */
|
||||
} rawTarHeader_t;
|
||||
#endif
|
||||
;
|
||||
|
||||
typedef struct rawArHeader { /* Byte Offset */
|
||||
char name[16]; /* 0-15 */
|
||||
char date[12]; /* 16-27 */
|
||||
char uid[6], gid[6]; /* 28-39 */
|
||||
char mode[8]; /* 40-47 */
|
||||
char size[10]; /* 48-57 */
|
||||
char fmag[2]; /* 58-59 */
|
||||
} rawArHeader_t;
|
||||
|
||||
typedef struct headerL {
|
||||
char name[MAX_NAME_LENGTH];
|
||||
size_t size;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
mode_t mode;
|
||||
time_t mtime;
|
||||
off_t offset;
|
||||
struct headerL *next;
|
||||
} headerL_t;
|
||||
|
||||
#if defined BB_AR_EXPERIMENTAL_UNTAR
|
||||
/*
|
||||
* Display details of a file, verbosly if funct=2
|
||||
* identify Tar header (magic field) and reset srcFd to entry position
|
||||
*/
|
||||
static void displayEntry(struct ArInfo *entry, int funct)
|
||||
static int checkTarMagic(int srcFd)
|
||||
{
|
||||
/* 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);
|
||||
off_t headerStart;
|
||||
char magic[6];
|
||||
|
||||
headerStart = lseek(srcFd, 0, SEEK_CUR);
|
||||
lseek(srcFd, (off_t) 257, SEEK_CUR);
|
||||
fullRead(srcFd, magic, 6);
|
||||
lseek(srcFd, headerStart, SEEK_SET);
|
||||
if (strncmp(magic, "ustar", 5)!=0)
|
||||
return(FALSE);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
/* this is from tar.c remove later*/
|
||||
static long getOctal(const char *cp, int size)
|
||||
|
||||
static int readTarHeader(int srcFd, headerL_t *current)
|
||||
{
|
||||
long val = 0;
|
||||
rawTarHeader_t rawTarHeader;
|
||||
unsigned char *temp = (unsigned char *) &rawTarHeader;
|
||||
long sum = 0;
|
||||
int i;
|
||||
off_t initialOffset;
|
||||
|
||||
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 ");
|
||||
initialOffset = lseek(srcFd, 0, SEEK_CUR);
|
||||
if (fullRead(srcFd, (char *) &rawTarHeader, 512) != 512) {
|
||||
lseek(srcFd, initialOffset, SEEK_SET);
|
||||
return(FALSE);
|
||||
}
|
||||
return arFd;
|
||||
for (i = 0; i < 148 ; i++)
|
||||
sum += temp[i];
|
||||
sum += ' ' * 8;
|
||||
for (i = 156; i < 512 ; i++)
|
||||
sum += temp[i];
|
||||
if (sum!= strtol(rawTarHeader.chksum, NULL, 8))
|
||||
return(FALSE);
|
||||
sscanf(rawTarHeader.name, "%s", current->name);
|
||||
current->size = strtol(rawTarHeader.size, NULL, 8);
|
||||
current->uid = strtol(rawTarHeader.uid, NULL, 8);
|
||||
current->gid = strtol(rawTarHeader.gid, NULL, 8);
|
||||
current->mode = strtol(rawTarHeader.mode, NULL, 8);
|
||||
current->mtime = strtol(rawTarHeader.mtime, NULL, 8);
|
||||
current->offset = lseek(srcFd, 0 , SEEK_CUR);
|
||||
|
||||
current->next = (headerL_t *) xmalloc(sizeof(headerL_t));
|
||||
current = current->next;
|
||||
return(TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* identify Ar header (magic) and reset srcFd to entry position
|
||||
*/
|
||||
static int checkArMagic(int srcFd)
|
||||
{
|
||||
off_t headerStart;
|
||||
char arMagic[8];
|
||||
|
||||
headerStart = lseek(srcFd, 0, SEEK_CUR);
|
||||
if (fullRead(srcFd, arMagic, 8) != 8) {
|
||||
errorMsg("fatal error\n");
|
||||
return (FALSE);
|
||||
}
|
||||
lseek(srcFd, headerStart, SEEK_SET);
|
||||
|
||||
if (strncmp(arMagic,"!<arch>",7) != 0)
|
||||
return(FALSE);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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)
|
||||
* get, check and correct the converted header
|
||||
*/
|
||||
static int readArEntry(int srcFd, headerL_t *entry)
|
||||
{
|
||||
int arFd, status, extFileFlag, i, lastOffset=0;
|
||||
ArHeader rawArHeader;
|
||||
ArInfo arEntry;
|
||||
size_t nameLength;
|
||||
rawArHeader_t rawArHeader;
|
||||
off_t initialOffset;
|
||||
|
||||
/* open the ar archive */
|
||||
arFd=getArFd(fileList[0]);
|
||||
initialOffset = lseek(srcFd, 0, SEEK_CUR);
|
||||
if (fullRead(srcFd, (char *) &rawArHeader, 60) != 60) {
|
||||
lseek(srcFd, initialOffset, SEEK_SET);
|
||||
return(FALSE);
|
||||
}
|
||||
if ((rawArHeader.fmag[0]!='`') || (rawArHeader.fmag[1]!='\n')) {
|
||||
lseek(srcFd, initialOffset, SEEK_SET);
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
/* read the first header, then loop until ono more headers */
|
||||
while ((status = fullRead(arFd, (char *) &rawArHeader, AR_BLOCK_SIZE))
|
||||
== AR_BLOCK_SIZE) {
|
||||
strncpy(entry->name, rawArHeader.name, 16);
|
||||
nameLength=strcspn(entry->name, " \\");
|
||||
entry->name[nameLength]='\0';
|
||||
parse_mode(rawArHeader.mode, &entry->mode);
|
||||
entry->mtime = atoi(rawArHeader.date);
|
||||
entry->uid = atoi(rawArHeader.uid);
|
||||
entry->gid = atoi(rawArHeader.gid);
|
||||
entry->size = (size_t) atoi(rawArHeader.size);
|
||||
entry->offset = initialOffset + (off_t) 60;
|
||||
|
||||
/* 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;
|
||||
nameLength = strcspn(entry->name, "/");
|
||||
|
||||
/* handle GNU style short filenames, strip trailing '/' */
|
||||
if (nameLength > 0)
|
||||
entry->name[nameLength]='\0';
|
||||
|
||||
/* handle GNU style long filenames */
|
||||
if (nameLength == 0) {
|
||||
/* escape from recursive call */
|
||||
if (entry->name[1]=='0')
|
||||
return(TRUE);
|
||||
|
||||
/* the data section contains the real filename */
|
||||
if (entry->name[1]=='/') {
|
||||
char tempName[MAX_NAME_LENGTH];
|
||||
|
||||
if (entry->size > MAX_NAME_LENGTH)
|
||||
entry->size = MAX_NAME_LENGTH;
|
||||
fullRead(srcFd, tempName, entry->size);
|
||||
tempName[entry->size-3]='\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;
|
||||
}
|
||||
/* read the second header for this entry */
|
||||
/* be carefull, this is recursive */
|
||||
if (readArEntry(srcFd, entry)==FALSE)
|
||||
return(FALSE);
|
||||
|
||||
if ((entry->name[0]='/') && (entry->name[1]='0'))
|
||||
strcpy(entry->name, tempName);
|
||||
else {
|
||||
errorMsg("Invalid long filename\n");
|
||||
return(FALSE);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* return the headerL_t struct for the specified filename
|
||||
*/
|
||||
static headerL_t *getHeaders(int srcFd, headerL_t *head, int funct)
|
||||
{
|
||||
#if defined BB_AR_EXPERIMENTAL_UNTAR
|
||||
int tar=FALSE;
|
||||
#endif
|
||||
int ar=FALSE;
|
||||
headerL_t *list;
|
||||
off_t initialOffset;
|
||||
|
||||
list = (headerL_t *) xmalloc(sizeof(headerL_t));
|
||||
initialOffset=lseek(srcFd, 0, SEEK_CUR);
|
||||
if (checkArMagic(srcFd)==TRUE)
|
||||
ar=TRUE;
|
||||
|
||||
#if defined BB_AR_EXPERIMENTAL_UNTAR
|
||||
if (checkTarMagic(srcFd)==TRUE)
|
||||
tar=TRUE;
|
||||
|
||||
if (tar==TRUE) {
|
||||
while(readTarHeader(srcFd, list)==TRUE) {
|
||||
off_t tarOffset;
|
||||
list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
|
||||
*list->next = *head;
|
||||
*head = *list;
|
||||
|
||||
/* recursive check for sub-archives */
|
||||
if ((funct & RECURSIVE) == RECURSIVE)
|
||||
head = getHeaders(srcFd, head, funct);
|
||||
tarOffset = (off_t) head->size/512;
|
||||
if ( head->size % 512 > 0)
|
||||
tarOffset++;
|
||||
tarOffset=tarOffset*512;
|
||||
lseek(srcFd, head->offset + tarOffset, SEEK_SET);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ar==TRUE) {
|
||||
lseek(srcFd, 8, SEEK_CUR);
|
||||
while(1) {
|
||||
if (readArEntry(srcFd, list) == FALSE) {
|
||||
lseek(srcFd, ++initialOffset, SEEK_CUR);
|
||||
if (readArEntry(srcFd, list) == FALSE)
|
||||
return(head);
|
||||
}
|
||||
list->next = (headerL_t *) xmalloc(sizeof(headerL_t));
|
||||
*list->next = *head;
|
||||
*head = *list;
|
||||
/* recursive check for sub-archives */
|
||||
if (funct & RECURSIVE)
|
||||
head = getHeaders(srcFd, head, funct);
|
||||
lseek(srcFd, head->offset + head->size, SEEK_SET);
|
||||
}
|
||||
}
|
||||
return(head);
|
||||
}
|
||||
|
||||
/*
|
||||
* find an entry in the linked list matching the filename
|
||||
*/
|
||||
static headerL_t *findEntry(headerL_t *head, const char *filename)
|
||||
{
|
||||
while(head->next != NULL) {
|
||||
if (strcmp(filename, head->name)==0)
|
||||
return(head);
|
||||
head=head->next;
|
||||
}
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
extern int ar_main(int argc, char **argv)
|
||||
{
|
||||
int funct = 0, ret=0, i=0;
|
||||
char *fileList[16], c, *opt_ptr;
|
||||
int funct = 0, opt=0;
|
||||
int srcFd=0, dstFd=0;
|
||||
headerL_t *header, *entry, *extractList;
|
||||
|
||||
if (argc < 2)
|
||||
usage(ar_usage);
|
||||
|
||||
opt_ptr = argv[1];
|
||||
if (*opt_ptr == '-')
|
||||
++opt_ptr;
|
||||
while ((c = *opt_ptr++) != '\0') {
|
||||
switch (c) {
|
||||
while ((opt = getopt(argc, argv, "ovtpxR")) != -1) {
|
||||
switch (opt) {
|
||||
case 'o':
|
||||
funct = funct | AR_PRESERVE_DATE;
|
||||
funct |= PRESERVE_DATE;
|
||||
break;
|
||||
case 'v':
|
||||
funct = funct | AR_VERBOSE;
|
||||
funct |= VERBOSE;
|
||||
break;
|
||||
case 't':
|
||||
funct = funct | AR_DISPLAY;
|
||||
funct |= DISPLAY;
|
||||
break;
|
||||
case 'x':
|
||||
funct = funct | AR_EXT_TO_FILE;
|
||||
funct |= EXT_TO_FILE;
|
||||
break;
|
||||
case 'p':
|
||||
funct = funct | AR_EXT_TO_STDOUT;
|
||||
funct |= EXT_TO_STDOUT;
|
||||
break;
|
||||
case 'R':
|
||||
funct |= RECURSIVE;
|
||||
break;
|
||||
default:
|
||||
usage(ar_usage);
|
||||
}
|
||||
}
|
||||
|
||||
/* check the src filename was specified */
|
||||
if (optind == argc)
|
||||
usage(ar_usage);
|
||||
|
||||
if ( (srcFd = open(argv[optind], O_RDONLY)) < 0)
|
||||
fatalError("Cannot read %s\n", argv[optind]);
|
||||
|
||||
for(i=0; i<(argc-2); i++)
|
||||
fileList[i]=argv[i+2];
|
||||
optind++;
|
||||
entry = (headerL_t *) xmalloc(sizeof(headerL_t));
|
||||
header = (headerL_t *) xmalloc(sizeof(headerL_t));
|
||||
extractList = (headerL_t *) xmalloc(sizeof(headerL_t));
|
||||
|
||||
header = getHeaders(srcFd, header, funct);
|
||||
/* find files to extract or display */
|
||||
if (optind<argc) {
|
||||
/* only handle specified files */
|
||||
while(optind < argc) {
|
||||
if ( (entry = findEntry(header, argv[optind])) != NULL) {
|
||||
entry->next = (headerL_t *) xmalloc(sizeof(headerL_t));
|
||||
*entry->next = *extractList;
|
||||
*extractList = *entry;
|
||||
}
|
||||
optind++;
|
||||
}
|
||||
}
|
||||
else
|
||||
extractList = header;
|
||||
|
||||
if (funct > 3)
|
||||
ret = readArFile(fileList, (argc-2), funct);
|
||||
|
||||
return (ret);
|
||||
while(extractList->next != NULL) {
|
||||
if (funct & EXT_TO_FILE) {
|
||||
if (isDirectory(extractList->name, TRUE, NULL)==FALSE)
|
||||
createPath(extractList->name, 0666);
|
||||
dstFd = open(extractList->name, O_WRONLY | O_CREAT, extractList->mode);
|
||||
lseek(srcFd, extractList->offset, SEEK_SET);
|
||||
copySubFile(srcFd, dstFd, (size_t) extractList->size);
|
||||
}
|
||||
if (funct & EXT_TO_STDOUT) {
|
||||
lseek(srcFd, extractList->offset, SEEK_SET);
|
||||
copySubFile(srcFd, fileno(stdout), (size_t) extractList->size);
|
||||
}
|
||||
if ( (funct & DISPLAY) || (funct & VERBOSE)) {
|
||||
if (funct & VERBOSE)
|
||||
printf("%s %d/%d %8d %s ", modeString(extractList->mode),
|
||||
extractList->uid, extractList->gid,
|
||||
extractList->size, timeString(extractList->mtime));
|
||||
printf("%s\n", extractList->name);
|
||||
}
|
||||
extractList=extractList->next;
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
+31
-37
@@ -27,22 +27,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <getopt.h>
|
||||
|
||||
static const char gunzip_usage[] =
|
||||
"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"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
/* These defines are very important for BusyBox. Without these,
|
||||
/* 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
|
||||
@@ -106,7 +94,6 @@ static char *license_msg[] = {
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* #include "tailor.h" */
|
||||
@@ -212,7 +199,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(memory_exhausted, "gunzip"); \
|
||||
if (array == NULL) errorMsg(memory_exhausted); \
|
||||
}
|
||||
# define FREE(array) {if (array != NULL) free(array), array=NULL;}
|
||||
#else
|
||||
@@ -377,9 +364,6 @@ extern void flush_outbuf (void);
|
||||
static void flush_window (void);
|
||||
extern void write_buf (int fd, void * buf, unsigned cnt);
|
||||
|
||||
#ifndef __linux__
|
||||
static char *basename (char *fname);
|
||||
#endif /* not __linux__ */
|
||||
void read_error_msg (void);
|
||||
void write_error_msg (void);
|
||||
|
||||
@@ -581,45 +565,56 @@ local int get_method (int in);
|
||||
int gunzip_main(int argc, char **argv)
|
||||
{
|
||||
int file_count; /* number of files to precess */
|
||||
int to_stdout = 0;
|
||||
int tostdout = 0;
|
||||
int fromstdin = 0;
|
||||
int result;
|
||||
int inFileNum;
|
||||
int outFileNum;
|
||||
int delInputFile = 0;
|
||||
int force = 0;
|
||||
struct stat statBuf;
|
||||
char *delFileName;
|
||||
char ifname[MAX_PATH_LEN + 1]; /* input file name */
|
||||
char ofname[MAX_PATH_LEN + 1]; /* output file name */
|
||||
|
||||
if (strcmp(*argv, "zcat") == 0) {
|
||||
to_stdout = 1;
|
||||
if (argc == 1) {
|
||||
fromstdin = 1;
|
||||
}
|
||||
if (strcmp(applet_name, "zcat") == 0) {
|
||||
force = 1;
|
||||
tostdout = 1;
|
||||
}
|
||||
|
||||
/* Parse any options */
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
if (*((*argv) + 1) == '\0') {
|
||||
fromstdin = 1;
|
||||
to_stdout = 1;
|
||||
tostdout = 1;
|
||||
}
|
||||
while (*(++(*argv))) {
|
||||
switch (**argv) {
|
||||
case 'c':
|
||||
to_stdout = 1;
|
||||
tostdout = 1;
|
||||
break;
|
||||
case 't':
|
||||
test_mode = 1;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
force = 1;
|
||||
break;
|
||||
default:
|
||||
usage(gunzip_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argc <= 0) {
|
||||
tostdout = 1;
|
||||
fromstdin = 1;
|
||||
}
|
||||
|
||||
if (isatty(fileno(stdin)) && fromstdin==1 && force==0)
|
||||
fatalError( "data not read from terminal. Use -f to force it.\n");
|
||||
if (isatty(fileno(stdout)) && tostdout==1 && force==0)
|
||||
fatalError( "data not written to terminal. Use -f to force it.\n");
|
||||
|
||||
|
||||
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
||||
if (foreground) {
|
||||
(void) signal(SIGINT, (sig_type) abort_gzip);
|
||||
@@ -656,10 +651,10 @@ int gunzip_main(int argc, char **argv)
|
||||
ifile_size = -1L; /* convention for unknown size */
|
||||
} else {
|
||||
/* Open up the input file */
|
||||
if (*argv == '\0')
|
||||
if (argc <= 0)
|
||||
usage(gunzip_usage);
|
||||
if (strlen(*argv) > MAX_PATH_LEN) {
|
||||
fprintf(stderr, name_too_long, "gunzip");
|
||||
errorMsg(name_too_long);
|
||||
exit(WARNING);
|
||||
}
|
||||
strcpy(ifname, *argv);
|
||||
@@ -679,7 +674,7 @@ int gunzip_main(int argc, char **argv)
|
||||
ifile_size = statBuf.st_size;
|
||||
}
|
||||
|
||||
if (to_stdout == 1) {
|
||||
if (tostdout == 1) {
|
||||
/* And get to work */
|
||||
strcpy(ofname, "stdout");
|
||||
outFileNum = fileno(stdout);
|
||||
@@ -698,7 +693,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");
|
||||
errorMsg(name_too_long);
|
||||
exit(WARNING);
|
||||
}
|
||||
strcpy(ofname, ifname);
|
||||
@@ -753,7 +748,7 @@ int gunzip_main(int argc, char **argv)
|
||||
|
||||
/* ========================================================================
|
||||
* Check the magic number of the input file and update ofname if an
|
||||
* original name was given and to_stdout is not set.
|
||||
* original name was given and tostdout is not set.
|
||||
* Return the compression method, -1 for error, -2 for warning.
|
||||
* Set inptr to the offset of the next byte to be processed.
|
||||
* Updates time_stamp if there is one and --no-time is not used.
|
||||
@@ -780,8 +775,7 @@ int in; /* input file descriptor */
|
||||
|
||||
method = (int) get_byte();
|
||||
if (method != DEFLATED) {
|
||||
fprintf(stderr,
|
||||
"unknown method %d -- get newer version of gzip\n",
|
||||
errorMsg("unknown method %d -- get newer version of gzip\n",
|
||||
method);
|
||||
exit_code = ERROR;
|
||||
return -1;
|
||||
@@ -930,7 +924,7 @@ int in, out; /* input and output file descriptors */
|
||||
int res = inflate();
|
||||
|
||||
if (res == 3) {
|
||||
errorMsg(memory_exhausted, "gunzip");
|
||||
errorMsg(memory_exhausted);
|
||||
} else if (res != 0) {
|
||||
errorMsg("invalid compressed data--format violated");
|
||||
}
|
||||
|
||||
+21
-22
@@ -29,7 +29,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_memory_exhausted
|
||||
#include "messages.c"
|
||||
@@ -40,19 +40,6 @@
|
||||
#define SMALL_MEM
|
||||
#define DYN_ALLOC
|
||||
|
||||
|
||||
static const char gzip_usage[] =
|
||||
"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"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
/* I don't like nested includes, but the string and io functions are used
|
||||
* too often
|
||||
*/
|
||||
@@ -127,7 +114,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(memory_exhausted, "gzip"); \
|
||||
if (array == NULL) errorMsg(memory_exhausted); \
|
||||
}
|
||||
# define FREE(array) {if (array != NULL) free(array), array=NULL;}
|
||||
#else
|
||||
@@ -1622,7 +1609,6 @@ ulg deflate()
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* configuration */
|
||||
@@ -1814,14 +1800,11 @@ int gzip_main(int argc, char **argv)
|
||||
char *delFileName;
|
||||
int tostdout = 0;
|
||||
int fromstdin = 0;
|
||||
|
||||
if (argc == 1)
|
||||
usage(gzip_usage);
|
||||
int force = 0;
|
||||
|
||||
/* Parse any options */
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
if (*((*argv) + 1) == '\0') {
|
||||
fromstdin = 1;
|
||||
tostdout = 1;
|
||||
}
|
||||
while (*(++(*argv))) {
|
||||
@@ -1829,11 +1812,27 @@ int gzip_main(int argc, char **argv)
|
||||
case 'c':
|
||||
tostdout = 1;
|
||||
break;
|
||||
case 'f':
|
||||
force = 1;
|
||||
break;
|
||||
/* Ignore 1-9 (compression level) options */
|
||||
case '1': case '2': case '3': case '4': case '5':
|
||||
case '6': case '7': case '8': case '9':
|
||||
break;
|
||||
default:
|
||||
usage(gzip_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (argc <= 0 ) {
|
||||
fromstdin = 1;
|
||||
tostdout = 1;
|
||||
}
|
||||
|
||||
if (isatty(fileno(stdin)) && fromstdin==1 && force==0)
|
||||
fatalError( "data not read from terminal. Use -f to force it.\n");
|
||||
if (isatty(fileno(stdout)) && tostdout==1 && force==0)
|
||||
fatalError( "data not written to terminal. Use -f to force it.\n");
|
||||
|
||||
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
||||
if (foreground) {
|
||||
@@ -1873,7 +1872,7 @@ int gzip_main(int argc, char **argv)
|
||||
ifile_size = -1L; /* convention for unknown size */
|
||||
} else {
|
||||
/* Open up the input file */
|
||||
if (*argv == '\0')
|
||||
if (argc <= 0)
|
||||
usage(gzip_usage);
|
||||
strncpy(ifname, *argv, MAX_PATH_LEN);
|
||||
|
||||
@@ -3251,7 +3250,7 @@ char *env; /* name of environment variable */
|
||||
nargv = (char **) calloc(*argcp + 1, sizeof(char *));
|
||||
|
||||
if (nargv == NULL)
|
||||
errorMsg(memory_exhausted, "gzip");
|
||||
errorMsg(memory_exhausted);
|
||||
oargv = *argvp;
|
||||
*argvp = nargv;
|
||||
|
||||
|
||||
+178
-155
@@ -36,9 +36,10 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_io_error
|
||||
#define bb_need_name_longer_then_foo
|
||||
#include "messages.c"
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
@@ -49,37 +50,7 @@
|
||||
#include <utime.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysmacros.h>
|
||||
|
||||
|
||||
static const char tar_usage[] =
|
||||
#ifdef BB_FEATURE_TAR_CREATE
|
||||
"tar -[cxtvO] "
|
||||
#else
|
||||
"tar -[xtvO] "
|
||||
#endif
|
||||
#if defined BB_FEATURE_TAR_EXCLUDE
|
||||
"[--exclude File] "
|
||||
#endif
|
||||
"[-f tarFile] [FILE] ...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCreate, extract, or list files from a tar file. Note that\n"
|
||||
"this version of tar treats hard links as separate files.\n\n"
|
||||
"Main operation mode:\n"
|
||||
#ifdef BB_FEATURE_TAR_CREATE
|
||||
"\tc\t\tcreate\n"
|
||||
#endif
|
||||
"\tx\t\textract\n"
|
||||
"\tt\t\tlist\n"
|
||||
"\nFile selection:\n"
|
||||
"\tf\t\tname of tarfile or \"-\" for stdin\n"
|
||||
"\tO\t\textract to stdout\n"
|
||||
#if defined BB_FEATURE_TAR_EXCLUDE
|
||||
"\t--exclude\tfile to exclude\n"
|
||||
#endif
|
||||
"\nInformative output:\n"
|
||||
"\tv\t\tverbosely list files processed\n"
|
||||
#endif
|
||||
;
|
||||
#include <getopt.h>
|
||||
|
||||
/* Tar file constants */
|
||||
#ifndef MAJOR
|
||||
@@ -87,12 +58,13 @@ static const char tar_usage[] =
|
||||
#define MINOR(dev) ((dev)&0xff)
|
||||
#endif
|
||||
|
||||
#define NAME_SIZE 100
|
||||
|
||||
/* POSIX tar Header Block, from POSIX 1003.1-1990 */
|
||||
struct TarHeader
|
||||
{
|
||||
/* byte offset */
|
||||
char name[100]; /* 0-99 */
|
||||
char name[NAME_SIZE]; /* 0-99 */
|
||||
char mode[8]; /* 100-107 */
|
||||
char uid[8]; /* 108-115 */
|
||||
char gid[8]; /* 116-123 */
|
||||
@@ -100,7 +72,7 @@ struct TarHeader
|
||||
char mtime[12]; /* 136-147 */
|
||||
char chksum[8]; /* 148-155 */
|
||||
char typeflag; /* 156-156 */
|
||||
char linkname[100]; /* 157-256 */
|
||||
char linkname[NAME_SIZE]; /* 157-256 */
|
||||
char magic[6]; /* 257-262 */
|
||||
char version[2]; /* 263-264 */
|
||||
char uname[32]; /* 265-296 */
|
||||
@@ -132,6 +104,8 @@ enum TarFileType
|
||||
DIRTYPE = '5', /* directory */
|
||||
FIFOTYPE = '6', /* FIFO special */
|
||||
CONTTYPE = '7', /* reserved */
|
||||
GNULONGLINK = 'K', /* GNU long (>100 chars) link name */
|
||||
GNULONGNAME = 'L', /* GNU long (>100 chars) file name */
|
||||
};
|
||||
typedef enum TarFileType TarFileType;
|
||||
|
||||
@@ -156,7 +130,8 @@ typedef struct TarInfo TarInfo;
|
||||
|
||||
/* Local procedures to restore files from a tar file. */
|
||||
static int readTarFile(const char* tarName, int extractFlag, int listFlag,
|
||||
int tostdoutFlag, int verboseFlag, char** excludeList);
|
||||
int tostdoutFlag, int verboseFlag, char** extractList,
|
||||
char** excludeList);
|
||||
|
||||
|
||||
|
||||
@@ -166,7 +141,6 @@ static int writeTarFile(const char* tarName, int tostdoutFlag,
|
||||
int verboseFlag, int argc, char **argv, char** excludeList);
|
||||
#endif
|
||||
|
||||
|
||||
extern int tar_main(int argc, char **argv)
|
||||
{
|
||||
char** excludeList=NULL;
|
||||
@@ -179,16 +153,42 @@ extern int tar_main(int argc, char **argv)
|
||||
int createFlag = FALSE;
|
||||
int verboseFlag = FALSE;
|
||||
int tostdoutFlag = FALSE;
|
||||
int firstOpt = TRUE;
|
||||
int stopIt;
|
||||
|
||||
|
||||
if (argc <= 1)
|
||||
usage(tar_usage);
|
||||
|
||||
/* Parse any options */
|
||||
while (--argc > 0 && strspn(*(++argv), "-cxt") >0 ) {
|
||||
/* do normal option parsing */
|
||||
while (--argc > 0 && ((*argv && **(++argv) == '-') ||
|
||||
(firstOpt==TRUE && strspn(*argv, "-cxt") ))) {
|
||||
firstOpt=FALSE;
|
||||
stopIt=FALSE;
|
||||
while (stopIt==FALSE && *argv && **argv) {
|
||||
switch (**argv) {
|
||||
case 'c':
|
||||
if (extractFlag == TRUE || listFlag == TRUE)
|
||||
goto flagError;
|
||||
createFlag = TRUE;
|
||||
break;
|
||||
case 'x':
|
||||
if (listFlag == TRUE || createFlag == TRUE)
|
||||
goto flagError;
|
||||
extractFlag = TRUE;
|
||||
break;
|
||||
case 't':
|
||||
if (extractFlag == TRUE || createFlag == TRUE)
|
||||
goto flagError;
|
||||
listFlag = TRUE;
|
||||
break;
|
||||
case 'v':
|
||||
verboseFlag = TRUE;
|
||||
break;
|
||||
case 'O':
|
||||
tostdoutFlag = TRUE;
|
||||
tarName = "-";
|
||||
break;
|
||||
case 'f':
|
||||
if (--argc == 0) {
|
||||
fatalError( "Option requires an argument: No file specified\n");
|
||||
@@ -198,64 +198,31 @@ extern int tar_main(int argc, char **argv)
|
||||
tarName = *(++argv);
|
||||
if (tarName == NULL)
|
||||
fatalError( "Option requires an argument: No file specified\n");
|
||||
if (!strcmp(tarName, "-"))
|
||||
if (!strcmp(tarName, "-") && createFlag == TRUE)
|
||||
tostdoutFlag = TRUE;
|
||||
stopIt=TRUE;
|
||||
break;
|
||||
|
||||
case 't':
|
||||
if (extractFlag == TRUE || createFlag == TRUE)
|
||||
goto flagError;
|
||||
listFlag = TRUE;
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
if (listFlag == TRUE || createFlag == TRUE)
|
||||
goto flagError;
|
||||
extractFlag = TRUE;
|
||||
break;
|
||||
case 'c':
|
||||
if (extractFlag == TRUE || listFlag == TRUE)
|
||||
goto flagError;
|
||||
createFlag = TRUE;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
verboseFlag = TRUE;
|
||||
break;
|
||||
|
||||
case 'O':
|
||||
tostdoutFlag = TRUE;
|
||||
tarName = "-";
|
||||
break;
|
||||
case '-':
|
||||
#if defined BB_FEATURE_TAR_EXCLUDE
|
||||
case 'e':
|
||||
if (strcmp(*argv, "-exclude")==0) {
|
||||
if (--argc == 0) {
|
||||
fatalError( "Option requires an argument: No file specified\n");
|
||||
}
|
||||
excludeList=realloc( excludeList, sizeof(char**) * (excludeListSize+2));
|
||||
excludeList=xrealloc( excludeList, sizeof(char**) * (excludeListSize+2));
|
||||
excludeList[excludeListSize] = *(++argv);
|
||||
/* Remove leading "/"s */
|
||||
if (*excludeList[excludeListSize] =='/') {
|
||||
if (*excludeList[excludeListSize] =='/')
|
||||
excludeList[excludeListSize] = (excludeList[excludeListSize])+1;
|
||||
}
|
||||
if (excludeList[excludeListSize++] == NULL)
|
||||
fatalError( "Option requires an argument: No file specified\n");
|
||||
/* Tack a NULL onto the end of the list */
|
||||
excludeList[excludeListSize] = NULL;
|
||||
excludeList[++excludeListSize] = NULL;
|
||||
stopIt=TRUE;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if (strcmp(*argv, "-help")==0) {
|
||||
usage(tar_usage);
|
||||
}
|
||||
break;
|
||||
|
||||
case '-':
|
||||
break;
|
||||
default:
|
||||
fatalError( "Unknown tar flag '%c'\n"
|
||||
"Try `tar --help' for more information\n", **argv);
|
||||
usage(tar_usage);
|
||||
}
|
||||
++(*argv);
|
||||
}
|
||||
@@ -273,7 +240,7 @@ extern int tar_main(int argc, char **argv)
|
||||
#endif
|
||||
}
|
||||
if (listFlag == TRUE || extractFlag == TRUE) {
|
||||
exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag, verboseFlag, excludeList));
|
||||
exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag, verboseFlag, &argv[optind], excludeList));
|
||||
}
|
||||
|
||||
flagError:
|
||||
@@ -330,7 +297,7 @@ tarExtractRegularFile(TarInfo *header, int extractFlag, int tostdoutFlag)
|
||||
}
|
||||
if ( (readSize = fullRead(header->tarFd, buffer, readSize)) <= 0 ) {
|
||||
/* Tarball seems to have a problem */
|
||||
errorMsg("tar: Unexpected EOF in archive\n");
|
||||
errorMsg("Unexpected EOF in archive\n");
|
||||
return( FALSE);
|
||||
}
|
||||
if ( readSize < writeSize )
|
||||
@@ -368,7 +335,7 @@ tarExtractDirectory(TarInfo *header, int extractFlag, int tostdoutFlag)
|
||||
return( TRUE);
|
||||
|
||||
if (createPath(header->name, header->mode) != TRUE) {
|
||||
errorMsg("tar: %s: Cannot mkdir: %s\n",
|
||||
errorMsg("%s: Cannot mkdir: %s\n",
|
||||
header->name, strerror(errno));
|
||||
return( FALSE);
|
||||
}
|
||||
@@ -388,7 +355,7 @@ tarExtractHardLink(TarInfo *header, int extractFlag, int tostdoutFlag)
|
||||
return( TRUE);
|
||||
|
||||
if (link(header->linkname, header->name) < 0) {
|
||||
errorMsg("tar: %s: Cannot create hard link to '%s': %s\n",
|
||||
errorMsg("%s: Cannot create hard link to '%s': %s\n",
|
||||
header->name, header->linkname, strerror(errno));
|
||||
return( FALSE);
|
||||
}
|
||||
@@ -406,7 +373,7 @@ tarExtractSymLink(TarInfo *header, int extractFlag, int tostdoutFlag)
|
||||
|
||||
#ifdef S_ISLNK
|
||||
if (symlink(header->linkname, header->name) < 0) {
|
||||
errorMsg("tar: %s: Cannot create symlink to '%s': %s\n",
|
||||
errorMsg("%s: Cannot create symlink to '%s': %s\n",
|
||||
header->name, header->linkname, strerror(errno));
|
||||
return( FALSE);
|
||||
}
|
||||
@@ -421,7 +388,7 @@ tarExtractSymLink(TarInfo *header, int extractFlag, int tostdoutFlag)
|
||||
/* Do not change permissions or date on symlink,
|
||||
* since it changes the pointed to file instead. duh. */
|
||||
#else
|
||||
errorMsg("tar: %s: Cannot create symlink to '%s': %s\n",
|
||||
errorMsg("%s: Cannot create symlink to '%s': %s\n",
|
||||
header->name, header->linkname,
|
||||
"symlinks not supported");
|
||||
#endif
|
||||
@@ -436,13 +403,13 @@ tarExtractSpecial(TarInfo *header, int extractFlag, int tostdoutFlag)
|
||||
|
||||
if (S_ISCHR(header->mode) || S_ISBLK(header->mode) || S_ISSOCK(header->mode)) {
|
||||
if (mknod(header->name, header->mode, makedev(header->devmajor, header->devminor)) < 0) {
|
||||
errorMsg("tar: %s: Cannot mknod: %s\n",
|
||||
errorMsg("%s: Cannot mknod: %s\n",
|
||||
header->name, strerror(errno));
|
||||
return( FALSE);
|
||||
}
|
||||
} else if (S_ISFIFO(header->mode)) {
|
||||
if (mkfifo(header->name, header->mode) < 0) {
|
||||
errorMsg("tar: %s: Cannot mkfifo: %s\n",
|
||||
errorMsg("%s: Cannot mkfifo: %s\n",
|
||||
header->name, strerror(errno));
|
||||
return( FALSE);
|
||||
}
|
||||
@@ -490,7 +457,7 @@ readTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
|
||||
++*(header->name);
|
||||
|
||||
if (alreadyWarned == FALSE) {
|
||||
errorMsg("tar: Removing leading '/' from member names\n");
|
||||
errorMsg("Removing leading '/' from member names\n");
|
||||
alreadyWarned = TRUE;
|
||||
}
|
||||
}
|
||||
@@ -528,15 +495,15 @@ readTarHeader(struct TarHeader *rawHeader, struct TarInfo *header)
|
||||
* If the list is empty than all files are extracted or listed.
|
||||
*/
|
||||
static int readTarFile(const char* tarName, int extractFlag, int listFlag,
|
||||
int tostdoutFlag, int verboseFlag, char** excludeList)
|
||||
int tostdoutFlag, int verboseFlag, char** extractList,
|
||||
char** excludeList)
|
||||
{
|
||||
int status, tarFd=-1;
|
||||
int errorFlag=FALSE;
|
||||
int skipNextHeaderFlag=FALSE;
|
||||
TarHeader rawHeader;
|
||||
TarInfo header;
|
||||
#if defined BB_FEATURE_TAR_EXCLUDE
|
||||
char** tmpList;
|
||||
#endif
|
||||
|
||||
/* Open the tar file for reading. */
|
||||
if (!strcmp(tarName, "-"))
|
||||
@@ -555,7 +522,7 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
|
||||
/* Read the tar file, and iterate over it one file at a time */
|
||||
while ( (status = fullRead(tarFd, (char*)&rawHeader, TAR_BLOCK_SIZE)) == TAR_BLOCK_SIZE ) {
|
||||
|
||||
/* First, try to read the header */
|
||||
/* Try to read the header */
|
||||
if ( readTarHeader(&rawHeader, &header) == FALSE ) {
|
||||
if ( *(header.name) == '\0' ) {
|
||||
goto endgame;
|
||||
@@ -569,6 +536,19 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
|
||||
goto endgame;
|
||||
header.tarFd = tarFd;
|
||||
|
||||
/* Skip funky extra GNU headers that precede long files */
|
||||
if ( (header.type == GNULONGNAME) || (header.type == GNULONGLINK) ) {
|
||||
skipNextHeaderFlag=TRUE;
|
||||
tarExtractRegularFile(&header, FALSE, FALSE);
|
||||
continue;
|
||||
}
|
||||
if ( skipNextHeaderFlag == TRUE ) {
|
||||
skipNextHeaderFlag=FALSE;
|
||||
errorMsg(name_longer_then_foo, NAME_SIZE);
|
||||
tarExtractRegularFile(&header, FALSE, FALSE);
|
||||
continue;
|
||||
}
|
||||
|
||||
#if defined BB_FEATURE_TAR_EXCLUDE
|
||||
{
|
||||
int skipFlag=FALSE;
|
||||
@@ -595,63 +575,89 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
/* Special treatment if the list (-t) flag is on */
|
||||
if (verboseFlag == TRUE && extractFlag == FALSE) {
|
||||
int len, len1;
|
||||
char buf[35];
|
||||
struct tm *tm = localtime (&(header.mtime));
|
||||
|
||||
len=printf("%s ", modeString(header.mode));
|
||||
memset(buf, 0, 8*sizeof(char));
|
||||
my_getpwuid(buf, header.uid);
|
||||
if (! *buf)
|
||||
len+=printf("%d", header.uid);
|
||||
else
|
||||
len+=printf("%s", buf);
|
||||
memset(buf, 0, 8*sizeof(char));
|
||||
my_getgrgid(buf, header.gid);
|
||||
if (! *buf)
|
||||
len+=printf("/%-d ", header.gid);
|
||||
else
|
||||
len+=printf("/%-s ", buf);
|
||||
|
||||
if (header.type==CHRTYPE || header.type==BLKTYPE) {
|
||||
len1=snprintf(buf, sizeof(buf), "%ld,%-ld ",
|
||||
header.devmajor, header.devminor);
|
||||
} else {
|
||||
len1=snprintf(buf, sizeof(buf), "%lu ", (long)header.size);
|
||||
if (*extractList != NULL) {
|
||||
int skipFlag = TRUE;
|
||||
for (tmpList = extractList; *tmpList != NULL; tmpList++) {
|
||||
if (strncmp( *tmpList, header.name, strlen(*tmpList))==0 || (
|
||||
header.name[strlen(header.name)-1]=='/'
|
||||
&& strncmp( *tmpList, header.name,
|
||||
MIN(strlen(header.name)-1, strlen(*tmpList)))==0)) {
|
||||
/* If it is a regular file, pretend to extract it with
|
||||
* the extractFlag set to FALSE, so the junk in the tarball
|
||||
* is properly skipped over */
|
||||
skipFlag = FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* Jump through some hoops to make the columns match up */
|
||||
for(;(len+len1)<31;len++)
|
||||
printf(" ");
|
||||
printf(buf);
|
||||
|
||||
/* Use ISO 8610 time format */
|
||||
if (tm) {
|
||||
printf ("%04d-%02d-%02d %02d:%02d:%02d ",
|
||||
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
|
||||
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
||||
/* There are not the droids you're looking for, move along */
|
||||
if (skipFlag == TRUE) {
|
||||
if ( header.type==REGTYPE || header.type==REGTYPE0 )
|
||||
tarExtractRegularFile(&header, FALSE, FALSE);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/* List contents if we are supposed to do that */
|
||||
if (verboseFlag == TRUE || listFlag == TRUE) {
|
||||
/* Now the normal listing */
|
||||
|
||||
if (listFlag == TRUE) {
|
||||
/* Special treatment if the list (-t) flag is on */
|
||||
if (verboseFlag == TRUE) {
|
||||
int len, len1;
|
||||
char buf[35];
|
||||
struct tm *tm = localtime (&(header.mtime));
|
||||
|
||||
len=printf("%s ", modeString(header.mode));
|
||||
memset(buf, 0, 8*sizeof(char));
|
||||
my_getpwuid(buf, header.uid);
|
||||
if (! *buf)
|
||||
len+=printf("%d", header.uid);
|
||||
else
|
||||
len+=printf("%s", buf);
|
||||
memset(buf, 0, 8*sizeof(char));
|
||||
my_getgrgid(buf, header.gid);
|
||||
if (! *buf)
|
||||
len+=printf("/%-d ", header.gid);
|
||||
else
|
||||
len+=printf("/%-s ", buf);
|
||||
|
||||
if (header.type==CHRTYPE || header.type==BLKTYPE) {
|
||||
len1=snprintf(buf, sizeof(buf), "%ld,%-ld ",
|
||||
header.devmajor, header.devminor);
|
||||
} else {
|
||||
len1=snprintf(buf, sizeof(buf), "%lu ", (long)header.size);
|
||||
}
|
||||
/* Jump through some hoops to make the columns match up */
|
||||
for(;(len+len1)<31;len++)
|
||||
printf(" ");
|
||||
printf(buf);
|
||||
|
||||
/* Use ISO 8610 time format */
|
||||
if (tm) {
|
||||
printf ("%04d-%02d-%02d %02d:%02d:%02d ",
|
||||
tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
|
||||
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
||||
}
|
||||
}
|
||||
printf("%s", header.name);
|
||||
}
|
||||
if (verboseFlag == TRUE && listFlag == TRUE) {
|
||||
/* If this is a link, say so */
|
||||
if (header.type==LNKTYPE)
|
||||
printf(" link to %s", header.linkname);
|
||||
else if (header.type==SYMTYPE)
|
||||
printf(" -> %s", header.linkname);
|
||||
}
|
||||
if (verboseFlag == TRUE || listFlag == TRUE) {
|
||||
if (verboseFlag == TRUE) {
|
||||
if (header.type==LNKTYPE) /* If this is a link, say so */
|
||||
printf(" link to %s", header.linkname);
|
||||
else if (header.type==SYMTYPE)
|
||||
printf(" -> %s", header.linkname);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/* Remove any clutter lying in our way */
|
||||
if (extractFlag == TRUE) /* .. but only if we are extracting (as */
|
||||
unlink( header.name); /* opposed to listing) (rob@sysgo.de) */
|
||||
/* List contents if we are supposed to do that */
|
||||
if (verboseFlag == TRUE && extractFlag == TRUE) {
|
||||
/* Now the normal listing */
|
||||
FILE *vbFd = stdout;
|
||||
if (tostdoutFlag == TRUE) // If the archive goes to stdout, verbose to stderr
|
||||
vbFd = stderr;
|
||||
fprintf(vbFd, "%s\n", header.name);
|
||||
}
|
||||
|
||||
/* Remove files if we would overwrite them */
|
||||
if (extractFlag == TRUE && tostdoutFlag == FALSE)
|
||||
unlink(header.name);
|
||||
|
||||
/* If we got here, we can be certain we have a legitimate
|
||||
* header to work with. So work with it. */
|
||||
@@ -683,7 +689,15 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
|
||||
if (tarExtractSpecial( &header, extractFlag, tostdoutFlag)==FALSE)
|
||||
errorFlag=TRUE;
|
||||
break;
|
||||
#if 0
|
||||
/* Handled earlier */
|
||||
case GNULONGNAME:
|
||||
case GNULONGLINK:
|
||||
skipNextHeaderFlag=TRUE;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
errorMsg("Unknown file type '%c' in tar file\n", header.type);
|
||||
close( tarFd);
|
||||
return( FALSE);
|
||||
}
|
||||
@@ -695,7 +709,7 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
|
||||
return ( FALSE);
|
||||
}
|
||||
else if (errorFlag==TRUE) {
|
||||
errorMsg( "tar: Error exit delayed from previous errors\n");
|
||||
errorMsg( "Error exit delayed from previous errors\n");
|
||||
return( FALSE);
|
||||
} else
|
||||
return( status);
|
||||
@@ -705,7 +719,7 @@ endgame:
|
||||
close( tarFd);
|
||||
if ( *(header.name) == '\0' ) {
|
||||
if (errorFlag==TRUE)
|
||||
errorMsg( "tar: Error exit delayed from previous errors\n");
|
||||
errorMsg( "Error exit delayed from previous errors\n");
|
||||
else
|
||||
return( TRUE);
|
||||
}
|
||||
@@ -776,13 +790,13 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
|
||||
#endif
|
||||
const unsigned char *cp = (const unsigned char *) &header;
|
||||
ssize_t size = sizeof(struct TarHeader);
|
||||
|
||||
|
||||
memset( &header, 0, size);
|
||||
|
||||
if (*fileName=='/') {
|
||||
static int alreadyWarned=FALSE;
|
||||
if (alreadyWarned==FALSE) {
|
||||
errorMsg("tar: Removing leading '/' from member names\n");
|
||||
errorMsg("Removing leading '/' from member names\n");
|
||||
alreadyWarned=TRUE;
|
||||
}
|
||||
strncpy(header.name, fileName+1, sizeof(header.name));
|
||||
@@ -854,7 +868,7 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
|
||||
header.typeflag = REGTYPE;
|
||||
putOctal(header.size, sizeof(header.size), statbuf->st_size);
|
||||
} else {
|
||||
errorMsg("tar: %s: Unknown file type\n", fileName);
|
||||
errorMsg("%s: Unknown file type\n", fileName);
|
||||
return ( FALSE);
|
||||
}
|
||||
|
||||
@@ -879,8 +893,12 @@ writeTarHeader(struct TarBallInfo *tbInfo, const char *fileName, struct stat *st
|
||||
write(tbInfo->tarFd, "\0", 1);
|
||||
}
|
||||
/* Now do the verbose thing (or not) */
|
||||
if (tbInfo->verboseFlag==TRUE)
|
||||
fprintf(stdout, "%s\n", header.name);
|
||||
if (tbInfo->verboseFlag==TRUE) {
|
||||
FILE *vbFd = stdout;
|
||||
if (tbInfo->tarFd == fileno(stdout)) // If the archive goes to stdout, verbose to stderr
|
||||
vbFd = stderr;
|
||||
fprintf(vbFd, "%s\n", header.name);
|
||||
}
|
||||
|
||||
return ( TRUE);
|
||||
}
|
||||
@@ -892,7 +910,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void*
|
||||
|
||||
/* It is against the rules to archive a socket */
|
||||
if (S_ISSOCK(statbuf->st_mode)) {
|
||||
errorMsg("tar: %s: socket ignored\n", fileName);
|
||||
errorMsg("%s: socket ignored\n", fileName);
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
@@ -901,10 +919,15 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void*
|
||||
* the new tarball */
|
||||
if (tbInfo->statBuf.st_dev == statbuf->st_dev &&
|
||||
tbInfo->statBuf.st_ino == statbuf->st_ino) {
|
||||
errorMsg("tar: %s: file is the archive; skipping\n", fileName);
|
||||
errorMsg("%s: file is the archive; skipping\n", fileName);
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
if (strlen(fileName) >= NAME_SIZE) {
|
||||
errorMsg(name_longer_then_foo, NAME_SIZE);
|
||||
return ( TRUE);
|
||||
}
|
||||
|
||||
if (writeTarHeader(tbInfo, fileName, statbuf)==FALSE) {
|
||||
return( FALSE);
|
||||
}
|
||||
@@ -917,7 +940,7 @@ static int writeFileToTarball(const char *fileName, struct stat *statbuf, void*
|
||||
|
||||
/* open the file we want to archive, and make sure all is well */
|
||||
if ((inputFileFd = open(fileName, O_RDONLY)) < 0) {
|
||||
errorMsg("tar: %s: Cannot open: %s\n", fileName, strerror(errno));
|
||||
errorMsg("%s: Cannot open: %s\n", fileName, strerror(errno));
|
||||
return( FALSE);
|
||||
}
|
||||
|
||||
@@ -955,7 +978,7 @@ static int writeTarFile(const char* tarName, int tostdoutFlag,
|
||||
|
||||
/* Make sure there is at least one file to tar up. */
|
||||
if (argc <= 0)
|
||||
fatalError("tar: Cowardly refusing to create an empty archive\n");
|
||||
fatalError("Cowardly refusing to create an empty archive\n");
|
||||
|
||||
/* Open the tar file for writing. */
|
||||
if (tostdoutFlag == TRUE)
|
||||
@@ -963,7 +986,7 @@ static int writeTarFile(const char* tarName, int tostdoutFlag,
|
||||
else
|
||||
tbInfo.tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0644);
|
||||
if (tbInfo.tarFd < 0) {
|
||||
errorMsg( "tar: Error opening '%s': %s\n", tarName, strerror(errno));
|
||||
errorMsg( "Error opening '%s': %s\n", tarName, strerror(errno));
|
||||
return ( FALSE);
|
||||
}
|
||||
tbInfo.excludeList=excludeList;
|
||||
@@ -997,7 +1020,7 @@ static int writeTarFile(const char* tarName, int tostdoutFlag,
|
||||
/* Hang up the tools, close up shop, head home */
|
||||
close(tarFd);
|
||||
if (errorFlag == TRUE) {
|
||||
errorMsg("tar: Error exit delayed from previous errors\n");
|
||||
errorMsg("Error exit delayed from previous errors\n");
|
||||
return(FALSE);
|
||||
}
|
||||
return( TRUE);
|
||||
|
||||
+1
-9
@@ -21,17 +21,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.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;
|
||||
|
||||
@@ -1,364 +1,375 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
static int been_there_done_that = 0;
|
||||
#define bb_need_full_version
|
||||
#define BB_DECLARE_EXTERN
|
||||
#include "messages.c"
|
||||
|
||||
/* It has been alledged that doing such things can
|
||||
* help reduce binary size when staticly linking,
|
||||
* of course with glibc, this is unlikely as long
|
||||
* as we use things like printf -- perhaps a printf
|
||||
* replacement may be in order
|
||||
*/
|
||||
#if 0
|
||||
void exit(int status) __attribute__ ((noreturn));
|
||||
void exit(int status)
|
||||
{
|
||||
_exit(status);
|
||||
};
|
||||
void abort(void) __attribute__ ((__noreturn__));
|
||||
void abort(void)
|
||||
{
|
||||
_exit(0);
|
||||
};
|
||||
int atexit(void (*__func) (void))
|
||||
{
|
||||
_exit(0);
|
||||
};
|
||||
void *__libc_stack_end;
|
||||
#endif
|
||||
static int been_there_done_that = 0;
|
||||
|
||||
const struct BB_applet applets[] = {
|
||||
|
||||
#ifdef BB_AR
|
||||
{"ar", ar_main, _BB_DIR_USR_BIN},
|
||||
{"ar", ar_main, _BB_DIR_USR_BIN, ar_usage},
|
||||
#endif
|
||||
#ifdef BB_BASENAME
|
||||
{"basename", basename_main, _BB_DIR_USR_BIN},
|
||||
{"basename", basename_main, _BB_DIR_USR_BIN, basename_usage},
|
||||
#endif
|
||||
{"busybox", busybox_main, _BB_DIR_BIN},
|
||||
{"busybox", busybox_main, _BB_DIR_BIN, NULL},
|
||||
#ifdef BB_CAT
|
||||
{"cat", cat_main, _BB_DIR_BIN},
|
||||
{"cat", cat_main, _BB_DIR_BIN, cat_usage},
|
||||
#endif
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
{"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN, chgrp_usage},
|
||||
#endif
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
{"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN, chmod_usage},
|
||||
#endif
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP
|
||||
{"chown", chmod_chown_chgrp_main, _BB_DIR_BIN},
|
||||
{"chown", chmod_chown_chgrp_main, _BB_DIR_BIN, chown_usage},
|
||||
#endif
|
||||
#ifdef BB_CHROOT
|
||||
{"chroot", chroot_main, _BB_DIR_SBIN},
|
||||
{"chroot", chroot_main, _BB_DIR_USR_SBIN, chroot_usage},
|
||||
#endif
|
||||
#ifdef BB_CLEAR
|
||||
{"clear", clear_main, _BB_DIR_USR_BIN},
|
||||
{"clear", clear_main, _BB_DIR_USR_BIN, clear_usage},
|
||||
#endif
|
||||
#ifdef BB_CHVT
|
||||
{"chvt", chvt_main, _BB_DIR_USR_BIN},
|
||||
{"chvt", chvt_main, _BB_DIR_USR_BIN, chvt_usage},
|
||||
#endif
|
||||
#ifdef BB_CP_MV
|
||||
{"cp", cp_mv_main, _BB_DIR_BIN},
|
||||
{"cp", cp_mv_main, _BB_DIR_BIN, cp_usage},
|
||||
#endif
|
||||
#ifdef BB_CUT
|
||||
{"cut", cut_main, _BB_DIR_USR_BIN},
|
||||
{"cut", cut_main, _BB_DIR_USR_BIN, cut_usage},
|
||||
#endif
|
||||
#ifdef BB_DATE
|
||||
{"date", date_main, _BB_DIR_BIN},
|
||||
{"date", date_main, _BB_DIR_BIN, date_usage},
|
||||
#endif
|
||||
#ifdef BB_DC
|
||||
{"dc", dc_main, _BB_DIR_USR_BIN},
|
||||
{"dc", dc_main, _BB_DIR_USR_BIN, dc_usage},
|
||||
#endif
|
||||
#ifdef BB_DD
|
||||
{"dd", dd_main, _BB_DIR_BIN},
|
||||
{"dd", dd_main, _BB_DIR_BIN, dd_usage},
|
||||
#endif
|
||||
#ifdef BB_DF
|
||||
{"df", df_main, _BB_DIR_BIN},
|
||||
{"df", df_main, _BB_DIR_BIN, df_usage},
|
||||
#endif
|
||||
#ifdef BB_DIRNAME
|
||||
{"dirname", dirname_main, _BB_DIR_USR_BIN},
|
||||
{"dirname", dirname_main, _BB_DIR_USR_BIN, dirname_usage},
|
||||
#endif
|
||||
#ifdef BB_DMESG
|
||||
{"dmesg", dmesg_main, _BB_DIR_BIN},
|
||||
{"dmesg", dmesg_main, _BB_DIR_BIN, dmesg_usage},
|
||||
#endif
|
||||
#ifdef BB_DOS2UNIX
|
||||
{"dos2unix", dos2unix_main, _BB_DIR_USR_BIN, dos2unix_usage},
|
||||
#endif
|
||||
#ifdef BB_DU
|
||||
{"du", du_main, _BB_DIR_BIN},
|
||||
{"du", du_main, _BB_DIR_USR_BIN, du_usage},
|
||||
#endif
|
||||
#ifdef BB_DUMPKMAP
|
||||
{"dumpkmap", dumpkmap_main, _BB_DIR_BIN},
|
||||
{"dumpkmap", dumpkmap_main, _BB_DIR_BIN, dumpkmap_usage},
|
||||
#endif
|
||||
#ifdef BB_DUTMP
|
||||
{"dutmp", dutmp_main, _BB_DIR_USR_SBIN},
|
||||
{"dutmp", dutmp_main, _BB_DIR_USR_SBIN, dutmp_usage},
|
||||
#endif
|
||||
#ifdef BB_ECHO
|
||||
{"echo", echo_main, _BB_DIR_BIN},
|
||||
{"echo", echo_main, _BB_DIR_BIN, echo_usage},
|
||||
#endif
|
||||
#ifdef BB_EXPR
|
||||
{"expr", expr_main, _BB_DIR_USR_BIN, expr_usage},
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE
|
||||
{"false", false_main, _BB_DIR_BIN},
|
||||
{"false", false_main, _BB_DIR_BIN, false_usage},
|
||||
#endif
|
||||
#ifdef BB_FBSET
|
||||
{"fbset", fbset_main, _BB_DIR_USR_SBIN},
|
||||
{"fbset", fbset_main, _BB_DIR_USR_SBIN, NULL},
|
||||
#endif
|
||||
#ifdef BB_FDFLUSH
|
||||
{"fdflush", fdflush_main, _BB_DIR_BIN},
|
||||
{"fdflush", fdflush_main, _BB_DIR_BIN, fdflush_usage},
|
||||
#endif
|
||||
#ifdef BB_FIND
|
||||
{"find", find_main, _BB_DIR_USR_BIN},
|
||||
{"find", find_main, _BB_DIR_USR_BIN, find_usage},
|
||||
#endif
|
||||
#ifdef BB_FREE
|
||||
{"free", free_main, _BB_DIR_USR_BIN},
|
||||
{"free", free_main, _BB_DIR_USR_BIN, free_usage},
|
||||
#endif
|
||||
#ifdef BB_FREERAMDISK
|
||||
{"freeramdisk", freeramdisk_main, _BB_DIR_SBIN},
|
||||
{"freeramdisk", freeramdisk_main, _BB_DIR_SBIN, freeramdisk_usage},
|
||||
#endif
|
||||
#ifdef BB_DEALLOCVT
|
||||
{"deallocvt", deallocvt_main, _BB_DIR_USR_BIN},
|
||||
{"deallocvt", deallocvt_main, _BB_DIR_USR_BIN, deallocvt_usage},
|
||||
#endif
|
||||
#ifdef BB_FSCK_MINIX
|
||||
{"fsck.minix", fsck_minix_main, _BB_DIR_SBIN},
|
||||
{"fsck.minix", fsck_minix_main, _BB_DIR_SBIN, fsck_minix_usage},
|
||||
#endif
|
||||
#ifdef BB_GETOPT
|
||||
{"getopt", getopt_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_GREP
|
||||
{"grep", grep_main, _BB_DIR_BIN},
|
||||
{"grep", grep_main, _BB_DIR_BIN, grep_usage},
|
||||
#endif
|
||||
#ifdef BB_GUNZIP
|
||||
{"gunzip", gunzip_main, _BB_DIR_BIN},
|
||||
{"gunzip", gunzip_main, _BB_DIR_BIN, gunzip_usage},
|
||||
#endif
|
||||
#ifdef BB_GZIP
|
||||
{"gzip", gzip_main, _BB_DIR_BIN},
|
||||
{"gzip", gzip_main, _BB_DIR_BIN, gzip_usage},
|
||||
#endif
|
||||
#ifdef BB_HALT
|
||||
{"halt", halt_main, _BB_DIR_SBIN},
|
||||
{"halt", halt_main, _BB_DIR_SBIN, halt_usage},
|
||||
#endif
|
||||
#ifdef BB_HEAD
|
||||
{"head", head_main, _BB_DIR_BIN},
|
||||
{"head", head_main, _BB_DIR_USR_BIN, head_usage},
|
||||
#endif
|
||||
#ifdef BB_HOSTID
|
||||
{"hostid", hostid_main, _BB_DIR_USR_BIN},
|
||||
{"hostid", hostid_main, _BB_DIR_USR_BIN, hostid_usage},
|
||||
#endif
|
||||
#ifdef BB_HOSTNAME
|
||||
{"hostname", hostname_main, _BB_DIR_BIN},
|
||||
{"hostname", hostname_main, _BB_DIR_BIN, hostname_usage},
|
||||
#endif
|
||||
#ifdef BB_ID
|
||||
{"id", id_main, _BB_DIR_USR_BIN},
|
||||
{"id", id_main, _BB_DIR_USR_BIN, id_usage},
|
||||
#endif
|
||||
#ifdef BB_INIT
|
||||
{"init", init_main, _BB_DIR_SBIN},
|
||||
{"init", init_main, _BB_DIR_SBIN, NULL},
|
||||
#endif
|
||||
#ifdef BB_INSMOD
|
||||
{"insmod", insmod_main, _BB_DIR_SBIN},
|
||||
{"insmod", insmod_main, _BB_DIR_SBIN, insmod_usage},
|
||||
#endif
|
||||
#ifdef BB_KILL
|
||||
{"kill", kill_main, _BB_DIR_BIN},
|
||||
{"kill", kill_main, _BB_DIR_BIN, kill_usage},
|
||||
#endif
|
||||
#ifdef BB_KILLALL
|
||||
{"killall", kill_main, _BB_DIR_USR_BIN},
|
||||
{"killall", kill_main, _BB_DIR_USR_BIN, kill_usage},
|
||||
#endif
|
||||
#ifdef BB_LENGTH
|
||||
{"length", length_main, _BB_DIR_USR_BIN},
|
||||
{"length", length_main, _BB_DIR_USR_BIN, length_usage},
|
||||
#endif
|
||||
#ifdef BB_LINUXRC
|
||||
{"linuxrc", init_main, _BB_DIR_ROOT},
|
||||
{"linuxrc", init_main, _BB_DIR_ROOT, NULL},
|
||||
#endif
|
||||
#ifdef BB_LN
|
||||
{"ln", ln_main, _BB_DIR_BIN},
|
||||
{"ln", ln_main, _BB_DIR_BIN, ln_usage},
|
||||
#endif
|
||||
#ifdef BB_LOADACM
|
||||
{"loadacm", loadacm_main, _BB_DIR_USR_BIN},
|
||||
{"loadacm", loadacm_main, _BB_DIR_USR_BIN, loadacm_usage},
|
||||
#endif
|
||||
#ifdef BB_LOADFONT
|
||||
{"loadfont", loadfont_main, _BB_DIR_USR_BIN},
|
||||
{"loadfont", loadfont_main, _BB_DIR_USR_BIN, loadfont_usage},
|
||||
#endif
|
||||
#ifdef BB_LOADKMAP
|
||||
{"loadkmap", loadkmap_main, _BB_DIR_SBIN},
|
||||
{"loadkmap", loadkmap_main, _BB_DIR_SBIN, loadkmap_usage},
|
||||
#endif
|
||||
#ifdef BB_LOGGER
|
||||
{"logger", logger_main, _BB_DIR_USR_BIN},
|
||||
{"logger", logger_main, _BB_DIR_USR_BIN, logger_usage},
|
||||
#endif
|
||||
#ifdef BB_LOGNAME
|
||||
{"logname", logname_main, _BB_DIR_USR_BIN},
|
||||
{"logname", logname_main, _BB_DIR_USR_BIN, logname_usage},
|
||||
#endif
|
||||
#ifdef BB_LS
|
||||
{"ls", ls_main, _BB_DIR_BIN},
|
||||
{"ls", ls_main, _BB_DIR_BIN, ls_usage},
|
||||
#endif
|
||||
#ifdef BB_LSMOD
|
||||
{"lsmod", lsmod_main, _BB_DIR_SBIN},
|
||||
{"lsmod", lsmod_main, _BB_DIR_SBIN, lsmod_usage},
|
||||
#endif
|
||||
#ifdef BB_MAKEDEVS
|
||||
{"makedevs", makedevs_main, _BB_DIR_SBIN},
|
||||
{"makedevs", makedevs_main, _BB_DIR_SBIN, makedevs_usage},
|
||||
#endif
|
||||
#ifdef BB_MD5SUM
|
||||
{"md5sum", md5sum_main, _BB_DIR_USR_BIN},
|
||||
{"md5sum", md5sum_main, _BB_DIR_USR_BIN, md5sum_usage},
|
||||
#endif
|
||||
#ifdef BB_MKDIR
|
||||
{"mkdir", mkdir_main, _BB_DIR_BIN},
|
||||
{"mkdir", mkdir_main, _BB_DIR_BIN, mkdir_usage},
|
||||
#endif
|
||||
#ifdef BB_MKFIFO
|
||||
{"mkfifo", mkfifo_main, _BB_DIR_USR_BIN},
|
||||
{"mkfifo", mkfifo_main, _BB_DIR_USR_BIN, mkfifo_usage},
|
||||
#endif
|
||||
#ifdef BB_MKFS_MINIX
|
||||
{"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN},
|
||||
{"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN, mkfs_minix_usage},
|
||||
#endif
|
||||
#ifdef BB_MKNOD
|
||||
{"mknod", mknod_main, _BB_DIR_BIN},
|
||||
{"mknod", mknod_main, _BB_DIR_BIN, mknod_usage},
|
||||
#endif
|
||||
#ifdef BB_MKSWAP
|
||||
{"mkswap", mkswap_main, _BB_DIR_SBIN},
|
||||
{"mkswap", mkswap_main, _BB_DIR_SBIN, mkswap_usage},
|
||||
#endif
|
||||
#ifdef BB_MKTEMP
|
||||
{"mktemp", mktemp_main, _BB_DIR_BIN},
|
||||
{"mktemp", mktemp_main, _BB_DIR_BIN, mktemp_usage},
|
||||
#endif
|
||||
#ifdef BB_NC
|
||||
{"nc", nc_main, _BB_DIR_USR_BIN},
|
||||
{"nc", nc_main, _BB_DIR_USR_BIN, nc_usage},
|
||||
#endif
|
||||
#ifdef BB_MORE
|
||||
{"more", more_main, _BB_DIR_BIN},
|
||||
{"more", more_main, _BB_DIR_BIN, more_usage},
|
||||
#endif
|
||||
#ifdef BB_MOUNT
|
||||
{"mount", mount_main, _BB_DIR_BIN},
|
||||
{"mount", mount_main, _BB_DIR_BIN, mount_usage},
|
||||
#endif
|
||||
#ifdef BB_MT
|
||||
{"mt", mt_main, _BB_DIR_BIN},
|
||||
{"mt", mt_main, _BB_DIR_BIN, mt_usage},
|
||||
#endif
|
||||
#ifdef BB_CP_MV
|
||||
{"mv", cp_mv_main, _BB_DIR_BIN},
|
||||
{"mv", cp_mv_main, _BB_DIR_BIN, mv_usage},
|
||||
#endif
|
||||
#ifdef BB_NSLOOKUP
|
||||
{"nslookup", nslookup_main, _BB_DIR_USR_BIN},
|
||||
{"nslookup", nslookup_main, _BB_DIR_USR_BIN, nslookup_usage},
|
||||
#endif
|
||||
#ifdef BB_PING
|
||||
{"ping", ping_main, _BB_DIR_BIN},
|
||||
{"ping", ping_main, _BB_DIR_BIN, ping_usage},
|
||||
#endif
|
||||
#ifdef BB_POWEROFF
|
||||
{"poweroff", poweroff_main, _BB_DIR_SBIN},
|
||||
{"poweroff", poweroff_main, _BB_DIR_SBIN, poweroff_usage},
|
||||
#endif
|
||||
#ifdef BB_PRINTF
|
||||
{"printf", printf_main, _BB_DIR_USR_BIN},
|
||||
{"printf", printf_main, _BB_DIR_USR_BIN, printf_usage},
|
||||
#endif
|
||||
#ifdef BB_PS
|
||||
{"ps", ps_main, _BB_DIR_BIN},
|
||||
{"ps", ps_main, _BB_DIR_BIN, ps_usage},
|
||||
#endif
|
||||
#ifdef BB_PWD
|
||||
{"pwd", pwd_main, _BB_DIR_BIN},
|
||||
{"pwd", pwd_main, _BB_DIR_BIN, pwd_usage},
|
||||
#endif
|
||||
#ifdef BB_RDATE
|
||||
{"rdate", rdate_main, _BB_DIR_USR_BIN, rdate_usage},
|
||||
#endif
|
||||
#ifdef BB_REBOOT
|
||||
{"reboot", reboot_main, _BB_DIR_SBIN},
|
||||
{"reboot", reboot_main, _BB_DIR_SBIN, reboot_usage},
|
||||
#endif
|
||||
#ifdef BB_RENICE
|
||||
{"renice", renice_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_RESET
|
||||
{"reset", reset_main, _BB_DIR_USR_BIN, reset_usage},
|
||||
#endif
|
||||
#ifdef BB_RM
|
||||
{"rm", rm_main, _BB_DIR_BIN},
|
||||
{"rm", rm_main, _BB_DIR_BIN, rm_usage},
|
||||
#endif
|
||||
#ifdef BB_RMDIR
|
||||
{"rmdir", rmdir_main, _BB_DIR_BIN},
|
||||
{"rmdir", rmdir_main, _BB_DIR_BIN, rmdir_usage},
|
||||
#endif
|
||||
#ifdef BB_RMMOD
|
||||
{"rmmod", rmmod_main, _BB_DIR_SBIN},
|
||||
{"rmmod", rmmod_main, _BB_DIR_SBIN, rmmod_usage},
|
||||
#endif
|
||||
#ifdef BB_SED
|
||||
{"sed", sed_main, _BB_DIR_BIN},
|
||||
{"sed", sed_main, _BB_DIR_BIN, sed_usage},
|
||||
#endif
|
||||
#ifdef BB_SETKEYCODES
|
||||
{"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN},
|
||||
{"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN, setkeycodes_usage},
|
||||
#endif
|
||||
#ifdef BB_SH
|
||||
{"sh", shell_main, _BB_DIR_BIN},
|
||||
{"sh", shell_main, _BB_DIR_BIN, shell_usage},
|
||||
#endif
|
||||
#ifdef BB_SLEEP
|
||||
{"sleep", sleep_main, _BB_DIR_BIN},
|
||||
{"sleep", sleep_main, _BB_DIR_BIN, sleep_usage},
|
||||
#endif
|
||||
#ifdef BB_SORT
|
||||
{"sort", sort_main, _BB_DIR_BIN},
|
||||
{"sort", sort_main, _BB_DIR_USR_BIN, sort_usage},
|
||||
#endif
|
||||
#ifdef BB_SYNC
|
||||
{"sync", sync_main, _BB_DIR_BIN},
|
||||
{"sync", sync_main, _BB_DIR_BIN, sync_usage},
|
||||
#endif
|
||||
#ifdef BB_SYSLOGD
|
||||
{"syslogd", syslogd_main, _BB_DIR_SBIN},
|
||||
{"syslogd", syslogd_main, _BB_DIR_SBIN, syslogd_usage},
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF
|
||||
{"swapon", swap_on_off_main, _BB_DIR_SBIN},
|
||||
{"swapon", swap_on_off_main, _BB_DIR_SBIN, swapon_usage},
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF
|
||||
{"swapoff", swap_on_off_main, _BB_DIR_SBIN},
|
||||
{"swapoff", swap_on_off_main, _BB_DIR_SBIN, swapoff_usage},
|
||||
#endif
|
||||
#ifdef BB_TAIL
|
||||
{"tail", tail_main, _BB_DIR_USR_BIN},
|
||||
{"tail", tail_main, _BB_DIR_USR_BIN, tail_usage},
|
||||
#endif
|
||||
#ifdef BB_TAR
|
||||
{"tar", tar_main, _BB_DIR_BIN},
|
||||
{"tar", tar_main, _BB_DIR_BIN, tar_usage},
|
||||
#endif
|
||||
#ifdef BB_TELNET
|
||||
{"telnet", telnet_main, _BB_DIR_USR_BIN},
|
||||
{"telnet", telnet_main, _BB_DIR_USR_BIN, telnet_usage},
|
||||
#endif
|
||||
#ifdef BB_TEST
|
||||
{"test", test_main, _BB_DIR_USR_BIN},
|
||||
{"test", test_main, _BB_DIR_USR_BIN, test_usage},
|
||||
#endif
|
||||
#ifdef BB_TEE
|
||||
{"tee", tee_main, _BB_DIR_BIN},
|
||||
{"tee", tee_main, _BB_DIR_USR_BIN, tee_usage},
|
||||
#endif
|
||||
#ifdef BB_TOUCH
|
||||
{"touch", touch_main, _BB_DIR_USR_BIN},
|
||||
{"touch", touch_main, _BB_DIR_BIN, touch_usage},
|
||||
#endif
|
||||
#ifdef BB_TR
|
||||
{"tr", tr_main, _BB_DIR_USR_BIN},
|
||||
{"tr", tr_main, _BB_DIR_USR_BIN, tr_usage},
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE
|
||||
{"true", true_main, _BB_DIR_BIN},
|
||||
{"true", true_main, _BB_DIR_BIN, true_usage},
|
||||
#endif
|
||||
#ifdef BB_TTY
|
||||
{"tty", tty_main, _BB_DIR_USR_BIN},
|
||||
{"tty", tty_main, _BB_DIR_USR_BIN, tty_usage},
|
||||
#endif
|
||||
#ifdef BB_UMOUNT
|
||||
{"umount", umount_main, _BB_DIR_BIN},
|
||||
{"umount", umount_main, _BB_DIR_BIN, umount_usage},
|
||||
#endif
|
||||
#ifdef BB_UNAME
|
||||
{"uname", uname_main, _BB_DIR_BIN},
|
||||
{"uname", uname_main, _BB_DIR_BIN, uname_usage},
|
||||
#endif
|
||||
#ifdef BB_UNIQ
|
||||
{"uniq", uniq_main, _BB_DIR_USR_BIN},
|
||||
{"uniq", uniq_main, _BB_DIR_USR_BIN, uniq_usage},
|
||||
#endif
|
||||
#ifdef BB_UNIX2DOS
|
||||
{"unix2dos", unix2dos_main, _BB_DIR_USR_BIN, unix2dos_usage},
|
||||
#endif
|
||||
#ifdef BB_UNRPM
|
||||
{"unrpm", unrpm_main, _BB_DIR_USR_BIN, unrpm_usage},
|
||||
#endif
|
||||
#ifdef BB_UPDATE
|
||||
{"update", update_main, _BB_DIR_SBIN},
|
||||
{"update", update_main, _BB_DIR_SBIN, update_usage},
|
||||
#endif
|
||||
#ifdef BB_UPTIME
|
||||
{"uptime", uptime_main, _BB_DIR_USR_BIN},
|
||||
{"uptime", uptime_main, _BB_DIR_USR_BIN, uptime_usage},
|
||||
#endif
|
||||
#ifdef BB_UUENCODE
|
||||
{"uuencode", uuencode_main, _BB_DIR_USR_BIN},
|
||||
{"uuencode", uuencode_main, _BB_DIR_USR_BIN, uuencode_usage},
|
||||
#endif
|
||||
#ifdef BB_UUDECODE
|
||||
{"uudecode", uudecode_main, _BB_DIR_USR_BIN},
|
||||
{"uudecode", uudecode_main, _BB_DIR_USR_BIN, uudecode_usage},
|
||||
#endif
|
||||
#ifdef BB_USLEEP
|
||||
{"usleep", usleep_main, _BB_DIR_BIN},
|
||||
{"usleep", usleep_main, _BB_DIR_BIN, usleep_usage},
|
||||
#endif
|
||||
#ifdef BB_WC
|
||||
{"wc", wc_main, _BB_DIR_USR_BIN},
|
||||
{"wc", wc_main, _BB_DIR_USR_BIN, wc_usage},
|
||||
#endif
|
||||
#ifdef BB_WGET
|
||||
{"wget", wget_main, _BB_DIR_USR_BIN, wget_usage},
|
||||
#endif
|
||||
#ifdef BB_WHICH
|
||||
{"which", which_main, _BB_DIR_USR_BIN},
|
||||
{"which", which_main, _BB_DIR_USR_BIN, which_usage},
|
||||
#endif
|
||||
#ifdef BB_WHOAMI
|
||||
{"whoami", whoami_main, _BB_DIR_USR_BIN},
|
||||
{"whoami", whoami_main, _BB_DIR_USR_BIN, whoami_usage},
|
||||
#endif
|
||||
#ifdef BB_XARGS
|
||||
{"xargs", xargs_main, _BB_DIR_USR_BIN, xargs_usage},
|
||||
#endif
|
||||
#ifdef BB_YES
|
||||
{"yes", yes_main, _BB_DIR_USR_BIN},
|
||||
{"yes", yes_main, _BB_DIR_USR_BIN, yes_usage},
|
||||
#endif
|
||||
#ifdef BB_GUNZIP
|
||||
{"zcat", gunzip_main, _BB_DIR_BIN},
|
||||
{"zcat", gunzip_main, _BB_DIR_BIN, gunzip_usage},
|
||||
#endif
|
||||
#ifdef BB_TEST
|
||||
{"[", test_main, _BB_DIR_USR_BIN},
|
||||
{"[", test_main, _BB_DIR_USR_BIN, test_usage},
|
||||
#endif
|
||||
{0}
|
||||
{0,NULL,0,NULL}
|
||||
};
|
||||
|
||||
const char *applet_name;
|
||||
|
||||
#ifdef BB_FEATURE_INSTALLER
|
||||
/*
|
||||
* directory table
|
||||
* this should be consistent w/ the enum, internal.h::Location,
|
||||
* this should be consistent w/ the enum, busybox.h::Location,
|
||||
* or else...
|
||||
*/
|
||||
static char* install_dir[] = {
|
||||
@@ -391,53 +402,43 @@ static char *busybox_fullpath()
|
||||
if (len != -1) {
|
||||
path[len] = 0;
|
||||
} else {
|
||||
fprintf(stderr, "busybox : %s : %s\n", proc, strerror(errno));
|
||||
errorMsg("%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)
|
||||
static void install_links(const char *busybox, int use_symbolic_links)
|
||||
{
|
||||
__link_f Link = link;
|
||||
|
||||
char command[256];
|
||||
int i;
|
||||
int rc = 0;
|
||||
int rc;
|
||||
|
||||
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
|
||||
sprintf ( command, "%s/%s",
|
||||
install_dir[applets[i].location],
|
||||
applets[i].name);
|
||||
rc = Link(busybox, command);
|
||||
|
||||
if (rc) {
|
||||
fprintf(stderr,"busybox : %s : %s\n", command, strerror(errno));
|
||||
errorMsg("%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;
|
||||
char *name;
|
||||
const char *s;
|
||||
const struct BB_applet *a = applets;
|
||||
applet_name = "busybox";
|
||||
|
||||
#ifdef BB_FEATURE_INSTALLER
|
||||
/*
|
||||
@@ -469,22 +470,25 @@ int main(int argc, char **argv)
|
||||
}
|
||||
#endif /* BB_FEATURE_INSTALLER */
|
||||
|
||||
for (s = name = argv[0]; *s != '\0';) {
|
||||
for (s = applet_name = argv[0]; *s != '\0';) {
|
||||
if (*s++ == '/')
|
||||
name = s;
|
||||
applet_name = s;
|
||||
}
|
||||
|
||||
*argv = name;
|
||||
*argv = (char*)applet_name;
|
||||
|
||||
#ifdef BB_SH
|
||||
/* Add in a special case hack -- whenever **argv == '-'
|
||||
* (i.e. '-su' or '-sh') always invoke the shell */
|
||||
if (**argv == '-')
|
||||
if (**argv == '-' && *(*argv+1)!= '-') {
|
||||
exit(((*(shell_main)) (argc, argv)));
|
||||
}
|
||||
#endif
|
||||
|
||||
while (a->name != 0) {
|
||||
if (strcmp(name, a->name) == 0) {
|
||||
if (strcmp(applet_name, a->name) == 0) {
|
||||
if (a->usage && argv[1] && strcmp(argv[1], "--help") == 0)
|
||||
usage(a->usage);
|
||||
exit(((*(a->main)) (argc, argv)));
|
||||
}
|
||||
a++;
|
||||
@@ -503,14 +507,14 @@ int busybox_main(int argc, char **argv)
|
||||
if (been_there_done_that == 1 || argc < 1) {
|
||||
const struct BB_applet *a = applets;
|
||||
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n"
|
||||
fprintf(stderr, "%s\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);
|
||||
"\nCurrently defined functions:\n", full_version);
|
||||
|
||||
while (a->name != 0) {
|
||||
col +=
|
||||
|
||||
+148
-16
@@ -24,7 +24,11 @@
|
||||
#ifndef _BB_INTERNAL_H_
|
||||
#define _BB_INTERNAL_H_ 1
|
||||
|
||||
#include "busybox.def.h"
|
||||
#include "Config.h"
|
||||
|
||||
#ifdef DMALLOC
|
||||
#include "dmalloc.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
@@ -99,12 +103,14 @@ struct BB_applet {
|
||||
const char* name;
|
||||
int (*main)(int argc, char** argv);
|
||||
enum Location location;
|
||||
const char* usage;
|
||||
};
|
||||
/* From busybox.c */
|
||||
extern const struct BB_applet applets[];
|
||||
|
||||
extern int ar_main(int argc, char **argv);
|
||||
extern int basename_main(int argc, char **argv);
|
||||
extern int bogomips_main(int argc, char **argv);
|
||||
extern int busybox_main(int argc, char** argv);
|
||||
extern int cat_main(int argc, char** argv);
|
||||
extern int chmod_chown_chgrp_main(int argc, char** argv);
|
||||
@@ -120,10 +126,12 @@ extern int dirname_main(int argc, char** argv);
|
||||
extern int deallocvt_main(int argc, char** argv);
|
||||
extern int df_main(int argc, char** argv);
|
||||
extern int dmesg_main(int argc, char** argv);
|
||||
extern int dos2unix_main(int argc, char** argv);
|
||||
extern int du_main(int argc, char** argv);
|
||||
extern int dumpkmap_main(int argc, char** argv);
|
||||
extern int dutmp_main(int argc, char** argv);
|
||||
extern int echo_main(int argc, char** argv);
|
||||
extern int expr_main(int argc, char** argv);
|
||||
extern int false_main(int argc, char** argv);
|
||||
extern int fbset_main(int argc, char** argv);
|
||||
extern int fdisk_main(int argc, char** argv);
|
||||
@@ -132,6 +140,7 @@ extern int fsck_minix_main(int argc, char **argv);
|
||||
extern int find_main(int argc, char** argv);
|
||||
extern int free_main(int argc, char** argv);
|
||||
extern int freeramdisk_main(int argc, char** argv);
|
||||
extern int getopt_main(int argc, char** argv);
|
||||
extern int grep_main(int argc, char** argv);
|
||||
extern int gunzip_main (int argc, char** argv);
|
||||
extern int gzip_main(int argc, char** argv);
|
||||
@@ -171,7 +180,10 @@ extern int poweroff_main(int argc, char **argv);
|
||||
extern int printf_main(int argc, char** argv);
|
||||
extern int ps_main(int argc, char** argv);
|
||||
extern int pwd_main(int argc, char** argv);
|
||||
extern int rdate_main(int argc, char** argv);
|
||||
extern int reboot_main(int argc, char** argv);
|
||||
extern int renice_main(int argc, char** argv);
|
||||
extern int reset_main(int argc, char** argv);
|
||||
extern int rm_main(int argc, char** argv);
|
||||
extern int rmdir_main(int argc, char **argv);
|
||||
extern int rmmod_main(int argc, char** argv);
|
||||
@@ -195,19 +207,135 @@ extern int true_main(int argc, char** argv);
|
||||
extern int tput_main(int argc, char** argv);
|
||||
extern int tryopen_main(int argc, char** argv);
|
||||
extern int tty_main(int argc, char** argv);
|
||||
extern int uuencode_main(int argc, char** argv);
|
||||
extern int uudecode_main(int argc, char** argv);
|
||||
extern int umount_main(int argc, char** argv);
|
||||
extern int uname_main(int argc, char** argv);
|
||||
extern int uptime_main(int argc, char** argv);
|
||||
extern int uniq_main(int argc, char** argv);
|
||||
extern int unix2dos_main(int argc, char** argv);
|
||||
extern int unrpm_main(int argc, char** argv);
|
||||
extern int update_main(int argc, char** argv);
|
||||
extern int uptime_main(int argc, char** argv);
|
||||
extern int usleep_main(int argc, char** argv);
|
||||
extern int uuencode_main(int argc, char** argv);
|
||||
extern int uudecode_main(int argc, char** argv);
|
||||
extern int wc_main(int argc, char** argv);
|
||||
extern int wget_main(int argc, char** argv);
|
||||
extern int which_main(int argc, char** argv);
|
||||
extern int whoami_main(int argc, char** argv);
|
||||
extern int xargs_main(int argc, char** argv);
|
||||
extern int yes_main(int argc, char** argv);
|
||||
|
||||
extern const char ar_usage[];
|
||||
extern const char basename_usage[];
|
||||
extern const char cat_usage[];
|
||||
extern const char chgrp_usage[];
|
||||
extern const char chmod_usage[];
|
||||
extern const char chown_usage[];
|
||||
extern const char chroot_usage[];
|
||||
extern const char chvt_usage[];
|
||||
extern const char clear_usage[];
|
||||
extern const char cp_usage[];
|
||||
extern const char cut_usage[];
|
||||
extern const char date_usage[];
|
||||
extern const char dc_usage[];
|
||||
extern const char dd_usage[];
|
||||
extern const char deallocvt_usage[];
|
||||
extern const char df_usage[];
|
||||
extern const char dirname_usage[];
|
||||
extern const char dmesg_usage[];
|
||||
extern const char dos2unix_usage[];
|
||||
extern const char du_usage[];
|
||||
extern const char dumpkmap_usage[];
|
||||
extern const char dutmp_usage[];
|
||||
extern const char echo_usage[];
|
||||
extern const char expr_usage[];
|
||||
extern const char false_usage[];
|
||||
extern const char fdflush_usage[];
|
||||
extern const char find_usage[];
|
||||
extern const char free_usage[];
|
||||
extern const char freeramdisk_usage[];
|
||||
extern const char fsck_minix_usage[];
|
||||
extern const char grep_usage[];
|
||||
extern const char gunzip_usage[];
|
||||
extern const char gzip_usage[];
|
||||
extern const char halt_usage[];
|
||||
extern const char head_usage[];
|
||||
extern const char hostid_usage[];
|
||||
extern const char hostname_usage[];
|
||||
extern const char id_usage[];
|
||||
extern const char insmod_usage[];
|
||||
extern const char kill_usage[];
|
||||
extern const char killall_usage[];
|
||||
extern const char length_usage[];
|
||||
extern const char ln_usage[];
|
||||
extern const char loadacm_usage[];
|
||||
extern const char loadfont_usage[];
|
||||
extern const char loadkmap_usage[];
|
||||
extern const char logger_usage[];
|
||||
extern const char logname_usage[];
|
||||
extern const char ls_usage[];
|
||||
extern const char lsmod_usage[];
|
||||
extern const char makedevs_usage[];
|
||||
extern const char md5sum_usage[];
|
||||
extern const char mkdir_usage[];
|
||||
extern const char mkfifo_usage[];
|
||||
extern const char mkfs_minix_usage[];
|
||||
extern const char mknod_usage[];
|
||||
extern const char mkswap_usage[];
|
||||
extern const char mktemp_usage[];
|
||||
extern const char more_usage[];
|
||||
extern const char mount_usage[];
|
||||
extern const char mt_usage[];
|
||||
extern const char mv_usage[];
|
||||
extern const char nc_usage[];
|
||||
extern const char nslookup_usage[];
|
||||
extern const char ping_usage[];
|
||||
extern const char poweroff_usage[];
|
||||
extern const char printf_usage[];
|
||||
extern const char ps_usage[];
|
||||
extern const char pwd_usage[];
|
||||
extern const char rdate_usage[];
|
||||
extern const char reboot_usage[];
|
||||
extern const char renice_usage[];
|
||||
extern const char reset_usage[];
|
||||
extern const char rm_usage[];
|
||||
extern const char rmdir_usage[];
|
||||
extern const char rmmod_usage[];
|
||||
extern const char sed_usage[];
|
||||
extern const char setkeycodes_usage[];
|
||||
extern const char shell_usage[];
|
||||
extern const char sleep_usage[];
|
||||
extern const char sort_usage[];
|
||||
extern const char swapoff_usage[];
|
||||
extern const char swapon_usage[];
|
||||
extern const char sync_usage[];
|
||||
extern const char syslogd_usage[];
|
||||
extern const char tail_usage[];
|
||||
extern const char tar_usage[];
|
||||
extern const char tee_usage[];
|
||||
extern const char telnet_usage[];
|
||||
extern const char test_usage[];
|
||||
extern const char touch_usage[];
|
||||
extern const char tr_usage[];
|
||||
extern const char true_usage[];
|
||||
extern const char tty_usage[];
|
||||
extern const char umount_usage[];
|
||||
extern const char uname_usage[];
|
||||
extern const char uniq_usage[];
|
||||
extern const char unix2dos_usage[];
|
||||
extern const char unrpm_usage[];
|
||||
extern const char update_usage[];
|
||||
extern const char uptime_usage[];
|
||||
extern const char usleep_usage[];
|
||||
extern const char uudecode_usage[];
|
||||
extern const char uuencode_usage[];
|
||||
extern const char wc_usage[];
|
||||
extern const char wget_usage[];
|
||||
extern const char which_usage[];
|
||||
extern const char whoami_usage[];
|
||||
extern const char xargs_usage[];
|
||||
extern const char yes_usage[];
|
||||
|
||||
extern const char *applet_name;
|
||||
|
||||
extern void usage(const char *usage) __attribute__ ((noreturn));
|
||||
extern void errorMsg(const char *s, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
@@ -230,6 +358,7 @@ void reset_ino_dev_hashtable(void);
|
||||
|
||||
int copyFile(const char *srcName, const char *destName,
|
||||
int setModes, int followLinks, int forceFlag);
|
||||
int copySubFile(int srcFd, int dstFd, size_t remaining);
|
||||
char *buildName(const char *dirName, const char *fileName);
|
||||
int makeString(int argc, const char **argv, char *buf, int bufLen);
|
||||
char *getChunk(int size);
|
||||
@@ -241,7 +370,6 @@ int recursiveAction(const char *fileName, int recurse, int followLinks, int dept
|
||||
int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData),
|
||||
int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData),
|
||||
void* userData);
|
||||
const char* timeString(time_t timeVal);
|
||||
|
||||
extern int createPath (const char *name, int mode);
|
||||
extern int parse_mode( const char* s, mode_t* theMode);
|
||||
@@ -262,28 +390,32 @@ extern long getNum (const char *cp);
|
||||
extern pid_t* findPidByName( char* pidName);
|
||||
extern int find_real_root_device_name(char* name);
|
||||
extern char *get_line_from_file(FILE *file);
|
||||
extern void print_file(FILE *file);
|
||||
extern int print_file_by_name(char *filename);
|
||||
extern char process_escape_sequence(char **ptr);
|
||||
extern char *get_last_path_component(char *path);
|
||||
extern int bb_regcomp(regex_t *preg, const char *regex, int cflags);
|
||||
extern void xregcomp(regex_t *preg, const char *regex, int cflags);
|
||||
|
||||
#ifndef DMALLOC
|
||||
extern void *xmalloc (size_t size);
|
||||
extern void *xrealloc(void *old, size_t size);
|
||||
extern void *xcalloc(size_t nmemb, size_t size);
|
||||
extern char *xstrdup (const char *s);
|
||||
#endif
|
||||
extern char *xstrndup (const char *s, int n);
|
||||
|
||||
|
||||
/* These parse entries in /etc/passwd and /etc/group. This is desirable
|
||||
* for BusyBox since we want to avoid using the glibc NSS stuff, which
|
||||
* increases target size and is often not needed embedded systems. */
|
||||
extern unsigned long my_getpwnam(char *name);
|
||||
extern unsigned long my_getgrnam(char *name);
|
||||
extern void my_getpwuid(char *name, unsigned long uid);
|
||||
extern void my_getgrgid(char *group, unsigned long gid);
|
||||
extern unsigned long my_getpwnamegid(char *name);
|
||||
extern long my_getpwnam(char *name);
|
||||
extern long my_getgrnam(char *name);
|
||||
extern void my_getpwuid(char *name, long uid);
|
||||
extern void my_getgrgid(char *group, long gid);
|
||||
extern long my_getpwnamegid(char *name);
|
||||
|
||||
|
||||
#if defined BB_INIT || defined BB_SYSLOGD
|
||||
extern int device_open(char *device, int mode);
|
||||
#endif
|
||||
|
||||
#if defined BB_FEATURE_MOUNT_LOOP
|
||||
extern int del_loop(const char *device);
|
||||
extern int set_loop(const char *device, const char *file, int offset, int *loopro);
|
||||
@@ -296,8 +428,8 @@ extern int vdprintf(int d, const char *format, va_list ap);
|
||||
#endif
|
||||
|
||||
#if defined BB_NFSMOUNT
|
||||
int nfsmount(const char *spec, const char *node, unsigned long *flags,
|
||||
char **extra_opts, char **mount_opts, int running_bg);
|
||||
int nfsmount(const char *spec, const char *node, int *flags,
|
||||
char **extra_opts, char **mount_opts, int running_bg);
|
||||
#endif
|
||||
|
||||
#ifndef RB_POWER_OFF
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
# Make busybox links list file.
|
||||
|
||||
DF="busybox.def.h"
|
||||
DF="Config.h"
|
||||
MF="busybox.c"
|
||||
|
||||
LIST="$(gcc -E -dM $DF | sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/BB_\1/gp;' | sort)"
|
||||
|
||||
+2
-2
@@ -3,8 +3,8 @@
|
||||
# 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 | \
|
||||
gcc -E -dM Config.h | \
|
||||
sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/\1.c/gp;' \
|
||||
| tr [:upper:] [:lower:] | sort
|
||||
| tr '[:upper:]' '[:lower:]' | sort
|
||||
` 2>/dev/null | sed -e 's/\.c$/\.o/g'
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
Name: busybox
|
||||
Version: 0.46
|
||||
Version: 0.47
|
||||
Release: 1
|
||||
Group: System/Utilities
|
||||
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
||||
|
||||
@@ -21,45 +21,23 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
static void print_file(FILE * file)
|
||||
{
|
||||
int c;
|
||||
|
||||
while ((c = getc(file)) != EOF)
|
||||
putc(c, stdout);
|
||||
fclose(file);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
extern int cat_main(int argc, char **argv)
|
||||
{
|
||||
FILE *file;
|
||||
|
||||
if (argc == 1) {
|
||||
print_file(stdin);
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
if (**(argv + 1) == '-') {
|
||||
usage("cat [FILE ...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nConcatenates FILE(s) and prints them to the standard output.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
argc--;
|
||||
|
||||
while (argc-- > 0 && *(argv++) != '\0' && strlen(*argv)) {
|
||||
file = fopen(*argv, "r");
|
||||
if (file == NULL) {
|
||||
while (--argc > 0) {
|
||||
if(!(strcmp(*++argv, "-"))) {
|
||||
print_file(stdin);
|
||||
} else if (print_file_by_name(*argv) == FALSE) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
}
|
||||
print_file(file);
|
||||
}
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
+19
-42
@@ -22,7 +22,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_invalid_option
|
||||
#define bb_need_too_few_args
|
||||
@@ -33,10 +33,9 @@
|
||||
#include <pwd.h>
|
||||
|
||||
|
||||
static unsigned long uid = -1;
|
||||
static unsigned long gid = -1;
|
||||
static long uid = -1;
|
||||
static long gid = -1;
|
||||
static int whichApp;
|
||||
static char *invocationName = NULL;
|
||||
static char *theMode = NULL;
|
||||
|
||||
|
||||
@@ -44,29 +43,6 @@ static char *theMode = NULL;
|
||||
#define CHOWN_APP 2
|
||||
#define CHMOD_APP 3
|
||||
|
||||
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"
|
||||
#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"
|
||||
#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\tChanges files and directories recursively.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
switch (whichApp) {
|
||||
@@ -88,7 +64,7 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
case CHMOD_APP:
|
||||
/* Parse the specified modes */
|
||||
if (parse_mode(theMode, &(statbuf->st_mode)) == FALSE) {
|
||||
fatalError( "%s: unknown mode: %s\n", invocationName, theMode);
|
||||
fatalError( "unknown mode: %s\n", theMode);
|
||||
}
|
||||
if (chmod(fileName, statbuf->st_mode) == 0)
|
||||
return (TRUE);
|
||||
@@ -100,13 +76,14 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
|
||||
int chmod_chown_chgrp_main(int argc, char **argv)
|
||||
{
|
||||
int stopIt = FALSE;
|
||||
int recursiveFlag = FALSE;
|
||||
char *groupName=NULL;
|
||||
char *p=NULL;
|
||||
const char *appUsage;
|
||||
|
||||
whichApp = (strcmp(*argv, "chown") == 0)?
|
||||
CHOWN_APP : (strcmp(*argv, "chmod") == 0)?
|
||||
whichApp = (strcmp(applet_name, "chown") == 0)?
|
||||
CHOWN_APP : (strcmp(applet_name, "chmod") == 0)?
|
||||
CHMOD_APP : CHGRP_APP;
|
||||
|
||||
appUsage = (whichApp == CHOWN_APP)?
|
||||
@@ -114,31 +91,32 @@ int chmod_chown_chgrp_main(int argc, char **argv)
|
||||
|
||||
if (argc < 2)
|
||||
usage(appUsage);
|
||||
invocationName = *argv;
|
||||
argv++;
|
||||
|
||||
/* Parse options */
|
||||
while (--argc >= 0 && *argv && (**argv == '-')) {
|
||||
while (*++(*argv)) {
|
||||
while (stopIt==FALSE && *++(*argv)) {
|
||||
switch (**argv) {
|
||||
case 'R':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, invalid_option, invocationName, **argv);
|
||||
usage(appUsage);
|
||||
theMode=*argv-1;
|
||||
stopIt = TRUE;
|
||||
}
|
||||
}
|
||||
if (stopIt==TRUE)
|
||||
break;
|
||||
argv++;
|
||||
}
|
||||
|
||||
if (argc == 0 || *argv == NULL) {
|
||||
fprintf(stderr, too_few_args, invocationName);
|
||||
usage(appUsage);
|
||||
errorMsg(too_few_args);
|
||||
}
|
||||
|
||||
if (whichApp == CHMOD_APP) {
|
||||
theMode = *argv;
|
||||
if (theMode==NULL)
|
||||
theMode = *argv;
|
||||
} else {
|
||||
|
||||
/* Find the selected group */
|
||||
@@ -171,15 +149,14 @@ int chmod_chown_chgrp_main(int argc, char **argv)
|
||||
if (*argv == p)
|
||||
uid = my_getpwnam(*argv);
|
||||
if (uid == -1) {
|
||||
fatalError( "%s: unknown user name: %s\n",
|
||||
invocationName, *argv);
|
||||
fatalError( "unknown user name: %s\n", *argv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Ok, ready to do the deed now */
|
||||
if (argc <= 1) {
|
||||
fatalError( "%s: too few arguments\n", invocationName);
|
||||
if (argc < 1) {
|
||||
fatalError(too_few_args);
|
||||
}
|
||||
while (argc-- > 1) {
|
||||
if (recursiveAction (*(++argv), recursiveFlag, FALSE, FALSE,
|
||||
@@ -189,7 +166,7 @@ int chmod_chown_chgrp_main(int argc, char **argv)
|
||||
exit(TRUE);
|
||||
|
||||
bad_group:
|
||||
fatalError( "%s: unknown group name: %s\n", invocationName, groupName);
|
||||
fatalError( "unknown group name: %s\n", groupName);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -22,20 +22,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
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;
|
||||
@@ -47,8 +38,7 @@ int chroot_main(int argc, char **argv)
|
||||
argv++;
|
||||
|
||||
if (chroot(*argv) || (chdir("/"))) {
|
||||
fatalError("chroot: cannot change root directory to %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
fatalError("cannot change root directory to %s: %s\n", *argv, strerror(errno));
|
||||
}
|
||||
|
||||
argc--;
|
||||
@@ -57,13 +47,17 @@ int chroot_main(int argc, char **argv)
|
||||
prog = *argv;
|
||||
execvp(*argv, argv);
|
||||
} else {
|
||||
#ifndef BB_SH
|
||||
prog = getenv("SHELL");
|
||||
if (!prog)
|
||||
prog = "/bin/sh";
|
||||
execlp(prog, prog, NULL);
|
||||
#else
|
||||
shell_main(argc, argv);
|
||||
exit (0);
|
||||
#endif
|
||||
}
|
||||
fatalError("chroot: cannot execute %s: %s\n",
|
||||
prog, strerror(errno));
|
||||
fatalError("cannot execute %s: %s\n", prog, strerror(errno));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* busyboxed by Erik Andersen
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
@@ -15,18 +15,12 @@
|
||||
#define VT_ACTIVATE 0x5606 /* make vt active */
|
||||
#define VT_WAITACTIVE 0x5607 /* wait for vt active */
|
||||
|
||||
|
||||
int chvt_main(int argc, char **argv)
|
||||
{
|
||||
int fd, num;
|
||||
|
||||
if ((argc != 2) || (**(argv + 1) == '-')) {
|
||||
usage ("chvt N\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nChanges the foreground virtual terminal to /dev/ttyN\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
if ((argc != 2) || (**(argv + 1) == '-'))
|
||||
usage (chvt_usage);
|
||||
fd = get_console_fd("/dev/console");
|
||||
num = atoi(argv[1]);
|
||||
if (ioctl(fd, VT_ACTIVATE, num)) {
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
terminal width. (more then one line.) However, history will.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#ifdef BB_FEATURE_SH_COMMAND_EDITING
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -84,6 +84,7 @@ 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 */
|
||||
static int exithandler_set = 0; /* Set to true when atexit() has been called */
|
||||
|
||||
struct history {
|
||||
char *s;
|
||||
@@ -93,6 +94,11 @@ struct history {
|
||||
|
||||
#define xwrite write
|
||||
|
||||
/*
|
||||
* TODO: Someday we want to implement 'horizontal scrolling' of the
|
||||
* command-line when the user has typed more than the current width. This
|
||||
* would allow the user to see a 'window' of what he has typed.
|
||||
*/
|
||||
void
|
||||
cmdedit_setwidth(int w)
|
||||
{
|
||||
@@ -110,6 +116,18 @@ 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);
|
||||
#ifdef BB_FEATURE_CLEAN_UP
|
||||
if (his_front) {
|
||||
struct history *n;
|
||||
//while(his_front!=his_end) {
|
||||
while(his_front!=his_end) {
|
||||
n = his_front->n;
|
||||
free(his_front->s);
|
||||
free(his_front);
|
||||
his_front=n;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void clean_up_and_die(int sig)
|
||||
@@ -228,11 +246,11 @@ char** username_tab_completion(char* command, int *num_matches)
|
||||
char** exe_n_cwd_tab_completion(char* command, int *num_matches)
|
||||
{
|
||||
char *dirName;
|
||||
char **matches = (char **) NULL;
|
||||
char **matches;
|
||||
DIR *dir;
|
||||
struct dirent *next;
|
||||
|
||||
matches = malloc( sizeof(char*)*50);
|
||||
matches = xmalloc( sizeof(char*)*50);
|
||||
|
||||
/* Stick a wildcard onto the command, for later use */
|
||||
strcat( command, "*");
|
||||
@@ -255,7 +273,7 @@ char** exe_n_cwd_tab_completion(char* command, int *num_matches)
|
||||
/* 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);
|
||||
matches[*num_matches] = xmalloc(strlen(next->d_name)+1);
|
||||
strcpy( matches[*num_matches], next->d_name);
|
||||
++*num_matches;
|
||||
//matches = realloc( matches, sizeof(char*)*(*num_matches));
|
||||
@@ -284,7 +302,7 @@ void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len)
|
||||
|
||||
/* Make a local copy of the string -- up
|
||||
* to the position of the cursor */
|
||||
matchBuf = (char *) calloc(BUFSIZ, sizeof(char));
|
||||
matchBuf = (char *) xcalloc(BUFSIZ, sizeof(char));
|
||||
strncpy(matchBuf, command, cursor);
|
||||
tmp=matchBuf;
|
||||
|
||||
@@ -365,14 +383,16 @@ void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len)
|
||||
|
||||
void get_previous_history(struct history **hp, char* command)
|
||||
{
|
||||
free((*hp)->s);
|
||||
if ((*hp)->s)
|
||||
free((*hp)->s);
|
||||
(*hp)->s = strdup(command);
|
||||
*hp = (*hp)->p;
|
||||
}
|
||||
|
||||
void get_next_history(struct history **hp, char* command)
|
||||
{
|
||||
free((*hp)->s);
|
||||
if ((*hp)->s)
|
||||
free((*hp)->s);
|
||||
(*hp)->s = strdup(command);
|
||||
*hp = (*hp)->n;
|
||||
}
|
||||
@@ -409,7 +429,6 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
|
||||
char c = 0;
|
||||
struct history *hp = his_end;
|
||||
|
||||
memset(command, 0, sizeof(command));
|
||||
if (!reset_term) {
|
||||
|
||||
getTermSettings(inputFd, (void*) &initial_settings);
|
||||
@@ -457,7 +476,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
|
||||
xwrite(outputFd, prompt, strlen(prompt));
|
||||
|
||||
/* Reset the command string */
|
||||
memset(command, 0, sizeof(command));
|
||||
memset(command, 0, BUFSIZ);
|
||||
len = cursor = 0;
|
||||
|
||||
break;
|
||||
@@ -650,9 +669,9 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
|
||||
struct history *h = his_end;
|
||||
|
||||
if (!h) {
|
||||
/* No previous history */
|
||||
h = his_front = malloc(sizeof(struct history));
|
||||
h->n = malloc(sizeof(struct history));
|
||||
/* No previous history -- this memory is never freed */
|
||||
h = his_front = xmalloc(sizeof(struct history));
|
||||
h->n = xmalloc(sizeof(struct history));
|
||||
|
||||
h->p = NULL;
|
||||
h->s = strdup(command);
|
||||
@@ -662,8 +681,8 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
|
||||
his_end = h->n;
|
||||
history_counter++;
|
||||
} else {
|
||||
/* Add a new history command */
|
||||
h->n = malloc(sizeof(struct history));
|
||||
/* Add a new history command -- this memory is never freed */
|
||||
h->n = xmalloc(sizeof(struct history));
|
||||
|
||||
h->n->p = h;
|
||||
h->n->n = NULL;
|
||||
@@ -691,10 +710,32 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
|
||||
|
||||
extern void cmdedit_init(void)
|
||||
{
|
||||
atexit(cmdedit_reset_term);
|
||||
if(exithandler_set == 0) {
|
||||
atexit(cmdedit_reset_term); /* be sure to do this only once */
|
||||
exithandler_set = 1;
|
||||
}
|
||||
signal(SIGKILL, clean_up_and_die);
|
||||
signal(SIGINT, clean_up_and_die);
|
||||
signal(SIGQUIT, clean_up_and_die);
|
||||
signal(SIGTERM, clean_up_and_die);
|
||||
}
|
||||
|
||||
/*
|
||||
** Undo the effects of cmdedit_init() as good as we can:
|
||||
** I am not aware of a way to revoke an atexit() handler,
|
||||
** but, fortunately, our particular handler can be made
|
||||
** a no-op by setting reset_term = 0.
|
||||
*/
|
||||
extern void cmdedit_terminate(void)
|
||||
{
|
||||
cmdedit_reset_term();
|
||||
reset_term = 0;
|
||||
signal(SIGKILL, SIG_DFL);
|
||||
signal(SIGINT, SIG_DFL);
|
||||
signal(SIGQUIT, SIG_DFL);
|
||||
signal(SIGTERM, SIG_DFL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* BB_FEATURE_SH_COMMAND_EDITING */
|
||||
@@ -11,6 +11,7 @@
|
||||
typedef size_t (*cmdedit_strwidth_proc)(char *);
|
||||
|
||||
void cmdedit_init(void);
|
||||
void cmdedit_terminate(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 */
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*
|
||||
* busyboxed by Erik Andersen
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
@@ -15,18 +15,12 @@
|
||||
#define VT_ACTIVATE 0x5606 /* make vt active */
|
||||
#define VT_WAITACTIVE 0x5607 /* wait for vt active */
|
||||
|
||||
|
||||
int chvt_main(int argc, char **argv)
|
||||
{
|
||||
int fd, num;
|
||||
|
||||
if ((argc != 2) || (**(argv + 1) == '-')) {
|
||||
usage ("chvt N\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nChanges the foreground virtual terminal to /dev/ttyN\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
if ((argc != 2) || (**(argv + 1) == '-'))
|
||||
usage (chvt_usage);
|
||||
fd = get_console_fd("/dev/console");
|
||||
num = atoi(argv[1]);
|
||||
if (ioctl(fd, VT_ACTIVATE, num)) {
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
+10
-20
@@ -3,7 +3,7 @@
|
||||
* disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
|
||||
* Renamed deallocvt.
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
@@ -13,46 +13,36 @@
|
||||
/* From <linux/vt.h> */
|
||||
#define VT_DISALLOCATE 0x5608 /* free memory associated to vt */
|
||||
|
||||
|
||||
char *progname;
|
||||
|
||||
int deallocvt_main(int argc, char *argv[])
|
||||
{
|
||||
int fd, num, i;
|
||||
|
||||
if ((argc != 2) || (**(argv + 1) == '-')) {
|
||||
usage
|
||||
("deallocvt N\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nDeallocate unused virtual terminal /dev/ttyN\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
progname = argv[0];
|
||||
//if ((argc > 2) || ((argv == 2) && (**(argv + 1) == '-')))
|
||||
if (argc > 2)
|
||||
usage(deallocvt_usage);
|
||||
|
||||
fd = get_console_fd("/dev/console");
|
||||
|
||||
if (argc == 1) {
|
||||
printf("erik: A\n");
|
||||
/* deallocate all unused consoles */
|
||||
if (ioctl(fd, VT_DISALLOCATE, 0)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
exit( FALSE);
|
||||
}
|
||||
} else
|
||||
printf("erik: B\n");
|
||||
for (i = 1; i < argc; i++) {
|
||||
num = atoi(argv[i]);
|
||||
if (num == 0)
|
||||
fprintf(stderr, "%s: 0: illegal VT number\n", progname);
|
||||
errorMsg("0: illegal VT number\n");
|
||||
else if (num == 1)
|
||||
fprintf(stderr, "%s: VT 1 cannot be deallocated\n",
|
||||
progname);
|
||||
errorMsg("VT 1 cannot be deallocated\n");
|
||||
else if (ioctl(fd, VT_DISALLOCATE, num)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
fprintf(stderr, "%s: could not deallocate console %d\n",
|
||||
progname, num);
|
||||
exit( FALSE);
|
||||
fatalError("could not deallocate console %d\n", num);
|
||||
}
|
||||
}
|
||||
printf("erik: C\n");
|
||||
return( TRUE);
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
@@ -38,14 +38,6 @@ struct kbentry {
|
||||
#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;
|
||||
@@ -58,7 +50,7 @@ int dumpkmap_main(int argc, char **argv)
|
||||
|
||||
fd = open("/dev/tty0", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
|
||||
errorMsg("Error opening /dev/tty0: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -86,10 +78,10 @@ int dumpkmap_main(int argc, char **argv)
|
||||
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);
|
||||
errorMsg("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);
|
||||
write(1,(void*)&ke.kb_value,2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+9
-18
@@ -7,7 +7,7 @@
|
||||
* Peter Novodvorsky <petya@logic.ru>
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
@@ -18,16 +18,9 @@
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#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);
|
||||
@@ -46,12 +39,12 @@ int loadacm_main(int argc, char **argv)
|
||||
|
||||
fd = open("/dev/tty", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty1: %s\n", strerror(errno));
|
||||
errorMsg("Error opening /dev/tty1: %s\n", strerror(errno));
|
||||
return( FALSE);
|
||||
}
|
||||
|
||||
if (screen_map_load(fd, stdin)) {
|
||||
fprintf(stderr, "Error loading acm: %s\n", strerror(errno));
|
||||
errorMsg("Error loading acm: %s\n", strerror(errno));
|
||||
return( FALSE);
|
||||
}
|
||||
|
||||
@@ -79,8 +72,7 @@ int screen_map_load(int fd, FILE * fp)
|
||||
if (parse_failed) {
|
||||
if (-1 == fseek(fp, 0, SEEK_SET)) {
|
||||
if (errno == ESPIPE)
|
||||
fprintf(stderr,
|
||||
"16bit screen-map MUST be a regular file.\n"),
|
||||
errorMsg("16bit screen-map MUST be a regular file.\n"),
|
||||
exit(1);
|
||||
else
|
||||
perror("fseek failed reading binary 16bit screen-map"),
|
||||
@@ -91,7 +83,7 @@ int screen_map_load(int fd, FILE * fp)
|
||||
perror("Cannot read [new] map from file"), exit(1);
|
||||
#if 0
|
||||
else
|
||||
fprintf(stderr, "Input screen-map is binary.\n");
|
||||
errorMsg("Input screen-map is binary.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -108,8 +100,7 @@ int screen_map_load(int fd, FILE * fp)
|
||||
/* rewind... */
|
||||
if (-1 == fseek(fp, 0, SEEK_SET)) {
|
||||
if (errno == ESPIPE)
|
||||
fprintf(stderr,
|
||||
"Assuming 8bit screen-map - MUST be a regular file.\n"),
|
||||
errorMsg("Assuming 8bit screen-map - MUST be a regular file.\n"),
|
||||
exit(1);
|
||||
else
|
||||
perror("fseek failed assuming 8bit screen-map"), exit(1);
|
||||
@@ -122,7 +113,7 @@ int screen_map_load(int fd, FILE * fp)
|
||||
if (-1 == fseek(fp, 0, SEEK_SET)) {
|
||||
if (errno == ESPIPE)
|
||||
/* should not - it succedeed above */
|
||||
fprintf(stderr, "fseek() returned ESPIPE !\n"),
|
||||
errorMsg("fseek() returned ESPIPE !\n"),
|
||||
exit(1);
|
||||
else
|
||||
perror("fseek for binary 8bit screen-map"), exit(1);
|
||||
@@ -132,7 +123,7 @@ int screen_map_load(int fd, FILE * fp)
|
||||
perror("Cannot read [old] map from file"), exit(1);
|
||||
#if 0
|
||||
else
|
||||
fprintf(stderr, "Input screen-map is binary.\n");
|
||||
errorMsg("Input screen-map is binary.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -141,7 +132,7 @@ int screen_map_load(int fd, FILE * fp)
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
fprintf(stderr, "Error parsing symbolic map\n");
|
||||
errorMsg("Error parsing symbolic map\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
+12
-23
@@ -7,7 +7,7 @@
|
||||
* Loads the console font, and possibly the corresponding screen map(s).
|
||||
* (Adapted for busybox by Matej Vela.)
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
@@ -15,7 +15,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <sys/ioctl.h>
|
||||
@@ -30,12 +29,6 @@
|
||||
#define PSF_MAXMODE 0x03
|
||||
#define PSF_SEPARATOR 0xFFFF
|
||||
|
||||
static const char loadfont_usage[] = "loadfont\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"Loads a console font from standard input.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
struct psf_header {
|
||||
unsigned char magic1, magic2; /* Magic number */
|
||||
unsigned char mode; /* PSF font mode */
|
||||
@@ -56,7 +49,7 @@ extern int loadfont_main(int argc, char **argv)
|
||||
|
||||
fd = open("/dev/tty0", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
|
||||
errorMsg("Error opening /dev/tty0: %s\n", strerror(errno));
|
||||
return( FALSE);
|
||||
}
|
||||
loadnewfont(fd);
|
||||
@@ -72,7 +65,7 @@ static void do_loadfont(int fd, char *inbuf, int unit, int fontsize)
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
if (unit < 1 || unit > 32) {
|
||||
fprintf(stderr, "Bad character size %d\n", unit);
|
||||
errorMsg("Bad character size %d\n", unit);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -109,12 +102,8 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
|
||||
u_short unicode;
|
||||
|
||||
maxct = tailsz; /* more than enough */
|
||||
up = (struct unipair *) malloc(maxct * sizeof(struct unipair));
|
||||
up = (struct unipair *) xmalloc(maxct * sizeof(struct unipair));
|
||||
|
||||
if (!up) {
|
||||
fprintf(stderr, "Out of memory?\n");
|
||||
exit(1);
|
||||
}
|
||||
for (glyph = 0; glyph < fontsize; glyph++) {
|
||||
while (tailsz >= 2) {
|
||||
unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
|
||||
@@ -137,8 +126,8 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
|
||||
if (ioctl(fd, PIO_UNIMAPCLR, &advice)) {
|
||||
#ifdef ENOIOCTLCMD
|
||||
if (errno == ENOIOCTLCMD) {
|
||||
fprintf(stderr, "It seems this kernel is older than 1.1.92\n");
|
||||
fprintf(stderr, "No Unicode mapping table loaded.\n");
|
||||
errorMsg("It seems this kernel is older than 1.1.92\n");
|
||||
errorMsg("No Unicode mapping table loaded.\n");
|
||||
} else
|
||||
#endif
|
||||
perror("PIO_UNIMAPCLR");
|
||||
@@ -161,7 +150,7 @@ static void loadnewfont(int fd)
|
||||
{
|
||||
int unit;
|
||||
char inbuf[32768]; /* primitive */
|
||||
int inputlth, offset;
|
||||
unsigned int inputlth, offset;
|
||||
|
||||
/*
|
||||
* We used to look at the length of the input file
|
||||
@@ -187,7 +176,7 @@ static void loadnewfont(int fd)
|
||||
struct psf_header psfhdr;
|
||||
int fontsize;
|
||||
int hastable;
|
||||
int head0, head;
|
||||
unsigned int head0, head;
|
||||
|
||||
if (inputlth < sizeof(struct psf_header))
|
||||
goto no_psf;
|
||||
@@ -198,13 +187,13 @@ static void loadnewfont(int fd)
|
||||
goto no_psf;
|
||||
|
||||
if (psfhdr.mode > PSF_MAXMODE) {
|
||||
fprintf(stderr, "Unsupported psf file mode\n");
|
||||
errorMsg("Unsupported psf file mode\n");
|
||||
exit(1);
|
||||
}
|
||||
fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256);
|
||||
#if !defined( PIO_FONTX ) || defined( __sparc__ )
|
||||
if (fontsize != 256) {
|
||||
fprintf(stderr, "Only fontsize 256 supported\n");
|
||||
errorMsg("Only fontsize 256 supported\n");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
@@ -214,7 +203,7 @@ static void loadnewfont(int fd)
|
||||
|
||||
head = head0 + fontsize * unit;
|
||||
if (head > inputlth || (!hastable && head != inputlth)) {
|
||||
fprintf(stderr, "Input file: bad length\n");
|
||||
errorMsg("Input file: bad length\n");
|
||||
exit(1);
|
||||
}
|
||||
do_loadfont(fd, inbuf + head0, unit, fontsize);
|
||||
@@ -231,7 +220,7 @@ static void loadnewfont(int fd)
|
||||
} else {
|
||||
/* bare font */
|
||||
if (inputlth & 0377) {
|
||||
fprintf(stderr, "Bad input file size\n");
|
||||
errorMsg("Bad input file size\n");
|
||||
exit(1);
|
||||
}
|
||||
offset = 0;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
@@ -38,14 +38,6 @@ struct kbentry {
|
||||
#define NR_KEYS 128
|
||||
#define MAX_NR_KEYMAPS 256
|
||||
|
||||
|
||||
static const char loadkmap_usage[] = "loadkmap\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nLoads a binary keyboard translation table from standard input.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
int loadkmap_main(int argc, char **argv)
|
||||
{
|
||||
struct kbentry ke;
|
||||
@@ -59,27 +51,23 @@ int loadkmap_main(int argc, char **argv)
|
||||
|
||||
fd = open("/dev/tty0", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
|
||||
errorMsg("Error opening /dev/tty0: %s\n", strerror(errno));
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
read(0, buff, 7);
|
||||
if (0 != strncmp(buff, magic, 7)) {
|
||||
fprintf(stderr, "This is not a valid binary keymap.\n");
|
||||
errorMsg("This is not a valid binary keymap.\n");
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS)) {
|
||||
fprintf(stderr, "Error reading keymap flags: %s\n",
|
||||
errorMsg("Error reading keymap flags: %s\n",
|
||||
strerror(errno));
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
ibuff = (u_short *) malloc(ibuffsz);
|
||||
if (!ibuff) {
|
||||
fprintf(stderr, "Out of memory.\n");
|
||||
exit(FALSE);
|
||||
}
|
||||
ibuff = (u_short *) xmalloc(ibuffsz);
|
||||
|
||||
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
|
||||
if (flags[i] == 1) {
|
||||
@@ -87,7 +75,7 @@ int loadkmap_main(int argc, char **argv)
|
||||
while (pos < ibuffsz) {
|
||||
if ((readsz = read(0, (char *) ibuff + pos, ibuffsz - pos))
|
||||
< 0) {
|
||||
fprintf(stderr, "Error reading keymap: %s\n",
|
||||
errorMsg("Error reading keymap: %s\n",
|
||||
strerror(errno));
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini reset implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* and Kent Robotti <robotti@metconnect.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 "busybox.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern int reset_main(int argc, char **argv)
|
||||
{
|
||||
printf("\033c");
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
@@ -35,17 +35,6 @@ struct kbkeycode {
|
||||
};
|
||||
#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)
|
||||
{
|
||||
|
||||
@@ -21,17 +21,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.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;
|
||||
|
||||
+5
-27
@@ -21,45 +21,23 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
static void print_file(FILE * file)
|
||||
{
|
||||
int c;
|
||||
|
||||
while ((c = getc(file)) != EOF)
|
||||
putc(c, stdout);
|
||||
fclose(file);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
extern int cat_main(int argc, char **argv)
|
||||
{
|
||||
FILE *file;
|
||||
|
||||
if (argc == 1) {
|
||||
print_file(stdin);
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
if (**(argv + 1) == '-') {
|
||||
usage("cat [FILE ...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nConcatenates FILE(s) and prints them to the standard output.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
argc--;
|
||||
|
||||
while (argc-- > 0 && *(argv++) != '\0' && strlen(*argv)) {
|
||||
file = fopen(*argv, "r");
|
||||
if (file == NULL) {
|
||||
while (--argc > 0) {
|
||||
if(!(strcmp(*++argv, "-"))) {
|
||||
print_file(stdin);
|
||||
} else if (print_file_by_name(*argv) == FALSE) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
}
|
||||
print_file(file);
|
||||
}
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
+8
-14
@@ -22,20 +22,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
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;
|
||||
@@ -47,8 +38,7 @@ int chroot_main(int argc, char **argv)
|
||||
argv++;
|
||||
|
||||
if (chroot(*argv) || (chdir("/"))) {
|
||||
fatalError("chroot: cannot change root directory to %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
fatalError("cannot change root directory to %s: %s\n", *argv, strerror(errno));
|
||||
}
|
||||
|
||||
argc--;
|
||||
@@ -57,13 +47,17 @@ int chroot_main(int argc, char **argv)
|
||||
prog = *argv;
|
||||
execvp(*argv, argv);
|
||||
} else {
|
||||
#ifndef BB_SH
|
||||
prog = getenv("SHELL");
|
||||
if (!prog)
|
||||
prog = "/bin/sh";
|
||||
execlp(prog, prog, NULL);
|
||||
#else
|
||||
shell_main(argc, argv);
|
||||
exit (0);
|
||||
#endif
|
||||
}
|
||||
fatalError("chroot: cannot execute %s: %s\n",
|
||||
prog, strerror(errno));
|
||||
fatalError("cannot execute %s: %s\n", prog, strerror(errno));
|
||||
|
||||
}
|
||||
|
||||
|
||||
+203
-359
@@ -1,11 +1,8 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* cut implementation for busybox
|
||||
* cut.c - minimalist version of cut
|
||||
*
|
||||
* 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.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Mark Whitley <markw@lineo.com>, <markw@enol.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
|
||||
@@ -20,369 +17,216 @@
|
||||
* 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
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h> /* getopt */
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include "busybox.h"
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
/* globals from other files */
|
||||
extern int optind;
|
||||
extern char *optarg;
|
||||
|
||||
|
||||
void get_args()
|
||||
{
|
||||
int i = 0;
|
||||
int arg_ptr = 0;
|
||||
int flag;
|
||||
/* globals in this file only */
|
||||
static char part = 0; /* (b)yte, (c)har, (f)ields */
|
||||
static int startpos = 1;
|
||||
static int endpos = -1;
|
||||
static char delim = '\t'; /* delimiter, default is tab */
|
||||
static unsigned int supress_non_delimited_lines = 0;
|
||||
|
||||
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.
|
||||
*
|
||||
* decompose_list() - parses a list and puts values into startpos and endpos.
|
||||
* valid list formats: N, N-, N-M, -M
|
||||
*/
|
||||
static void decompose_list(const char *list)
|
||||
{
|
||||
unsigned int nminus = 0;
|
||||
char *ptr;
|
||||
|
||||
/* the list must contain only digits and no more than one minus sign */
|
||||
for (ptr = (char *)list; *ptr; ptr++) {
|
||||
if (!isdigit(*ptr) && *ptr != '-') {
|
||||
fatalError("invalid byte or field list\n");
|
||||
}
|
||||
if (*ptr == '-') {
|
||||
nminus++;
|
||||
if (nminus > 1) {
|
||||
fatalError("invalid byte or field list\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* handle single value 'N' case */
|
||||
if (nminus == 0) {
|
||||
startpos = strtol(list, &ptr, 10);
|
||||
if (startpos == 0) {
|
||||
fatalError("missing list of fields\n");
|
||||
}
|
||||
endpos = startpos;
|
||||
}
|
||||
/* handle multi-value cases */
|
||||
else if (nminus == 1) {
|
||||
/* handle 'N-' case */
|
||||
if (list[strlen(list) - 1] == '-') {
|
||||
startpos = strtol(list, &ptr, 10);
|
||||
}
|
||||
/* handle '-M' case */
|
||||
else if (list[0] == '-') {
|
||||
endpos = strtol(&list[1], NULL, 10);
|
||||
}
|
||||
/* handle 'N-M' case */
|
||||
else {
|
||||
startpos = strtol(list, &ptr, 10);
|
||||
endpos = strtol(ptr+1, &ptr, 10);
|
||||
}
|
||||
|
||||
/* a sanity check */
|
||||
if (startpos == 0) {
|
||||
startpos = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* snippy-snip
|
||||
*/
|
||||
static void cut_file(FILE *file)
|
||||
{
|
||||
char *line;
|
||||
|
||||
/* go through every line in the file */
|
||||
for (line = NULL; (line = get_line_from_file(file)) != NULL; free(line)) {
|
||||
|
||||
/* cut based on chars/bytes */
|
||||
if (part == 'c' || part == 'b') {
|
||||
int i;
|
||||
/* a valid end position has been specified */
|
||||
if (endpos > 0) {
|
||||
for (i = startpos-1; i < endpos; i++) {
|
||||
fputc(line[i], stdout);
|
||||
}
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
/* otherwise, just go to the end of the line */
|
||||
else {
|
||||
for (i = startpos-1; line[i]; i++) {
|
||||
fputc(line[i], stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* cut based on fields */
|
||||
else if (part == 'f') {
|
||||
char *ptr;
|
||||
char *start = line;
|
||||
unsigned int delims_hit = 0;
|
||||
|
||||
for (ptr = line; (ptr = strchr(ptr, delim)) != NULL; ptr++) {
|
||||
delims_hit++;
|
||||
if (delims_hit == (startpos - 1)) {
|
||||
start = ptr+1;
|
||||
}
|
||||
if (delims_hit == endpos) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* we didn't hit any delimeters */
|
||||
if (delims_hit == 0 && !supress_non_delimited_lines) {
|
||||
fputs(line, stdout);
|
||||
}
|
||||
/* we =did= hit some delimiters */
|
||||
else if (delims_hit > 0) {
|
||||
/* we have a fixed end point */
|
||||
if (ptr) {
|
||||
while (start < ptr) {
|
||||
fputc(*start, stdout);
|
||||
start++;
|
||||
}
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
/* or we're just going til the end of the line */
|
||||
else {
|
||||
while (*start) {
|
||||
fputc(*start, stdout);
|
||||
start++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern int cut_main(int argc, char **argv)
|
||||
{
|
||||
int opt;
|
||||
|
||||
while ((opt = getopt(argc, argv, "b:c:d:f:ns")) > 0) {
|
||||
switch (opt) {
|
||||
case 'b':
|
||||
case 'c':
|
||||
case 'f':
|
||||
/* make sure they didn't ask for two types of lists */
|
||||
if (part != 0) {
|
||||
fatalError("only one type of list may be specified");
|
||||
}
|
||||
part = (char)opt;
|
||||
decompose_list(optarg);
|
||||
break;
|
||||
case 'd':
|
||||
if (strlen(optarg) > 1) {
|
||||
fatalError("the delimiter must be a single character\n");
|
||||
}
|
||||
delim = optarg[0];
|
||||
break;
|
||||
case 'n':
|
||||
/* no-op */
|
||||
break;
|
||||
case 's':
|
||||
supress_non_delimited_lines++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (part == 0) {
|
||||
fatalError("you must specify a list of bytes, characters, or fields\n");
|
||||
}
|
||||
|
||||
if (supress_non_delimited_lines && part != 'f') {
|
||||
fatalError("suppressing non-delimited lines makes sense
|
||||
only when operating on fields\n");
|
||||
}
|
||||
|
||||
if (delim != '\t' && part != 'f') {
|
||||
fatalError("a delimiter may be specified only when operating on fields\n");
|
||||
}
|
||||
|
||||
/* argv[(optind)..(argc-1)] should be names of file to process. If no
|
||||
* files were specified or '-' was specified, take input from stdin.
|
||||
* Otherwise, we process all the files specified. */
|
||||
if (argv[optind] == NULL || (strcmp(argv[optind], "-") == 0)) {
|
||||
cut_file(stdin);
|
||||
}
|
||||
else {
|
||||
int i;
|
||||
FILE *file;
|
||||
for (i = optind; i < argc; i++) {
|
||||
file = fopen(argv[i], "r");
|
||||
if (file == NULL) {
|
||||
errorMsg("%s: %s\n", argv[i], strerror(errno));
|
||||
} else {
|
||||
cut_file(file);
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
+36
-56
@@ -20,7 +20,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_invalid_date
|
||||
#define bb_need_memory_exhausted
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <getopt.h>
|
||||
|
||||
|
||||
/* This 'date' command supports only 2 time setting formats,
|
||||
@@ -39,17 +40,6 @@
|
||||
an RFC 822 complient date output for shell scripting
|
||||
mail commands */
|
||||
|
||||
static const char date_usage[] = "date [OPTION]... [+FORMAT]\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
|
||||
much as possible, missed out a lot of bounds checking */
|
||||
|
||||
@@ -66,7 +56,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) {
|
||||
fatalError(invalid_date, "date", t_string);
|
||||
fatalError(invalid_date, t_string);
|
||||
}
|
||||
|
||||
/* correct for century - minor Y2K problem here? */
|
||||
@@ -150,7 +140,7 @@ struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
|
||||
|
||||
}
|
||||
|
||||
fatalError(invalid_date, "date", t_string);
|
||||
fatalError(invalid_date, t_string);
|
||||
}
|
||||
|
||||
|
||||
@@ -159,7 +149,7 @@ int date_main(int argc, char **argv)
|
||||
char *date_str = NULL;
|
||||
char *date_fmt = NULL;
|
||||
char *t_buff;
|
||||
int i;
|
||||
int c;
|
||||
int set_time = 0;
|
||||
int rfc822 = 0;
|
||||
int utc = 0;
|
||||
@@ -168,49 +158,39 @@ int date_main(int argc, char **argv)
|
||||
struct tm tm_time;
|
||||
|
||||
/* Interpret command line args */
|
||||
i = --argc;
|
||||
argv++;
|
||||
while (i > 0 && **argv) {
|
||||
if (**argv == '-') {
|
||||
while (i > 0 && *++(*argv))
|
||||
switch (**argv) {
|
||||
case 'R':
|
||||
rfc822 = 1;
|
||||
break;
|
||||
case 's':
|
||||
set_time = 1;
|
||||
if (date_str != NULL)
|
||||
usage(date_usage);
|
||||
date_str = *argv;
|
||||
break;
|
||||
case 'u':
|
||||
utc = 1;
|
||||
if (putenv("TZ=UTC0") != 0)
|
||||
fatalError(memory_exhausted, "date");
|
||||
break;
|
||||
case 'd':
|
||||
use_arg = 1;
|
||||
if (date_str != NULL)
|
||||
usage(date_usage);
|
||||
date_str = *argv;
|
||||
break;
|
||||
case '-':
|
||||
usage(date_usage);
|
||||
}
|
||||
} else {
|
||||
if ((date_fmt == NULL) && (**argv == '+'))
|
||||
date_fmt = *argv + 1; /* Skip over the '+' */
|
||||
else if (date_str == NULL) {
|
||||
set_time = 1;
|
||||
date_str = *argv;
|
||||
} else {
|
||||
while ((c = getopt(argc, argv, "Rs:ud:")) != EOF) {
|
||||
switch (c) {
|
||||
case 'R':
|
||||
rfc822 = 1;
|
||||
break;
|
||||
case 's':
|
||||
set_time = 1;
|
||||
if ((date_str != NULL) || ((date_str = optarg) == NULL))
|
||||
usage(date_usage);
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
utc = 1;
|
||||
if (putenv("TZ=UTC0") != 0)
|
||||
fatalError(memory_exhausted);
|
||||
break;
|
||||
case 'd':
|
||||
use_arg = 1;
|
||||
if ((date_str != NULL) || ((date_str = optarg) == NULL))
|
||||
usage(date_usage);
|
||||
break;
|
||||
default:
|
||||
usage(date_usage);
|
||||
}
|
||||
i--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+'))
|
||||
date_fmt = &argv[optind][1]; /* Skip over the '+' */
|
||||
else if (date_str == NULL) {
|
||||
set_time = 1;
|
||||
date_str = argv[optind];
|
||||
} else {
|
||||
usage(date_usage);
|
||||
}
|
||||
|
||||
/* Now we have parsed all the information except the date format
|
||||
which depends on whether the clock is being set or read */
|
||||
@@ -236,12 +216,12 @@ 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)
|
||||
fatalError(invalid_date, "date", date_str);
|
||||
fatalError(invalid_date, date_str);
|
||||
|
||||
/* if setting time, set it */
|
||||
if (set_time) {
|
||||
if (stime(&tm) < 0) {
|
||||
fatalError("date: can't set date.\n");
|
||||
fatalError("can't set date.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+35
-75
@@ -29,7 +29,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <features.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
@@ -40,39 +40,25 @@
|
||||
typedef unsigned long long int uintmax_t;
|
||||
#endif
|
||||
|
||||
static const char dd_usage[] =
|
||||
"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"
|
||||
"\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)
|
||||
{
|
||||
char *inFile = NULL;
|
||||
char *outFile = NULL;
|
||||
char *cp;
|
||||
int inFd;
|
||||
int outFd;
|
||||
int inCc = 0;
|
||||
int outCc;
|
||||
int trunc=TRUE;
|
||||
long blockSize = 512;
|
||||
uintmax_t skipBlocks = 0;
|
||||
uintmax_t seekBlocks = 0;
|
||||
uintmax_t count = (uintmax_t) - 1;
|
||||
uintmax_t intotal;
|
||||
uintmax_t outTotal;
|
||||
unsigned char *buf;
|
||||
uintmax_t inTotal = 0;
|
||||
uintmax_t outTotal = 0;
|
||||
uintmax_t totalSize;
|
||||
uintmax_t readSize;
|
||||
unsigned char buf[BUFSIZ];
|
||||
char *keyword = NULL;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
@@ -85,30 +71,33 @@ extern int dd_main(int argc, char **argv)
|
||||
outFile = ((strchr(*argv, '=')) + 1);
|
||||
else if (strncmp("count", *argv, 5) == 0) {
|
||||
count = getNum((strchr(*argv, '=')) + 1);
|
||||
if (count <= 0) {
|
||||
fprintf(stderr, "Bad count value %s\n", *argv);
|
||||
if (count < 0) {
|
||||
errorMsg("Bad count value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
} else if (strncmp(*argv, "bs", 2) == 0) {
|
||||
blockSize = getNum((strchr(*argv, '=')) + 1);
|
||||
if (blockSize <= 0) {
|
||||
fprintf(stderr, "Bad block size value %s\n", *argv);
|
||||
errorMsg("Bad block size value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
} else if (strncmp(*argv, "skip", 4) == 0) {
|
||||
skipBlocks = getNum((strchr(*argv, '=')) + 1);
|
||||
if (skipBlocks <= 0) {
|
||||
fprintf(stderr, "Bad skip value %s\n", *argv);
|
||||
errorMsg("Bad skip value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
|
||||
} else if (strncmp(*argv, "seek", 4) == 0) {
|
||||
seekBlocks = getNum((strchr(*argv, '=')) + 1);
|
||||
if (seekBlocks <= 0) {
|
||||
fprintf(stderr, "Bad seek value %s\n", *argv);
|
||||
errorMsg("Bad seek value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
|
||||
} else if (strncmp(*argv, "conv", 4) == 0) {
|
||||
keyword = (strchr(*argv, '=') + 1);
|
||||
if (strcmp(keyword, "notrunc") == 0)
|
||||
trunc=FALSE;
|
||||
} else {
|
||||
goto usage;
|
||||
}
|
||||
@@ -116,11 +105,6 @@ extern int dd_main(int argc, char **argv)
|
||||
argv++;
|
||||
}
|
||||
|
||||
buf = xmalloc(blockSize);
|
||||
|
||||
intotal = 0;
|
||||
outTotal = 0;
|
||||
|
||||
if (inFile == NULL)
|
||||
inFd = fileno(stdin);
|
||||
else
|
||||
@@ -138,7 +122,7 @@ extern int dd_main(int argc, char **argv)
|
||||
if (outFile == NULL)
|
||||
outFd = fileno(stdout);
|
||||
else
|
||||
outFd = open(outFile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
outFd = open(outFile, O_WRONLY | O_CREAT, 0666);
|
||||
|
||||
if (outFd < 0) {
|
||||
/* Note that we are not freeing buf or closing
|
||||
@@ -150,54 +134,30 @@ extern int dd_main(int argc, char **argv)
|
||||
fatalError( outFile);
|
||||
}
|
||||
|
||||
lseek(inFd, skipBlocks * blockSize, SEEK_SET);
|
||||
lseek(outFd, seekBlocks * blockSize, SEEK_SET);
|
||||
//
|
||||
//TODO: Convert to using fullRead & fullWrite
|
||||
// from utility.c
|
||||
// -Erik
|
||||
while (outTotal < count * blockSize) {
|
||||
inCc = read(inFd, buf, blockSize);
|
||||
if (inCc < 0) {
|
||||
perror(inFile);
|
||||
goto cleanup;
|
||||
} else if (inCc == 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
intotal += inCc;
|
||||
cp = buf;
|
||||
|
||||
while (intotal > outTotal) {
|
||||
if (outTotal + inCc > count * blockSize)
|
||||
inCc = count * blockSize - outTotal;
|
||||
outCc = write(outFd, cp, inCc);
|
||||
if (outCc < 0) {
|
||||
perror(outFile);
|
||||
goto cleanup;
|
||||
} else if (outCc == 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
inCc -= outCc;
|
||||
cp += outCc;
|
||||
outTotal += outCc;
|
||||
}
|
||||
lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET);
|
||||
lseek(outFd, (off_t) (seekBlocks * blockSize), SEEK_SET);
|
||||
totalSize=count*blockSize;
|
||||
while ((readSize = totalSize - inTotal) > 0) {
|
||||
if (readSize > BUFSIZ)
|
||||
readSize=BUFSIZ;
|
||||
inCc = fullRead(inFd, buf, readSize);
|
||||
inTotal += inCc;
|
||||
if ((outCc = fullWrite(outFd, buf, inCc)) < 1)
|
||||
break;
|
||||
outTotal += outCc;
|
||||
}
|
||||
if (trunc == TRUE) {
|
||||
ftruncate(outFd, lseek(outFd, 0, SEEK_CUR));
|
||||
}
|
||||
|
||||
if (inCc < 0)
|
||||
perror(inFile);
|
||||
|
||||
cleanup:
|
||||
/* Note that we are not freeing memory or closing
|
||||
* files here, to save a few bytes. */
|
||||
#if 0
|
||||
#ifdef BB_FEATURE_CLEAN_UP
|
||||
close(inFd);
|
||||
close(outFd);
|
||||
free(buf);
|
||||
#endif
|
||||
|
||||
printf("%ld+%d records in\n", (long) (intotal / blockSize),
|
||||
(intotal % blockSize) != 0);
|
||||
printf("%ld+%d records in\n", (long) (inTotal / blockSize),
|
||||
(inTotal % blockSize) != 0);
|
||||
printf("%ld+%d records out\n", (long) (outTotal / blockSize),
|
||||
(outTotal % blockSize) != 0);
|
||||
exit(TRUE);
|
||||
|
||||
+2
-9
@@ -22,18 +22,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <mntent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/vfs.h>
|
||||
|
||||
static const char df_usage[] = "df [filesystem ...]\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 */
|
||||
|
||||
static int df(char *device, const char *mountPoint)
|
||||
@@ -82,7 +75,7 @@ extern int df_main(int argc, char **argv)
|
||||
}
|
||||
while (argc > 1) {
|
||||
if ((mountEntry = findMountPoint(argv[1], mtab_file)) == 0) {
|
||||
fprintf(stderr, "%s: can't find mount point.\n", argv[1]);
|
||||
errorMsg("%s: can't find mount point.\n", argv[1]);
|
||||
exit(FALSE);
|
||||
}
|
||||
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
|
||||
+3
-8
@@ -20,20 +20,15 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include "busybox.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
|
||||
);
|
||||
}
|
||||
if ((argc < 2) || (**(argv + 1) == '-'))
|
||||
usage(dirname_usage);
|
||||
argv++;
|
||||
|
||||
s=*argv+strlen(*argv)-1;
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Mini dos2unix implementation for busybox
|
||||
|
||||
Copyright 1994,1995 Patrick Volkerding, Moorhead, Minnesota USA
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this source code, with or without modification, is
|
||||
permitted provided that the following condition is met:
|
||||
|
||||
1. Redistributions of this source code must retain the above copyright
|
||||
notice, this condition, and the following disclaimer.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int dos2unix_main( int argc, char **argv ) {
|
||||
int c;
|
||||
if (argc > 1) {
|
||||
c = *argv[1];
|
||||
if (c == '-') {
|
||||
usage(dos2unix_usage);
|
||||
}
|
||||
}
|
||||
c = getchar();
|
||||
while (c != EOF) {
|
||||
/* Eat any \r's... they shouldn't be here */
|
||||
while (c == '\r') c = getchar();
|
||||
if (c == EOF) break;
|
||||
putchar(c);
|
||||
c = getchar();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+13
-34
@@ -22,7 +22,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_name_too_long
|
||||
#include "messages.c"
|
||||
@@ -35,17 +35,6 @@
|
||||
|
||||
typedef void (Display) (long, char *);
|
||||
|
||||
static const char du_usage[] =
|
||||
"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;
|
||||
|
||||
@@ -108,7 +97,7 @@ static long du(char *filename)
|
||||
}
|
||||
|
||||
if (len + strlen(name) + 1 > BUFSIZ) {
|
||||
fprintf(stderr, name_too_long, "du");
|
||||
errorMsg(name_too_long);
|
||||
du_depth--;
|
||||
return 0;
|
||||
}
|
||||
@@ -137,42 +126,32 @@ static long du(char *filename)
|
||||
int du_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char opt;
|
||||
int c;
|
||||
|
||||
/* default behaviour */
|
||||
print = print_normal;
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
while ((c = getopt(argc, argv, "sl")) != EOF) {
|
||||
switch (c) {
|
||||
case 's':
|
||||
print = print_summary;
|
||||
break;
|
||||
print = print_summary;
|
||||
break;
|
||||
case 'l':
|
||||
count_hardlinks = 1;
|
||||
break;
|
||||
case 'h':
|
||||
case '-':
|
||||
usage(du_usage);
|
||||
break;
|
||||
count_hardlinks = 1;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "du: invalid option -- %c\n", opt);
|
||||
usage(du_usage);
|
||||
usage(du_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* go through remaining args (if any) */
|
||||
if (i >= argc) {
|
||||
if (optind >= argc) {
|
||||
du(".");
|
||||
} else {
|
||||
long sum;
|
||||
|
||||
for (; i < argc; i++) {
|
||||
for (i=optind; i < argc; i++) {
|
||||
sum = du(argv[i]);
|
||||
if (sum && isDirectory(argv[i], FALSE, NULL)) {
|
||||
print_normal(sum, argv[i]);
|
||||
@@ -184,7 +163,7 @@ int du_main(int argc, char **argv)
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* $Id: du.c,v 1.20 2000/06/19 17:25:39 andersen Exp $ */
|
||||
/* $Id: du.c,v 1.25 2000/09/25 21:45:57 andersen Exp $ */
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
|
||||
+15
-25
@@ -22,46 +22,36 @@
|
||||
* Original copyright notice is retained at the end of this file.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.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 c;
|
||||
int nflag = 0;
|
||||
int eflag = 0;
|
||||
|
||||
ap = argv;
|
||||
if (argc)
|
||||
ap++;
|
||||
while ((p = *ap) != NULL && *p == '-') {
|
||||
if (strcmp(p, "-n")==0) {
|
||||
|
||||
while ((c = getopt(argc, argv, "neE")) != EOF) {
|
||||
switch (c) {
|
||||
case 'n':
|
||||
nflag = 1;
|
||||
} else if (strcmp(p, "-e")==0) {
|
||||
break;
|
||||
case 'e':
|
||||
eflag = 1;
|
||||
} else if (strcmp(p, "-E")==0) {
|
||||
break;
|
||||
case 'E':
|
||||
eflag = 0;
|
||||
break;
|
||||
default:
|
||||
usage(echo_usage);
|
||||
}
|
||||
else if (strncmp(p, "--", 2)==0) {
|
||||
usage( uname_usage);
|
||||
}
|
||||
else break;
|
||||
ap++;
|
||||
}
|
||||
|
||||
ap = &argv[optind];
|
||||
while ((p = *ap++) != NULL) {
|
||||
while ((c = *p++) != '\0') {
|
||||
if (c == '\\' && eflag) {
|
||||
|
||||
@@ -0,0 +1,531 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini expr implementation for busybox
|
||||
*
|
||||
* based on GNU expr Mike Parker.
|
||||
* Copyright (C) 86, 1991-1997, 1999 Free Software Foundation, Inc.
|
||||
*
|
||||
* Busybox modifications
|
||||
* Copyright (c) 2000 Edward Betts <edward@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
|
||||
*
|
||||
*/
|
||||
|
||||
/* This program evaluates expressions. Each token (operator, operand,
|
||||
* parenthesis) of the expression must be a seperate argument. The
|
||||
* parser used is a reasonably general one, though any incarnation of
|
||||
* it is language-specific. It is especially nice for expressions.
|
||||
*
|
||||
* No parse tree is needed; a new node is evaluated immediately.
|
||||
* One function can handle multiple operators all of equal precedence,
|
||||
* provided they all associate ((x op x) op x). */
|
||||
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <regex.h>
|
||||
|
||||
/* The kinds of value we can have. */
|
||||
enum valtype {
|
||||
integer,
|
||||
string
|
||||
};
|
||||
typedef enum valtype TYPE;
|
||||
|
||||
/* A value is.... */
|
||||
struct valinfo {
|
||||
TYPE type; /* Which kind. */
|
||||
union { /* The value itself. */
|
||||
int i;
|
||||
char *s;
|
||||
} u;
|
||||
};
|
||||
typedef struct valinfo VALUE;
|
||||
|
||||
/* The arguments given to the program, minus the program name. */
|
||||
static char **args;
|
||||
|
||||
static VALUE *docolon (VALUE *sv, VALUE *pv);
|
||||
static VALUE *eval (void);
|
||||
static VALUE *int_value (int i);
|
||||
static VALUE *str_value (char *s);
|
||||
static int nextarg (char *str);
|
||||
static int null (VALUE *v);
|
||||
static int toarith (VALUE *v);
|
||||
static void freev (VALUE *v);
|
||||
static void tostring (VALUE *v);
|
||||
|
||||
int expr_main (int argc, char **argv)
|
||||
{
|
||||
VALUE *v;
|
||||
|
||||
if (argc == 1) {
|
||||
fatalError("too few arguments\n");
|
||||
}
|
||||
|
||||
args = argv + 1;
|
||||
|
||||
v = eval ();
|
||||
if (*args)
|
||||
fatalError ("syntax error\n");
|
||||
|
||||
if (v->type == integer)
|
||||
printf ("%d\n", v->u.i);
|
||||
else
|
||||
printf ("%s\n", v->u.s);
|
||||
|
||||
exit (null (v));
|
||||
}
|
||||
|
||||
/* Return a VALUE for I. */
|
||||
|
||||
static VALUE *int_value (int i)
|
||||
{
|
||||
VALUE *v;
|
||||
|
||||
v = xmalloc (sizeof(VALUE));
|
||||
v->type = integer;
|
||||
v->u.i = i;
|
||||
return v;
|
||||
}
|
||||
|
||||
/* Return a VALUE for S. */
|
||||
|
||||
static VALUE *str_value (char *s)
|
||||
{
|
||||
VALUE *v;
|
||||
|
||||
v = xmalloc (sizeof(VALUE));
|
||||
v->type = string;
|
||||
v->u.s = strdup (s);
|
||||
return v;
|
||||
}
|
||||
|
||||
/* Free VALUE V, including structure components. */
|
||||
|
||||
static void freev (VALUE *v)
|
||||
{
|
||||
if (v->type == string)
|
||||
free (v->u.s);
|
||||
free (v);
|
||||
}
|
||||
|
||||
/* Return nonzero if V is a null-string or zero-number. */
|
||||
|
||||
static int null (VALUE *v)
|
||||
{
|
||||
switch (v->type) {
|
||||
case integer:
|
||||
return v->u.i == 0;
|
||||
case string:
|
||||
return v->u.s[0] == '\0' || strcmp (v->u.s, "0") == 0;
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
}
|
||||
|
||||
/* Coerce V to a string value (can't fail). */
|
||||
|
||||
static void tostring (VALUE *v)
|
||||
{
|
||||
char *temp;
|
||||
|
||||
if (v->type == integer) {
|
||||
temp = xmalloc (4 * (sizeof (int) / sizeof (char)));
|
||||
sprintf (temp, "%d", v->u.i);
|
||||
v->u.s = temp;
|
||||
v->type = string;
|
||||
}
|
||||
}
|
||||
|
||||
/* Coerce V to an integer value. Return 1 on success, 0 on failure. */
|
||||
|
||||
static int toarith (VALUE *v)
|
||||
{
|
||||
int i;
|
||||
|
||||
switch (v->type) {
|
||||
case integer:
|
||||
return 1;
|
||||
case string:
|
||||
i = 0;
|
||||
/* Don't interpret the empty string as an integer. */
|
||||
if (v->u.s == 0)
|
||||
return 0;
|
||||
i = atoi(v->u.s);
|
||||
free (v->u.s);
|
||||
v->u.i = i;
|
||||
v->type = integer;
|
||||
return 1;
|
||||
default:
|
||||
abort ();
|
||||
}
|
||||
}
|
||||
|
||||
/* Return nonzero if the next token matches STR exactly.
|
||||
STR must not be NULL. */
|
||||
|
||||
static int
|
||||
nextarg (char *str)
|
||||
{
|
||||
if (*args == NULL)
|
||||
return 0;
|
||||
return strcmp (*args, str) == 0;
|
||||
}
|
||||
|
||||
/* The comparison operator handling functions. */
|
||||
|
||||
#define cmpf(name, rel) \
|
||||
static int name (l, r) VALUE *l; VALUE *r; \
|
||||
{ \
|
||||
if (l->type == string || r->type == string) { \
|
||||
tostring (l); \
|
||||
tostring (r); \
|
||||
return strcmp (l->u.s, r->u.s) rel 0; \
|
||||
} \
|
||||
else \
|
||||
return l->u.i rel r->u.i; \
|
||||
}
|
||||
cmpf (less_than, <)
|
||||
cmpf (less_equal, <=)
|
||||
cmpf (equal, ==)
|
||||
cmpf (not_equal, !=)
|
||||
cmpf (greater_equal, >=)
|
||||
cmpf (greater_than, >)
|
||||
|
||||
#undef cmpf
|
||||
|
||||
/* The arithmetic operator handling functions. */
|
||||
|
||||
#define arithf(name, op) \
|
||||
static \
|
||||
int name (l, r) VALUE *l; VALUE *r; \
|
||||
{ \
|
||||
if (!toarith (l) || !toarith (r)) \
|
||||
fatalError ("non-numeric argument\n"); \
|
||||
return l->u.i op r->u.i; \
|
||||
}
|
||||
|
||||
#define arithdivf(name, op) \
|
||||
int name (l, r) VALUE *l; VALUE *r; \
|
||||
{ \
|
||||
if (!toarith (l) || !toarith (r)) \
|
||||
fatalError ( "non-numeric argument\n"); \
|
||||
if (r->u.i == 0) \
|
||||
fatalError ( "division by zero\n"); \
|
||||
return l->u.i op r->u.i; \
|
||||
}
|
||||
|
||||
arithf (plus, +)
|
||||
arithf (minus, -)
|
||||
arithf (multiply, *)
|
||||
arithdivf (divide, /)
|
||||
arithdivf (mod, %)
|
||||
|
||||
#undef arithf
|
||||
#undef arithdivf
|
||||
|
||||
/* Do the : operator.
|
||||
SV is the VALUE for the lhs (the string),
|
||||
PV is the VALUE for the rhs (the pattern). */
|
||||
|
||||
static VALUE *docolon (VALUE *sv, VALUE *pv)
|
||||
{
|
||||
VALUE *v;
|
||||
const char *errmsg;
|
||||
struct re_pattern_buffer re_buffer;
|
||||
struct re_registers re_regs;
|
||||
int len;
|
||||
|
||||
tostring (sv);
|
||||
tostring (pv);
|
||||
|
||||
if (pv->u.s[0] == '^') {
|
||||
fprintf (stderr, "\
|
||||
warning: unportable BRE: `%s': using `^' as the first character\n\
|
||||
of a basic regular expression is not portable; it is being ignored",
|
||||
pv->u.s);
|
||||
}
|
||||
|
||||
len = strlen (pv->u.s);
|
||||
memset (&re_buffer, 0, sizeof (re_buffer));
|
||||
memset (&re_regs, 0, sizeof (re_regs));
|
||||
re_buffer.allocated = 2 * len;
|
||||
re_buffer.buffer = (unsigned char *) xmalloc (re_buffer.allocated);
|
||||
re_buffer.translate = 0;
|
||||
re_syntax_options = RE_SYNTAX_POSIX_BASIC;
|
||||
errmsg = re_compile_pattern (pv->u.s, len, &re_buffer);
|
||||
if (errmsg) {
|
||||
fatalError("%s\n", errmsg);
|
||||
}
|
||||
|
||||
len = re_match (&re_buffer, sv->u.s, strlen (sv->u.s), 0, &re_regs);
|
||||
if (len >= 0) {
|
||||
/* Were \(...\) used? */
|
||||
if (re_buffer.re_nsub > 0) { /* was (re_regs.start[1] >= 0) */
|
||||
sv->u.s[re_regs.end[1]] = '\0';
|
||||
v = str_value (sv->u.s + re_regs.start[1]);
|
||||
}
|
||||
else
|
||||
v = int_value (len);
|
||||
}
|
||||
else {
|
||||
/* Match failed -- return the right kind of null. */
|
||||
if (re_buffer.re_nsub > 0)
|
||||
v = str_value ("");
|
||||
else
|
||||
v = int_value (0);
|
||||
}
|
||||
free (re_buffer.buffer);
|
||||
return v;
|
||||
}
|
||||
|
||||
/* Handle bare operands and ( expr ) syntax. */
|
||||
|
||||
static VALUE *eval7 (void)
|
||||
{
|
||||
VALUE *v;
|
||||
|
||||
if (!*args)
|
||||
fatalError ( "syntax error\n");
|
||||
|
||||
if (nextarg ("(")) {
|
||||
args++;
|
||||
v = eval ();
|
||||
if (!nextarg (")"))
|
||||
fatalError ( "syntax error\n");
|
||||
args++;
|
||||
return v;
|
||||
}
|
||||
|
||||
if (nextarg (")"))
|
||||
fatalError ( "syntax error\n");
|
||||
|
||||
return str_value (*args++);
|
||||
}
|
||||
|
||||
/* Handle match, substr, index, length, and quote keywords. */
|
||||
|
||||
static VALUE *eval6 (void)
|
||||
{
|
||||
VALUE *l, *r, *v, *i1, *i2;
|
||||
|
||||
if (nextarg ("quote")) {
|
||||
args++;
|
||||
if (!*args)
|
||||
fatalError ( "syntax error\n");
|
||||
return str_value (*args++);
|
||||
}
|
||||
else if (nextarg ("length")) {
|
||||
args++;
|
||||
r = eval6 ();
|
||||
tostring (r);
|
||||
v = int_value (strlen (r->u.s));
|
||||
freev (r);
|
||||
return v;
|
||||
}
|
||||
else if (nextarg ("match")) {
|
||||
args++;
|
||||
l = eval6 ();
|
||||
r = eval6 ();
|
||||
v = docolon (l, r);
|
||||
freev (l);
|
||||
freev (r);
|
||||
return v;
|
||||
}
|
||||
else if (nextarg ("index")) {
|
||||
args++;
|
||||
l = eval6 ();
|
||||
r = eval6 ();
|
||||
tostring (l);
|
||||
tostring (r);
|
||||
v = int_value (strcspn (l->u.s, r->u.s) + 1);
|
||||
if (v->u.i == (int) strlen (l->u.s) + 1)
|
||||
v->u.i = 0;
|
||||
freev (l);
|
||||
freev (r);
|
||||
return v;
|
||||
}
|
||||
else if (nextarg ("substr")) {
|
||||
args++;
|
||||
l = eval6 ();
|
||||
i1 = eval6 ();
|
||||
i2 = eval6 ();
|
||||
tostring (l);
|
||||
if (!toarith (i1) || !toarith (i2)
|
||||
|| i1->u.i > (int) strlen (l->u.s)
|
||||
|| i1->u.i <= 0 || i2->u.i <= 0)
|
||||
v = str_value ("");
|
||||
else {
|
||||
v = xmalloc (sizeof(VALUE));
|
||||
v->type = string;
|
||||
v->u.s = strncpy ((char *) xmalloc (i2->u.i + 1),
|
||||
l->u.s + i1->u.i - 1, i2->u.i);
|
||||
v->u.s[i2->u.i] = 0;
|
||||
}
|
||||
freev (l);
|
||||
freev (i1);
|
||||
freev (i2);
|
||||
return v;
|
||||
}
|
||||
else
|
||||
return eval7 ();
|
||||
}
|
||||
|
||||
/* Handle : operator (pattern matching).
|
||||
Calls docolon to do the real work. */
|
||||
|
||||
static VALUE *eval5 (void)
|
||||
{
|
||||
VALUE *l, *r, *v;
|
||||
|
||||
l = eval6 ();
|
||||
while (nextarg (":")) {
|
||||
args++;
|
||||
r = eval6 ();
|
||||
v = docolon (l, r);
|
||||
freev (l);
|
||||
freev (r);
|
||||
l = v;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
/* Handle *, /, % operators. */
|
||||
|
||||
static VALUE *eval4 (void)
|
||||
{
|
||||
VALUE *l, *r;
|
||||
int (*fxn) (), val;
|
||||
|
||||
l = eval5 ();
|
||||
while (1) {
|
||||
if (nextarg ("*"))
|
||||
fxn = multiply;
|
||||
else if (nextarg ("/"))
|
||||
fxn = divide;
|
||||
else if (nextarg ("%"))
|
||||
fxn = mod;
|
||||
else
|
||||
return l;
|
||||
args++;
|
||||
r = eval5 ();
|
||||
val = (*fxn) (l, r);
|
||||
freev (l);
|
||||
freev (r);
|
||||
l = int_value (val);
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle +, - operators. */
|
||||
|
||||
static VALUE *eval3 (void)
|
||||
{
|
||||
VALUE *l, *r;
|
||||
int (*fxn) (), val;
|
||||
|
||||
l = eval4 ();
|
||||
while (1) {
|
||||
if (nextarg ("+"))
|
||||
fxn = plus;
|
||||
else if (nextarg ("-"))
|
||||
fxn = minus;
|
||||
else
|
||||
return l;
|
||||
args++;
|
||||
r = eval4 ();
|
||||
val = (*fxn) (l, r);
|
||||
freev (l);
|
||||
freev (r);
|
||||
l = int_value (val);
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle comparisons. */
|
||||
|
||||
static VALUE *eval2 (void)
|
||||
{
|
||||
VALUE *l, *r;
|
||||
int (*fxn) (), val;
|
||||
|
||||
l = eval3 ();
|
||||
while (1) {
|
||||
if (nextarg ("<"))
|
||||
fxn = less_than;
|
||||
else if (nextarg ("<="))
|
||||
fxn = less_equal;
|
||||
else if (nextarg ("=") || nextarg ("=="))
|
||||
fxn = equal;
|
||||
else if (nextarg ("!="))
|
||||
fxn = not_equal;
|
||||
else if (nextarg (">="))
|
||||
fxn = greater_equal;
|
||||
else if (nextarg (">"))
|
||||
fxn = greater_than;
|
||||
else
|
||||
return l;
|
||||
args++;
|
||||
r = eval3 ();
|
||||
toarith (l);
|
||||
toarith (r);
|
||||
val = (*fxn) (l, r);
|
||||
freev (l);
|
||||
freev (r);
|
||||
l = int_value (val);
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle &. */
|
||||
|
||||
static VALUE *eval1 (void)
|
||||
{
|
||||
VALUE *l, *r;
|
||||
|
||||
l = eval2 ();
|
||||
while (nextarg ("&")) {
|
||||
args++;
|
||||
r = eval2 ();
|
||||
if (null (l) || null (r)) {
|
||||
freev (l);
|
||||
freev (r);
|
||||
l = int_value (0);
|
||||
}
|
||||
else
|
||||
freev (r);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
/* Handle |. */
|
||||
|
||||
static VALUE *eval (void)
|
||||
{
|
||||
VALUE *l, *r;
|
||||
|
||||
l = eval1 ();
|
||||
while (nextarg ("|")) {
|
||||
args++;
|
||||
r = eval1 ();
|
||||
if (null (l)) {
|
||||
freev (l);
|
||||
l = r;
|
||||
}
|
||||
else
|
||||
freev (r);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
+4
-16
@@ -22,21 +22,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
const char head_usage[] =
|
||||
"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"
|
||||
#endif
|
||||
;
|
||||
|
||||
int head(int len, FILE * src)
|
||||
{
|
||||
int i;
|
||||
@@ -75,7 +64,7 @@ int head_main(int argc, char **argv)
|
||||
case 'h':
|
||||
usage(head_usage);
|
||||
default:
|
||||
fprintf(stderr, "head: invalid option -- %c\n", opt);
|
||||
errorMsg("invalid option -- %c\n", opt);
|
||||
usage(head_usage);
|
||||
}
|
||||
} else {
|
||||
@@ -95,8 +84,7 @@ int head_main(int argc, char **argv)
|
||||
|
||||
src = fopen(argv[i], "r");
|
||||
if (!src) {
|
||||
fprintf(stderr, "head: %s: %s\n", argv[i],
|
||||
strerror(errno));
|
||||
errorMsg("%s: %s\n", argv[i], strerror(errno));
|
||||
} else {
|
||||
/* emulating GNU behaviour */
|
||||
if (need_headers) {
|
||||
@@ -112,4 +100,4 @@ int head_main(int argc, char **argv)
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* $Id: head.c,v 1.11 2000/06/19 17:25:39 andersen Exp $ */
|
||||
/* $Id: head.c,v 1.14 2000/09/25 21:45:57 andersen Exp $ */
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern int hostid_main(int argc, char **argv)
|
||||
|
||||
+34
-37
@@ -2,7 +2,6 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -21,54 +20,48 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <getopt.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;
|
||||
long gid;
|
||||
long pwnam, grnam;
|
||||
int opt;
|
||||
|
||||
cp = user = group = NULL;
|
||||
gid = 0;
|
||||
|
||||
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;
|
||||
while ((opt = getopt(argc, argv, "ugr")) > 0) {
|
||||
switch (opt) {
|
||||
case 'u':
|
||||
no_group++;
|
||||
break;
|
||||
case 'g':
|
||||
no_user++;
|
||||
break;
|
||||
case 'r':
|
||||
print_real++;
|
||||
break;
|
||||
default:
|
||||
usage(id_usage);
|
||||
}
|
||||
argc--; argv++;
|
||||
}
|
||||
|
||||
if (no_user && no_group) usage(id_usage);
|
||||
|
||||
user = argv[optind];
|
||||
|
||||
if (user == NULL) {
|
||||
user = xmalloc(9);
|
||||
group = xmalloc(9);
|
||||
user = xcalloc(9, sizeof(char));
|
||||
group = xcalloc(9, sizeof(char));
|
||||
if (print_real) {
|
||||
my_getpwuid(user, getuid());
|
||||
my_getgrgid(group, getgid());
|
||||
@@ -77,18 +70,22 @@ extern int id_main(int argc, char **argv)
|
||||
my_getgrgid(group, getegid());
|
||||
}
|
||||
} else {
|
||||
group = xmalloc(9);
|
||||
group = xcalloc(9, sizeof(char));
|
||||
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));
|
||||
pwnam=my_getpwnam(user);
|
||||
grnam=my_getgrnam(group);
|
||||
if (gid == -1 || pwnam==-1 || grnam==-1) {
|
||||
fatalError("%s: No such user\n", user);
|
||||
}
|
||||
if (no_group)
|
||||
printf("%ld\n", pwnam);
|
||||
else if (no_user)
|
||||
printf("%ld\n", grnam);
|
||||
else
|
||||
printf("uid=%lu(%s) gid=%lu(%s)\n",
|
||||
my_getpwnam(user), user, my_getgrnam(group), group);
|
||||
|
||||
|
||||
printf("uid=%ld(%s) gid=%ld(%s)\n", pwnam, user, grnam, group);
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
+3
-8
@@ -1,18 +1,13 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern int length_main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 2 || **(argv + 1) == '-') {
|
||||
usage("length STRING\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrints out the length of the specified STRING.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
if (argc != 2 || **(argv + 1) == '-')
|
||||
usage(length_usage);
|
||||
printf("%lu\n", (long)strlen(argv[1]));
|
||||
return (TRUE);
|
||||
}
|
||||
+3
-17
@@ -21,9 +21,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_name_too_long
|
||||
#define bb_need_not_a_directory
|
||||
#include "messages.c"
|
||||
|
||||
@@ -31,19 +30,6 @@
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char ln_usage[] =
|
||||
"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"
|
||||
#endif
|
||||
;
|
||||
|
||||
static int symlinkFlag = FALSE;
|
||||
static int removeoldFlag = FALSE;
|
||||
static int followLinks = TRUE;
|
||||
@@ -92,7 +78,7 @@ extern int ln_main(int argc, char **argv)
|
||||
|
||||
linkIntoDirFlag = isDirectory(linkName, followLinks, NULL);
|
||||
if ((argc >= 3) && linkIntoDirFlag == FALSE) {
|
||||
fprintf(stderr, not_a_directory, "ln", linkName);
|
||||
errorMsg(not_a_directory, linkName);
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
@@ -104,7 +90,7 @@ extern int ln_main(int argc, char **argv)
|
||||
|
||||
if (linkIntoDirFlag == TRUE) {
|
||||
char *baseName = get_last_path_component(*argv);
|
||||
linkName = (char *)malloc(strlen(dirName)+strlen(baseName)+2);
|
||||
linkName = (char *)xmalloc(strlen(dirName)+strlen(baseName)+2);
|
||||
strcpy(linkName, dirName);
|
||||
if(dirName[strlen(dirName)-1] != '/')
|
||||
strcat(linkName, "/");
|
||||
|
||||
+2
-8
@@ -20,15 +20,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
|
||||
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 *user = xmalloc(9);
|
||||
@@ -41,6 +35,6 @@ extern int logname_main(int argc, char **argv)
|
||||
puts(user);
|
||||
exit(TRUE);
|
||||
}
|
||||
fprintf(stderr, "no login name\n");
|
||||
errorMsg("no login name\n");
|
||||
return(FALSE);
|
||||
}
|
||||
+712
-487
File diff suppressed because it is too large.
Load diff
+7
-24
@@ -20,7 +20,7 @@
|
||||
/* Written by Ulrich Drepper <drepper@gnu.ai.mit.edu> */
|
||||
/* Hacked to work with BusyBox by Alfred M. Szmidt <ams@trillian.itslinux.org> */
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
@@ -66,7 +66,7 @@ extern _IO_ssize_t getline __P ((char **, size_t *, FILE *));
|
||||
#include <string.h>
|
||||
#include <endian.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
//----------------------------------------------------------------------------
|
||||
//--------md5.h
|
||||
//----------------------------------------------------------------------------
|
||||
@@ -96,7 +96,7 @@ extern _IO_ssize_t getline __P ((char **, size_t *, FILE *));
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined HAVE_LIMITS_H || _LIBC
|
||||
#if defined HAVE_LIMITS_H || defined _LIBC
|
||||
# include <limits.h>
|
||||
#endif
|
||||
|
||||
@@ -582,23 +582,6 @@ static int status_only = 0; /* With -c, don't generate any output.
|
||||
static int warn = 0; /* With -w, print a message to standard error warning
|
||||
about each improperly formatted MD5 checksum line */
|
||||
|
||||
static const char md5sum_usage[] =
|
||||
"md5sum [OPTION] [FILE]...\n"
|
||||
"or: md5sum [OPTION] -c [FILE]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint or check MD5 checksums.\n\n"
|
||||
"Options:\n"
|
||||
"With no FILE, or when FILE is -, read standard input.\n\n"
|
||||
"\t-b\tread files in binary mode\n"
|
||||
"\t-c\tcheck MD5 sums against given list\n"
|
||||
"\t-t\tread files in text mode (default)\n"
|
||||
"\t-g\tread a string\n"
|
||||
"\nThe following two options are useful only when verifying checksums:\n"
|
||||
"\t-s,\tdon't output anything, status code shows success\n"
|
||||
"\t-w,\twarn about improperly formated MD5 checksum lines\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
static int split_3(char *s,
|
||||
size_t s_len,
|
||||
unsigned char **u,
|
||||
@@ -708,13 +691,13 @@ static int md5_file(const char *filename,
|
||||
} else {
|
||||
fp = fopen(filename, OPENOPTS(binary));
|
||||
if (fp == NULL) {
|
||||
errorMsg("md5sum: %s: %s\n", filename, strerror(errno));
|
||||
errorMsg("%s: %s\n", filename, strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (md5_stream(fp, md5_result)) {
|
||||
errorMsg("md5sum: %s: %s\n", filename, strerror(errno));
|
||||
errorMsg("%s: %s\n", filename, strerror(errno));
|
||||
|
||||
if (fp != stdin)
|
||||
fclose(fp);
|
||||
@@ -722,7 +705,7 @@ static int md5_file(const char *filename,
|
||||
}
|
||||
|
||||
if (fp != stdin && fclose(fp) == EOF) {
|
||||
errorMsg("md5sum: %s: %s\n", filename, strerror(errno));
|
||||
errorMsg("%s: %s\n", filename, strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -746,7 +729,7 @@ static int md5_check(const char *checkfile_name)
|
||||
} else {
|
||||
checkfile_stream = fopen(checkfile_name, "r");
|
||||
if (checkfile_stream == NULL) {
|
||||
errorMsg("md5sum: %s: %s\n", checkfile_name, strerror(errno));
|
||||
errorMsg("%s: %s\n", checkfile_name, strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-16
@@ -21,7 +21,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#define bb_need_name_too_long
|
||||
#define BB_DECLARE_EXTERN
|
||||
#include "messages.c"
|
||||
@@ -29,18 +29,6 @@
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char mkdir_usage[] =
|
||||
"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"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
static int parentFlag = FALSE;
|
||||
static mode_t mode = 0777;
|
||||
|
||||
@@ -62,7 +50,7 @@ extern int mkdir_main(int argc, char **argv)
|
||||
/* Find the specified modes */
|
||||
mode = 0;
|
||||
if (parse_mode(*(++argv), &mode) == FALSE) {
|
||||
fprintf(stderr, "Unknown mode: %s\n", *argv);
|
||||
errorMsg("Unknown mode: %s\n", *argv);
|
||||
exit FALSE;
|
||||
}
|
||||
/* Set the umask for this process so it doesn't
|
||||
@@ -91,13 +79,13 @@ extern int mkdir_main(int argc, char **argv)
|
||||
char buf[BUFSIZ + 1];
|
||||
|
||||
if (strlen(*argv) > BUFSIZ - 1) {
|
||||
fprintf(stderr, name_too_long, "mkdir");
|
||||
errorMsg(name_too_long);
|
||||
exit FALSE;
|
||||
}
|
||||
strcpy(buf, *argv);
|
||||
status = stat(buf, &statBuf);
|
||||
if (parentFlag == FALSE && status != -1 && errno != ENOENT) {
|
||||
fprintf(stderr, "%s: File exists\n", buf);
|
||||
errorMsg("%s: File exists\n", buf);
|
||||
exit FALSE;
|
||||
}
|
||||
if (parentFlag == TRUE) {
|
||||
|
||||
+1
-10
@@ -20,20 +20,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
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 pipe using the specified mode (default a=rw)\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int mkfifo_main(int argc, char **argv)
|
||||
{
|
||||
char *thisarg;
|
||||
|
||||
+1
-14
@@ -20,26 +20,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
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"
|
||||
#endif
|
||||
;
|
||||
|
||||
int mknod_main(int argc, char **argv)
|
||||
{
|
||||
char *thisarg;
|
||||
|
||||
+1
-9
@@ -47,11 +47,10 @@
|
||||
|
||||
// 19990508 Busy Boxed! Dave Cinege
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
@@ -137,13 +136,6 @@ 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"
|
||||
#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)
|
||||
{
|
||||
char *format;
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
@@ -31,7 +31,7 @@ extern int pwd_main(int argc, char **argv)
|
||||
char buf[BUFSIZ + 1];
|
||||
|
||||
if (getcwd(buf, sizeof(buf)) == NULL)
|
||||
fatalError("pwd: %s\n", strerror(errno));
|
||||
fatalError("%s\n", strerror(errno));
|
||||
|
||||
printf("%s\n", buf);
|
||||
return(TRUE);
|
||||
|
||||
+6
-12
@@ -22,24 +22,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
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"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
static int recursiveFlag = FALSE;
|
||||
static int forceFlag = FALSE;
|
||||
static const char *srcName;
|
||||
@@ -56,6 +45,11 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
|
||||
static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
if (recursiveFlag == FALSE) {
|
||||
errno = EISDIR;
|
||||
perror(fileName);
|
||||
return (FALSE);
|
||||
}
|
||||
if (rmdir(fileName) < 0) {
|
||||
perror(fileName);
|
||||
return (FALSE);
|
||||
|
||||
+4
-11
@@ -22,25 +22,18 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
extern int rmdir_main(int argc, char **argv)
|
||||
{
|
||||
if (argc == 1 || **(argv + 1) == '-') {
|
||||
usage
|
||||
("rmdir [OPTION]... DIRECTORY...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nRemove the DIRECTORY(ies), if they are empty.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
if (argc == 1 || **(argv + 1) == '-')
|
||||
usage(rmdir_usage);
|
||||
|
||||
while (--argc > 0) {
|
||||
if (rmdir(*(++argv)) == -1) {
|
||||
fprintf(stderr, "%s: %s\n", *argv, strerror(errno));
|
||||
errorMsg("%s\n", strerror(errno));
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-7
@@ -21,15 +21,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
|
||||
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)
|
||||
{
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
|
||||
+5
-21
@@ -22,23 +22,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
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;
|
||||
@@ -74,7 +64,7 @@ static const int max = 1024;
|
||||
static Line *line_alloc()
|
||||
{
|
||||
Line *self;
|
||||
self = malloc(1 * sizeof(Line));
|
||||
self = xmalloc(1 * sizeof(Line));
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -86,9 +76,6 @@ static Line *line_newFromFile(FILE * src)
|
||||
|
||||
if ((cstring = get_line_from_file(src))) {
|
||||
self = line_alloc();
|
||||
if (self == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
self->data = cstring;
|
||||
self->next = NULL;
|
||||
return self;
|
||||
@@ -183,10 +170,7 @@ static List *list_sort(List * self, Compare * compare)
|
||||
Line *line;
|
||||
|
||||
/* mallocate array of Line*s */
|
||||
self->sorted = (Line **) malloc(self->len * sizeof(Line *));
|
||||
if (self->sorted == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
self->sorted = (Line **) xmalloc(self->len * sizeof(Line *));
|
||||
|
||||
/* fill array w/ List's contents */
|
||||
i = 0;
|
||||
@@ -263,7 +247,7 @@ int sort_main(int argc, char **argv)
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
fprintf(stderr, "sort: invalid option -- %c\n", opt);
|
||||
errorMsg("invalid option -- %c\n", opt);
|
||||
usage(sort_usage);
|
||||
}
|
||||
} else {
|
||||
@@ -304,4 +288,4 @@ int sort_main(int argc, char **argv)
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* $Id: sort.c,v 1.18 2000/06/28 22:15:26 markw Exp $ */
|
||||
/* $Id: sort.c,v 1.22 2000/09/25 21:45:58 andersen Exp $ */
|
||||
+3
-8
@@ -21,17 +21,12 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern int sync_main(int argc, char **argv)
|
||||
{
|
||||
if (argc > 1 && **(argv + 1) == '-') {
|
||||
usage("sync\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nWrite all buffered filesystem blocks to disk.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
if (argc > 1 && **(argv + 1) == '-')
|
||||
usage(sync_usage);
|
||||
return(sync());
|
||||
}
|
||||
+261
-1151
File diff suppressed because it is too large.
Load diff
+32
-100
@@ -2,9 +2,8 @@
|
||||
/*
|
||||
* Mini tee implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
* Written by Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
||||
*
|
||||
* 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
|
||||
@@ -22,115 +21,48 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <errno.h>
|
||||
#include "busybox.h"
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static const char tee_usage[] =
|
||||
"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;
|
||||
static int FL_end;
|
||||
|
||||
typedef void (FL_Function) (FILE * file, char c);
|
||||
|
||||
|
||||
/* apply a function to everything in FileList */
|
||||
static void FL_apply(FL_Function * f, char c)
|
||||
int
|
||||
tee_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char *mode = "w";
|
||||
int c, i, status = 0, nfiles = 0;
|
||||
FILE **files;
|
||||
|
||||
for (i = 0; i <= FL_end; i++) {
|
||||
f(FileList[i], c);
|
||||
}
|
||||
}
|
||||
|
||||
/* FL_Function for writing to files*/
|
||||
static void tee_fwrite(FILE * file, char c)
|
||||
{
|
||||
fputc(c, file);
|
||||
}
|
||||
|
||||
/* FL_Function for closing files */
|
||||
static void tee_fclose(FILE * file, char c)
|
||||
{
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
/* ________________________________________________________________________ */
|
||||
|
||||
/* BusyBoxed tee(1) */
|
||||
int tee_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char c;
|
||||
char opt;
|
||||
char opt_fopen[2] = "w";
|
||||
FILE *file;
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 'a':
|
||||
opt_fopen[0] = 'a';
|
||||
break;
|
||||
#if 0
|
||||
case 'i':
|
||||
fprintf(stderr, "ignore interrupt not implemented\n");
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
usage(tee_usage);
|
||||
}
|
||||
} else {
|
||||
while ((c = getopt(argc, argv, "a")) != EOF) {
|
||||
switch (c) {
|
||||
case 'a':
|
||||
mode = "a";
|
||||
break;
|
||||
default:
|
||||
usage(tee_usage);
|
||||
}
|
||||
}
|
||||
|
||||
/* 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++) {
|
||||
/* add a file to FileList */
|
||||
file = fopen(argv[i], opt_fopen);
|
||||
if (!file) {
|
||||
continue;
|
||||
}
|
||||
if (FL_end < FL_MAX) {
|
||||
FileList[++FL_end] = file;
|
||||
files = (FILE **)xmalloc(sizeof(FILE *) * (argc - optind + 1));
|
||||
files[nfiles++] = stdout;
|
||||
while (optind < argc) {
|
||||
if ((files[nfiles++] = fopen(argv[optind++], mode)) == NULL) {
|
||||
nfiles--;
|
||||
errorMsg("%s: %s\n", argv[optind-1], strerror(errno));
|
||||
status = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* read and redirect */
|
||||
while ((c = (char) getchar()) && (!feof(stdin))) {
|
||||
FL_apply(tee_fwrite, c);
|
||||
}
|
||||
while ((c = getchar()) != EOF)
|
||||
for (i = 0; i < nfiles; i++)
|
||||
putc(c, files[i]);
|
||||
|
||||
/* clean up */
|
||||
FL_apply(tee_fclose, 0);
|
||||
/* Don't bother to close files Exit does that
|
||||
* automagically, so we can save a few bytes */
|
||||
/* free(FileList); */
|
||||
return(0);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* $Id: tee.c,v 1.11 2000/06/19 17:25:40 andersen Exp $ */
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
+5
-18
@@ -31,9 +31,8 @@
|
||||
* "This program is in the Public Domain."
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
@@ -183,21 +182,11 @@ test_main(int argc, char** argv)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (strcmp(argv[0], "[") == 0) {
|
||||
if (strcmp(applet_name, "[") == 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:
|
||||
@@ -372,7 +361,7 @@ filstat(nm, mode)
|
||||
enum token mode;
|
||||
{
|
||||
struct stat s;
|
||||
int i;
|
||||
unsigned int i;
|
||||
|
||||
if (mode == FILSYM) {
|
||||
#ifdef S_IFLNK
|
||||
@@ -535,7 +524,7 @@ char *path;
|
||||
int mode;
|
||||
{
|
||||
struct stat st;
|
||||
int euid = geteuid();
|
||||
unsigned int euid = geteuid();
|
||||
|
||||
if (stat (path, &st) < 0)
|
||||
return (-1);
|
||||
@@ -566,9 +555,7 @@ 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");
|
||||
|
||||
group_array = xrealloc(group_array, ngroups * sizeof(gid_t));
|
||||
getgroups(ngroups, group_array);
|
||||
}
|
||||
|
||||
|
||||
+3
-14
@@ -22,24 +22,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <utime.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
int fd;
|
||||
@@ -70,12 +59,12 @@ extern int touch_main(int argc, char **argv)
|
||||
if (create == FALSE && errno == ENOENT)
|
||||
exit(TRUE);
|
||||
else {
|
||||
fatalError("touch: %s", strerror(errno));
|
||||
fatalError("%s", strerror(errno));
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
if (utime(*argv, NULL)) {
|
||||
fatalError("touch: %s", strerror(errno));
|
||||
fatalError("%s", strerror(errno));
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
+32
-41
@@ -24,7 +24,7 @@
|
||||
* Original copyright notice is retained at the end of this file.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@@ -34,19 +34,6 @@
|
||||
#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
|
||||
@@ -98,21 +85,23 @@ static void convert()
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
static void map(register unsigned char *string1, register unsigned char *string2)
|
||||
static void map(register unsigned char *string1, unsigned int string1_len,
|
||||
register unsigned char *string2, unsigned int string2_len)
|
||||
{
|
||||
unsigned char last = '0';
|
||||
unsigned int i, j;
|
||||
|
||||
while (*string1) {
|
||||
if (*string2 == '\0')
|
||||
vector[*string1] = last;
|
||||
for (j = 0, i = 0; i < string1_len; i++) {
|
||||
if (string2_len <= j)
|
||||
vector[string1[i]] = last;
|
||||
else
|
||||
vector[*string1] = last = *string2++;
|
||||
string1++;
|
||||
vector[string1[i]] = last = string2[j++];
|
||||
}
|
||||
}
|
||||
|
||||
static void expand(char *arg, register unsigned char *buffer)
|
||||
static unsigned int expand(char *arg, register unsigned char *buffer)
|
||||
{
|
||||
unsigned char *buffer_start = buffer;
|
||||
int i, ac;
|
||||
|
||||
while (*arg) {
|
||||
@@ -134,31 +123,33 @@ static void expand(char *arg, register unsigned char *buffer)
|
||||
} else
|
||||
*buffer++ = *arg++;
|
||||
}
|
||||
|
||||
return (buffer - buffer_start);
|
||||
}
|
||||
|
||||
static void complement(unsigned char *buffer)
|
||||
static int complement(unsigned char *buffer, int buffer_len)
|
||||
{
|
||||
register unsigned char *ptr;
|
||||
register short i, index;
|
||||
unsigned char conv[ASCII + 2];
|
||||
register short i, j, index;
|
||||
char conv[ASCII + 2];
|
||||
|
||||
index = 0;
|
||||
for (i = 1; i <= ASCII; i++) {
|
||||
for (ptr = buffer; *ptr; ptr++)
|
||||
if (*ptr == i)
|
||||
for (i = 0; i <= ASCII; i++) {
|
||||
for (j = 0; j < buffer_len; j++)
|
||||
if (buffer[j] == i)
|
||||
break;
|
||||
if (*ptr == '\0')
|
||||
if (j == buffer_len)
|
||||
conv[index++] = i & ASCII;
|
||||
}
|
||||
conv[index] = '\0';
|
||||
strcpy((char *) buffer, (char *) conv);
|
||||
memcpy(buffer, conv, index);
|
||||
return index;
|
||||
}
|
||||
|
||||
extern int tr_main(int argc, char **argv)
|
||||
{
|
||||
register unsigned char *ptr;
|
||||
int output_length=0, input_length;
|
||||
int index = 1;
|
||||
short i;
|
||||
int i;
|
||||
|
||||
if (argc > 1 && argv[index][0] == '-') {
|
||||
for (ptr = (unsigned char *) &argv[index][1]; *ptr; ptr++) {
|
||||
@@ -184,19 +175,19 @@ extern int tr_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (argv[index] != NULL) {
|
||||
expand(argv[index++], input);
|
||||
input_length = expand(argv[index++], input);
|
||||
if (com_fl)
|
||||
complement(input);
|
||||
input_length = complement(input, input_length);
|
||||
if (argv[index] != NULL) {
|
||||
if (*argv[index] == '\0')
|
||||
fatalError("tr: STRING2 cannot be empty\n");
|
||||
expand(argv[index], output);
|
||||
map(input, output);
|
||||
fatalError("STRING2 cannot be empty\n");
|
||||
output_length = expand(argv[index], output);
|
||||
map(input, input_length, output, output_length);
|
||||
}
|
||||
for (ptr = input; *ptr; ptr++)
|
||||
invec[*ptr] = TRUE;
|
||||
for (ptr = output; *ptr; ptr++)
|
||||
outvec[*ptr] = TRUE;
|
||||
for (i = 0; i < input_length; i++)
|
||||
invec[input[i]] = TRUE;
|
||||
for (i = 0; i < output_length; i++)
|
||||
outvec[output[i]] = TRUE;
|
||||
}
|
||||
convert();
|
||||
return (0);
|
||||
|
||||
+1
-9
@@ -20,18 +20,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
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)
|
||||
{
|
||||
char *tty;
|
||||
|
||||
+1
-19
@@ -31,7 +31,7 @@
|
||||
|
||||
/* Busyboxed by Erik Andersen */
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/utsname.h>
|
||||
@@ -40,24 +40,6 @@
|
||||
# include <sys/systeminfo.h>
|
||||
#endif
|
||||
|
||||
|
||||
static const char uname_usage[] =
|
||||
"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"
|
||||
"\t-n\tprint the machine's network node hostname\n"
|
||||
"\t-r\tprint the operating system release\n"
|
||||
"\t-s\tprint the operating system name\n"
|
||||
|
||||
"\t-p\tprint the host processor type\n"
|
||||
"\t-v\tprint the operating system version\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
static void print_element(unsigned int mask, char *element);
|
||||
|
||||
/* Values that are bitwise or'd into `toprint'. */
|
||||
|
||||
+4
-12
@@ -22,19 +22,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char uniq_usage[] =
|
||||
"uniq [OPTION]... [INPUT [OUTPUT]]\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
|
||||
|
||||
@@ -127,11 +119,11 @@ set_file_pointers(int schema, FILE ** in, FILE ** out, char **argv)
|
||||
break;
|
||||
}
|
||||
if (*in == NULL) {
|
||||
fprintf(stderr, "uniq: %s: %s\n", argv[0], strerror(errno));
|
||||
errorMsg("%s: %s\n", argv[0], strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
if (*out == NULL) {
|
||||
fprintf(stderr, "uniq: %s: %s\n", argv[1], strerror(errno));
|
||||
errorMsg("%s: %s\n", argv[1], strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
@@ -187,4 +179,4 @@ int uniq_main(int argc, char **argv)
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* $Id: uniq.c,v 1.11 2000/06/19 17:25:40 andersen Exp $ */
|
||||
/* $Id: uniq.c,v 1.14 2000/09/25 21:45:58 andersen Exp $ */
|
||||
+1
-7
@@ -21,16 +21,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.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) == '-')) {
|
||||
|
||||
+3
-12
@@ -51,7 +51,7 @@
|
||||
|
||||
/* Reworked to GNU style by Ian Lance Taylor, ian@airs.com, August 93. */
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
@@ -286,7 +286,7 @@ static int decode (const char *inname,
|
||||
&& (freopen (outname, "w", stdout) == NULL
|
||||
|| chmod (outname, mode & (S_IRWXU | S_IRWXG | S_IRWXO))
|
||||
)) {
|
||||
errorMsg("uudeoce %s: %s %s\n", outname, inname, strerror(errno)); /* */
|
||||
errorMsg("%s: %s %s\n", outname, inname, strerror(errno)); /* */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -300,15 +300,6 @@ static int decode (const char *inname,
|
||||
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)
|
||||
{
|
||||
@@ -340,7 +331,7 @@ int uudecode_main (int argc,
|
||||
if (decode (argv[optind], outname) != 0)
|
||||
exit_status = FALSE;
|
||||
} else {
|
||||
errorMsg("uudecode: %s: %s\n", argv[optind], strerror(errno));
|
||||
errorMsg("%s: %s\n", argv[optind], strerror(errno));
|
||||
exit_status = FALSE;
|
||||
}
|
||||
optind++;
|
||||
|
||||
+2
-11
@@ -52,7 +52,7 @@
|
||||
/* 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 "busybox.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
@@ -180,15 +180,6 @@ static void encode()
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -217,7 +208,7 @@ int uuencode_main (int argc,
|
||||
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));
|
||||
errorMsg("%s: %s\n", argv[optind], strerror(errno));
|
||||
exit FALSE;
|
||||
}
|
||||
mode = sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
|
||||
+19
-34
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Mini wc implementation for busybox
|
||||
*
|
||||
* by Edward Betts <edward@debian.org>
|
||||
* Copyright (C) 2000 Edward Betts <edward@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
|
||||
@@ -20,21 +20,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
|
||||
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"
|
||||
#endif
|
||||
;
|
||||
#include <getopt.h>
|
||||
|
||||
static int total_lines, total_words, total_chars, max_length;
|
||||
static int print_lines, print_words, print_chars, print_length;
|
||||
@@ -116,13 +104,14 @@ static void wc_file(FILE * file, const char *name)
|
||||
int wc_main(int argc, char **argv)
|
||||
{
|
||||
FILE *file;
|
||||
unsigned int num_files_counted = 0;
|
||||
int opt;
|
||||
|
||||
total_lines = total_words = total_chars = max_length = 0;
|
||||
print_lines = print_words = print_chars = print_length = 0;
|
||||
|
||||
while (--argc && **(++argv) == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
while ((opt = getopt(argc, argv, "clLw")) > 0) {
|
||||
switch (opt) {
|
||||
case 'c':
|
||||
print_chars = 1;
|
||||
break;
|
||||
@@ -143,28 +132,24 @@ int wc_main(int argc, char **argv)
|
||||
if (!print_lines && !print_words && !print_chars && !print_length)
|
||||
print_lines = print_words = print_chars = 1;
|
||||
|
||||
if (argc == 0) {
|
||||
if (argv[optind] == NULL || strcmp(argv[optind], "-") == 0) {
|
||||
wc_file(stdin, "");
|
||||
exit(TRUE);
|
||||
} else if (argc == 1) {
|
||||
file = fopen(*argv, "r");
|
||||
if (file == NULL) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
}
|
||||
wc_file(file, *argv);
|
||||
} else {
|
||||
while (argc-- > 0 && *argv != '\0' && strlen(*argv)) {
|
||||
file = fopen(*argv, "r");
|
||||
while (optind < argc) {
|
||||
file = fopen(argv[optind], "r");
|
||||
if (file == NULL) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
fatalError(argv[optind]);
|
||||
}
|
||||
wc_file(file, *argv);
|
||||
argv++;
|
||||
wc_file(file, argv[optind]);
|
||||
num_files_counted++;
|
||||
optind++;
|
||||
}
|
||||
}
|
||||
|
||||
if (num_files_counted > 1)
|
||||
print_counts(total_lines, total_words, total_chars,
|
||||
max_length, "total");
|
||||
}
|
||||
return(TRUE);
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
+2
-9
@@ -20,16 +20,10 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
|
||||
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)
|
||||
{
|
||||
char *user = xmalloc(9);
|
||||
@@ -43,7 +37,6 @@ extern int whoami_main(int argc, char **argv)
|
||||
puts(user);
|
||||
exit(TRUE);
|
||||
}
|
||||
fprintf(stderr, "%s: cannot find username for UID %u\n", argv[0],
|
||||
(unsigned) uid);
|
||||
errorMsg("cannot find username for UID %u\n", (unsigned) uid);
|
||||
return(FALSE);
|
||||
}
|
||||
+7
-11
@@ -20,26 +20,21 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern int yes_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
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 >= 2 && *argv[1] == '-')
|
||||
usage(yes_usage);
|
||||
|
||||
if (argc == 1) {
|
||||
while (1)
|
||||
if (puts("y") == EOF) {
|
||||
perror("yes");
|
||||
exit(FALSE);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +43,8 @@ extern int yes_main(int argc, char **argv)
|
||||
if (fputs(argv[i], stdout) == EOF
|
||||
|| putchar(i == argc - 1 ? '\n' : ' ') == EOF) {
|
||||
perror("yes");
|
||||
exit(FALSE);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
exit(TRUE);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -25,7 +25,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_name_too_long
|
||||
#define bb_need_omitting_directory
|
||||
@@ -41,30 +41,16 @@
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.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 const char *cp_mv_usage[] = /* .rodata */
|
||||
{
|
||||
"cp [OPTION]... SOURCE DEST\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\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"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nRename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n"
|
||||
#endif
|
||||
cp_usage,
|
||||
mv_usage
|
||||
};
|
||||
|
||||
static int recursiveFlag;
|
||||
@@ -89,8 +75,7 @@ static void name_too_long__exit (void) __attribute__((noreturn));
|
||||
static
|
||||
void name_too_long__exit (void)
|
||||
{
|
||||
fprintf(stderr, name_too_long, dz);
|
||||
exit(FALSE);
|
||||
fatalError(name_too_long);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -124,14 +109,14 @@ cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
|
||||
|
||||
if (srcDirFlag == TRUE) {
|
||||
if (recursiveFlag == FALSE) {
|
||||
fprintf(stderr, omitting_directory, dz, baseSrcName);
|
||||
errorMsg(omitting_directory, baseSrcName);
|
||||
return TRUE;
|
||||
}
|
||||
srcBasename = (strstr(fileName, baseSrcName)
|
||||
+ strlen(baseSrcName));
|
||||
|
||||
if (destLen + strlen(srcBasename) > BUFSIZ) {
|
||||
fprintf(stderr, name_too_long, dz);
|
||||
errorMsg(name_too_long);
|
||||
return FALSE;
|
||||
}
|
||||
strcat(destName, srcBasename);
|
||||
@@ -145,8 +130,8 @@ cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
|
||||
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));
|
||||
errorMsg("rename(%s, %s): %s\n", fileName, destName,
|
||||
strerror(errno));
|
||||
goto do_copyFile; /* Try anyway... */
|
||||
}
|
||||
else if (errno == EXDEV)
|
||||
@@ -158,8 +143,7 @@ cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
|
||||
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));
|
||||
errorMsg("link(%s, %s): %s\n", name, destName, strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
@@ -178,11 +162,11 @@ rm_Action(const char *fileName, struct stat *statbuf, void* junk)
|
||||
|
||||
if (S_ISDIR(statbuf->st_mode)) {
|
||||
if (rmdir(fileName) < 0) {
|
||||
fprintf(stderr, "%s: rmdir(%s): %s\n", dz, fileName, strerror(errno));
|
||||
errorMsg("rmdir(%s): %s\n", fileName, strerror(errno));
|
||||
status = FALSE;
|
||||
}
|
||||
} else if (unlink(fileName) < 0) {
|
||||
fprintf(stderr, "%s: unlink(%s): %s\n", dz, fileName, strerror(errno));
|
||||
errorMsg("unlink(%s): %s\n", fileName, strerror(errno));
|
||||
status = FALSE;
|
||||
}
|
||||
return status;
|
||||
@@ -190,22 +174,21 @@ rm_Action(const char *fileName, struct stat *statbuf, void* junk)
|
||||
|
||||
extern int cp_mv_main(int argc, char **argv)
|
||||
{
|
||||
dz = *argv; /* already basename'd by busybox.c:main */
|
||||
if (*dz == 'c' && *(dz + 1) == 'p')
|
||||
volatile int i;
|
||||
int c;
|
||||
|
||||
if (*applet_name == 'c' && *(applet_name + 1) == 'p')
|
||||
dz_i = is_cp;
|
||||
else
|
||||
dz_i = is_mv;
|
||||
if (argc < 3)
|
||||
usage(cp_mv_usage[dz_i]);
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
if (dz_i == is_cp) {
|
||||
recursiveFlag = preserveFlag = forceFlag = FALSE;
|
||||
followLinks = TRUE;
|
||||
while (*argv && **argv == '-') {
|
||||
while (*++(*argv)) {
|
||||
switch (**argv) {
|
||||
while ((c = getopt(argc, argv, "adpRf")) != EOF) {
|
||||
switch (c) {
|
||||
case 'a':
|
||||
followLinks = FALSE;
|
||||
preserveFlag = TRUE;
|
||||
@@ -226,21 +209,22 @@ extern int cp_mv_main(int argc, char **argv)
|
||||
default:
|
||||
usage(cp_mv_usage[is_cp]);
|
||||
}
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
if (argc < 2) {
|
||||
if ((argc - optind) < 2) {
|
||||
usage(cp_mv_usage[dz_i]);
|
||||
}
|
||||
} else { /* (dz_i == is_mv) */
|
||||
/* Initialize optind to 1, since in libc5 optind
|
||||
* is not initialized until getopt() is called
|
||||
* (or until sneaky programmers force it...). */
|
||||
optind = 1;
|
||||
recursiveFlag = preserveFlag = TRUE;
|
||||
followLinks = FALSE;
|
||||
}
|
||||
|
||||
|
||||
if (strlen(argv[argc - 1]) > BUFSIZ) {
|
||||
fprintf(stderr, name_too_long, "cp");
|
||||
errorMsg(name_too_long);
|
||||
goto exit_false;
|
||||
}
|
||||
strcpy(baseDestName, argv[argc - 1]);
|
||||
@@ -249,17 +233,17 @@ extern int cp_mv_main(int argc, char **argv)
|
||||
goto exit_false;
|
||||
|
||||
destDirFlag = isDirectory(baseDestName, TRUE, &destStatBuf);
|
||||
if ((argc > 3) && destDirFlag == FALSE) {
|
||||
fprintf(stderr, not_a_directory, "cp", baseDestName);
|
||||
if (argc - optind > 2 && destDirFlag == FALSE) {
|
||||
errorMsg(not_a_directory, baseDestName);
|
||||
goto exit_false;
|
||||
}
|
||||
|
||||
while (argc-- > 1) {
|
||||
for (i = optind; i < (argc-1); i++) {
|
||||
size_t srcLen;
|
||||
volatile int flags_memo;
|
||||
int status;
|
||||
|
||||
baseSrcName = *(argv++);
|
||||
baseSrcName=argv[i];
|
||||
|
||||
if ((srcLen = strlen(baseSrcName)) > BUFSIZ)
|
||||
name_too_long__exit();
|
||||
@@ -276,29 +260,28 @@ extern int cp_mv_main(int argc, char **argv)
|
||||
char *pushd, *d, *p;
|
||||
|
||||
if ((pushd = getcwd(NULL, BUFSIZ + 1)) == NULL) {
|
||||
fprintf(stderr, "%s: getcwd(): %s\n", dz, strerror(errno));
|
||||
errorMsg("getcwd(): %s\n", strerror(errno));
|
||||
continue;
|
||||
}
|
||||
if (chdir(baseDestName) < 0) {
|
||||
fprintf(stderr, "%s: chdir(%s): %s\n", dz, baseSrcName, strerror(errno));
|
||||
errorMsg("chdir(%s): %s\n", baseSrcName, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
if ((d = getcwd(NULL, BUFSIZ + 1)) == NULL) {
|
||||
fprintf(stderr, "%s: getcwd(): %s\n", dz, strerror(errno));
|
||||
errorMsg("getcwd(): %s\n", 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));
|
||||
errorMsg("stat(%s): %s\n", 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);
|
||||
errorMsg("Cannot %s `%s' into a subdirectory of itself, "
|
||||
"`%s/%s'\n", applet_name, baseSrcName,
|
||||
baseDestName, baseSrcName);
|
||||
state = -1;
|
||||
continue;
|
||||
}
|
||||
@@ -307,7 +290,7 @@ extern int cp_mv_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
if (chdir(pushd) < 0) {
|
||||
fprintf(stderr, "%s: chdir(%s): %s\n", dz, pushd, strerror(errno));
|
||||
errorMsg("chdir(%s): %s\n", pushd, strerror(errno));
|
||||
free(pushd);
|
||||
free(d);
|
||||
continue;
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* cut implementation for busybox
|
||||
* cut.c - minimalist version of cut
|
||||
*
|
||||
* 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.
|
||||
* Copyright (C) 1999,2000 by Lineo, inc.
|
||||
* Written by Mark Whitley <markw@lineo.com>, <markw@enol.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
|
||||
@@ -20,369 +17,216 @@
|
||||
* 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
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h> /* getopt */
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include "busybox.h"
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
/* globals from other files */
|
||||
extern int optind;
|
||||
extern char *optarg;
|
||||
|
||||
|
||||
void get_args()
|
||||
{
|
||||
int i = 0;
|
||||
int arg_ptr = 0;
|
||||
int flag;
|
||||
/* globals in this file only */
|
||||
static char part = 0; /* (b)yte, (c)har, (f)ields */
|
||||
static int startpos = 1;
|
||||
static int endpos = -1;
|
||||
static char delim = '\t'; /* delimiter, default is tab */
|
||||
static unsigned int supress_non_delimited_lines = 0;
|
||||
|
||||
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.
|
||||
*
|
||||
* decompose_list() - parses a list and puts values into startpos and endpos.
|
||||
* valid list formats: N, N-, N-M, -M
|
||||
*/
|
||||
static void decompose_list(const char *list)
|
||||
{
|
||||
unsigned int nminus = 0;
|
||||
char *ptr;
|
||||
|
||||
/* the list must contain only digits and no more than one minus sign */
|
||||
for (ptr = (char *)list; *ptr; ptr++) {
|
||||
if (!isdigit(*ptr) && *ptr != '-') {
|
||||
fatalError("invalid byte or field list\n");
|
||||
}
|
||||
if (*ptr == '-') {
|
||||
nminus++;
|
||||
if (nminus > 1) {
|
||||
fatalError("invalid byte or field list\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* handle single value 'N' case */
|
||||
if (nminus == 0) {
|
||||
startpos = strtol(list, &ptr, 10);
|
||||
if (startpos == 0) {
|
||||
fatalError("missing list of fields\n");
|
||||
}
|
||||
endpos = startpos;
|
||||
}
|
||||
/* handle multi-value cases */
|
||||
else if (nminus == 1) {
|
||||
/* handle 'N-' case */
|
||||
if (list[strlen(list) - 1] == '-') {
|
||||
startpos = strtol(list, &ptr, 10);
|
||||
}
|
||||
/* handle '-M' case */
|
||||
else if (list[0] == '-') {
|
||||
endpos = strtol(&list[1], NULL, 10);
|
||||
}
|
||||
/* handle 'N-M' case */
|
||||
else {
|
||||
startpos = strtol(list, &ptr, 10);
|
||||
endpos = strtol(ptr+1, &ptr, 10);
|
||||
}
|
||||
|
||||
/* a sanity check */
|
||||
if (startpos == 0) {
|
||||
startpos = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* snippy-snip
|
||||
*/
|
||||
static void cut_file(FILE *file)
|
||||
{
|
||||
char *line;
|
||||
|
||||
/* go through every line in the file */
|
||||
for (line = NULL; (line = get_line_from_file(file)) != NULL; free(line)) {
|
||||
|
||||
/* cut based on chars/bytes */
|
||||
if (part == 'c' || part == 'b') {
|
||||
int i;
|
||||
/* a valid end position has been specified */
|
||||
if (endpos > 0) {
|
||||
for (i = startpos-1; i < endpos; i++) {
|
||||
fputc(line[i], stdout);
|
||||
}
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
/* otherwise, just go to the end of the line */
|
||||
else {
|
||||
for (i = startpos-1; line[i]; i++) {
|
||||
fputc(line[i], stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* cut based on fields */
|
||||
else if (part == 'f') {
|
||||
char *ptr;
|
||||
char *start = line;
|
||||
unsigned int delims_hit = 0;
|
||||
|
||||
for (ptr = line; (ptr = strchr(ptr, delim)) != NULL; ptr++) {
|
||||
delims_hit++;
|
||||
if (delims_hit == (startpos - 1)) {
|
||||
start = ptr+1;
|
||||
}
|
||||
if (delims_hit == endpos) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* we didn't hit any delimeters */
|
||||
if (delims_hit == 0 && !supress_non_delimited_lines) {
|
||||
fputs(line, stdout);
|
||||
}
|
||||
/* we =did= hit some delimiters */
|
||||
else if (delims_hit > 0) {
|
||||
/* we have a fixed end point */
|
||||
if (ptr) {
|
||||
while (start < ptr) {
|
||||
fputc(*start, stdout);
|
||||
start++;
|
||||
}
|
||||
fputc('\n', stdout);
|
||||
}
|
||||
/* or we're just going til the end of the line */
|
||||
else {
|
||||
while (*start) {
|
||||
fputc(*start, stdout);
|
||||
start++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern int cut_main(int argc, char **argv)
|
||||
{
|
||||
int opt;
|
||||
|
||||
while ((opt = getopt(argc, argv, "b:c:d:f:ns")) > 0) {
|
||||
switch (opt) {
|
||||
case 'b':
|
||||
case 'c':
|
||||
case 'f':
|
||||
/* make sure they didn't ask for two types of lists */
|
||||
if (part != 0) {
|
||||
fatalError("only one type of list may be specified");
|
||||
}
|
||||
part = (char)opt;
|
||||
decompose_list(optarg);
|
||||
break;
|
||||
case 'd':
|
||||
if (strlen(optarg) > 1) {
|
||||
fatalError("the delimiter must be a single character\n");
|
||||
}
|
||||
delim = optarg[0];
|
||||
break;
|
||||
case 'n':
|
||||
/* no-op */
|
||||
break;
|
||||
case 's':
|
||||
supress_non_delimited_lines++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (part == 0) {
|
||||
fatalError("you must specify a list of bytes, characters, or fields\n");
|
||||
}
|
||||
|
||||
if (supress_non_delimited_lines && part != 'f') {
|
||||
fatalError("suppressing non-delimited lines makes sense
|
||||
only when operating on fields\n");
|
||||
}
|
||||
|
||||
if (delim != '\t' && part != 'f') {
|
||||
fatalError("a delimiter may be specified only when operating on fields\n");
|
||||
}
|
||||
|
||||
/* argv[(optind)..(argc-1)] should be names of file to process. If no
|
||||
* files were specified or '-' was specified, take input from stdin.
|
||||
* Otherwise, we process all the files specified. */
|
||||
if (argv[optind] == NULL || (strcmp(argv[optind], "-") == 0)) {
|
||||
cut_file(stdin);
|
||||
}
|
||||
else {
|
||||
int i;
|
||||
FILE *file;
|
||||
for (i = optind; i < argc; i++) {
|
||||
file = fopen(argv[i], "r");
|
||||
if (file == NULL) {
|
||||
errorMsg("%s: %s\n", argv[i], strerror(errno));
|
||||
} else {
|
||||
cut_file(file);
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_invalid_date
|
||||
#define bb_need_memory_exhausted
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <getopt.h>
|
||||
|
||||
|
||||
/* This 'date' command supports only 2 time setting formats,
|
||||
@@ -39,17 +40,6 @@
|
||||
an RFC 822 complient date output for shell scripting
|
||||
mail commands */
|
||||
|
||||
static const char date_usage[] = "date [OPTION]... [+FORMAT]\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
|
||||
much as possible, missed out a lot of bounds checking */
|
||||
|
||||
@@ -66,7 +56,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) {
|
||||
fatalError(invalid_date, "date", t_string);
|
||||
fatalError(invalid_date, t_string);
|
||||
}
|
||||
|
||||
/* correct for century - minor Y2K problem here? */
|
||||
@@ -150,7 +140,7 @@ struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
|
||||
|
||||
}
|
||||
|
||||
fatalError(invalid_date, "date", t_string);
|
||||
fatalError(invalid_date, t_string);
|
||||
}
|
||||
|
||||
|
||||
@@ -159,7 +149,7 @@ int date_main(int argc, char **argv)
|
||||
char *date_str = NULL;
|
||||
char *date_fmt = NULL;
|
||||
char *t_buff;
|
||||
int i;
|
||||
int c;
|
||||
int set_time = 0;
|
||||
int rfc822 = 0;
|
||||
int utc = 0;
|
||||
@@ -168,49 +158,39 @@ int date_main(int argc, char **argv)
|
||||
struct tm tm_time;
|
||||
|
||||
/* Interpret command line args */
|
||||
i = --argc;
|
||||
argv++;
|
||||
while (i > 0 && **argv) {
|
||||
if (**argv == '-') {
|
||||
while (i > 0 && *++(*argv))
|
||||
switch (**argv) {
|
||||
case 'R':
|
||||
rfc822 = 1;
|
||||
break;
|
||||
case 's':
|
||||
set_time = 1;
|
||||
if (date_str != NULL)
|
||||
usage(date_usage);
|
||||
date_str = *argv;
|
||||
break;
|
||||
case 'u':
|
||||
utc = 1;
|
||||
if (putenv("TZ=UTC0") != 0)
|
||||
fatalError(memory_exhausted, "date");
|
||||
break;
|
||||
case 'd':
|
||||
use_arg = 1;
|
||||
if (date_str != NULL)
|
||||
usage(date_usage);
|
||||
date_str = *argv;
|
||||
break;
|
||||
case '-':
|
||||
usage(date_usage);
|
||||
}
|
||||
} else {
|
||||
if ((date_fmt == NULL) && (**argv == '+'))
|
||||
date_fmt = *argv + 1; /* Skip over the '+' */
|
||||
else if (date_str == NULL) {
|
||||
set_time = 1;
|
||||
date_str = *argv;
|
||||
} else {
|
||||
while ((c = getopt(argc, argv, "Rs:ud:")) != EOF) {
|
||||
switch (c) {
|
||||
case 'R':
|
||||
rfc822 = 1;
|
||||
break;
|
||||
case 's':
|
||||
set_time = 1;
|
||||
if ((date_str != NULL) || ((date_str = optarg) == NULL))
|
||||
usage(date_usage);
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
utc = 1;
|
||||
if (putenv("TZ=UTC0") != 0)
|
||||
fatalError(memory_exhausted);
|
||||
break;
|
||||
case 'd':
|
||||
use_arg = 1;
|
||||
if ((date_str != NULL) || ((date_str = optarg) == NULL))
|
||||
usage(date_usage);
|
||||
break;
|
||||
default:
|
||||
usage(date_usage);
|
||||
}
|
||||
i--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+'))
|
||||
date_fmt = &argv[optind][1]; /* Skip over the '+' */
|
||||
else if (date_str == NULL) {
|
||||
set_time = 1;
|
||||
date_str = argv[optind];
|
||||
} else {
|
||||
usage(date_usage);
|
||||
}
|
||||
|
||||
/* Now we have parsed all the information except the date format
|
||||
which depends on whether the clock is being set or read */
|
||||
@@ -236,12 +216,12 @@ 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)
|
||||
fatalError(invalid_date, "date", date_str);
|
||||
fatalError(invalid_date, date_str);
|
||||
|
||||
/* if setting time, set it */
|
||||
if (set_time) {
|
||||
if (stime(&tm) < 0) {
|
||||
fatalError("date: can't set date.\n");
|
||||
fatalError("can't set date.\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -8,21 +8,13 @@
|
||||
|
||||
/* Tiny RPN calculator, because "expr" didn't give me bitwise operations. */
|
||||
|
||||
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;
|
||||
|
||||
static void push(double a)
|
||||
{
|
||||
if (pointer >= (sizeof(stack) / sizeof(*stack))) {
|
||||
fprintf(stderr, "dc: stack overflow\n");
|
||||
errorMsg("stack overflow\n");
|
||||
exit(-1);
|
||||
} else
|
||||
stack[pointer++] = a;
|
||||
@@ -31,7 +23,7 @@ static void push(double a)
|
||||
static double pop()
|
||||
{
|
||||
if (pointer == 0) {
|
||||
fprintf(stderr, "dc: stack underflow\n");
|
||||
errorMsg("stack underflow\n");
|
||||
exit(-1);
|
||||
}
|
||||
return stack[--pointer];
|
||||
@@ -132,7 +124,7 @@ static void stack_machine(const char *argument)
|
||||
}
|
||||
o++;
|
||||
}
|
||||
fprintf(stderr, "dc: %s: syntax error.\n", argument);
|
||||
errorMsg("%s: syntax error.\n", argument);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <features.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
@@ -40,39 +40,25 @@
|
||||
typedef unsigned long long int uintmax_t;
|
||||
#endif
|
||||
|
||||
static const char dd_usage[] =
|
||||
"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"
|
||||
"\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)
|
||||
{
|
||||
char *inFile = NULL;
|
||||
char *outFile = NULL;
|
||||
char *cp;
|
||||
int inFd;
|
||||
int outFd;
|
||||
int inCc = 0;
|
||||
int outCc;
|
||||
int trunc=TRUE;
|
||||
long blockSize = 512;
|
||||
uintmax_t skipBlocks = 0;
|
||||
uintmax_t seekBlocks = 0;
|
||||
uintmax_t count = (uintmax_t) - 1;
|
||||
uintmax_t intotal;
|
||||
uintmax_t outTotal;
|
||||
unsigned char *buf;
|
||||
uintmax_t inTotal = 0;
|
||||
uintmax_t outTotal = 0;
|
||||
uintmax_t totalSize;
|
||||
uintmax_t readSize;
|
||||
unsigned char buf[BUFSIZ];
|
||||
char *keyword = NULL;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
@@ -85,30 +71,33 @@ extern int dd_main(int argc, char **argv)
|
||||
outFile = ((strchr(*argv, '=')) + 1);
|
||||
else if (strncmp("count", *argv, 5) == 0) {
|
||||
count = getNum((strchr(*argv, '=')) + 1);
|
||||
if (count <= 0) {
|
||||
fprintf(stderr, "Bad count value %s\n", *argv);
|
||||
if (count < 0) {
|
||||
errorMsg("Bad count value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
} else if (strncmp(*argv, "bs", 2) == 0) {
|
||||
blockSize = getNum((strchr(*argv, '=')) + 1);
|
||||
if (blockSize <= 0) {
|
||||
fprintf(stderr, "Bad block size value %s\n", *argv);
|
||||
errorMsg("Bad block size value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
} else if (strncmp(*argv, "skip", 4) == 0) {
|
||||
skipBlocks = getNum((strchr(*argv, '=')) + 1);
|
||||
if (skipBlocks <= 0) {
|
||||
fprintf(stderr, "Bad skip value %s\n", *argv);
|
||||
errorMsg("Bad skip value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
|
||||
} else if (strncmp(*argv, "seek", 4) == 0) {
|
||||
seekBlocks = getNum((strchr(*argv, '=')) + 1);
|
||||
if (seekBlocks <= 0) {
|
||||
fprintf(stderr, "Bad seek value %s\n", *argv);
|
||||
errorMsg("Bad seek value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
|
||||
} else if (strncmp(*argv, "conv", 4) == 0) {
|
||||
keyword = (strchr(*argv, '=') + 1);
|
||||
if (strcmp(keyword, "notrunc") == 0)
|
||||
trunc=FALSE;
|
||||
} else {
|
||||
goto usage;
|
||||
}
|
||||
@@ -116,11 +105,6 @@ extern int dd_main(int argc, char **argv)
|
||||
argv++;
|
||||
}
|
||||
|
||||
buf = xmalloc(blockSize);
|
||||
|
||||
intotal = 0;
|
||||
outTotal = 0;
|
||||
|
||||
if (inFile == NULL)
|
||||
inFd = fileno(stdin);
|
||||
else
|
||||
@@ -138,7 +122,7 @@ extern int dd_main(int argc, char **argv)
|
||||
if (outFile == NULL)
|
||||
outFd = fileno(stdout);
|
||||
else
|
||||
outFd = open(outFile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
outFd = open(outFile, O_WRONLY | O_CREAT, 0666);
|
||||
|
||||
if (outFd < 0) {
|
||||
/* Note that we are not freeing buf or closing
|
||||
@@ -150,54 +134,30 @@ extern int dd_main(int argc, char **argv)
|
||||
fatalError( outFile);
|
||||
}
|
||||
|
||||
lseek(inFd, skipBlocks * blockSize, SEEK_SET);
|
||||
lseek(outFd, seekBlocks * blockSize, SEEK_SET);
|
||||
//
|
||||
//TODO: Convert to using fullRead & fullWrite
|
||||
// from utility.c
|
||||
// -Erik
|
||||
while (outTotal < count * blockSize) {
|
||||
inCc = read(inFd, buf, blockSize);
|
||||
if (inCc < 0) {
|
||||
perror(inFile);
|
||||
goto cleanup;
|
||||
} else if (inCc == 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
intotal += inCc;
|
||||
cp = buf;
|
||||
|
||||
while (intotal > outTotal) {
|
||||
if (outTotal + inCc > count * blockSize)
|
||||
inCc = count * blockSize - outTotal;
|
||||
outCc = write(outFd, cp, inCc);
|
||||
if (outCc < 0) {
|
||||
perror(outFile);
|
||||
goto cleanup;
|
||||
} else if (outCc == 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
inCc -= outCc;
|
||||
cp += outCc;
|
||||
outTotal += outCc;
|
||||
}
|
||||
lseek(inFd, (off_t) (skipBlocks * blockSize), SEEK_SET);
|
||||
lseek(outFd, (off_t) (seekBlocks * blockSize), SEEK_SET);
|
||||
totalSize=count*blockSize;
|
||||
while ((readSize = totalSize - inTotal) > 0) {
|
||||
if (readSize > BUFSIZ)
|
||||
readSize=BUFSIZ;
|
||||
inCc = fullRead(inFd, buf, readSize);
|
||||
inTotal += inCc;
|
||||
if ((outCc = fullWrite(outFd, buf, inCc)) < 1)
|
||||
break;
|
||||
outTotal += outCc;
|
||||
}
|
||||
if (trunc == TRUE) {
|
||||
ftruncate(outFd, lseek(outFd, 0, SEEK_CUR));
|
||||
}
|
||||
|
||||
if (inCc < 0)
|
||||
perror(inFile);
|
||||
|
||||
cleanup:
|
||||
/* Note that we are not freeing memory or closing
|
||||
* files here, to save a few bytes. */
|
||||
#if 0
|
||||
#ifdef BB_FEATURE_CLEAN_UP
|
||||
close(inFd);
|
||||
close(outFd);
|
||||
free(buf);
|
||||
#endif
|
||||
|
||||
printf("%ld+%d records in\n", (long) (intotal / blockSize),
|
||||
(intotal % blockSize) != 0);
|
||||
printf("%ld+%d records in\n", (long) (inTotal / blockSize),
|
||||
(inTotal % blockSize) != 0);
|
||||
printf("%ld+%d records out\n", (long) (outTotal / blockSize),
|
||||
(outTotal % blockSize) != 0);
|
||||
exit(TRUE);
|
||||
|
||||
+10
-20
@@ -3,7 +3,7 @@
|
||||
* disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
|
||||
* Renamed deallocvt.
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
@@ -13,46 +13,36 @@
|
||||
/* From <linux/vt.h> */
|
||||
#define VT_DISALLOCATE 0x5608 /* free memory associated to vt */
|
||||
|
||||
|
||||
char *progname;
|
||||
|
||||
int deallocvt_main(int argc, char *argv[])
|
||||
{
|
||||
int fd, num, i;
|
||||
|
||||
if ((argc != 2) || (**(argv + 1) == '-')) {
|
||||
usage
|
||||
("deallocvt N\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nDeallocate unused virtual terminal /dev/ttyN\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
progname = argv[0];
|
||||
//if ((argc > 2) || ((argv == 2) && (**(argv + 1) == '-')))
|
||||
if (argc > 2)
|
||||
usage(deallocvt_usage);
|
||||
|
||||
fd = get_console_fd("/dev/console");
|
||||
|
||||
if (argc == 1) {
|
||||
printf("erik: A\n");
|
||||
/* deallocate all unused consoles */
|
||||
if (ioctl(fd, VT_DISALLOCATE, 0)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
exit( FALSE);
|
||||
}
|
||||
} else
|
||||
printf("erik: B\n");
|
||||
for (i = 1; i < argc; i++) {
|
||||
num = atoi(argv[i]);
|
||||
if (num == 0)
|
||||
fprintf(stderr, "%s: 0: illegal VT number\n", progname);
|
||||
errorMsg("0: illegal VT number\n");
|
||||
else if (num == 1)
|
||||
fprintf(stderr, "%s: VT 1 cannot be deallocated\n",
|
||||
progname);
|
||||
errorMsg("VT 1 cannot be deallocated\n");
|
||||
else if (ioctl(fd, VT_DISALLOCATE, num)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
fprintf(stderr, "%s: could not deallocate console %d\n",
|
||||
progname, num);
|
||||
exit( FALSE);
|
||||
fatalError("could not deallocate console %d\n", num);
|
||||
}
|
||||
}
|
||||
printf("erik: C\n");
|
||||
return( TRUE);
|
||||
}
|
||||
Vendored
+6
@@ -1,3 +1,9 @@
|
||||
busybox (0.47-1) unstable; urgency=low
|
||||
|
||||
* New version released. See changelog for details.
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Mon, 25 Sep 2000 23:00:56 -0600
|
||||
|
||||
busybox (0.46-1) unstable; urgency=low
|
||||
|
||||
* New version released. See changelog for details.
|
||||
|
||||
@@ -22,18 +22,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <mntent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/vfs.h>
|
||||
|
||||
static const char df_usage[] = "df [filesystem ...]\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 */
|
||||
|
||||
static int df(char *device, const char *mountPoint)
|
||||
@@ -82,7 +75,7 @@ extern int df_main(int argc, char **argv)
|
||||
}
|
||||
while (argc > 1) {
|
||||
if ((mountEntry = findMountPoint(argv[1], mtab_file)) == 0) {
|
||||
fprintf(stderr, "%s: can't find mount point.\n", argv[1]);
|
||||
errorMsg("%s: can't find mount point.\n", argv[1]);
|
||||
exit(FALSE);
|
||||
}
|
||||
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
|
||||
@@ -20,20 +20,15 @@
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include "busybox.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
|
||||
);
|
||||
}
|
||||
if ((argc < 2) || (**(argv + 1) == '-'))
|
||||
usage(dirname_usage);
|
||||
argv++;
|
||||
|
||||
s=*argv+strlen(*argv)-1;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* Support, replaced getopt, added some gotos for redundant stuff.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -32,62 +32,39 @@ 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 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)
|
||||
{
|
||||
char *buf;
|
||||
int c;
|
||||
int bufsize = 8196;
|
||||
int i;
|
||||
int n;
|
||||
int level = 0;
|
||||
int lastc;
|
||||
int cmd = 3;
|
||||
int stopDoingThat;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (argc && **argv == '-') {
|
||||
stopDoingThat = FALSE;
|
||||
while (stopDoingThat == FALSE && *++(*argv)) {
|
||||
switch (**argv) {
|
||||
case 'c':
|
||||
cmd = 4;
|
||||
break;
|
||||
case 'n':
|
||||
cmd = 8;
|
||||
if (--argc == 0)
|
||||
goto end;
|
||||
level = atoi(*(++argv));
|
||||
if (--argc > 0)
|
||||
++argv;
|
||||
stopDoingThat = TRUE;
|
||||
break;
|
||||
case 's':
|
||||
if (--argc == 0)
|
||||
goto end;
|
||||
bufsize = atoi(*(++argv));
|
||||
if (--argc > 0)
|
||||
++argv;
|
||||
stopDoingThat = TRUE;
|
||||
break;
|
||||
default:
|
||||
goto end;
|
||||
}
|
||||
while ((c = getopt(argc, argv, "cn:s:")) != EOF) {
|
||||
switch (c) {
|
||||
case 'c':
|
||||
cmd = 4;
|
||||
break;
|
||||
case 'n':
|
||||
cmd = 8;
|
||||
if (optarg == NULL)
|
||||
usage(dmesg_usage);
|
||||
level = atoi(optarg);
|
||||
break;
|
||||
case 's':
|
||||
if (optarg == NULL)
|
||||
usage(dmesg_usage);
|
||||
bufsize = atoi(optarg);
|
||||
break;
|
||||
default:
|
||||
usage(dmesg_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argc > 1) {
|
||||
if (optind < argc) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ To subscribe, go and visit <a href="http://opensource.lineo.com/mailman/listinfo
|
||||
This release fixes several bugs (including a ugly bug in tar,
|
||||
and fixes for NFSv3 mount support). Added a dumpkmap to allow
|
||||
people to dump a binary keymaps for use with 'loadkmap', and a
|
||||
completely reworked 'grep' and 'sed' with should behave better.
|
||||
completely reworked 'grep' and 'sed' which should behave better.
|
||||
BusyBox shell can now also be used as a login shell.
|
||||
See the <a href="ftp://ftp.lineo.com/pub/busybox/Changelog">changelog</a> for complete details.
|
||||
|
||||
@@ -93,7 +93,7 @@ To subscribe, go and visit <a href="http://opensource.lineo.com/mailman/listinfo
|
||||
This release has been slow in coming, but is very solid at this
|
||||
point. BusyBox now supports libc5 as well as GNU libc. This
|
||||
release provides the following new apps: cut, tr, insmod, ar,
|
||||
mktemp, ,setkeycodes md5sum, uuencode, uudecode, which , and
|
||||
mktemp, setkeycodes, md5sum, uuencode, uudecode, which, and
|
||||
telnet. There are bug fixes for just about every app as well (see
|
||||
the <a href="ftp://ftp.lineo.com/pub/busybox/Changelog">changelog</a> for
|
||||
details).
|
||||
@@ -170,11 +170,12 @@ Current documentation for BusyBox includes:
|
||||
|
||||
<TR><TD BGCOLOR="#ccccc0" ALIGN=center>
|
||||
<A NAME="projects"><BIG><B>
|
||||
Projects using BusyBox
|
||||
Products/Projects using BusyBox
|
||||
</A></B></BIG>
|
||||
</TD></TR>
|
||||
<TR><TD BGCOLOR="#eeeee0">
|
||||
I know of the following projects that use BusyBox
|
||||
I know of the following products and/or projects that use BusyBox -- listed
|
||||
in the order I happen to add them to the web page:
|
||||
<ul>
|
||||
<li> <a href="http://www.lineo.com/products/embedix_linux/">Lineo Embedix Linux</a>
|
||||
<li> <a href="http://cvs.debian.org/boot-floppies/">Debian boot floppies project</a>
|
||||
@@ -184,7 +185,11 @@ I know of the following projects that use BusyBox
|
||||
<li> <a href="http://www.stormix.com/">Stormix Installer</a>
|
||||
<li> <a href="http://www.emacinc.com/linux2_sbc.htm">EMAC Linux 2.0 SBC</a>
|
||||
<li> <a href="http://www.trinux.org/">Trinux</a>
|
||||
<li> <a href="http://www.suse.com/~peterb/x86/tinynet.html">tinynet</a>
|
||||
<li> <a href="http://oddas.sourceforge.net/">ODDAS project</a>
|
||||
<li> <a href="http://www.kerbango.com/">The Kerbango Internet Radio</a>
|
||||
<li> <a href="http://www.linuxmagic.com/vpn/">LinuxMagic VPN Firewall</a>
|
||||
<li> <a href="http://byld.sourceforge.net/">Build Your Linux Disk</a>
|
||||
<li> <a href="http://homepages.ihug.co.nz/~ichi/baslinux.html">BasicLinux</a>
|
||||
|
||||
</ul>
|
||||
Do you use BusyBox? I'd love to know about it and I'd be happy to link to you.
|
||||
|
||||
+257
-24
@@ -55,16 +55,17 @@ terse runtime description of their behavior.
|
||||
|
||||
Currently defined functions include:
|
||||
|
||||
ar, basename, cat, chgrp, chmod, chown, chroot, chvt, clear, cp, cut, date,
|
||||
dc, dd, deallocvt, df, dirname, dmesg, du, dumpkmap, dutmp, echo, false, fbset,
|
||||
fdflush, find, free, freeramdisk, fsck.minix, grep, gunzip, gzip, halt,
|
||||
head, hostid, hostname, id, init, insmod, kill, killall, length, ln,
|
||||
loadacm, loadfont, loadkmap, logger, logname, ls, lsmod, makedevs, mkdir,
|
||||
mkfifo, mkfs.minix, mknod, mkswap, mktemp, more, mount, mt, mv, nc,
|
||||
nslookup, ping, poweroff, printf, ps, pwd, reboot, rm, rmdir, rmmod, sed,
|
||||
setkeycodes, sh, sleep, sort, swapoff, swapon, sync, syslogd, tail,
|
||||
tar, tee, telnet, test, touch, tr, true, tty, umount, uname, uniq, update,
|
||||
uptime, usleep, uudecode, uuencode, wc, which, whoami, yes, zcat, [
|
||||
ar, basename, cat, chgrp, chmod, chown, chroot, chvt, clear, cp, cut, date, dc,
|
||||
dd, deallocvt, df, dirname, dmesg, dos2unix, du, dumpkmap, dutmp, echo, false,
|
||||
fbset, fdflush, find, free, freeramdisk, fsck.minix, getopt, grep, gunzip,
|
||||
gzip, halt, head, hostid, hostname, id, init, insmod, kill, killall, length,
|
||||
ln, loadacm, loadfont, loadkmap, logger, logname, ls, lsmod, makedevs, mkdir,
|
||||
mkfifo, mkfs.minix, mknod, mkswap, mktemp, more, mount, mt, mv, nc, nslookup,
|
||||
ping, poweroff, printf, ps, pwd, rdate, reboot, renice, reset, rm, rmdir,
|
||||
rmmod, sed, setkeycodes, sh, sleep, sort, swapoff, swapon, sync, syslogd, tail,
|
||||
tar, tee, telnet, test, touch, tr, true, tty, umount, uname, uniq, unix2dos,
|
||||
unrpm, update, uptime, usleep, uudecode, uuencode, wc, which, whoami, xargs,
|
||||
yes, zcat, [
|
||||
|
||||
-------------------------------
|
||||
|
||||
@@ -279,7 +280,7 @@ Options:
|
||||
-b LIST Output only bytes from LIST
|
||||
-c LIST Output only characters from LIST
|
||||
-d CHAR Use CHAR instead of tab as the field delimiter
|
||||
-s Only output Lines if the include DELIM
|
||||
-s Output only the lines containing delimiter
|
||||
-f N Print only these fields
|
||||
-n Ignored
|
||||
|
||||
@@ -412,6 +413,14 @@ Print or controls the kernel ring buffer.
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item dos2unix
|
||||
|
||||
Usage: dos2unix < dosfile > unixfile
|
||||
|
||||
Converts a text file from dos format to unix format.
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item du
|
||||
|
||||
Usage: du [OPTION]... [FILE]...
|
||||
@@ -446,6 +455,10 @@ Usage: dumpkmap
|
||||
|
||||
Prints out a binary keyboard translation table to standard input.
|
||||
|
||||
Example:
|
||||
|
||||
$ dumpkmap > keymap
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item dutmp
|
||||
@@ -493,6 +506,45 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item echo
|
||||
|
||||
|
||||
Usage: expr EXPRESSION
|
||||
|
||||
Prints the value of EXPRESSION to standard output.
|
||||
|
||||
EXPRESSION may be:
|
||||
|
||||
ARG1 | ARG2 ARG1 if it is neither null nor 0, otherwise ARG2
|
||||
ARG1 & ARG2 ARG1 if neither argument is null or 0, otherwise 0
|
||||
ARG1 < ARG2 ARG1 is less than ARG2
|
||||
ARG1 <= ARG2 ARG1 is less than or equal to ARG2
|
||||
ARG1 = ARG2 ARG1 is equal to ARG2
|
||||
ARG1 != ARG2 ARG1 is unequal to ARG2
|
||||
ARG1 >= ARG2 ARG1 is greater than or equal to ARG2
|
||||
ARG1 > ARG2 ARG1 is greater than ARG2
|
||||
ARG1 + ARG2 arithmetic sum of ARG1 and ARG2
|
||||
ARG1 - ARG2 arithmetic difference of ARG1 and ARG2
|
||||
ARG1 * ARG2 arithmetic product of ARG1 and ARG2
|
||||
ARG1 / ARG2 arithmetic quotient of ARG1 divided by ARG2
|
||||
ARG1 % ARG2 arithmetic remainder of ARG1 divided by ARG2
|
||||
STRING : REGEXP anchored pattern match of REGEXP in STRING
|
||||
match STRING REGEXP same as STRING : REGEXP
|
||||
substr STRING POS LENGTH substring of STRING, POS counted from 1
|
||||
index STRING CHARS index in STRING where any CHARS is found, or 0
|
||||
length STRING length of STRING
|
||||
quote TOKEN interpret TOKEN as a string, even if it is a
|
||||
keyword like `match' or an operator like `/'
|
||||
( EXPRESSION ) value of EXPRESSION
|
||||
|
||||
Beware that many operators need to be escaped or quoted for shells.
|
||||
Comparisons are arithmetic if both ARGs are numbers, else
|
||||
lexicographical. Pattern matches return the string matched between
|
||||
\( and \) or null; if \( and \) are not used, they return the number
|
||||
of characters matched or 0.
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item false
|
||||
|
||||
Returns an exit code of FALSE (1)
|
||||
@@ -614,6 +666,49 @@ Options:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item getopt
|
||||
|
||||
Usage: getopt [OPTIONS]...
|
||||
|
||||
Parse command options
|
||||
|
||||
Options:
|
||||
|
||||
-a, --alternative Allow long options starting with single -\n"
|
||||
-l, --longoptions=longopts Long options to be recognized\n"
|
||||
-n, --name=progname The name under which errors are reported\n"
|
||||
-o, --options=optstring Short options to be recognized\n"
|
||||
-q, --quiet Disable error reporting by getopt(3)\n"
|
||||
-Q, --quiet-output No normal output\n"
|
||||
-s, --shell=shell Set shell quoting conventions\n"
|
||||
-T, --test Test for getopt(1) version\n"
|
||||
-u, --unqote Do not quote the output\n"
|
||||
|
||||
Example:
|
||||
|
||||
$ cat getopt.test
|
||||
#!/bin/sh
|
||||
GETOPT=`getopt -o ab:c:: --long a-long,b-long:,c-long:: \
|
||||
-n 'example.busybox' -- "$@"`
|
||||
if [ $? != 0 ] ; then exit 1 ; fi
|
||||
eval set -- "$GETOPT"
|
||||
while true ; do
|
||||
case $1 in
|
||||
-a|--a-long) echo "Option a" ; shift ;;
|
||||
-b|--b-long) echo "Option b, argument \`$2'" ; shift 2 ;;
|
||||
-c|--c-long)
|
||||
case "$2" in
|
||||
"") echo "Option c, no argument"; shift 2 ;;
|
||||
*) echo "Option c, argument \`$2'" ; shift 2 ;;
|
||||
esac ;;
|
||||
--) shift ; break ;;
|
||||
*) echo "Internal error!" ; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item grep
|
||||
|
||||
Usage: grep [OPTIONS]... PATTERN [FILE]...
|
||||
@@ -827,14 +922,16 @@ Example /etc/inittab file:
|
||||
# /bin/sh invocations on selected ttys
|
||||
#
|
||||
# Start an "askfirst" shell on the console (whatever that may be)
|
||||
::askfirst:/bin/sh
|
||||
# Start an "askfirst" shell on /dev/tty2
|
||||
tty2::askfirst:/bin/sh
|
||||
::askfirst:-/bin/sh
|
||||
# Start an "askfirst" shell on /dev/tty2-4
|
||||
tty2::askfirst:-/bin/sh
|
||||
tty3::askfirst:-/bin/sh
|
||||
tty4::askfirst:-/bin/sh
|
||||
|
||||
# /sbin/getty invocations for selected ttys
|
||||
#
|
||||
tty4::respawn:/sbin/getty 38400 tty4
|
||||
tty5::respawn:/sbin/getty 38400 tty5
|
||||
tty4::respawn:/sbin/getty 38400 tty5
|
||||
tty5::respawn:/sbin/getty 38400 tty6
|
||||
|
||||
|
||||
# Example of how to put a getty on a serial line (for a terminal)
|
||||
@@ -846,8 +943,8 @@ Example /etc/inittab file:
|
||||
#ttyS2::respawn:/sbin/getty -x0 -s 57600 ttyS2
|
||||
|
||||
# Stuff to do before rebooting
|
||||
::ctrlaltdel:/bin/umount -a -r > /dev/null 2>&1
|
||||
::ctrlaltdel:/sbin/swapoff -a > /dev/null 2>&1
|
||||
::ctrlaltdel:/bin/umount -a -r
|
||||
::ctrlaltdel:/sbin/swapoff -a
|
||||
|
||||
-------------------------------
|
||||
|
||||
@@ -1008,7 +1105,7 @@ Example:
|
||||
|
||||
=item ls
|
||||
|
||||
Usage: ls [B<-1acdelnpuxACFR>] [filenames...]
|
||||
Usage: ls [B<-1acdelnpuxACFLR>] [filenames...]
|
||||
|
||||
Options:
|
||||
|
||||
@@ -1027,6 +1124,7 @@ Options:
|
||||
-C list entries by columns
|
||||
-F append indicator (one of */=@|) to entries
|
||||
-R list subdirectories recursively
|
||||
-L list entries pointed to by symbolic links
|
||||
|
||||
-------------------------------
|
||||
|
||||
@@ -1380,12 +1478,43 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item rdate
|
||||
|
||||
Usage: rdate [OPTION] HOST
|
||||
|
||||
Get and possibly set the system date and time from a remote HOST.
|
||||
|
||||
Options:
|
||||
|
||||
-s Set the system date and time (default).
|
||||
-p Print the date and time.
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item reboot
|
||||
|
||||
Instructs the kernel to reboot the system.
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item renice
|
||||
|
||||
Usage: renice priority pid [pid ...]
|
||||
|
||||
Changes priority of running processes. Allowed priorities range
|
||||
from 20 (the process runs only when nothing else is running) to 0
|
||||
(default priority) to -20 (almost nothing else ever gets to run).
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item reset
|
||||
|
||||
Usage: reset
|
||||
|
||||
Resets the screen.
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item rm
|
||||
|
||||
Usage: rm [OPTION]... FILE...
|
||||
@@ -1577,6 +1706,12 @@ Options:
|
||||
-n Run as a foreground process
|
||||
-K Do not start up the klogd process
|
||||
-O FILE Use an alternate log file (default=/var/log/messages)
|
||||
-R HOST[:PORT] Log messages to HOST on PORT (default=514) over UDP.
|
||||
|
||||
Example:
|
||||
|
||||
$ syslogd -R masterlog:514
|
||||
$ syslogd -R 192.168.1.1:601
|
||||
|
||||
-------------------------------
|
||||
|
||||
@@ -1618,7 +1753,7 @@ File selection:
|
||||
|
||||
f name of tarfile or "-" for stdin
|
||||
O extract to stdout
|
||||
--exclude file to exclude
|
||||
exclude file to exclude
|
||||
|
||||
Informative output:
|
||||
|
||||
@@ -1804,6 +1939,22 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item unix2dos
|
||||
|
||||
Usage: unix2dos < unixfile > dosfile
|
||||
|
||||
Converts a text file from unix format to dos format.
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item unrpm
|
||||
|
||||
Usage: unrpm < package.rpm | gzip B<-d> | cpio -idmuv
|
||||
|
||||
Extracts an rpm archive.
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item update
|
||||
|
||||
Usage: update [options]
|
||||
@@ -1930,6 +2081,23 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item xargs
|
||||
|
||||
Usage: xargs [OPTIONS] [COMMAND] [ARGS...]
|
||||
|
||||
Executes COMMAND on every item given by standard input.
|
||||
|
||||
Options:
|
||||
|
||||
-t Print the command just before it is run
|
||||
|
||||
Example:
|
||||
|
||||
$ ls | xargs gzip
|
||||
$ find . -name '*.c' -print | xargs rm
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item yes
|
||||
|
||||
Usage: yes [OPTION]... [STRING]...
|
||||
@@ -1974,58 +2142,123 @@ Erik Andersen <andersee@debian.org> <andersen@lineo.com>
|
||||
The following people have contributed code to BusyBox whether
|
||||
they know it or not.
|
||||
|
||||
Erik Andersen <andersee@debian.org>
|
||||
|
||||
=for html <br>
|
||||
|
||||
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.
|
||||
|
||||
=for html <br>
|
||||
|
||||
Edward Betts <edward@debian.org>
|
||||
|
||||
expr, hostid, logname, tty, wc, whoami, yes
|
||||
|
||||
=for html <br>
|
||||
|
||||
John Beppu <beppu@lineo.com>
|
||||
|
||||
du, head, nslookup, sort, tee, uniq
|
||||
|
||||
=for html <br>
|
||||
|
||||
Brian Candler <B.Candler@pobox.com>
|
||||
|
||||
tiny-ls(ls)
|
||||
|
||||
=for html <br>
|
||||
|
||||
Randolph Chung <tausq@debian.org>
|
||||
|
||||
fbset, ping, hostname, and mkfifo
|
||||
|
||||
=for html <br>
|
||||
|
||||
Dave Cinege <dcinege@psychosis.com>
|
||||
|
||||
more(v2), makedevs, dutmp, modularization, auto links file,
|
||||
various fixes, Linux Router Project maintenance
|
||||
|
||||
=for html <br>
|
||||
|
||||
Karl M. Hegbloom <karlheg@debian.org>
|
||||
|
||||
cp_mv.c, the test suite, various fixes to utility.c, &c.
|
||||
|
||||
=for html <br>
|
||||
|
||||
Daniel Jacobowitz <dan@debian.org>
|
||||
|
||||
mktemp.c
|
||||
|
||||
=for html <br>
|
||||
|
||||
Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
||||
|
||||
documentation, bugfixes
|
||||
|
||||
=for html <br>
|
||||
|
||||
John Lombardo <john@deltanet.com>
|
||||
|
||||
dirname, tr
|
||||
|
||||
=for html <br>
|
||||
|
||||
Glenn McGrath <bug1@netconnect.com.au>
|
||||
|
||||
ar.c
|
||||
|
||||
=for html <br>
|
||||
|
||||
Bruce Perens <bruce@perens.com>
|
||||
Bruce Perens <bruce@pixar.com>
|
||||
|
||||
Original author of BusyBox. His code is still in many apps.
|
||||
|
||||
=for html <br>
|
||||
|
||||
Chip Rosenthal <chip@unicom.com>, <crosenth@covad.com>
|
||||
|
||||
wget - Contributed by permission of Covad Communications
|
||||
|
||||
=for html <br>
|
||||
|
||||
Pavel Roskin <proski@gnu.org>
|
||||
|
||||
Lots of bugs fixes and patches.
|
||||
|
||||
=for html <br>
|
||||
|
||||
Gyepi Sam <gyepi@praxis-sw.com>
|
||||
|
||||
Remote logging feature for syslogd
|
||||
|
||||
=for html <br>
|
||||
|
||||
Linus Torvalds <torvalds@transmeta.com>
|
||||
|
||||
mkswap, fsck.minix, mkfs.minix
|
||||
|
||||
=for html <br>
|
||||
|
||||
Mark Whitley <markw@lineo.com>
|
||||
|
||||
sed remix, bug fixes, style-guide, etc.
|
||||
|
||||
=for html <br>
|
||||
|
||||
Charles P. Wright <cpwright@villagenet.com>
|
||||
|
||||
gzip, mini-netcat(nc)
|
||||
|
||||
=for html <br>
|
||||
|
||||
Enrique Zanardi <ezanardi@ull.es>
|
||||
|
||||
=for html <br>
|
||||
tarcat (since removed), loadkmap, various fixes, Debian maintenance
|
||||
|
||||
=cut
|
||||
|
||||
# $Id: busybox.pod,v 1.56 2000/07/11 17:29:36 andersen Exp $
|
||||
# $Id: busybox.pod,v 1.73 2000/09/24 02:41:44 andersen Exp $
|
||||
+322
-47
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V3.1//EN" [...]>
|
||||
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V3.1//EN" [ ]>
|
||||
<book id="BusyBoxDocumentation">
|
||||
<bookinfo>
|
||||
<title>BusyBox - The Swiss Army Knife of Embedded Linux</title>
|
||||
@@ -59,8 +59,8 @@
|
||||
|
||||
<chapter id="Syntax">
|
||||
<title>How to use BusyBox</title>
|
||||
<sect1 id="How to use BusyBox">
|
||||
<title>Syntax</title
|
||||
<sect1 id="How-to-use-BusyBox">
|
||||
<title>Syntax</title>
|
||||
|
||||
<para>
|
||||
<screen>
|
||||
@@ -75,7 +75,9 @@
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="Invoking BusyBox">
|
||||
<sect1 id="Invoking-BusyBox">
|
||||
<title>Invoking BusyBox</title>
|
||||
|
||||
<para>
|
||||
When you create a link to BusyBox for the function you wish to use, when
|
||||
BusyBox is called using that link it will behave as if the command itself
|
||||
@@ -115,7 +117,9 @@
|
||||
|
||||
</sect1>
|
||||
|
||||
<sect1 id="Common options">
|
||||
<sect1 id="Common-options">
|
||||
<title>Common options</title>
|
||||
|
||||
<para>
|
||||
Most BusyBox commands support the <emphasis>--help</emphasis> option to provide
|
||||
a terse runtime description of their behavior.
|
||||
@@ -125,7 +129,7 @@
|
||||
|
||||
<chapter id="Commands">
|
||||
<title>BusyBox Commands</title>
|
||||
<sect1 id="Available BusyBox Commands">
|
||||
<sect1 id="Available-BusyBox-Commands">
|
||||
<title>Available BusyBox Commands</title>
|
||||
<para>
|
||||
Currently defined functions include:
|
||||
@@ -140,7 +144,7 @@
|
||||
loadacm, loadfont, loadkmap, logger, logname, ls, lsmod,
|
||||
makedevs, mkdir, mkfifo, mkfs.minix, mknod, mkswap, mktemp,
|
||||
more, mount, mt, mv, nc, nslookup, ping, poweroff, printf, ps,
|
||||
pwd, reboot, rm, rmdir, rmmod, sed, setkeycodes, sh, sleep,
|
||||
pwd, reboot, renice, reset, rm, rmdir, rmmod, sed, setkeycodes, sh, sleep,
|
||||
sort, swapoff, swapon, sync, syslogd, tail, tar, tee, telnet,
|
||||
test, touch, tr, true, tty, umount, uname, uniq, update,
|
||||
uptime, usleep, uudecode, uuencode, wc, which, whoami, yes,
|
||||
@@ -507,7 +511,7 @@
|
||||
-b LIST Output only bytes from LIST
|
||||
-c LIST Output only characters from LIST
|
||||
-d CHAR Use CHAR instead of tab as the field delimiter
|
||||
-s Only output Lines if the include DELIM
|
||||
-s Output only the lines containing delimiter
|
||||
-f N Print only these fields
|
||||
-n Ignored
|
||||
</screen>
|
||||
@@ -741,6 +745,19 @@
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="dos2unix">
|
||||
<title>dos2unix</title>
|
||||
|
||||
<para>
|
||||
Usage: dos2unix < dosfile > unixfile
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Converts a text file from dos format to unix format.
|
||||
</para>
|
||||
|
||||
</sect1>
|
||||
|
||||
<sect1 id="du">
|
||||
<title>du</title>
|
||||
|
||||
@@ -796,6 +813,16 @@
|
||||
<para>
|
||||
Prints out a binary keyboard translation table to standard input.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Example:
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<screen>
|
||||
$ dumpkmap < keymap
|
||||
</screen>
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="dutmp">
|
||||
@@ -869,6 +896,58 @@
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="expr">
|
||||
<title>expr</title>
|
||||
|
||||
<para>
|
||||
Usage: expr EXPRESSION
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Prints the value of EXPRESSION to standard output.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
EXPRESSION may be:
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<screen>
|
||||
ARG1 | ARG2 ARG1 if it is neither null nor 0, otherwise ARG2
|
||||
ARG1 & ARG2 ARG1 if neither argument is null or 0, otherwise 0
|
||||
ARG1 < ARG2 ARG1 is less than ARG2
|
||||
ARG1 <= ARG2 ARG1 is less than or equal to ARG2
|
||||
ARG1 = ARG2 ARG1 is equal to ARG2
|
||||
ARG1 != ARG2 ARG1 is unequal to ARG2
|
||||
ARG1 >= ARG2 ARG1 is greater than or equal to ARG2
|
||||
ARG1 > ARG2 ARG1 is greater than ARG2
|
||||
ARG1 + ARG2 arithmetic sum of ARG1 and ARG2
|
||||
ARG1 - ARG2 arithmetic difference of ARG1 and ARG2
|
||||
ARG1 * ARG2 arithmetic product of ARG1 and ARG2
|
||||
ARG1 / ARG2 arithmetic quotient of ARG1 divided by ARG2
|
||||
ARG1 % ARG2 arithmetic remainder of ARG1 divided by ARG2
|
||||
STRING : REGEXP anchored pattern match of REGEXP in STRING
|
||||
match STRING REGEXP same as STRING : REGEXP
|
||||
substr STRING POS LENGTH substring of STRING, POS counted from 1
|
||||
index STRING CHARS index in STRING where any CHARS is found, or 0
|
||||
length STRING length of STRING
|
||||
quote TOKEN interpret TOKEN as a string, even if it is a
|
||||
keyword like `match' or an operator like `/'
|
||||
( EXPRESSION ) value of EXPRESSION
|
||||
</screen>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Beware that many operators need to be escaped or quoted for shells.
|
||||
Comparisons are arithmetic if both ARGs are numbers, else
|
||||
lexicographical. Pattern matches return the string matched between
|
||||
\( and \) or null; if \( and \) are not used, they return the number
|
||||
of characters matched or 0.
|
||||
</para>
|
||||
|
||||
</sect1>
|
||||
|
||||
|
||||
<sect1 id="false">
|
||||
<title>false</title>
|
||||
|
||||
@@ -1063,6 +1142,61 @@
|
||||
</screen>
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="getopt">
|
||||
<title>getopt</title>
|
||||
|
||||
<para>
|
||||
Usage: getopt [OPTIONS]...
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Parse command options
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<screen>
|
||||
-a, --alternative Allow long options starting with single -\n"
|
||||
-l, --longoptions=longopts Long options to be recognized\n"
|
||||
-n, --name=progname The name under which errors are reported\n"
|
||||
-o, --options=optstring Short options to be recognized\n"
|
||||
-q, --quiet Disable error reporting by getopt(3)\n"
|
||||
-Q, --quiet-output No normal output\n"
|
||||
-s, --shell=shell Set shell quoting conventions\n"
|
||||
-T, --test Test for getopt(1) version\n"
|
||||
-u, --unqote Do not quote the output\n"
|
||||
</screen>
|
||||
</para>
|
||||
|
||||
|
||||
<para>
|
||||
Example:
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<screen>
|
||||
$ cat getopt.test
|
||||
#!/bin/sh
|
||||
GETOPT=`getopt -o ab:c:: --long a-long,b-long:,c-long:: \
|
||||
-n 'example.busybox' -- "$@"`
|
||||
if [ $? != 0 ] ; then exit 1 ; fi
|
||||
eval set -- "$GETOPT"
|
||||
while true ; do
|
||||
case $1 in
|
||||
-a|--a-long) echo "Option a" ; shift ;;
|
||||
-b|--b-long) echo "Option b, argument \`$2'" ; shift 2 ;;
|
||||
-c|--c-long)
|
||||
case "$2" in
|
||||
"") echo "Option c, no argument"; shift 2 ;;
|
||||
*) echo "Option c, argument \`$2'" ; shift 2 ;;
|
||||
esac ;;
|
||||
--) shift ; break ;;
|
||||
*) echo "Internal error!" ; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
</screen>
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="grep">
|
||||
<title>grep</title>
|
||||
@@ -1144,7 +1278,7 @@
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
< <sect1 id="gzip">
|
||||
<sect1 id="gzip">
|
||||
<title>gzip</title>
|
||||
|
||||
<para>
|
||||
@@ -1372,7 +1506,7 @@
|
||||
<screen>
|
||||
<id>:<runlevels>:<action>:<process>
|
||||
</screen>
|
||||
<para>
|
||||
</para>
|
||||
|
||||
<sect2>
|
||||
<title>id</title>
|
||||
@@ -1433,41 +1567,43 @@
|
||||
</para>
|
||||
</sect2>
|
||||
|
||||
<para>
|
||||
Example /etc/inittab file:
|
||||
</para>
|
||||
<sect2>
|
||||
<title>Example /etc/inittab file</title>
|
||||
|
||||
<para>
|
||||
<screen>
|
||||
# This is run first except when booting in single-user mode.
|
||||
#
|
||||
::sysinit:/etc/init.d/rcS
|
||||
<para>
|
||||
<screen>
|
||||
# This is run first except when booting in single-user mode.
|
||||
#
|
||||
::sysinit:/etc/init.d/rcS
|
||||
|
||||
# /bin/sh invocations on selected ttys
|
||||
#
|
||||
# Start an "askfirst" shell on the console (whatever that may be)
|
||||
::askfirst:/bin/sh
|
||||
# Start an "askfirst" shell on /dev/tty2
|
||||
tty2::askfirst:/bin/sh
|
||||
# /bin/sh invocations on selected ttys
|
||||
#
|
||||
# Start an "askfirst" shell on the console (whatever that may be)
|
||||
::askfirst:-/bin/sh
|
||||
# Start an "askfirst" shell on /dev/tty2-4
|
||||
tty2::askfirst:-/bin/sh
|
||||
tty2::askfirst:-/bin/sh
|
||||
tty2::askfirst:-/bin/sh
|
||||
|
||||
# /sbin/getty invocations for selected ttys
|
||||
#
|
||||
tty4::respawn:/sbin/getty 38400 tty4
|
||||
tty5::respawn:/sbin/getty 38400 tty5
|
||||
# /sbin/getty invocations for selected ttys
|
||||
#
|
||||
tty4::respawn:/sbin/getty 38400 tty5
|
||||
tty5::respawn:/sbin/getty 38400 tty6
|
||||
|
||||
# Example of how to put a getty on a serial line (for a terminal)
|
||||
#
|
||||
#ttyS0::respawn:/sbin/getty -L ttyS0 9600 vt100
|
||||
#ttyS1::respawn:/sbin/getty -L ttyS1 9600 vt100
|
||||
#
|
||||
# Example how to put a getty on a modem line.
|
||||
#ttyS2::respawn:/sbin/getty -x0 -s 57600 ttyS2
|
||||
# Example of how to put a getty on a serial line (for a terminal)
|
||||
#
|
||||
#ttyS0::respawn:/sbin/getty -L ttyS0 9600 vt100
|
||||
#ttyS1::respawn:/sbin/getty -L ttyS1 9600 vt100
|
||||
#
|
||||
# Example how to put a getty on a modem line.
|
||||
#ttyS2::respawn:/sbin/getty -x0 -s 57600 ttyS2
|
||||
|
||||
# Stuff to do before rebooting
|
||||
::ctrlaltdel:/bin/umount -a -r > /dev/null 2>&1
|
||||
::ctrlaltdel:/sbin/swapoff -a > /dev/null 2>&1
|
||||
</screen>
|
||||
</para>
|
||||
# Stuff to do before rebooting
|
||||
::ctrlaltdel:/bin/umount -a -r
|
||||
::ctrlaltdel:/sbin/swapoff
|
||||
</screen>
|
||||
</para>
|
||||
</sect2>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="insmod">
|
||||
@@ -1786,6 +1922,7 @@
|
||||
-A Do not list implied . and ..
|
||||
-C List entries by columns
|
||||
-F Append indicator (one of */=@|) to entries
|
||||
-L list entries pointed to by symbolic links
|
||||
-R List subdirectories recursively
|
||||
</screen>
|
||||
</para>
|
||||
@@ -2433,6 +2570,29 @@
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="rdate">
|
||||
<title>rdate</title>
|
||||
|
||||
<para>
|
||||
Usage: rdate [OPTION] HOST
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Get and possibly set the system date and time from a remote HOST.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Options:
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<screen>
|
||||
-s Set the system date and time (default).
|
||||
-p Print the date and time.
|
||||
</screen>
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="reboot">
|
||||
<title>reboot</title>
|
||||
|
||||
@@ -2445,6 +2605,32 @@
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="renice">
|
||||
<title>renice</title>
|
||||
|
||||
<para>
|
||||
Usage: renice priority pid [pid ...]
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Changes priority of running processes. Allowed priorities range
|
||||
from 20 (the process runs only when nothing else is running) to 0
|
||||
(default priority) to -20 (almost nothing else ever gets to run).
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="reset">
|
||||
<title>reset</title>
|
||||
|
||||
<para>
|
||||
Usage: reset
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Resets the screen.
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="rm">
|
||||
<title>rm</title>
|
||||
|
||||
@@ -2804,6 +2990,7 @@
|
||||
-n Run as a foreground process
|
||||
-K Do not start up the klogd process
|
||||
-O FILE Use an alternate log file (default=/var/log/messages)
|
||||
-R HOST[:PORT] Log messages to HOST on PORT (default=514) over UDP.
|
||||
</screen>
|
||||
</para>
|
||||
|
||||
@@ -2813,6 +3000,8 @@
|
||||
|
||||
<para>
|
||||
<screen>
|
||||
$ syslogd -R masterlog:514
|
||||
$ syslogd -R 192.168.1.1:601
|
||||
</screen>
|
||||
</para>
|
||||
</sect1>
|
||||
@@ -2884,10 +3073,10 @@
|
||||
|
||||
<para>
|
||||
<screen>
|
||||
f FILE Use FILE for tarfile (or stdin if '-')
|
||||
O Extract to stdout
|
||||
--exclude FILE Exclude FILE
|
||||
v List files processed
|
||||
f FILE Use FILE for tarfile (or stdin if '-')
|
||||
O Extract to stdout
|
||||
exclude FILE File to exclude
|
||||
v List files processed
|
||||
</screen>
|
||||
</para>
|
||||
|
||||
@@ -2959,8 +3148,8 @@
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<screen>
|
||||
or: [ EXPRESSION ]
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Check file types and compare values returning an exit
|
||||
@@ -3218,6 +3407,32 @@
|
||||
</screen>
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="unix2dos">
|
||||
<title>unix2dos</title>
|
||||
|
||||
<para>
|
||||
Usage: unix2dos < unixfile > dosfile
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Converts a text file from unix format to dos format.
|
||||
</para>
|
||||
|
||||
</sect1>
|
||||
|
||||
<sect1 id="unrpm">
|
||||
<title>unrpm</title>
|
||||
|
||||
<para>
|
||||
Usage: unrpm < package.rpm | gzip -d | cpio -idmuv
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Extracts an rpm archive.
|
||||
</para>
|
||||
|
||||
</sect1>
|
||||
|
||||
<sect1 id="update">
|
||||
<title>update</title>
|
||||
@@ -3445,6 +3660,40 @@
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="xargs">
|
||||
<title>xargs</title>
|
||||
|
||||
<para>
|
||||
Usage: xargs [OPTIONS] [COMMAND] [ARGS...]
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Executes COMMAND on every item given by standard input.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Options:
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<screen>
|
||||
-t Print the command just before it is run
|
||||
</screen>
|
||||
</para>
|
||||
|
||||
|
||||
<para>
|
||||
Example:
|
||||
</para>
|
||||
|
||||
<para>
|
||||
<screen>
|
||||
$ ls | xargs gzip
|
||||
$ find . -name '*.c' -print | xargs rm
|
||||
</screen>
|
||||
</para>
|
||||
</sect1>
|
||||
|
||||
<sect1 id="yes">
|
||||
<title>yes</title>
|
||||
|
||||
@@ -3535,14 +3784,18 @@
|
||||
<title>AUTHORS</title>
|
||||
|
||||
<para>
|
||||
The following people have contributed code to BusyBox whether
|
||||
they know it or not.
|
||||
The following people have made significant contributions to
|
||||
BusyBox -- whether they know it or not.
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Erik Andersen <andersee@debian.org>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Edward Betts <edward@debian.org>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
John Beppu <beppu@lineo.com>
|
||||
</para>
|
||||
@@ -3563,6 +3816,14 @@
|
||||
Karl M. Hegbloom <karlheg@debian.org>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Daniel Jacobowitz <dan@debian.org>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
John Lombardo <john@deltanet.com>
|
||||
</para>
|
||||
@@ -3575,14 +3836,26 @@
|
||||
Bruce Perens <bruce@perens.com>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Chip Rosenthal <chip@unicom.com>, <crosenth@covad.com>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Pavel Roskin <proski@gnu.org>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Gyepi Sam <gyepi@praxis-sw.com>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Linus Torvalds <torvalds@transmeta.com>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Mark Whitley <markw@lineo.com>
|
||||
</para>
|
||||
|
||||
<para>
|
||||
Charles P. Wright <cpwright@villagenet.com>
|
||||
</para>
|
||||
@@ -3590,5 +3863,7 @@
|
||||
<para>
|
||||
Enrique Zanardi <ezanardi@ull.es>
|
||||
</para>
|
||||
|
||||
|
||||
</chapter>
|
||||
</book> <!-- End of the book -->
|
||||
@@ -0,0 +1,269 @@
|
||||
Busybox Style Guide
|
||||
===================
|
||||
|
||||
This document describes the coding style conventions used in Busybox. If you
|
||||
add a new file to Busybox or are editing an existing file, please format your
|
||||
code according to this style. If you are the maintainer of a file that does
|
||||
not follow these guidelines, please -- at your own convenience -- modify the
|
||||
file(s) you maintain to bring them into conformance with this style guide.
|
||||
Please note that this is a low priority task.
|
||||
|
||||
To help you format the whitespace of your programs, an ".indent.pro" file is
|
||||
included in the main Busybox source directory that contains option flags to
|
||||
format code as per this style guide. This way you can run GNU indent on your
|
||||
files by typing 'indent myfile.c myfile.h' and it will magically apply all the
|
||||
right formatting rules to your file. Please _do_not_ run this on all the files
|
||||
in the directory, just your own.
|
||||
|
||||
|
||||
Declaration Order
|
||||
-----------------
|
||||
|
||||
Here is the order in which code should be laid out in a file:
|
||||
|
||||
- commented author name and email address(es)
|
||||
- commented GPL boilerplate
|
||||
- commented description of program
|
||||
- #includes and #defines
|
||||
- const and globals variables
|
||||
- function declarations (if necessary)
|
||||
- function implementations
|
||||
|
||||
|
||||
Whitespace
|
||||
----------
|
||||
|
||||
This is everybody's favorite flame topic so let's get it out of the way right
|
||||
up front.
|
||||
|
||||
|
||||
Tabs vs Spaces in Line Indentation
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The preference in Busybox is to indent lines with tabs. Do not indent lines
|
||||
with spaces and do not indents lines using a mixture of tabs and spaces. (The
|
||||
indentation style in the Apache and Postfix source does this sort of thing:
|
||||
\s\s\s\sif (expr) {\n\tstmt; --ick.) The only exception to this rule is
|
||||
multi-line comments that use an asterisk at the beginning of each line, i.e.:
|
||||
|
||||
/t/*
|
||||
/t * This is a block comment.
|
||||
/t * Note that it has multiple lines
|
||||
/t * and that the beginning of each line has a tab plus a space
|
||||
/t * except for the opening '/*' line where the slash
|
||||
/t * is used instead of a space.
|
||||
/t */
|
||||
|
||||
Furthermore, The preference is that tabs be set to display at four spaces
|
||||
wide, but the beauty of using only tabs (and not spaces) at the beginning of
|
||||
lines is that you can set your editor to display tabs at *watever* number of
|
||||
spaces is desired and the code will still look fine.
|
||||
|
||||
|
||||
Operator Spacing
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
Put spaces between terms and operators. Example:
|
||||
|
||||
Don't do this:
|
||||
|
||||
for(i=0;i<num_items;i++){
|
||||
|
||||
Do this instead:
|
||||
|
||||
for (i = 0; i < num_items; i++) {
|
||||
|
||||
While it extends the line a bit longer, the spaced version is more
|
||||
readable. An allowable exception to this rule is the situation where
|
||||
excluding the spacing makes it more obvious that we are dealing with a
|
||||
single term (even if it is a compund term) such as:
|
||||
|
||||
if (str[idx] == '/' && str[idx-1] != '\\')
|
||||
|
||||
or
|
||||
|
||||
if ((argc-1) - (optind+1) > 0)
|
||||
|
||||
|
||||
Bracket Spacing
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
If an opening bracket starts a function, it should be on the
|
||||
next line with no spacing before it. However, if a bracet follows an opening
|
||||
control block, it should be on the same line with a single space (not a tab)
|
||||
between it and the opening control block statment. Examples:
|
||||
|
||||
Don't do this:
|
||||
|
||||
while (!done){
|
||||
do{
|
||||
|
||||
Do this instead:
|
||||
|
||||
while (!done) {
|
||||
do {
|
||||
|
||||
|
||||
Paren Spacing
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Put a space between C keywords and left parens, but not between
|
||||
function names and the left paren that starts it's parameter list (whether it
|
||||
is being declared or called). Examples:
|
||||
|
||||
Don't do this:
|
||||
|
||||
while(foo) {
|
||||
for(i = 0; i < n; i++) {
|
||||
|
||||
Do this instead:
|
||||
|
||||
while (foo) {
|
||||
for (i = 0; i < n; i++) {
|
||||
|
||||
Do functions like this:
|
||||
|
||||
static int my_func(int foo, char bar)
|
||||
...
|
||||
baz = my_func(1, 2);
|
||||
|
||||
|
||||
Cuddled Elses
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Also, please "cuddle" your else statments by putting the else keyword on the
|
||||
same line after the right bracket that closes an 'if' statment.
|
||||
|
||||
Don't do this:
|
||||
|
||||
if (foo) {
|
||||
stmt;
|
||||
}
|
||||
else {
|
||||
stmt;
|
||||
}
|
||||
|
||||
Do this instead:
|
||||
|
||||
if (foo) {
|
||||
stmt;
|
||||
} else {
|
||||
stmt;
|
||||
}
|
||||
|
||||
|
||||
Variable and Function Names
|
||||
---------------------------
|
||||
|
||||
Use the K&R style with names in all lower-case and underscores occasionally
|
||||
used to seperate words (e.g. "variable_name" and "numchars" are both
|
||||
acceptable). Using underscores makes variable and function names more readable
|
||||
because it looks like whitespace; using lower-case is easy on the eyes.
|
||||
|
||||
Note: The Busybox codebase is very much a mixture of code gathered from a
|
||||
variety of locations. This explains why the current codebase contains such a
|
||||
plethora of different naming styles (Java, Pascal, K&R, just-plain-weird,
|
||||
etc.). The K&R guideline explained above should therefore be used on new files
|
||||
that are added to the repository. Furthermore, the maintainer of an existing
|
||||
file that uses alternate naming conventions should -- at his own convenience
|
||||
-- convert those names over to K&R style; converting variable names is a very
|
||||
low priority task. Perhaps in the future we will include some magical Perl
|
||||
script that can go through and convert files--left as an exersize to the
|
||||
reader.
|
||||
|
||||
|
||||
Tip and Pointers
|
||||
----------------
|
||||
|
||||
The following are simple coding guidelines that should be followed:
|
||||
|
||||
- When in doubt about the propper behavior of a busybox program (output,
|
||||
formatting, options, etc.), model it after the equivalent GNU program.
|
||||
Doesn't matter how that program behaves on some other flavor of *NIX;
|
||||
doesn't matter what the POSIX standard says or doesn't say, just model
|
||||
busybox programs after their GNU counterparts and nobody has to get hurt.
|
||||
|
||||
- Don't use a '#define var 80' when you can use 'static const int var 80'
|
||||
instead. This makes the compiler do typechecking for you (rather than
|
||||
relying on the more error-prone preprocessor) and it makes debugging
|
||||
programs much easier since the value of the variable can be easily queried.
|
||||
|
||||
- If a const variable is used in only one function, do not make it global to
|
||||
the file. Instead, declare it inside the function body.
|
||||
|
||||
- Inside applet files, all functions should be declared static so as to keep
|
||||
the global namespace clean. The only exception to this rule is the
|
||||
"applet_main" function which must be declared extern.
|
||||
|
||||
- If you write a function that performs a task that could be useful outside
|
||||
the immediate file, turn it into a general-purpose function with no ties to
|
||||
any applet and put it in the utility.c file instead.
|
||||
|
||||
- Put all help/usage messages in usage.c. Put other strings in messages.c
|
||||
(Side Note: we might want to use a single file instead of two, food for
|
||||
thought).
|
||||
|
||||
- There's a right way and a wrong way to test for sting equivalence with
|
||||
strcmp:
|
||||
|
||||
The wrong way:
|
||||
|
||||
if (!strcmp(string, "foo")) {
|
||||
...
|
||||
|
||||
The right way:
|
||||
|
||||
if (strcmp(string, "foo") == 0){
|
||||
...
|
||||
|
||||
The use of the "equals" (==) operator in the latter example makes it much
|
||||
more obvious that you are testing for equivalence. The former example with
|
||||
the "not" (!) operator makes it look like you are testing for an error.
|
||||
|
||||
- Do not use old-style function declarations that declare variable types
|
||||
between the parameter list and opening bracket. Example:
|
||||
|
||||
Don't do this:
|
||||
|
||||
int foo(parm1, parm2)
|
||||
char parm1;
|
||||
float parm2;
|
||||
{
|
||||
....
|
||||
|
||||
Do this instead:
|
||||
|
||||
int foo(char parm1, float parm2)
|
||||
{
|
||||
....
|
||||
|
||||
- Please use brackets on all if and else statements, even if it is only one
|
||||
line. Example:
|
||||
|
||||
Don't do this:
|
||||
|
||||
if (foo)
|
||||
stmt;
|
||||
else
|
||||
stmt;
|
||||
|
||||
Do this instead:
|
||||
|
||||
if (foo) {
|
||||
stmt;
|
||||
} else {
|
||||
stmt;
|
||||
}
|
||||
|
||||
The "bracketless" approach is error prone because someday you might add a
|
||||
line like this:
|
||||
|
||||
if (foo)
|
||||
stmt;
|
||||
new_line();
|
||||
else
|
||||
stmt;
|
||||
|
||||
And the resulting behavior of your program would totally bewilder you.
|
||||
(Don't laugh, it happens to us all.) Remember folks, this is C, not
|
||||
Python.
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
Mini dos2unix implementation for busybox
|
||||
|
||||
Copyright 1994,1995 Patrick Volkerding, Moorhead, Minnesota USA
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this source code, with or without modification, is
|
||||
permitted provided that the following condition is met:
|
||||
|
||||
1. Redistributions of this source code must retain the above copyright
|
||||
notice, this condition, and the following disclaimer.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int dos2unix_main( int argc, char **argv ) {
|
||||
int c;
|
||||
if (argc > 1) {
|
||||
c = *argv[1];
|
||||
if (c == '-') {
|
||||
usage(dos2unix_usage);
|
||||
}
|
||||
}
|
||||
c = getchar();
|
||||
while (c != EOF) {
|
||||
/* Eat any \r's... they shouldn't be here */
|
||||
while (c == '\r') c = getchar();
|
||||
if (c == EOF) break;
|
||||
putchar(c);
|
||||
c = getchar();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loaded 100 of 256 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user