Compare commits

...
807 Commits
Author SHA1 Message Date
Eric Andersen f8263516c2 Log the devps patch update 2000-09-26 05:08:04 +00:00
Eric Andersen db7f2af089 Final touchups for the release...
-Erik
2000-09-26 05:02:50 +00:00
Eric Andersen f6b7139971 Add in busybox.h. I renamed it, and forgot to commit the newky named version.
-Erik
2000-09-26 01:09:18 +00:00
Eric Andersen d266748c76 Yet more polish (thanks again to kent robotti for the bug reports).
-Erik
2000-09-26 01:00:15 +00:00
Eric Andersen 53323695c5 Remove all reference to the now obsolete /dev/modules
-Erik
2000-09-26 00:52:05 +00:00
Eric Andersen 67fdf5e538 Update my devps patch for the latest 2.2 kernel.
-Erik
2000-09-26 00:20:28 +00:00
Eric Andersen ff1ed7215c Fix name 2000-09-25 22:53:33 +00:00
Eric Andersen d89882da16 Some more polish to make xargs act like GNU xargs (thanks to kent robotti
<robotti@metconnect.com> for testing and pointing out the differences)
 -Erik
2000-09-25 22:53:05 +00:00
Eric Andersen 3570a34de4 Renamed "internal.h" to the more sensible "busybox.h".
-Erik
2000-09-25 21:45:58 +00:00
Eric Andersen caffb6eff0 Gratuitously changed the file "busybox.defs.h" to the more
sensible and noticable "Config.h".
 -Erik
2000-09-25 21:28:07 +00:00
Eric Andersen c5949f62e5 Fix from Matt Kraai for the to the "busybox --install prints out on STDERR
"File already exists" messages for all files (including the ones that DON'T
exist)" problem reported by "Bruno L. F. Cabral" <bruno@openline.com.br>.

Thanks Matt!
 -Erik
2000-09-25 20:35:54 +00:00
Eric Andersen e081eae7a4 Final (I think) version of xargs. Throw away all that tedious string
scrubbing, and quit using system.  Instead, use fork() and exec(), which
yields and smaller, simpler, and cleaner design.
 -Erik
2000-09-25 20:23:21 +00:00
Eric Andersen bf73909f23 Be ever so pedantic about escaping chars that the shell might not like... 2000-09-25 18:41:18 +00:00
Eric Andersen 944be90b21 Remove a now unneeded check 2000-09-25 16:58:39 +00:00
Eric Andersen fe4208fe93 modified by Bryan Rittmeyer <bryan@ixiacom.com> to support SH4 2000-09-24 03:44:29 +00:00
Eric Andersen 488aac2e2a Update newdoc dependancy 2000-09-24 02:42:48 +00:00
Eric Andersen 896fa4ea1d Update a few entries for 0.47... 2000-09-24 02:42:18 +00:00
Eric Andersen 57f83fffd8 Doc update 2000-09-24 02:41:44 +00:00
Eric Andersen 6f283c2f77 Fix up xargs so that things like 'cat cat.c | xargs echo' will
work properly.
 -Erik
2000-09-24 02:40:56 +00:00
Eric Andersen 9ae3838657 Fix xargs option parsing 2000-09-24 01:12:54 +00:00
Eric Andersen 1b1cfde1f8 Fix bug#1043 -- hanlde long filenames and links (in this case, by complaining
that thay exist and skipping such files when extracting and when archiving.
 -Erik
2000-09-24 00:54:37 +00:00
Eric Andersen 0102a9fd48 Fix an obscure option parsing bug. 2000-09-23 22:36:24 +00:00
Eric Andersen 2da90d3b58 Force optind=1 for libc5 when doing cp in cp_mv.c 2000-09-23 20:55:59 +00:00
Eric Andersen 285b446d17 Fix potential memory overrun... 2000-09-23 19:56:46 +00:00
Eric Andersen 32e95f988d Fix the bandaid. 2000-09-23 19:55:59 +00:00
Eric Andersen 96bdde97fb Fix memory problems, and make behavior correct. 2000-09-23 19:53:31 +00:00
Eric Andersen 6d66817b6b update docs for xargs 2000-09-23 06:12:34 +00:00
Eric Andersen 82e0614101 update usage for xargs 2000-09-23 06:11:03 +00:00
Eric Andersen a37d5b772b rewrite, so it should be firly clean now 2000-09-23 06:10:14 +00:00
Eric Andersen 5b17693f0a Use minix xargs instead, and update docs accordingly
-Erik
2000-09-22 20:22:28 +00:00
Eric Andersen ebc0dd7a8a Comment on xargs choice. 2000-09-22 20:02:34 +00:00
Eric Andersen 92a61c1206 Add in xargs 2000-09-22 20:01:23 +00:00
Matt Kraai 90f580ad5b Start the great EXIT_{SUCCESS,FAILURE} migration. 2000-09-22 03:45:34 +00:00
Matt Kraai d995493987 Clean up error messages. 2000-09-22 03:36:27 +00:00
Matt Kraai a2f2a8f8c0 Add support for the -L option to ls. 2000-09-22 03:11:47 +00:00
Matt Kraai 810d38f850 Fix loop.h dependencies. 2000-09-22 02:33:29 +00:00
Eric Andersen a1b35c4512 Apply a bandaid suggested by Jon McClintock <jonm@bluemug.com>, since deallocvt
has code for handling no arguments, but the usage checking code aborted if
there are any other than two arguments.
 -Erik
2000-09-22 00:40:39 +00:00
Eric Andersen 8c185f9600 Fix for bug #1042 -- applied the patch from Larry Doolittle
<ldoolitt@recycle.lbl.gov> to fix the bug.
 -Erik
2000-09-22 00:38:07 +00:00
Eric Andersen 75610e18b3 Better cross libc compatibility (so Dave Cinege can stop complaining
that I broke it).
 -Erik
2000-09-22 00:22:10 +00:00
Eric Andersen 2c1faecba7 Decouple DODEBUG and DOSTATIC 2000-09-21 22:26:02 +00:00
Eric Andersen c873d61008 Remove all the kernel headers so it will compile under libc5
-Erik
2000-09-21 04:09:58 +00:00
Eric Andersen ba35b98444 Fix a potential warning 2000-09-21 04:05:38 +00:00
Eric Andersen d2f5677762 Add in exec support (patch from Torbj?rn Axelsson <torax@cendio.se>)
and disable backticks (since they are still wierdly broken in some
cases.
2000-09-21 02:48:07 +00:00
Eric Andersen d1de4a16ad Handle 'cat -' 2000-09-21 02:39:50 +00:00
Eric Andersen f34aa4c378 Hard code the name of init. 2000-09-21 02:32:11 +00:00
Eric Andersen 8a2e56c5df Large file >2Gib support. 2000-09-21 02:23:30 +00:00
Eric Andersen 350b3f9236 Typo fix. 2000-09-21 02:06:35 +00:00
Eric Andersen ae22612792 Ignore loop.h 2000-09-21 02:05:43 +00:00
Eric Andersen 624cc771da More portable handling of loop header files, as done in util-linux 2000-09-21 02:04:51 +00:00
Eric Andersen 8847b9a03a Remove a warning. Patch from Bryan Rittmeyer <bryan@ixiacom.com> 2000-09-21 01:33:05 +00:00
Matt Kraai 7c22b77162 Only remove directories when removing recursively. 2000-09-20 23:10:21 +00:00
Eric Andersen cff3fe3ae9 Added dos2unix, unix2dos, and unrpm.c thanks to robotti@metconnect.com.
-Erik
2000-09-20 19:22:26 +00:00
Eric Andersen 0cccdfaf36 When mounting a ro fs rw, print warning and then mount it ro. Patch
from Dave Cinege.
 -Erik
2000-09-20 06:23:36 +00:00
Matt Kraai b938e2ff99 Return failure if ping gets no response. 2000-09-20 04:33:30 +00:00
Eric Andersen 46a98dfb13 Reverted my conversion of tar to getopt to ensure tar can
handle traditional semantics (i.e. 'tar -xvf -' or 'tar xvf'
now both work).
 -Erik
2000-09-19 21:35:14 +00:00
Eric Andersen 56f3e353da Both of these commands were subtly broken. Fortunately when used together the
damage was only ugly fscks.  Reverted to the static inline code so they work
correctly again,
 -Erik
2000-09-19 21:13:55 +00:00
Eric Andersen 06f64b2370 I think these featires are fairly safe...
-Erik
2000-09-19 07:16:39 +00:00
Matt Kraai 0b2da467a8 Avoid segfaults by not using snprintf to copy strings. 2000-09-19 06:46:44 +00:00
Matt Kraai 721119e1db Clean up output. 2000-09-19 05:25:12 +00:00
Glenn L McGrath cd26ff4eac Only defines functions that will compile and are usefull under the 2000-09-19 02:25:36 +00:00
Eric Andersen 252bacc9ea Apply a patch from Chip Rosenthal <chip@unicom.com> to fix NFS mounting,
which had been inadvertantly broken...
 -Erik
2000-09-19 01:21:13 +00:00
Glenn L McGrath fd3741d712 Remove definition of basename.
It was defined out so that it would never be seen, and if it was ever seen it wasnt used for anything. It also stops gunzip compiling under the Hurd.
2000-09-18 10:20:16 +00:00
Glenn L McGrath 38c8551cf2 Path count was out by one, fixed it 2000-09-18 09:52:03 +00:00
Glenn L McGrath 63dde9d4ce Simplify and remove dependence on PATH_MAX
buf[PATH_MAX] now defined using strlen to the exact size to be used.
removed output that was displayed if which didnt find the command, this makes itmatch the behaviour of GNU's which.
These modifications result in a slight size decrease.
2000-09-18 09:37:40 +00:00
Matt Kraai b2f36af157 Updated stdin/stdout treatment to match that of gnu tar. 2000-09-15 22:47:34 +00:00
Matt Kraai 6fc2a7d04d Reorganize listing code. 2000-09-15 22:23:41 +00:00
Matt Kraai 82cfbad216 Allow non-verbose listing to work. 2000-09-15 21:18:43 +00:00
Pavel Roskin c9db2e8665 Updated to be in sync with the current sample inittab 2000-09-15 17:24:13 +00:00
Pavel Roskin d2d3aa39ef Fixed compliance with the DTD 2000-09-15 17:16:40 +00:00
John Beppu 2aee993118 + credit markw@lineo.com for his contributions 2000-09-15 08:04:42 +00:00
Pavel Roskin f5cf8c6c65 Don't suppress output of umount and swapoff - it is both unwise
and incompatible with lash that doesn't support >&1 yet.
2000-09-15 01:34:17 +00:00
Pavel Roskin 33bee33af0 Don't suppress output of umount and swapoff - it is both unwise
and incompatible with lash that doesn't support >&1 yet.
2000-09-15 01:02:50 +00:00
Pavel Roskin 5f84fd7066 "exit NUMBER" should exit, not return 2000-09-15 00:46:51 +00:00
Pavel Roskin cbe05e45db For "askfirst" don't just read one char from stdin,
read the whole line using getc(), so that everything before Enter
gets discarded.
2000-09-14 22:47:29 +00:00
Eric Andersen 7e3bf6e339 Add in a patch from robotti@metconnect.com and Chip Rosenthal to make
init do login shell stuff.
 -Erik
2000-09-14 22:01:31 +00:00
Eric Andersen ce40fc044b Note the syslogd bug fix 2000-09-14 21:56:18 +00:00
Eric Andersen 5d63884a8f Bug fix for wget, and proper attribution of Chip Rosenthal and
Covad Communications for the contribution of wget.
 -Erik
2000-09-14 21:46:30 +00:00
Eric Andersen 31e6829bd8 Fix the halt/reboot/poweroff segfault when used from within an initrd...
-Erik
2000-09-14 21:12:20 +00:00
Matt Kraai 131241f71c Backslashes shouldn't be treated as backticks. 2000-09-14 00:43:20 +00:00
Matt Kraai cbbe4d6bc2 Copy the string terminator. 2000-09-14 00:26:50 +00:00
Glenn L McGrath 56a328810b Fix looping bug, use fullRead 2000-09-13 23:08:07 +00:00
Eric Andersen b4c3c59a45 Add in BasicLinux by request 2000-09-13 23:06:41 +00:00
Pavel Roskin f8e04f7113 Added _install 2000-09-13 16:52:32 +00:00
Eric Andersen fb6a50820c Ensure forked processes always are on a controlling tty, so the
^C can be properly sent to /dev/console.
 -Erik
2000-09-13 16:15:29 +00:00
Pavel Roskin d39d120998 Make syslogd ignore SIGCLD only if SIGCLD is defined. This should fix SPARC.
Also ignore SIGCHLD - it must have been meant.
2000-09-13 14:14:29 +00:00
Pavel Roskin 5d513f7256 List of signals updated from util-linux-2.10o
Architecture names are no longer used - should now compile on SPARC
2000-09-13 14:03:48 +00:00
Matt Kraai dd450a0ded Don't fork for the . (source) command so that environment settings are
preserved.
2000-09-13 03:43:36 +00:00
Matt Kraai 322ae93a5e Fix calls to {m,c,re}alloc so that they use x{m,c,re}alloc instead of
segfaulting or handling errors the same way themselves.
2000-09-13 02:46:14 +00:00
Matt Kraai b89075298e Fix unchecked calls to {m,c,re}alloc so that they print an error and
exit rather than segfaulting (what an improvement).
2000-09-13 02:08:21 +00:00
Pavel Roskin 23ad7f7f06 Typo fix: resolv -> resolve 2000-09-12 22:05:17 +00:00
Eric Andersen ccb0a9ba88 Formatting cleanup patch from Bryan Rittmeyer <bryan@ixiacom.com>.
-Erik
2000-09-12 16:20:49 +00:00
Glenn L McGrath fca8050f0f Fix .deb unpack and experimental TAR support
The previous ar.c fialed to recognise one record in .debs

Experimental tar support, this is currently *very* cheap because ar and
tar are functionally similar. It  will need lots of testing so by
default tar support code is defined out.
To test uncomment the line "#define BB_AR_EXPERIMENTAL_UNTAR"
2000-09-11 05:25:39 +00:00
Glenn L McGrath ac19b7e032 Extra defines for ar 2000-09-11 05:06:13 +00:00
Eric Andersen 49352adf9c Simplify a few little things, and merge in a patch from
robotti@metconnect.com so that 'ar -xv' and 'ar -x -v'
both work.
 -Erik
2000-09-11 04:55:31 +00:00
Glenn L McGrath 605a819a17 New dd behaviour 2000-09-11 00:33:09 +00:00
Glenn L McGrath f0b073f55a dd now truncates files at the end its write, this can be turned of by
specifying conv=notrunc in the command line

This conforms to GNU dd behaviour
2000-09-11 00:32:13 +00:00
Eric Andersen de34e43755 MAke lsmod act just like modutils lsmod, by printing which modules use
other modules, and state info like (deleted) and such.
 -Erik
2000-09-10 16:16:00 +00:00
Eric Andersen cbb61c78ae Make init handle current 2.4.x sysinfo behavior
-Erik
2000-09-10 16:13:41 +00:00
Eric Andersen 73de6561ca Update free for current 2.4.x behavior...
-Erik
2000-09-10 16:10:41 +00:00
Glenn L McGrath 729216cb11 Remove some debugging code 2000-09-10 04:42:20 +00:00
Glenn L McGrath 18310f1ce3 Using seek=? used to cause part of the original file to be zero'ed, i
think this was caused by opening the file in truncate mode.
2000-09-10 04:39:37 +00:00
Glenn L McGrath 0ae8e5a645 My previous attempt to make dd use fullRead, fullWrite was very broken,
this should actually work.
2000-09-10 01:54:27 +00:00
Glenn L McGrath bd7c67136a remove some printf statements i forgot about 2000-09-09 15:04:34 +00:00
Glenn L McGrath 1c6917d2c4 Updated to match new -R ar functionality 2000-09-09 14:57:15 +00:00
Glenn L McGrath e2b345a6d8 Implemented new ar functionality unique to busybox ar (i think), the -R
option enable a Recursive extraction (or listing) to take place.

i.e. if any files being extracted are themselves ar archives then
busybox ar will extract their contents as well.

e.g. take bar.deb and do (with GNU ar) ar -q foo.deb b.ar
then with busybox ar can do ar -x b.ar data.tar.gz

-R isnt used for anything in GNU ar so i think it should be ok, could
have used long options

This functionality will become (more) usufull with tar, gz support.
2000-09-09 14:50:04 +00:00
Glenn L McGrath 437bf72785 Changed getopt so that options can be grouped together, the source
archive is now assumed to be the first non parameter.

This is how GNU ar behaves.
2000-09-09 13:38:26 +00:00
Glenn L McGrath 6fb88e73f7 Fix permisions 2000-09-09 12:48:40 +00:00
Glenn L McGrath 8324b9f1aa Now supports GNU style long filenames.
If no filenames are specifed to be (extracted/listed) it will act on
all files in the archive (i dont think the old version did this)

Code is structured to better support upcoming recursive extraction
functionality.

The old code was a bit strange in places, dont know what i was thinking.
2000-09-09 08:35:45 +00:00
Eric Andersen 11c655295c New ls sorting patch, as written by Sterling Huxley, and then updated
by kent robotti.  I then updated it to use my_getpwuid and my_getgrgid
(per busybox policy).
 -Erik
2000-09-07 17:24:47 +00:00
Matt Kraai 44e3840343 Stop leaking file handles. 2000-09-07 04:34:17 +00:00
Matt Kraai 17c8851813 Fix more typos. 2000-09-06 03:59:49 +00:00
Matt Kraai 6085c72b6e Reset optind so that getopt works in busybox applets called directly by sh.
Change the behavior of -c to correctly handle $1..$9.
2000-09-06 01:46:18 +00:00
Matt Kraai 9dd79791c8 Fixed a grammatical error. 2000-09-06 00:50:51 +00:00
Eric Andersen ebee301c8b Fixed for when BB_CP_MV is enabled. 2000-09-05 22:17:22 +00:00
Eric Andersen d13ebff163 Add BB_SH to get_last_path_component()... Fix thanks to
Bj�rn Eriksson.
2000-09-05 21:50:52 +00:00
Eric Andersen 1eec89df4c Apply segfault on no-args fix from robotti@metconnect.com 2000-09-05 18:21:53 +00:00
Eric Andersen 3639c5d950 Set environment variable to make ash happy. ash is a frequent enough
target....
2000-09-05 17:57:52 +00:00
Eric Andersen 1b355ebba6 Added expr, from Edward Betts <edward@debian.org>, with some fixups
and docs added by me.
 -Erik
2000-09-05 17:37:48 +00:00
Matt Kraai 43c8c38bbf Allow compilation when not using BB_FEATURE_TAR_EXCLUDE, and fix
handling of --exclude option.
2000-09-04 16:51:55 +00:00
Eric Andersen 61a9d8d145 Forgot this part of wget 2000-09-04 15:16:51 +00:00
Eric Andersen 9670083818 Initial implementation of wget, from Chip Rosenthal <chip@laserlink.net>.
Very cool.  Still lacks "chunked" transfer-coding, so not totally RFC
compliant for HTTP1.1, but very nice nonethe less, and very small.
 -Erik
2000-09-04 15:15:55 +00:00
Matt Kraai b92223b6f5 Allow selective extraction and listing of files. And fix an unchecked
return value of realloc (with xrealloc).
2000-09-04 08:25:42 +00:00
Eric Andersen fd50c3d2f9 Add in byld 2000-09-01 22:24:03 +00:00
Eric Andersen cb91d69b3f Fix compile when BB_FEATURE_LINUXRC is defined
-Erik
2000-09-01 18:43:02 +00:00
Eric Andersen 73bdf13d35 Fixed a stupid thinko preventing zcat from doing its job, thanks
to Torbj�rn Axelsson <torax@cendio.se> for the fix.
 -Erik
2000-09-01 16:25:33 +00:00
Eric Andersen 3a957b9d4c Turned off ls file-sorting till it can be fixed. 2000-09-01 16:15:51 +00:00
Eric Andersen 18a1014c95 updated some usage info from a patch from robotti@metconnect.com
-Erik
2000-09-01 16:12:57 +00:00
Matt Kraai da542f3a0c Argh. I *will* compile before checking in. 2000-09-01 02:53:01 +00:00
Matt Kraai f446297afd Don't unlink files if we are extracting to stdout. 2000-09-01 02:50:48 +00:00
Eric Andersen e99674a70f Correct the stdin/stdout behavior when no args are provided.
-Erik
2000-09-01 00:41:10 +00:00
Eric Andersen 5eb5912790 Sigh. Seems I screwed up last time. This fixed detecting
when on a console or not, and make default behavior compatible
with GNU gzip...
 -Erik
2000-09-01 00:33:06 +00:00
Eric Andersen 4e61db2284 Add an extra sanity check in parse_mode
-Erik
2000-09-01 00:06:17 +00:00
Eric Andersen ad3d90f91e Fix a spelling error
-Erik
2000-08-31 23:53:58 +00:00
Eric Andersen a3de24e85d Fix spelling error
-Erik
2000-08-31 23:52:46 +00:00
Matt Kraai 1638488d26 Rewritten by mistake. 2000-08-28 03:53:27 +00:00
Matt Kraai ab60f6987a Removed dead regular expression code. 2000-08-28 03:12:30 +00:00
Matt Kraai 88cc3057fd Compile xstrdup and xstrndup iff they are needed. 2000-08-26 16:52:28 +00:00
Glenn L McGrath 06aeb6c417 ar.c now uses a linked list to process headers, uses getopt, new internal function extractAr(srcFD, dstFd, filename) to make it easily accessable to other busybox functions.
moved copySubFile from ar.c to utilities.c

modified dd.c to use fullWrite

modified copyFile in utilities.c to use copySubFile
2000-08-25 03:50:10 +00:00
Eric Andersen 4d5ac2f346 Fix tab stops for sed usage. 2000-08-25 00:23:36 +00:00
Pavel Roskin 3a0f4baf2f Fixed a warning about a label not being used 2000-08-22 15:47:57 +00:00
Pavel Roskin 8237add8d0 Fixed misuse of type "char" 2000-08-22 15:38:16 +00:00
Pavel Roskin 32f2769800 From Ken Chalmers <chalmers@norscan.com>:
The current CVS mount.c is missing a semicolon, causing building to fail
if NFS is enabled (#define BB_NFSMOUNT).
2000-08-22 15:35:31 +00:00
Eric Andersen 089d12d762 Fix a unterminated string.
-Erik
2000-08-22 05:18:30 +00:00
Eric Andersen aaa94fb8a9 Note the chmod fix.
-Erik
2000-08-22 01:02:05 +00:00
Eric Andersen ce82c8ab77 Fix an option parsing bug where things like
chmod -r /tmp/file
wholdn't work (since it thought -r was an option).  Doh!
 -Erik
2000-08-22 01:00:56 +00:00
Mark Whitley 2368a387ed Some additional tips and formatting changes. 2000-08-22 00:20:21 +00:00
Eric Andersen e4c4d69c04 Fix a silly bug so it compiles up properly
-Erik
2000-08-21 23:29:45 +00:00
Eric Andersen 6ab22027d0 Oops. Forgot to commit rdate.c.
-Erik
2000-08-21 23:04:00 +00:00
Eric Andersen fba9c00071 Script to do regression test, by combining all possible options.
-Erik
2000-08-21 23:01:39 +00:00
Eric Andersen acf5551099 Script to do regression test, by combining all possible options.
Run this to check for combinitorial type build errors.
 -Erik
2000-08-21 23:01:20 +00:00
Eric Andersen 918507edda Added the 'rdate' command, thanks to Sterling Huxley <sterling@europa.com>.
I added the docs, and made behavior identical to the GNU version.
 -Erik
2000-08-21 22:46:33 +00:00
Eric Andersen 851ce895bd Turn off some debug noise.
-Erik
2000-08-21 22:34:23 +00:00
Eric Andersen a1f16bba72 Added getopt(1) from "Alfred M. Szmidt" <ams@trillian.itslinux.org>
-Erik
2000-08-21 22:02:34 +00:00
Eric Andersen e2205f093b Removed since this patch is now in the current 2.4.x kernel
tree.
 -Erik
2000-08-21 21:44:52 +00:00
Mark Whitley 0e4cec0be8 Applied patch from Mark Ferrell <mferrell@mvista.com> to use the 'p' option in
substitution expressions.
2000-08-21 21:29:20 +00:00
Eric Andersen dc746169cf Oops. Forgot to add in reset.c. Doh!
-Erik
2000-08-21 21:26:33 +00:00
Eric Andersen 282c364148 Fix a thinko, thanks to Klaasjan <klaasjan@europe.com>
-Erik
2000-08-21 21:23:48 +00:00
Eric Andersen fa405d0cb2 Add in the "reset" command.
-Erik
2000-08-21 21:18:52 +00:00
Eric Andersen 202995c612 Yet another patch to fixup lsmod
-Erik
2000-08-21 19:40:42 +00:00
Eric Andersen c86e5e6145 Some leftover stuff I forgot to commit for the lsmod change.
-Erik
2000-08-21 19:38:49 +00:00
Eric Andersen be0dc0d06a lsmod now uses the query_module syscall, rather then /proc
-Erik
2000-08-21 19:25:16 +00:00
Eric Andersen b2fc5a0647 syslogd was leaking processes that could forever busyloop. Fixed.
-Erik
2000-08-20 06:11:32 +00:00
Eric Andersen e89267c8b3 Minor fixups.
-Erik
2000-08-19 20:16:16 +00:00
Eric Andersen 8cbac440d6 Better 'mt' docs, thanks to Kent Robotti <robotti@metconnect.com>
-Erik
2000-08-11 20:14:11 +00:00
Eric Andersen 6ac18a3d83 Fix to make 'ar xv' work, thanks to Kent Robotti <robotti@metconnect.com>
-Erik
2000-08-11 20:11:35 +00:00
Eric Andersen bb39a31e33 Minor link update
-Erik
2000-08-11 18:13:21 +00:00
Eric Andersen 79565b6c91 Add optional ls file sorting, thanks to a patch from
Sterling Huxley <sterling@europa.com>
 -Erik
2000-08-11 18:10:21 +00:00
Eric Andersen f9ca653faa Added fix from David Vrabel <dvrabel@arcom.co.uk> for a
buffer overrun in find_real_root_device(), fixing bug #1019
 -Erik
2000-08-11 17:45:02 +00:00
Eric Andersen 88f50b6bf5 Some #include updates.
-Erik
2000-08-10 17:59:11 +00:00
Mark Whitley 40406e6bad Applied patch from Mark Ferrell <mferrell@mvista.com> to fix sed '1,$p' where
sed was only printing the first line and then exiting.
2000-08-10 00:09:47 +00:00
Matt Kraai adbf018dc4 We complained if the total number of arguments was greater than 3 and
the destination wasn't a directory.  We should only complain if the
there are multiple sources and target isn't a directory.
2000-08-06 15:36:50 +00:00
Matt Kraai deb95f69b6 Exit with the appropriate value when grepping multiple files. 2000-08-06 15:25:53 +00:00
Eric Andersen 46ade97983 Cleaner way to handle -NUM and +NUM, reduces the mem usage as well.
-Erik
2000-08-02 19:57:18 +00:00
Eric Andersen 0c8e2a6580 Fixed the "-f" option.
-Erik
2000-08-02 18:56:25 +00:00
Eric Andersen fdd5103348 Merge in two patches from Dave Cinege:
the first is a cleanup of tar --exclude
    the second changes mount so mtab works more as it should, and
    also allows mount to use the traditional short form (i.e.
    'mount / -o remount,rw' now works.

While inside tar, I changed it to use getopt...
 -Erik
2000-08-02 18:48:26 +00:00
Mark Whitley 5ae166813f Minor cleanup thingy. fprintf(stderr, ...) -> errorMsg(). 2000-08-02 18:34:41 +00:00
Mark Whitley 807f0fd637 Brand, new version of cut. This fixes the bugs in the old cut, is smaller, and
is a sight easier to understand than the Minix cut.
2000-08-02 18:30:11 +00:00
Eric Andersen d5fa3e3e9a Update to the tail rewrite by "Allen Soard" <esp-software@mail.hypermart.net>
-Erik
2000-08-02 16:42:58 +00:00
Eric Andersen 080d51bf45 Minor fix to clean target
-Erik
2000-08-01 22:44:32 +00:00
Matt Kraai 0f8f7b8a35 Fix bug 1017, which reports that insmod segfaults when /lib/modules doesn't
exist.  Also allow early search termination (per the comments).
2000-08-01 18:16:56 +00:00
Eric Andersen 98bbd688a8 Commit the rewrite of tail by Allen Soard
<esp-software@mail.hypermart.net>.  Thanks Allen for
you work at getting this into shape,
 -Erik
2000-07-31 17:05:58 +00:00
Pavel Roskin 43c17b3d96 New variable WARNINGS to hold all warning options 2000-07-28 19:41:32 +00:00
Pavel Roskin 616d13bcd1 Fixed to pass -Wundef 2000-07-28 19:38:27 +00:00
Pavel Roskin 259972e565 Disabled debugging output
Fine-grained checks for possible errors instead of "set -e"
The standard output shows what is being linked to what
2000-07-28 19:34:02 +00:00
Eric Andersen 9cf306d55e Fix for a potential uninitialized variable, thx to
Ken Chalmers <chalmers@norscan.com>
 -Erik
2000-07-28 19:05:20 +00:00
Eric Andersen 6a4c33c5c0 Clean up the nasty blunder I'd made of how different behaviors happen.
-Erik
2000-07-28 17:08:36 +00:00
Eric Andersen 6150df320a Some cleanups, based on a patch from Ken Chalmers
-Erik
2000-07-28 16:22:51 +00:00
Eric Andersen d5704686b1 Fix from Robert Kaiser for stdin behavior.
-Erik
2000-07-28 15:20:24 +00:00
Eric Andersen 1428c4f136 Oops. Forgot an ifdef
-Erik
2000-07-28 15:19:30 +00:00
Eric Andersen a5716d3029 Fix from Arne Bernin for return code -- now reflects whether the rmmod
failed or not.
 -Erik
2000-07-28 15:16:37 +00:00
Eric Andersen 501c88b245 More sh updates (with related changes to everything else). Switched
to using getopt and cleaned up the resulting mess.  if-then-else-fi
is now basically working (given a bunch of constraints).
 -Erik
2000-07-28 15:14:45 +00:00
Eric Andersen 6a99aaf020 More shell features.... if-then-else-fi is now basically usable (disable
by default pending further debugging).  Added in some basic shell environment
support (i.e. $?, $0-$9, $$, $!, $#).
 -Erik
2000-07-27 00:15:20 +00:00
Mark Whitley 7ce41ad692 Fixed a syntax error & superfluous param decl that was causing the build to
fail.
2000-07-26 18:09:22 +00:00
Eric Andersen e92108ae6d Minor style cleanups. 2000-07-26 00:53:56 +00:00
Eric Andersen 0d49dd53cf Better description 2000-07-26 00:53:34 +00:00
Eric Andersen cc10a5b42b Fix some bitrot.
-Erik
2000-07-26 00:52:04 +00:00
Mark Whitley 83e85f6a08 Modified print_subst_w_backrefs() so it will print backslash escaped
characters properly, just like GNU sed.
2000-07-25 20:48:44 +00:00
Mark Whitley 52681b48dc Added a note in the "Tips and Pointer" section on the correct way to test for
string equivalence with strcmp().
2000-07-25 20:30:00 +00:00
Eric Andersen fad9c1198a Finish off fixing up the memleaks (I think). Added the beginnings of
some if-then-else-fi support (nonfunctional and turned off)
 -Erik
2000-07-25 18:06:52 +00:00
Eric Andersen b040d4f3da Use BB_FEATURE_CLEAN_UP where appropriate
-Erik
2000-07-25 18:01:20 +00:00
Eric Andersen b9ea02c04b Add in BB_FEATURE_CLEAN_UP, which is whether to clean up mem leaks and close
files, or not.  Usually safe to leave it off and let the OS clean up...
 -Erik
2000-07-25 17:59:37 +00:00
Eric Andersen d34595d857 Remove some noise.
-Erik
2000-07-25 17:58:01 +00:00
Eric Andersen e5db406690 Clean up $1=$prefix
-Erik
2000-07-25 16:47:03 +00:00
Mark Whitley 40bfc76385 First revision of the Busybox Style Guide and an accompanying .indent.pro
file.
2000-07-24 22:36:06 +00:00
Pavel Roskin e99f7500e0 chroot can now call the builtin shell 2000-07-24 20:15:30 +00:00
Eric Andersen ea824fb937 Fixed stdin/stdout paths so things like
tar cvf - /etc/* | gzip -c9 >test.tgz
will now work.  Fix thanks to Dave Cinege <dcinege@psychosis.com>
with some adjustments by me to be mroe GNU-like.
 -Erik
2000-07-21 22:17:39 +00:00
Eric Andersen bf960f58e2 Added 'renice' command, thanks to Dave Cinege <dcinege@psychosis.com>
-Erik
2000-07-21 21:32:12 +00:00
Eric Andersen 7df345e149 Bump version number.
-Erik
2000-07-21 21:27:11 +00:00
Eric Andersen ec8d60f0f8 Add in the LinuxMagic VPN Firewall
-Erik
2000-07-21 17:22:19 +00:00
Pavel Roskin 0010ee45e3 Fixed usage info for "cut" 2000-07-21 15:10:57 +00:00
Mark Whitley c768ab490e Took -V out of the sed_usage string. 2000-07-20 23:54:42 +00:00
Eric Andersen ced2cefcca * syslogd can now log messages to a remote host -- patch thanks
to Gyepi Sam <gyepi@praxis-sw.com>
 -Erik
2000-07-20 23:41:24 +00:00
Mark Whitley 1f45b268cb As per a discussion on the mailing list between Matt and Pavel. I have removed
the -V (version) flag from busybox sed. It is unnecessary because sed is not a
standalone and should therefore be independently reporting a version number.
Moreover, it is extra code that we just don't need.
2000-07-20 23:08:40 +00:00
Mark Whitley 1ac435c15e Converted option parsing to getopt(). Also added some explanatory comments. 2000-07-20 23:06:27 +00:00
Eric Andersen 51154bacbe Adjusted install.sh to use relative symlinks, and to optionally
create hardlinks.  Added a makefile target to create hardlinks.
 -Erik
2000-07-20 21:57:11 +00:00
Mark Whitley 3950596e1e Converted option parsing to using getopt(). Also managed to remove an
extraneous logic loop that existed only for the purpose of the special case of
only one file. I replaced it with a variable to keep track of the number of
files read.
2000-07-20 00:08:10 +00:00
Mark Whitley 99e370f0c6 Whoops. Forgot to #include <getopt.h>. 2000-07-20 00:03:38 +00:00
Mark Whitley aa4f108338 Converted option parsing to getopt() and made some minor formatting changes. 2000-07-19 19:38:13 +00:00
Matt Kraai 27a804246a Centralize handling of --help. 2000-07-19 19:24:01 +00:00
Matt Kraai 869057238b Added some missing declarations and fixed some typos. I have to
remember to compile *before* committing.
2000-07-19 18:20:02 +00:00
Matt Kraai 2f46b664b7 Add usage messages for applets without them. 2000-07-19 18:01:00 +00:00
Eric Andersen 91a4400fd5 Avoid trying to free NULL ptrs. Comment on malloc usages.
-Erik
2000-07-19 17:37:57 +00:00
Eric Andersen a16c66335e Use FatalError()
-Erik
2000-07-19 17:36:27 +00:00
Eric Andersen ae6eae02dd Moved some code and add a coupld #defines to support use of dmalloc.
-Erik
2000-07-19 17:35:54 +00:00
Eric Andersen 52d6fa3bb3 Funny. Head was getting installed to the wrong spot.
-Erik
2000-07-19 17:34:40 +00:00
Eric Andersen 1d255be78d Updated to add support for dmalloc, and adjusted for better cross
compiler support.
 -Erik
2000-07-19 17:33:54 +00:00
Mark Whitley 2ef880b236 Consolodated some common code into print_matched_line to make 'grep_file' a
little more terse & clean. Also made a few minor formatting changes.
2000-07-18 21:02:06 +00:00
Eric Andersen a9d69fb568 Removed now incorrect message about NFS not working with
Linux 2.[34].x kernels.  It does work now,
 -Erik
2000-07-18 18:54:08 +00:00
Mark Whitley 8f122431f5 Added support for the -c (count matches) option. Made it so it works just like
GNU grep.
2000-07-18 18:37:01 +00:00
Eric Andersen 6efc48c1ae Sigh -- can't sleep. Clean up some mem leaks, fixed some bugs.
-Erik
2000-07-18 08:16:39 +00:00
Pavel Roskin 9c5fcc3408 New message added to messages.c: full_version
Used where possible
2000-07-17 23:45:12 +00:00
Pavel Roskin cc8a66b113 Moved functions used by "lsmod" from cat.c to utility.c
Adjusted to make lsmod and sh compilable as standalone apps.
Comment fixes
2000-07-17 20:18:42 +00:00
Mark Whitley 97562bd9d7 - Added support for backreferences in substitution expressions up to nine
(\1, \2...\9). This touched a lot of places in this file and I added a new
   function 'print_subst_w_backrefs' in order to keep 'do_subst_command' a
   little more tidy.

	* I tested this good 'n hard, but will always appreciate more testing from
	  other, willing folks.

 - Noticed that the index_of_next_unescaped_slash was subtly wrong so I
   changed both the functionality and behavior (it used to skip over the first
   char in the string you passed it, assuming it was a leading '/'--this
   assumption is no longer made) this necessitated changing the lines that
   call this function just slightly.
2000-07-17 20:06:42 +00:00
Pavel Roskin 21ddb38fcf Now it's possible to compile Busybox with only one app defined
(unless it's lsmod, to be fixed by the next commit)
2000-07-17 19:31:54 +00:00
Eric Andersen a1d187a8a8 Backtick support to infinite (memory limited) levels of nesting is
now implemented...  So now busybox shell can do cool stuff like:

    /home/andersen/CVS/busybox # echo foo `wc README` bar
    foo 71 422 2951 README bar

I love writing cool new features....  Muhahahaha...  (I think this is
leaking a little bit of memory every time it expands a backtick process,
so I still needs to do a bit of cleanup...)
 -Erik
2000-07-17 19:14:41 +00:00
Pavel Roskin bc0aed79a8 It is now possible to select in busybox.def.h whether minixfs version 2
is to be supported.
2000-07-17 17:52:00 +00:00
Pavel Roskin 47d4926244 The result of getopt() is "int" and should be treated as such 2000-07-17 16:17:19 +00:00
Matt Kraai bf181b9338 Extract usage information into a separate file. 2000-07-16 20:57:15 +00:00
Matt Kraai 3bd8bd89ee Don't use strings directly in calls to usage(). This is in preparation
for their extraction to a separate file.
2000-07-14 23:28:47 +00:00
Mark Whitley 464c5de00d Fixed a couple of buglets:
- add_cmd_str: segv's were being generated if there was a '# comment' line
   (and probably other kinds of lines, too) that was not followed by a
   semi-colon or whitespace
 - parse_edit_cmd: was returning a wrong number (too low) for the index; it
   was not accounting for backslashes eaten, for the fact that we start at the
   3rd index in the string, or for the fact that we add an extra newline.
 - parse_cmd_str: was returning a wrong number (again, too low) for the index
   in the case of single-letter commands (p,d). There was some
   over-compensation for this in the 'return' stmt at the end which also
   needed some help.
 - load_cmd_file: was not eating trailing newlines off the line read from the
   command file. This had the deleterious effect of printing an extra newlines
   after text displayed from edit (i,a,c) commands.
2000-07-14 23:24:00 +00:00
Mark Whitley 70705d7c96 - Added support for semicolon delimited command lines. (woo-hoo!)
- Obsoleted the trim_str function (#if 0'ed out -- maybedelete later) in
   favor of strrspn.
 - Obsoleted the strrspn function (#if 0'ed out as well) as soon as I
   discovered that it wasn't needed either.
 - Fixed a subtle bug in parse_subst_cmd where it would choke with an error if
   there was any trailing space after the s/match/replace/ expression.
2000-07-14 19:06:30 +00:00
Eric Andersen add09fd558 Getopt'ed by Marc Nijdam <marc_nijdam@hp.com>
-Erik
2000-07-14 18:39:08 +00:00
Eric Andersen 17ad45aace Getopt'rd by Marc Nijdam <marc_nijdam@hp.com>
-Erik
2000-07-14 18:38:26 +00:00
Pavel Roskin df4532bfa3 More fixes for "signed vs. unsigned" warnings. 2000-07-14 17:24:58 +00:00
Pavel Roskin ff5a9033f9 Reduced the number of "signed vs. unsigned" warnings.
Sometimes such warnings matter (esp. on PPC with char default to unsigned)
2000-07-14 16:23:32 +00:00
Pavel Roskin f626dcbc84 More fixes for "missing initializers" 2000-07-14 15:55:41 +00:00
Pavel Roskin 9027bcf2f4 Fixed a warning about missing initializer 2000-07-14 15:44:25 +00:00
Pavel Roskin 93c0d9f090 The result of getopt() should not be converted to "char" - it breaks on PPC 2000-07-14 15:18:57 +00:00
Eric Andersen fad04fdd12 More cleanups.
-Erik
2000-07-14 06:49:52 +00:00
Matt Kraai b870af09ae Fix argument parsing. 2000-07-14 06:47:33 +00:00
Eric Andersen d6912c97de Be more pedantic aboutthe terminating null applet.
-Erik
2000-07-14 06:29:10 +00:00
Eric Andersen 58361a44b5 uid and gid were unsigned, but were compared vs signed values (-1)
-Erik
2000-07-14 06:27:54 +00:00
Eric Andersen e7413a9cde A couple of minor warning cleanups.
-Erik
2000-07-14 06:19:41 +00:00
Matt Kraai d537a95fdb Use errorMsg rather than fprintf. 2000-07-14 01:51:25 +00:00
Eric Andersen 4ac6cb534d Fix some stupid memory bugs.
-Erik
2000-07-14 01:13:37 +00:00
Eric Andersen ec10b9d534 Add in redimentary backtick suport (doesn't work properly yet, but is
close).
 -Erik
2000-07-14 01:13:11 +00:00
Mark Whitley 34623db618 It dawned on me that I would need to grow a char buffer one extra char bigger
to accomodate a trailing '\n'ewline that I append to it later one. This is
only necessary for the case of one inserted, appended, or changed line, but
it's still necessary.
2000-07-14 00:49:59 +00:00
Mark Whitley 02008346c0 Added error checking for edit commands; only a beginning address can be
specified.
2000-07-14 00:13:52 +00:00
Mark Whitley 94074a980c Added support for (a)ppend, (i)nsert, and (c)hange commands to sed. 2000-07-14 00:00:15 +00:00
Mark Whitley 496e33feeb Fixed bug where sed '/foo/p' was printing "invalid command". 2000-07-13 22:52:02 +00:00
Mark Whitley 4f7fe77d07 (Something I should have done in the previous checkin...) Also broke out
substitution command execution from do_sed_command() and put it in it's own
do_subst_command() function.
2000-07-13 20:01:58 +00:00
Mark Whitley 06f3529ada Minor code reorg: Changed the interface to index_of_next_unescaped_slash to an
interface that seems a little more sensible to me. Also broke out s///
expression parsing into it's own subroutine.
2000-07-13 19:58:04 +00:00
Eric Andersen 156959ea93 Fix uninitialized variable.
-Erik
2000-07-13 19:49:12 +00:00
Eric Andersen f4c022649b Patch from Marc Nijdam <marc_nijdam@hp.com>
> First (of many more) patch of cp_mv to getopt use. I'm using the most
> simplistic approach, just get getopt used,  then worry about a cleaner
> option parsing style using getopt later.
>
> Marc
2000-07-13 18:42:58 +00:00
Mark Whitley 55380700d8 Added a smallish TODO comment. 2000-07-13 17:20:23 +00:00
Eric Andersen 00143ba921 From Matt Kraai <kraai@alumni.carnegiemellon.edu>
> Here is a patch so that tr can handle NULL characters as well.  Give it
> a shot and let me know what you think.  It is against the latest CVS
> version.
>
> In my tests, the following now works as expected.
>
> tr '\0' '\n'
>
> Later,
> Matt
2000-07-13 16:40:41 +00:00
Matt Kraai ac48461da9 Correct argument parsing and other minor cleanups. 2000-07-13 06:33:12 +00:00
Mark Whitley 37653aaf9c Added some smallish comments to help folks understand why we have two tables
of builtins and the reasoning behind it.
2000-07-12 23:36:17 +00:00
Mark Whitley c41e8c840f Changed bb_regcomp to xregcomp and #if 0'ed out destroy_cmd_strs in sed.c
(maybe I'll remove it later).
2000-07-12 23:35:21 +00:00
Eric Andersen 6f96e674b9 Patch from Jon McClintock <jonm@bluemug.com>
>The attached patch adds the ability to parse the actual mode specifier in
>fbset. So now
>
>    fbset -n 640x480-72
>
>Will actually work. I don't know if I've reinvented the wheel though...

 -Erik
2000-07-12 23:01:04 +00:00
Matt Kraai be84cd4ef6 Always report the applet name when doing error reporting. 2000-07-12 17:02:35 +00:00
Matt Kraai e58771e73c Use global applet_name instead of local versions. 2000-07-12 15:38:49 +00:00
Matt Kraai e714bce003 Use global applet_name instead of local versions. 2000-07-12 00:53:06 +00:00
Matt Kraai 3ecbe9f4dc The applet name isn't constant. 2000-07-12 00:43:28 +00:00
Eric Andersen 97426e082a Changed verbiage.
-Erik
2000-07-11 23:06:48 +00:00
Eric Andersen 8fbaeece53 Replaced projects with products/projects.
-Erik
2000-07-11 23:05:38 +00:00
Eric Andersen 68fda241d2 Added the Kerbango Internet Radio to projects/products using BusyBox.
-Erik
2000-07-11 23:03:40 +00:00
Mark Whitley 858c1adf2b Applied patch from Matt Kraai to call destroy_cmd_strs in atexit(), rather
than peppering it throughout the code.
2000-07-11 21:38:47 +00:00
Matt Kraai 7719008a85 Added applet_name to contain the applet name. 2000-07-11 20:03:24 +00:00
Eric Andersen aec27bca98 Final updates for release.
-Erik
2000-07-11 18:18:40 +00:00
Eric Andersen 960be79964 Final update for the release. 2000-07-11 18:06:01 +00:00
Eric Andersen be909b1cd5 Forgot to commit these cleanups it seems.
-Erik
2000-07-11 17:52:22 +00:00
Eric Andersen d006c9e630 More changelog updates
-Erik
2000-07-11 17:45:42 +00:00
Mark Whitley 9ebccb2891 Added changelog entries for grep/sed/regex changes. 2000-07-11 17:43:42 +00:00
Eric Andersen f1f6d58598 Some changelog updates.
-Erik
2000-07-11 17:42:56 +00:00
Eric Andersen 0c838af50b Re-enable ln -n in the help.
-Erik
2000-07-11 17:38:27 +00:00
Eric Andersen 195fa15caf Another patch from Matt Kraai <kraai@alumni.carnegiemellon.edu>:
>
> The following patch allows ln -n to function like GNU.  It also fixes a
> typo with my previous patch to add support for ln FILE DIRECTORY.  And
> it removes some code that checks the maximum length of the filenames.  I
> can't figure out why that code is necessary.  Anyone know?
>
> Matt
2000-07-11 17:35:32 +00:00
Eric Andersen 61dc057183 Added 'dumpkmap' to allow people to dump a binary keymap, which can then be
loaded in by 'loadkmap' -- submitted by Arne Bernin <arne@matrix.loopback.org>
 -Erik
2000-07-11 17:29:36 +00:00
Mark Whitley df5f6ba115 Applied patch from Matt Kraai which does the following:
- adds case-insensitive matching in sed s/// epxressions
 - consolodates common regcomp code in grep & sed into bb_regcomp and put in
   utility.c
 - cleans up a bunch of cruft
2000-07-11 16:53:56 +00:00
Matt Kraai da9841efc1 Fix dead link.
-Matt
2000-07-11 16:09:01 +00:00
Eric Andersen da1d1e763d Fixed NFS so it supports 2.4.x kernels and NFSv3. Should close bug #1009.
-Erik
2000-07-10 23:39:44 +00:00
Mark Whitley cc54d12ef7 Removed all trace of hand-tooled regexp routines. Bye bye, baby. 2000-07-10 23:07:54 +00:00
Mark Whitley dd23b8bb43 Added a rule to make tags files for vi(m). 2000-07-10 23:00:47 +00:00
Eric Andersen c674d70699 Comment on kernel stuff
-Erik
2000-07-10 22:57:14 +00:00
Mark Whitley 6315ce603b Brand, new sed that uses libc regex routines.
There is some common code used by both sed & grep that should be put into
utility.c as per Mat Kraai's suggestions/patch on the mailing list.
Specifically, a common regex_compile() and a regex_subst() function need to be
made.
2000-07-10 22:55:51 +00:00
Eric Andersen 85c552035e More linux kernel header file removal.
-Erik
2000-07-10 22:46:55 +00:00
Eric Andersen 9b2297a34e Remove yet more kernel header dependancies.
-Erik
2000-07-10 20:08:44 +00:00
Eric Andersen a0053735dc Remove unused variable.
-Erik
2000-07-10 20:08:09 +00:00
Eric Andersen 3849f9bfcc Remove the problematic CTRLCHAR macro.
-Erik
2000-07-10 19:56:47 +00:00
Mark Whitley 9a8243aa1e Put the GROWBY variable inside the get_line_from_file function, as that is the
only function where it's used and it's always good to keep the namespace
clean. :-)
2000-07-10 19:31:31 +00:00
Mark Whitley 928faac503 Removed unnecessary #include "regexp.h" line from find.c as per Matt Kraai's
suggestion on the mailing list.
2000-07-10 19:29:09 +00:00
Eric Andersen 34e1941c32 Function name cleanup.
-Erik
2000-07-10 18:47:24 +00:00
Eric Andersen 0b4551faf5 From Matt Kraai <kraai@alumni.carnegiemellon.edu>:
Howdy,

Bug #1006 reports that

ln -s /tmp/foo .

does not work correctly.  In fact, it appears that any instantiation of

ln -s FILE... DIRECTORY

does not work.  The following patch adds support for this form, which
then fixes the particular instance noted in the bug report.

In the process, I needed the basename function.  This appears in the
string.h provided by glibc, but not uC-libc.  So I wrote my own to go in
utility.c, called get_last_path_component.  I also modified the basename
utility to use this function.

At some point it might be desirous to use the basename from the library
if it exists, and otherwise compile our own.  But I don't know how to do
this.

Matt
2000-07-10 16:44:03 +00:00
Eric Andersen a03d86cf54 Patch from Matt Kraai <kraai@alumni.carnegiemellon.edu>:
GNU tr complains on the following:

$ tr a ''
tr: when not truncating set1, string2 must be non-empty

BusyBox tr does not complain:

$ tr a ''
a
^D
0

It should result in an error, not in some spurious output.  The attached
patch generates an error.

Matt
2000-07-10 16:38:50 +00:00
Mark Whitley 44735f8744 Applied patch from Matt Kraai as per his email:
However, the case of

	grep foo$ file

didn't work, due to a problem with the flags used in regular expression
compilation.  The attached patch fixes this problem.

---patch-------
Index: grep.c
===================================================================
RCS file: /var/cvs/busybox/grep.c,v
retrieving revision 1.30
diff -u -r1.30 grep.c
--- grep.c      2000/07/04 22:17:01     1.30
+++ grep.c      2000/07/10 08:57:04
@@ -141,8 +141,10 @@
        if (argv[optind] == NULL)
                usage(grep_usage);

-       /* compile the regular expression */
-       reflags = REG_NOSUB; /* we're not going to mess with sub-expressions
        */
+       /* compile the regular expression
+        * we're not going to mess with sub-expressions, and we need to
+        * treat newlines right. */
+       reflags = REG_NOSUB | REG_NEWLINE;
        if (ignore_case)
                reflags |= REG_ICASE;
        if ((ret = regcomp(&regex, argv[optind], reflags)) != 0) {
---patch-------

Thanks, Matt, it works great.
2000-07-10 15:50:26 +00:00
Eric Andersen 999bf72f49 More portability updates. Now compiles cleanly vs glibc, libc5, and uclibc
(except for mkfs_minix and fsck_minix -- and it doesn't yet link vs uclibc due
to missing stuff in the library).
 -Erik
2000-07-09 06:59:58 +00:00
Eric Andersen e9b527ae48 include getopt.h
-Erik
2000-07-09 05:56:14 +00:00
Eric Andersen 161cf93404 Fix a bug in get_line_from_file. If the length of the line is (GROWBY * n) +
GROWBY - 1, then it writes the null character just after the buffer.  Yipe.
Fix thanks to Matt Kraai <kraai@alumni.carnegiemellon.edu> Thanks Matt!
 -Erik
2000-07-09 02:38:01 +00:00
Eric Andersen f12724c21a The build depends were too strict. I depended on on debhelper (>= 2.0.80)
while debhelper 1.1.24 is available for slink.  Just forget the dependancy --
it isn't needed.
 -Erik
2000-07-09 01:54:33 +00:00
Eric Andersen a57ba4db64 Argh. More cross libc cleanup. Should be ok now...
-Erik
2000-07-08 19:20:49 +00:00
Eric Andersen 2cd439f7f0 More cleanup on umount
-Erik
2000-07-08 19:10:29 +00:00
Eric Andersen bd22ed8067 Update files to reduce dependance on kernel version...
-Erik
2000-07-08 18:55:24 +00:00
Eric Andersen 877a71bbf0 Add in tinynet
-Erik
2000-07-08 16:19:10 +00:00
Eric Andersen 9cf44e79aa Doc updates to remove sfdisk.
-Erik
2000-07-08 00:09:30 +00:00
Eric Andersen 8f282f1b02 Better description of the BB_FEATURE_USE_DEVPS_PATCH option.
-Erik
2000-07-07 23:51:37 +00:00
Eric Andersen acecc47261 Add in my fix for 2.4.x kernels so /proc/mounts will not have useless
deg entries which break mount, df, and friends.  Renamed WillThisGoIntoTheKernel
to avoid any confision.
 -Erik
2000-07-07 21:22:19 +00:00
Eric Andersen e6b9dfa967 Removed sfdisk from BusyBox. It was buggy, fat, and we really couldn't
maintain it very well, so including it was not very appropriate.  Those wanting
an fdisk are invited to grab a copy from util-linux.
 -Erik
2000-07-07 20:54:30 +00:00
Eric Andersen 53a955786d Added in Matt Kraai.
-Erik
2000-07-07 20:53:16 +00:00
Eric Andersen a2c83d885e Fix a dependancy bug for the docs.
-Erik
2000-07-07 20:52:56 +00:00
Eric Andersen 03f9c81cec Naming fix
-Erik
2000-07-07 20:37:12 +00:00
Eric Andersen bb374a6935 Recognize Matt's poweroff fix.
-Erik
2000-07-07 19:33:35 +00:00
Eric Andersen 4c95a28461 Fix for bug #1003 -- BusyBox should now poweroff when asked to
do so...  Fix thanks to Matt Kraai <kraai@alumni.carnegiemellon.edu>
 -Erik
2000-07-07 19:30:28 +00:00
Eric Andersen 3312b0b626 Web page update from Matt Kraai <kraai@alumni.carnegiemellon.edu>
-Erik
2000-07-07 19:23:10 +00:00
Eric Andersen 2158092344 This patch finishes the cleanup of all the commands. It also cleans up
the remaining chapters -- Matt Kraai <kraai@alumni.carnegiemellon.edu>
 -Erik
2000-07-07 19:07:47 +00:00
Eric Andersen b9eb0233a9 Yet another busybox documentation update from Matt Kraai <kraai@alumni.carnegiemellon.edu>
-Erik
2000-07-07 05:04:24 +00:00
Eric Andersen b0b732bfe4 Update 'make release' to remove all the .#filename files
the CVS leaves lying about...
 -Erik
2000-07-06 23:17:16 +00:00
Eric Andersen 03f4c27bd6 Turned some stuff into features that really are features, not apps.
-Erik
2000-07-06 23:10:29 +00:00
Eric Andersen 67536ffa43 Fix doc building so the dependancies work properly.
-Erik
2000-07-06 22:53:22 +00:00
Eric Andersen 8845adc545 * Fixed tar creation support when reading from stdin ('tar -cf - . ')
thanks to Daniel Quinlan <quinlan@transmeta.com>
 -Erik
2000-07-06 22:51:35 +00:00
Eric Andersen 02bc25be56 Fixed backspace and delete so they work properly again -- broken
since 0.44.
 -Erik
2000-07-06 21:29:32 +00:00
Eric Andersen e5cec4e3ac More doc patches from Matt Kraai <kraai@alumni.carnegiemellon.edu>.
Thanks Matt!
 -Erik
2000-07-06 19:59:22 +00:00
Eric Andersen 62bb2d02b6 Remove leftovers of block_device, which disapperared around
busybox 0.28.
 -Erik
2000-07-06 19:46:22 +00:00
Eric Andersen a5dbb39dac Change order.
-Erik
2000-07-06 19:11:34 +00:00
Eric Andersen c8c10c5715 Added (fixed) the '-n' option to fbset. Renumbered the command parameters to
put a gap between the normal commands and the fancy commands. This makes it
cleaner to add normal commands.  Patch from Jon McClintock <jonm@bluemug.com>.
 -Erik
2000-07-06 17:23:23 +00:00
Eric Andersen f86aee74ce setkeycodes needs get_console_fd(), so if you disable chvt and deallocvt, but
leave setkeycodes active, busybox will not link.  Also fix a trivial
use-before-initialize warning.  Both fixes from Jon McClintock
<jonm@bluemug.com>.

 -Erik
2000-07-06 17:20:46 +00:00
Eric Andersen b1e379f7f3 Remove some warning with glibc.
-Erik
2000-07-06 17:08:38 +00:00
Eric Andersen 78eab2f6c6 Comment on kill.c change.
-Erik
2000-07-06 17:06:08 +00:00
Eric Andersen 3cfa9ec09c Reorganized signal names for better architecture support -- patch
thanks to simon wood <simon@mungewell.uklinux.net>
 -Erik
2000-07-06 17:05:33 +00:00
Eric Andersen 6f5e281479 DocBook documentation update from Matt Kraai <kraai@alumni.carnegiemellon.edu>
-Erik
2000-07-06 16:58:45 +00:00
Eric Andersen b2731b11ef Had an extra tcsetpgrp.
-Erik
2000-07-06 16:56:56 +00:00
Eric Andersen 1e03add675 a few minor cleanups.
-Erik
2000-07-06 09:56:35 +00:00
Eric Andersen 5d893b6beb Remove MAXNAMLEN and use BUFSIZ instead.
-Erik
2000-07-06 01:57:20 +00:00
Eric Andersen 89bc256c94 Remove misguided klude around for 2.4.x-test* brokenness. Al Viro
will be removing this stuff from /proc/mounts real soon now I am assured.
 -Erik
2000-07-05 19:29:59 +00:00
Eric Andersen f7cf2f7ef9 * Fix to tr so it recognizes standard escape sequences. Merged common
escape seq. code from tr and echo into utility.c.  Fix thanks to
    Matt Kraai <kraai@alumni.carnegiemellon.edu>.
* This should close Bug #1015.  Please test.
 -Erik
2000-07-05 17:26:35 +00:00
Eric Andersen 57ebebfb01 Patch from Matt Kraai <kraai@alumni.carnegiemellon.edu> to
simplify ar.c and make it more readable.
 -Erik
2000-07-05 17:21:58 +00:00
Eric Andersen 2086e3d679 Some cosmetic updates. Changed "OPTIONS" to "Options".
-Erik
2000-07-04 22:17:01 +00:00
Eric Andersen 028fb625f5 More doc updates
-Erik
2000-07-04 20:07:13 +00:00
Eric Andersen 5331025f79 A first pass at integrating the SGML docs into the Makefile.
A first pass a cleaning up the current SGML (lots more cleanup
is needed though).
 -Erik
2000-07-04 19:42:23 +00:00
Eric Andersen b02c54ebee * Fix to init.c from Stuart Menefy <Stuart.Menefy@st.com> so that
it always sets the controlling terminal before running any programs
 -Erik
2000-07-04 19:41:23 +00:00
Eric Andersen 72965e3454 Fixed a potential infinite loop. First delete any chars after the
cursor, then delete everything before it.  Before this, we would just
delete everything before the cursor and freak out if there were still
chars left (i.e. stuff after the cursor).
 -Erik
2000-07-04 06:22:18 +00:00
Eric Andersen b54833cde0 sh fixes from Marius Groeger <mag@sysgo.de>
-Erik
2000-07-03 23:56:26 +00:00
Eric Andersen 7c31ea4e29 Added support for ignoring '-g' per GNU ls, thanks to David Vrabel
<dvrabel@arcom.co.uk>.  Seems some ftp clients expect the '-g' option
to exist.
 -Erik
2000-07-03 14:55:49 +00:00
Eric Andersen 5d41d60f1e Added support for being a login shell, so things like '-su' or '-sh' (stuff
where argv[0][0]=='-') will now always invoke the shell.  Now you can use
BusyBox as a login shell.
 -Erik
2000-06-29 20:20:14 +00:00
Mark Whitley 2e1148b239 Fixed comment. 2000-06-28 22:59:30 +00:00
Mark Whitley 8bd891cbec Added support for reading from stdin with '-' as file name arg. 2000-06-28 22:55:59 +00:00
Mark Whitley 1ca41775bb Yanked out the cstring_alloc() and cstring_lineFromFile() functions from
utility.c and replaced them with get_line_from_file() from the new grep.c.
Also changed declaration in internal.h and replaced instances of
cstring_lineFromFile() in dc.c and sort.c with get_line_from_file(). Tested
them and they worked fine.
2000-06-28 22:15:26 +00:00
Mark Whitley d37218941c Brand, spankin', new grep that uses libc regex routines instead of the
hand-rolled ones. Sed still needs to be replaced and then the regexp stuff can
be axed.
2000-06-28 22:00:26 +00:00
Mark Whitley 268b8c4f38 Moved some function decls, a struct, and a #define from regexp.h into here.
Also static-ified said functions so they do not have namespace conflicts with
the libc regex functions.
2000-06-28 21:59:31 +00:00
Mark Whitley 0c96eba3de Removed some function decls (regex, regcomp, etc.) and put them in regexp.c 2000-06-28 21:58:31 +00:00
Eric Andersen a44790f539 Better cross libc support.
-Erik
2000-06-28 20:11:28 +00:00
Eric Andersen a2db097d66 Forgot -- targeted the wrong release.
-Erik
2000-06-28 17:07:19 +00:00
Eric Andersen 1c314ad655 * Fixed a _horrible_ bug where 'tar -tvf' could unlink
local files!!!  Fix thanks to Marius Groeger <mgroeger@sysgo.de>
* Added support for "sh -c command args...", also thanks to
    Marius Groeger <mgroeger@sysgo.de>

 -Erik
2000-06-28 16:56:25 +00:00
Eric Andersen 47cac6779a Updates for the .deb
-Erik
2000-06-28 02:25:18 +00:00
John Beppu eb0283333b = minor formatting issues 2000-06-28 00:55:31 +00:00
John Beppu 7cdc76dfbf + busybox --install [-s]
is functional (but disabled in busybox.def.h by default)
  Someone email the guy who originally wanted this.
2000-06-28 00:41:26 +00:00
Eric Andersen d0edef3cbe Remove stuff now moved into the bug tracking system.
-Erik
2000-06-27 18:12:19 +00:00
John Beppu 495869f59a + s/int install_links/static int install_links/
? Did you want "busybox --install" or "busybox install" ?
  The TODO and mailing-list conflict on this issue.
  I would recommend against "busybox install", because
  people might confuse it w/ /usr/bin/install that does
  something different.
2000-06-27 07:54:33 +00:00
Eric Andersen cb1d841f09 This kernel patch is no longer needed, with the change I made to init
and free...
 -Erik
2000-06-27 06:22:09 +00:00
John Beppu 27b5924b96 + littering my code w/ comments about what troubles me. 2000-06-27 04:56:45 +00:00
John Beppu 8f425dbf9a + busybox --install [-s]
is almost good to go.  Here is my work in progress.

+ Look at the FIXME in busybox.c
  to see what I need.  The actual (sym)linking is disabled
  for now, although I'm sure it works ;)
  (Am I going to have to dig through /proc to find
  out where the currently running busybox is sitting?)

+ I put an #ifdef BB_FEATURE_INSTALLER around
  the new bits of code in busybox.c, and I have a
  #define BB_FEATURE_INSTALLER in busybox.def.h
  towards the bottom.
2000-06-27 04:50:02 +00:00
Mark Whitley 83a949cb22 Just converted busybox.pod to busybox.sgml using the Pod::DocBook Perl module.
The resulting file needs some massaging and once it gets presentable, I'll
edit the Makefile to use the SGML file as the "authoritative" file; the plan
here is to generate other file formats from the SGML.
2000-06-26 13:31:53 +00:00
Eric Andersen 1386e70210 Fixed segfault with 'cut -f 1 -d:' and added 'cut -s' suport.
Fix thanks to Arne Bernin <arne@matrix.loopback.org>
 -Erik
2000-06-26 12:14:30 +00:00
Eric Andersen ef40aa81c5 * Fixed insmod module option parsing for options lacking an '='.
Fix thanks to Marc Nijdam <marc_nijdam@hp.com>
 -Erik
2000-06-26 11:16:22 +00:00
Eric Andersen 3adffb7fc8 readlink(2) does not NULL terminate the buffer it reads in, but tar expected it
to do so.  This caused symlinks stored in tarballs to likely have trailing
crap in the stored symlink named.  Oops.
 -Erik
2000-06-26 10:54:06 +00:00
Eric Andersen 10dc9d4d17 Updates to handle Linux 2.4.0 kernels (kludged around the "none" entries in
/proc/mounts, added a hack to make sysinfo work with both old and new kernels).
 -Erik
2000-06-26 10:45:52 +00:00
Eric Andersen 8a24a6783a Better error checking in insmod. Remove left over %m's
-Erik
2000-06-22 18:19:31 +00:00
Eric Andersen 4a971aef59 Minor web page update.
-Erik
2000-06-22 01:27:11 +00:00
Eric Andersen 3c37598dc2 Fix version #
-Erik
2000-06-22 00:23:09 +00:00
Eric Andersen a29dec28cb More doc updates
-Erik
2000-06-22 00:19:33 +00:00
Mark Whitley ccd32cbb61 Merged two TODO items into one 2000-06-22 00:16:37 +00:00
Eric Andersen 9d9610b8de Update the list.
-Erik
2000-06-22 00:04:12 +00:00
Eric Andersen 6f9985e2f2 Pavel Roskin <proski@gnu.org> just found a nasty memory
corruption bug.  Disabling 'ln -n' till it is fixed.
 -Erik
2000-06-22 00:02:56 +00:00
Eric Andersen addc9c28ad Document 'ln --'
-Erik
2000-06-21 22:53:24 +00:00
Mark Whitley 4fa84e6b54 Cleaned up some #ifdef spiderwebs. 2000-06-21 22:53:16 +00:00
Eric Andersen c6cdf58747 Bump version number to 0.45
-Erik
2000-06-21 22:50:59 +00:00
Mark Whitley 07edff4ba4 Added an implicit rule for #defining BB_FEATURE_USE_TERMIOS if
BB_FEATURE_AUTOWIDTH is #defined.
2000-06-21 22:46:32 +00:00
Eric Andersen 45087b1010 More doc updates.
-Erik
2000-06-21 22:44:33 +00:00
Eric Andersen 766c012975 Web site updates.
-Erik
2000-06-21 22:43:07 +00:00
Eric Andersen c5c5e3d144 Add in my little patch for 2.4.x to make sysinfo binary compatable (again)
-Erik
2000-06-21 22:06:56 +00:00
Pavel Roskin afa0662860 Documented "which" 2000-06-21 21:43:24 +00:00
Pavel Roskin 1a804e4b3c Removed trailing spaces 2000-06-21 21:38:00 +00:00
Eric Andersen f929641c51 Add in telnet docs.
-Erik
2000-06-21 21:04:01 +00:00
Eric Andersen feb47c024a Add insmod docs
-Erik
2000-06-21 21:03:13 +00:00
Pavel Roskin f7a01951fb Updated the list of supported commands 2000-06-21 20:25:07 +00:00
Pavel Roskin 7ac06a3ff1 Removed all vestiges of "math" 2000-06-21 20:17:29 +00:00
John Beppu 0021679b0d + added dc (aka the function formerly known as math)
+ did all the housekeeping that this change requires.
2000-06-21 19:06:16 +00:00
Eric Andersen b405dfa54d 'tar --help' wasn't working. Fixed it.
-Erik
2000-06-21 18:37:36 +00:00
John Beppu c03525475e + made it so that you can use the mnemonics
(add, sub, mul, div) in lieu of (+, -, *, /)
2000-06-21 18:00:46 +00:00
Eric Andersen e63ad9ba06 Special case the memcopy stuff so it isn't enabled for uclibc
-Erik
2000-06-20 21:04:03 +00:00
Eric Andersen 28c88a9430 Some makefile fixes to allow compiling with ucLibc (stuff turned off
by default of course).
 -Erik
2000-06-20 21:03:24 +00:00
Pavel Roskin 339b892313 Updated e-mail address of Pavel Roskin to proski@gnu.org 2000-06-20 00:11:07 +00:00
Eric Andersen 4eb1b30411 Mention libc support, Pavel's rm fix is already merged.
-Erik
2000-06-19 20:19:04 +00:00
Eric Andersen bd4a75f6c8 Finish off the libc5 porting effort. Everything now works with libc5
except for md5sum, which uses the GNU libc addition getline().
 -Erik
2000-06-19 20:03:48 +00:00
Eric Andersen bb245ba0c2 Made insmod work with both libc5 and libc6.
-Erik
2000-06-19 19:53:30 +00:00
Eric Andersen 9ca57d377e Made ping work with libc5 and libc6.
-Erik
2000-06-19 18:51:53 +00:00
Eric Andersen e1e23eecab Make umount work and compile cleanly under libc5 and libc6.
-Erik
2000-06-19 18:38:51 +00:00
Eric Andersen 5e29c6ffce Make swaponoff compile cleanly under both libc5 and libc6.
-Erik
2000-06-19 18:25:49 +00:00
Eric Andersen a15cd0be34 Make syslogd.c, init.c, and update.c compile error/warning free under both libc5 and libc6.
-Erik
2000-06-19 18:14:20 +00:00
Eric Andersen b7362e36a8 printf now compiles cleanly under both libc5 and libc6.
-Erik
2000-06-19 17:52:17 +00:00
Eric Andersen 67e32304b1 Updated to compile and work with libc5.
-Erik
2000-06-19 17:48:02 +00:00
Eric Andersen be5023a84d Update internal.h to conditionally include asm/string.h
-Erik
2000-06-19 17:30:07 +00:00
Eric Andersen b610615be9 Updates to a number of apps to remove warnings/compile errors under libc5.
Tested under both libc5 and libc6 and all seems well with these fixes.
 -Erik
2000-06-19 17:25:40 +00:00
Mark Whitley dbb3019d0d Added a note to the "maybe by 0.44" list to prune sfdisk and graft fdisk. 2000-06-19 17:03:32 +00:00
Eric Andersen 30f0f2d040 Fix a stupid bug, where I cleaned things as the last makefile target. duh.
-Erik
2000-06-19 09:29:32 +00:00
Eric Andersen b108a5b780 Added support for building debian packages.
-Erik
2000-06-19 09:21:34 +00:00
Pavel Roskin 110fc0cacc Check for 3 and more arguments was incorrect
It is only allowed for linking to a directory
But linking to a directory still fails and may be removed
2000-06-18 00:02:24 +00:00
Eric Andersen 74c66ad06e Fix some spelling errors in the source as well.
-Erik
2000-06-16 19:57:44 +00:00
Eric Andersen 98cd53e86d Ran it through a spell checker and fixed the spelling errors.
-Erik
2000-06-16 19:56:44 +00:00
Eric Andersen 852ff13fc4 Update to ar.c from Glenn McGrath. His comments follow:
------------------------------

the attached diff applies to the ar.c i originally submitted

Changes

Preserve dates now works.
Extracted files are set to the uid, gid and mode specified in the
archive.
Checks for valid end of header marker.
Correctly unpacks newer debian files. (has a '\n' character between
entries)
Added more comments.
Cleaned up code.
Added a last modified date to help keep track of versions.


TODO

Common functionality in ar.c are in tar.c should be merged, in
particular getOctal and extractSubFile.

Should all functions that are used by multiple file go in utilities.c ?
2000-06-16 04:56:40 +00:00
Mark Whitley b991395405 Added some comments and changed a variable name to be more meaningful. No
fixes yet for the space bug, but should be coming soon.
2000-06-16 00:26:51 +00:00
Pavel Roskin 2e965239ee ln: fixed command line parser. Added support for "--" 2000-06-15 18:04:40 +00:00
Eric Andersen 3f75503fa0 Remove trailing space char.
-Erik
2000-06-14 22:16:59 +00:00
Eric Andersen 28c70b3a16 Integrate Tomi Ollila's telnet. Costs 3k. :)
-Erik
2000-06-14 20:42:57 +00:00
Pavel Roskin e97da40079 Fixed "rm foo" that had been broken while implementing "rm -- foo" 2000-06-14 17:39:41 +00:00
Mark Whitley 1af7ed5573 Modified status of some TODO items, added some others in preparation for the
0.44 release.
2000-06-14 17:35:54 +00:00
John Beppu 3c709b45b3 + minor typo fix
s/&gt/&gt;/
2000-06-14 09:11:05 +00:00
John Beppu d84990eb1f + removed some cruft left over from when lines could be too long. 2000-06-14 00:19:14 +00:00
Eric Andersen 854e11581f Urgh. revert Makefile. again. Forgot to do the 'cvs update -d now' trick
on my home box.
2000-06-13 06:57:56 +00:00
Eric Andersen 2b6ab3cbf8 Add new apps md5sum uudecode uuencode, fix some minor formatting things.
-Erik
2000-06-13 06:54:53 +00:00
Eric Andersen 053b1462b7 Fix a bug pointed out by Michal Jaegermann <michal@ellpspace.math.ualberta.ca>
where you used to see:
      ./grep -q -i B some_file
      B: No such file or directory
This is now fixed.
 -Erik
2000-06-13 06:24:53 +00:00
Eric Andersen baf22bff21 Give beppu credit for fixing grep "Line too long" bug.
-Erik
2000-06-13 00:49:41 +00:00
John Beppu c7ccfc99fc + utility.c
CSTRING_BUFFER_LENGTH = 1024 /* so it recurses less often */
+ grep.c
  uses cstring_lineFromFile(), and doesn't ever say
  Line is too long, anymore
2000-06-12 23:39:04 +00:00
Eric Andersen 9f16d61408 Added a slightly modified version of Ron Alder's insmod patch.
Very cool stuff.
 -Erik
2000-06-12 23:11:16 +00:00
John Beppu 44760d058c + updated docs to reflect math's filter capabilities. 2000-06-12 23:04:55 +00:00
John Beppu 5db60a7a7a + works as a filter, now!
- I have a feeling I could have used strtok, but the
  2 functions I added are really small, so it shouldn't
  be a big deal.  (They were just laying around, and I
  wanted to use them, again).
2000-06-12 22:59:12 +00:00
Eric Andersen 0c6a970eb2 * Fixed a small bug that could cause tar to emit warning messages
and not extract the first file in a directory in some cases
    of nested directories.  Thanks to Kevin Traas <kevin@netmaster.com>
    for helping track this one down.
 -Erik
2000-06-09 20:51:50 +00:00
Pavel Roskin b3d235f63b Fixed parsing of arguments for cp 2000-06-08 18:06:37 +00:00
Eric Andersen b3cf9baeb9 Formatting change.
-Erik
2000-06-08 15:25:39 +00:00
Pavel Roskin 049b706591 My pod2man (perl-5.00503) complains if there is no newline after "Options:" 2000-06-07 21:19:49 +00:00
Pavel Roskin da10ec0eaa Syslogd will not go to background if "-n" is given. Better help
and argument checking
2000-06-07 21:08:25 +00:00
Pavel Roskin 0024abcbbc Implemented "ping -s", fixed error messages and argument parsing 2000-06-07 20:38:15 +00:00
Eric Andersen 0b66577368 Debug should be off in the Makefile. I will now do (per Pavel's
suggestion) a "cvs up -D now Makefile" so I stop updating the
Makefile by accident.
 -Erik
2000-06-07 17:33:30 +00:00
Eric Andersen a42982e8f5 * Fixed 'swapon -a' and 'swapoff -a', which were broken.
* Fixed 'mount -a' so it works as expected.
* Implemented 'ls -R' (enabled by enabling BB_FEATURE_LS_RECURSIVE)
 -Erik
2000-06-07 17:28:53 +00:00
Eric Andersen 1f6262b8e2 Fix 'date -u'
-Erik
2000-06-06 22:17:43 +00:00
Eric Andersen fb8ba506bb Oops. Remove the debugging noise.
-Erik
2000-06-06 22:13:39 +00:00
Eric Andersen 3232203226 mkfs.minix rev 1.7 completely broke the option parser. This fixes it.
-Erik
2000-06-06 22:12:35 +00:00
Mark Whitley d05e3ce5c2 Removed chmod,chown,chgrp from the "Bugs that need fixing" list. 2000-06-06 18:12:47 +00:00
Mark Whitley eec2f63b3f Fixed segfaults for "chown -R" and "chgrp -R". Also added a message for "too
few arguments".
2000-06-06 18:11:46 +00:00
Pavel Roskin 700a5aed75 Fixed exit status for killall 2000-06-06 18:10:17 +00:00
Mark Whitley 517cab761f Added considering making a unified option parser someday. 2000-06-06 18:05:47 +00:00
Mark Whitley 6ca28ba65c Fixed segfault when you type "chmod -R". "chown -R" and "chgrp -R" are still
having problems...
2000-06-06 17:40:32 +00:00
Pavel Roskin 680d65a646 "mount" now reports errors from nfsmount() and assumes NFS mount
if ':' is present in the device name - Pavel Roskin
2000-06-06 17:03:55 +00:00
Mark Whitley 68480dc30f Updated TODO item re: 'cp -a /tmp/*' not producing the right error message
(it's been fixed).
2000-06-06 17:03:54 +00:00
Eric Andersen 815e904470 Fixed a bunch of stuff:
* Fixed segfault caused by "touch -c"
	* Fixed segfault caused by "rm -f"
	* Fixed segfault caused by "ln -s -s" and similar abuses.
	* Fixed segfault caused by "cp -a -a" and similar abuses.
	* Implemented "rm -- <foo>"
updated docs accordingly.
 -Erik
2000-06-06 16:15:23 +00:00
Pavel Roskin c389d91181 "which" rewritten to use stat(). Fixes to improve its compatability
with traditional implementations
2000-06-05 23:41:27 +00:00
Pavel Roskin 82c0ac7e4f Fix more spelling errors. 2000-06-05 20:19:47 +00:00
Eric Andersen f2fffefe49 Fix spelling error
-Erik
2000-06-05 17:23:06 +00:00
Eric Andersen 36fe1a30b1 Fix spelling errors.
-Erik
2000-06-05 17:22:37 +00:00
Eric Andersen 926e0e3465 More TODO items. Fix a dependancy bug on busybox.def.h
-Erik
2000-06-05 05:33:00 +00:00
Eric Andersen afeb683459 "nc" exits silently on errors. This patch makes it print something before
exit().

Note that calling perror() after gethostbyname() will most likely return
"No such file or directory" which is quite confusing, so I decided to use
fatalError instead.

Regards,
Pavel Roskin
2000-06-04 05:21:49 +00:00
Eric Andersen 46a38dbb9b Don't allow mkfifo to create files such as "--help"
This patch checks if the name of FIFO to be created begins with "-" and
calls usage() if it does.

Regards,
Pavel Roskin
2000-06-04 05:17:35 +00:00
Eric Andersen ef4268efa7 This patch
- eliminates the need to have a buffer and strcpy to it
- makes freeramdisk complain if it's given more than one argument

Regards,
Pavel Roskin
2000-06-04 05:08:29 +00:00
Eric Andersen 832000f7f3 Turn off debugging in the Makefile.
-Erik
2000-06-03 05:22:31 +00:00
Eric Andersen f0c30b71be Note that I broke mkfs_minix's parser in rev 1.7.
-Erik
2000-06-03 00:27:00 +00:00
Eric Andersen 5a0a2aa00b Fix touch so it behaves itself (it could segfault in some cases).
Fix uname help info formatting.
 -Erik
2000-06-02 23:26:44 +00:00
Eric Andersen 808d03ec19 This is a fix for chroot
- Fixed error message when the command is not specified (possibly crash on
libc5 systems!)
- Debugging output removed
- Using fatalError() whenever appropriate

Regards,
Pavel Roskin
2000-06-02 17:56:45 +00:00
Eric Andersen 9c8ffa02f4 Pavel fixed a segfault in yes.
-Erik
2000-06-02 17:51:39 +00:00
Eric Andersen 3199bda52e Fix /etc/passwd misspelling.
-Erik
2000-06-02 17:38:18 +00:00
Eric Andersen 6082917e34 Some Makefile fixes for the docs.
-Erik
2000-06-02 03:35:22 +00:00
Eric Andersen 380e58a05f Note the addition of ar.
-Erik
2000-06-02 03:25:00 +00:00
Eric Andersen ec480c49c2 oops. Don't commit autogenerated stuff.
-Erik
2000-06-02 03:23:28 +00:00
Eric Andersen 86ab8a32bd A number of additional fixed from Pavel Roskin, note some more bugs in the
TODO list.  Add Glenn to the Authors list for writing a mini ar for BusyBox,
which is now included.
 -Erik
2000-06-02 03:21:42 +00:00
Eric Andersen 4062268bc7 Acknowledge contributions of Pavel Roskin, and fix doc building
so the html goes into the website directory.
 -Erik
2000-06-02 03:21:41 +00:00
Eric Andersen 08e9289ab3 Acknowledge contributions of Pavel Roskin, and fix doc building
so the html goes into the website directory.
 -Erik
2000-06-02 03:21:36 +00:00
Eric Andersen b6c6d87a99 More stuff to do...
-Erik
2000-06-02 03:21:32 +00:00
Eric Andersen 77bd2db325 Acknowledge contributions of Pavel Roskin, and fix doc building
so the html goes into the website directory.
 -Erik
2000-06-02 03:21:32 +00:00
Eric Andersen 1624813459 Point to the local BusyBox.html docs.
-Erik
2000-06-02 03:20:22 +00:00
Eric Andersen b83e0ed3a1 Forgot to checkin the busybox website graphics. Here they are...
-Erik
2000-06-02 02:33:24 +00:00
Eric Andersen 89960b8af2 More stuff.
-Erik
2000-05-31 20:08:30 +00:00
Eric Andersen b5966368d7 Minor doc fix. Added several bugs to the todo list. Fixed the way init
scans /etc/inittab entries so that commands can contain ":"s.
 -Erik
2000-05-31 20:04:38 +00:00
Eric Andersen deb0331eb6 Remove the now-fixed tar segfault from the TODO list.
-Erik
2000-05-30 19:11:50 +00:00
Eric Andersen 108a44345c Fixed tar option parsing segfault, and make "tar xv" and "tar -xv"
both work (i.e. it works with or w/o the "-").
 -Erik
2000-05-30 19:05:57 +00:00
Eric Andersen e511e7c116 Minor update to web page.
-Erik
2000-05-25 00:18:59 +00:00
Erik Andersen 8ea7d8cdaf First pass at fixing tar segfault, and more portability updates.
-Erik
2000-05-20 00:40:08 +00:00
Erik Andersen 330fd2b576 More libc portability updates, add in the website (which has not been
archived previously).  Wrote 'which' during the meeting today.
 -Erik
2000-05-19 05:35:19 +00:00
Erik Andersen d356c6e9d1 Another bug to fix...
-Erik
2000-05-17 05:28:05 +00:00
Erik Andersen 5b46d792f1 Some more portability updates
-Erik
2000-05-17 05:24:24 +00:00
Erik Andersen 499f65fb98 Some updates for better portability.
-Erik
2000-05-16 20:07:38 +00:00
Erik Andersen 969f9b0486 TODO update
-Erik
2000-05-13 19:08:58 +00:00
Erik Andersen 67a0dd8f3c Change a description
-Erik
2000-05-13 19:08:42 +00:00
Erik Andersen c3f5c9c2ee Minor fixes to being a standalone shell.
-Erik
2000-05-13 19:00:07 +00:00
Erik Andersen bcd6177853 BusyBox shell (lash) can now be used as a standalone shell when
BB_FEATURE_STANDALONE_SHELL is defined (i.e. BusyBox can now completely replace
sash).  Also fixed it so shell builtins now respect pipes and redirects.
 -Erik
2000-05-13 06:33:19 +00:00
Erik Andersen 73c8c9cf9a More doc updates
-Erik
2000-05-13 05:36:13 +00:00
Erik Andersen 23dea9b712 So much for my evil optimization. Doesn't seem to work. Will test
more on it later.
 -Erik
2000-05-13 00:28:25 +00:00
Erik Andersen 7ab9c7ee52 Lots of updates. Finished implementing BB_FEATURE_TRIVIAL_HELP
which lets you compile out most of the "--help" output, saving
up to 17k.

Renamed mnc to nc.
 -Erik
2000-05-12 19:41:47 +00:00
Erik Andersen 3d427ac5ef Some experimental stuff (work in progress). heheh.
-Erik
2000-05-12 19:38:40 +00:00
Erik Andersen 59b9e87024 * cp -fa now works as expected for symlinks (it didn't before)
* zcat works again (wasn't working since option parsing was broken)
* more doc updates/more support for BB_FEATURE_SIMPLE_HELP
 -Erik
2000-05-10 05:05:45 +00:00
Erik Andersen ac130e1dca Add suffix stripping support to basename
-Erik
2000-05-10 05:00:31 +00:00
Mark Whitley 0a027e6880 Added some bugs / TODOs. 2000-05-08 23:25:59 +00:00
Erik Andersen 691f49d3c1 Fix umount dependency on find_real_root_device_name
-Erik
2000-05-08 17:56:25 +00:00
Erik Andersen 0e713cef9d Doc updates
-Erik
2000-05-05 19:50:32 +00:00
Erik Andersen 6c5f2c6021 Add support for "noatime" and "nodiratime" mount flags to mount.
Change umount "-f" to mean force, and actually use umount2.
Change umount "-l" to mean "Do not free loop device".
Updates docs accordingly.
 -Erik
2000-05-05 19:49:33 +00:00
Erik Andersen 9b15e50835 Tell cvs to never checkin the resultant docs.
-Erik
2000-05-03 03:25:43 +00:00
Erik Andersen a59d7094a6 Sensibly put the docs under the docs directory.
-Erik
2000-05-03 03:24:21 +00:00
Erik Andersen 0a704e8ff6 Remove BB_FEATURE_REMOUNT (small, and should always be present)
and fix documentation dependancy checks, so it is only built when
it should be built.
 -Erik
2000-05-03 03:19:06 +00:00
Erik Andersen a19bc64653 More formatting bugs fixed
-Erik
2000-05-02 06:40:02 +00:00
Erik Andersen e31c06608e Bug fixes in the docs
-Erik
2000-05-02 05:32:07 +00:00
Erik Andersen 03ccce6e30 Make the dependancies on the docs work properly
-Erik
2000-05-02 05:31:00 +00:00
Erik Andersen 5afc864422 More stuff
-Erik
2000-05-02 00:07:56 +00:00
Erik Andersen 3c1217cfad Document tr change
-Erik
2000-05-01 22:34:24 +00:00
Erik Andersen 8f8d6d5f2d Due to the license change I can now use Minix code. Minix tr
(adapted) now replaces BSD tr.  Goes from 5k to 1k, and eliminates
bsearch from the list of libc symbols.
 -Erik
2000-05-01 22:30:37 +00:00
Mark Whitley d16665810d Minor source modifications to improve readability. 2000-05-01 22:08:54 +00:00
Erik Andersen 12d1b378be Minor doc change 2000-05-01 19:50:37 +00:00
Erik Andersen 9b7d964581 My little adventure of analyzing lib usage has already rooted out
a big "P" Policy violator -- logname was using getlogin(3), which uses
utmp under the hood.  We don't need no stinkin' utmp (and if we
are using tinylogin, it is unlikely to be useful trying).
 -Erik
2000-05-01 19:49:20 +00:00
Erik Andersen f378fced43 Note how to find list of BusyBox libc dependancies, the ide being to
limit them much more.
 -Erik
2000-05-01 19:27:17 +00:00
Erik Andersen 4625240674 Oops.
-Erik
2000-05-01 19:11:16 +00:00
Erik Andersen 94f5e0ba7c Some accrued fixes/updates.
* cp/mv now accepts (and ignores) the -f flag, since it always
	does force anyway
    * tail can now accept -<num> commands (e.g. -10) for better
	compatibility with the standard tail command
    * added a simple id implementation; doesn't support supp. groups yet
2000-05-01 19:10:52 +00:00
Erik Andersen 28c49b6c9c Foo 2000-04-28 22:51:49 +00:00
Erik Andersen 25c44c623d Fix changelog
-Erik
2000-04-28 22:49:08 +00:00
Erik Andersen 923ef599f3 Fix tarball creation. In an attempt to accomodate the whiners
that wanted "tar cf foo.tar foo" (i.e. no "-" before options)
I broke creation of tarballs.  Now fixed.
 -Erik
2000-04-28 22:32:13 +00:00
Erik Andersen 6ed02a0ee0 Fix stupid bugs. update was segfaulting. mknod minor # was always 0
due to a parsing bug.  Oops.
 -Erik
2000-04-28 22:10:34 +00:00
Erik Andersen abc199eb0c Forgot this file...
-Erik
2000-04-28 01:26:31 +00:00
Erik Andersen 4f3f757d56 Latest and greatest. Some effort at libc5 (aiming towards newlib)
compatability.
 -Erik
2000-04-28 00:18:56 +00:00
Erik Andersen 227a59b05d Several more updates
-Erik
2000-04-25 23:24:55 +00:00
John Beppu f93a95de69 + grep -v # yay! 2000-04-24 18:07:30 +00:00
Erik Andersen e90f4045af Some more updates and such...
-Erik
2000-04-21 21:53:58 +00:00
Erik Andersen 1d1d95051a More Doc updates. cmdedit and more termio fixes. 2000-04-21 01:26:49 +00:00
Erik Andersen cf8d38a3eb Doc updates
-Erik
2000-04-21 01:23:36 +00:00
Erik Andersen 7d6ba57bba Add #include <sys/param.h> to syslogd.
-Erik
2000-04-19 20:02:50 +00:00
Erik Andersen e3ed156eeb Make the sys logger for so that concurrent logging will work
properly (see tests/syslog_test.c for example).
 -Erik
2000-04-19 18:52:56 +00:00
Erik Andersen 1101d23604 Fix email address
-Erik
2000-04-19 05:15:12 +00:00
Erik Andersen eef658068b Minor doc change
-Erik
2000-04-19 05:12:02 +00:00
Erik Andersen 2e397341d9 Some emails I exchanged with Alan Cox and Linus re my /dev/ps
kernel patch.  To summarize, it won't be going into the kernel.
 -Erik
2000-04-19 04:34:06 +00:00
Erik Andersen 262dd039eb Fix the makefile so docs get built
-Erik
2000-04-19 04:26:30 +00:00
Erik Andersen 3fe7f9f20b More minor updates to docs (and making apps behave as the docs
suggest they should)
 -Erik
2000-04-19 03:59:10 +00:00
Erik Andersen a3e57ca700 make ps accept (and ignore) all options (--help works of course).
tar now works with or without the leading "-" on the options.
 -Erik
2000-04-19 03:38:01 +00:00
Erik Andersen f13df3752c More stuff
-Erik
2000-04-18 23:51:51 +00:00
Erik Andersen 9a8195cc03 Fix creation of /linuxrc
-Erik
2000-04-18 23:32:10 +00:00
Erik Andersen b9167cb67f Really fix the killall segfault this time.
-Erik
2000-04-18 22:41:30 +00:00
Erik Andersen 632bb57135 Fix symlink following bug in chmod -R and friends. Allow SYSV style
'chown foo:bar' in addition to 'chown foo.bar', and fix a bug in the
busybox globbing routine such that 'find /dir -name [i]' no longer
segfaults.
 -Erik
2000-04-18 22:09:06 +00:00
Erik Andersen c366050a23 Fix stupid bug (wrong variable)
-Erik
2000-04-18 21:18:57 +00:00
Jim Gleason f29f797f54 Reset DODEBUG to false 2000-04-18 20:40:38 +00:00
Erik Andersen 0a64de9b4f More little stuff.
-Erik
2000-04-18 20:00:03 +00:00
Erik Andersen 229dd2b905 Fix killall
-Erik
2000-04-18 18:38:29 +00:00
Erik Andersen 5d68857b9c Remove debug noise
-Erik
2000-04-18 01:09:29 +00:00
Erik Andersen a6c752201e Updates
-Erik
2000-04-18 00:00:52 +00:00
John Beppu 91e581fa04 - grep -v ^\.PHONY < Makefile
+ busybox.def.h
  BB_FEATURE_TRIVIAL_HELP
+ uname.c has an example of how BB_FEATURE_TRIVIAL_HELP
  is to be applied.
2000-04-17 17:49:44 +00:00
John Beppu 5a50def0f4 - removal of (stray|stealth) spaces 2000-04-17 17:46:46 +00:00
John Beppu 6e703034f4 + no need for comments. 2000-04-17 16:53:45 +00:00
Erik Andersen 26702fe191 Bugfixes.
-Erik
2000-04-17 16:44:46 +00:00
Erik Andersen e5b6c7dd9c More updates to the docs, and fixes to sync things with the docs.
-Erik
2000-04-17 16:16:10 +00:00
John Beppu 4fd10fc73b + added John Lombardo to AUTHORS section 2000-04-17 05:13:59 +00:00
John Beppu 200be97e36 - got rid of the .PHONY: docs, because I didn't want it to
generate the qw(man html txt) documentation every time I
  ran make.

  Unfortunately, "make docs" never amounts to anything, because
  make sees the docs/ directory and thinks, "oh, I don't have
  to do any work".  Maybe the target should be "doc" to make it
  different from "docs"?
2000-04-17 04:41:15 +00:00
John Beppu 5a728cfdfe + in the interest of robustness, I added
utility.c :: cstring_alloc()
  utility.c :: cstring_lineFromFile()	/* they're at the bottom */
  so that I could read in lines of arbitrary length from FILE*s
  (instead of using fgets(huge_ass_buffer,...)).
+ I tested it out on sort, and it seems to be fine.
2000-04-17 04:22:09 +00:00
John Beppu 3becdfc316 + added a .PHONY: docs
target
2000-04-17 03:37:52 +00:00
John Beppu 53642b066c + fixed segfault when no parameters are given to math 2000-04-16 10:55:27 +00:00
John Beppu 9057b6a918 + wrap things in B<> to make pod2man happy 2000-04-16 10:22:28 +00:00
Erik Andersen ab01ed12bd Turn off debugging
-Erik
2000-04-15 16:37:45 +00:00
Erik Andersen 5e1189e187 More documentation updates, and minor fixes to make things sync
up with the docs.
 -Erik
2000-04-15 16:34:54 +00:00
Erik Andersen 95c1c1e05f Fix a tar bug: tar removed leading '/'s for symlink targets.
Fix a syslogd bug: Only the first sizeof(buffer) was read from the
/dev/log socket, causing (for most cases) only every other log item to be logged.
 -Erik
2000-04-14 21:45:29 +00:00
Erik Andersen d5ba77d03e Latest and greatest. Seems there is a bug.
-Erik
2000-04-14 00:40:31 +00:00
John Beppu 50ed0676ad + minor whitespace oddities removed
+ re-alphabetized AUTHORS section
+ added Id tag at bottom
2000-04-13 23:44:04 +00:00
John Beppu cbd6628c8c + VERSION wasn't being propagated to the sub-make happening in docs/
so I exported VERSION and invoked make with a -C docs
2000-04-13 22:57:45 +00:00
Erik Andersen 9cf3bfa7c1 More doc updates for BusyBox, with fixes to apps for bugs revealed
while trying to write docs . :-)
 -Erik
2000-04-13 18:49:43 +00:00
John Beppu b4f8606c05 - the message that comes up when busybox is invoked
w/o parameters was extending beyond the 80th column
2000-04-13 03:36:01 +00:00
John Beppu 08e7f75ba2 + a comment on line 1 w/ suggested pod2man invocation:
pod2man --center=Lineo --release="version 0.43" busybox.pod > busybox.1
2000-04-13 03:22:20 +00:00
John Beppu f17792ca9b + formatting modifications to make pod2man(1p) happy. 2000-04-13 03:16:01 +00:00
Erik Andersen 61677feff7 Upates to include copyright 2000 to everything
-Erik
2000-04-13 01:18:56 +00:00
Erik Andersen 62dc17a3b1 Some docs
-Erik
2000-04-13 01:18:23 +00:00
Erik Andersen f0657d3229 Some enhancements I've been working on over the weekend,
-Erik
2000-04-12 17:49:52 +00:00
Erik Andersen a2685735b1 Make tab completion an option
-Erik
2000-04-09 18:27:46 +00:00
Erik Andersen f3b3d17060 More minor patches
-Erik
2000-04-09 18:24:05 +00:00
Erik Andersen 0817d1372c This makes tar work perfectly, and adds in "--exclude" as an option
-Erik
2000-04-09 15:17:40 +00:00
Erik Andersen 84e09e4437 Fix tar checksum calculation bug.
-Erik
2000-04-08 20:58:35 +00:00
Erik Andersen ecd512453c Latest and greatest
-Erik
2000-04-08 03:08:21 +00:00
Erik Andersen 5dd853ad2a Oops. Left in some debug noise.
-Erik
2000-04-07 16:19:30 +00:00
Erik Andersen 6a34b539db Slightly better fringe case handling and GNU tar like error messages.
-Erik
2000-04-07 06:55:38 +00:00
Erik Andersen 825aead68b Patch to make killall actually kill all PIDs with the specified name,
rather then busylooping trying to kill the first one until it dies.
Should be more efficient now, and will only send one signal to each
specified process.
 -Erik
2000-04-07 06:00:07 +00:00
Erik Andersen 93d6513d93 Some more minor updates to better use some gcc attributes.
-Erik
2000-04-06 08:06:36 +00:00
Erik Andersen 7a4b719486 Fix sed regexp replacement, which I had hosed (thanks to
Jim Gleason for finding and fixing the problem)
 -Erik
2000-04-06 07:37:35 +00:00
Erik Andersen 6bd3602988 Fix time stamp style
-Erik
2000-04-06 07:25:44 +00:00
Erik Andersen c0dac18d6d Turn off static linking. Duh.
-Erik
2000-04-06 07:24:45 +00:00
Erik Andersen e9fee653dc Use gcc -E instead of cpp to enhance portability for brain
damaged platforms (i.e. OpenLinux) that do not have cpp in
the default path but instead hide it under /usr/lib/...
 -Erik
2000-04-06 00:10:39 +00:00
Erik Andersen d4bc1fcad8 Minor noise removal
-Erik
2000-04-05 05:19:03 +00:00
Erik Andersen 5661fe078e Tar now works perfectly. It behaves much better now then it
used to.  Only thing left to do is add in exclude (-X) option.
 -Erik
2000-04-05 01:00:52 +00:00
Erik Andersen cbb0a4b40d Oops. Forgot the usleep.c file.
/me dons a paper bag.
 -Erik
2000-04-04 18:52:02 +00:00
Erik Andersen b99ca13261 usleep contributed by Nicolas Pitre <nico@cam.org>
-Erik
2000-04-04 18:49:18 +00:00
Erik Andersen 68a9ea4208 Update tar so creation of tarballs is much closer to working...
-Erik
2000-04-04 18:39:50 +00:00
Erik Andersen 183da4ade1 Minor structural change to allow core dumping(or not) from init
-Erik
2000-04-04 18:36:37 +00:00
Erik Andersen 983b51b17b minor changes to mount/umount to support-by-ignoring the "-v" flag.
Added optional core dumping as a feature for init, and include a rewrite
of syslogd so that it now supports multiple concurrent connections.
 -Erik
2000-04-04 18:14:25 +00:00
Erik Andersen 3364d78b18 Yet another installment in the ongoing tar saga
-Erik
2000-03-28 00:58:14 +00:00
Erik Andersen 6acaa40f27 First stages of (re-)writing busybox's tar creation support.
-Erik
2000-03-26 14:03:20 +00:00
Erik Andersen deea048bec Latest and greatest
-Erik
2000-03-25 23:09:29 +00:00
Erik Andersen 1ad302ac90 The new tar for busybox is now done, and works just fine
for extracting files.  Creation of tarballs is next...
 -Erik
2000-03-24 00:54:46 +00:00
Erik Andersen e454fb68a3 More changes that are broken. It doesn't compile
yet, but is closer.
 -Erik
2000-03-23 04:27:58 +00:00
Erik Andersen 298854f029 My latest ramblings.
-Erik
2000-03-23 01:09:18 +00:00
Erik Andersen ec5bd90916 Use the nice new find_real_root_device function to find the
name of the root device, instead of having libc read whatever
lies happen to be in /etc/mtab.
 -Erik
2000-03-22 07:12:05 +00:00
Erik Andersen 016ffe9307 Add in a nifty function for mount to use.
-Erik
2000-03-22 00:58:54 +00:00
Erik Andersen 0d068a2067 * all mallocs now use xmalloc (and so are OOM error safe), and
the common error handling saves a few bytes.  Thanks to
Bob Tinsley <bob@earthrise.demon.co.uk> for the patch.
 -Erik
2000-03-21 22:32:57 +00:00
Erik Andersen c053e41fa0 Hmm. Missed this change 2000-03-21 01:31:24 +00:00
Erik Andersen 42094cdad5 Fix bug in memory total checking.
-Erik
2000-03-20 21:34:52 +00:00
Erik Andersen 1dbe340eba more minor fixes
-Erik
2000-03-19 10:46:06 +00:00
Erik Andersen c7c634bd88 Some more stuff.
-Erik
2000-03-19 05:28:55 +00:00
Erik Andersen 6c41c44898 Adjust the termio settings, and don't use octal since it
is impossible to read by mere mortals.
 -Erik
2000-03-19 05:13:49 +00:00
Erik Andersen 531bcb6826 Minor update 2000-03-17 20:49:55 +00:00
Erik Andersen 6273f655c8 Several fixes.
-Erik
2000-03-17 01:12:41 +00:00
Erik Andersen 161220c498 Fix fg bug
-Erik
2000-03-16 08:12:48 +00:00
Erik Andersen 13456d1fcd Forgot these files...
-Erik
2000-03-16 08:09:57 +00:00
Erik Andersen d75af99529 Major build system updates...
-Erik
2000-03-16 08:09:09 +00:00
Erik Andersen a967e3c8f0 Bug fix
-Erik
2000-03-14 16:34:49 +00:00
Erik Andersen ce91732416 Some bug fixes I forgot to check-in the other day.
Mounting loop devices w/o specifying the filesystem
type choked if it didn't guess right the first time.
 -Erik
2000-03-13 04:07:02 +00:00
Erik Andersen 3522eb1ab3 First pass at writing a shell for busybox.
Works fine, full job control support, etc.
No syntax yet (if, then, while, etc).  Handles
pipes and & processes fine.

TODO: add command editing, add syntax suport.

 -Erik
2000-03-12 23:49:18 +00:00
Erik Andersen 269bba2514 Change BB_FEATURE_USE_DEVPS_N_DEVMTAB to the simpler
BB_FEATURE_USE_DEVPS_PATCH.
 -Erik
2000-03-08 14:50:47 +00:00
Erik Andersen 47d3bb3b6d First edition of my Busybox kernel patch. implements devps, devmtab, and
devmodules.  With this patch, you can enable BB_FEATURE_USE_DEVPS_N_DEVMTAB and
have a completely full featured busybox without having to even compile /proc
into the kernel.  I'm pretty proud of this patch.  It has a few loose ends that
should be filled in sometime, but arn't used by busybox (so they arn't very
important).

 -Erik
2000-03-08 06:52:04 +00:00
Erik Andersen 54969a1f64 Fixed up lsmod so it works with my devmodules kernel driver,
and with /proc.
 -Erik
2000-03-08 06:42:34 +00:00
John Beppu 692a4502b0 + changed a static array (FileList) into a dynamically allocated one
in an attempt to make the .bss section smaller.
2000-03-08 00:14:35 +00:00
Erik Andersen 2ac2fae728 Fix bugs related to finding PIDs.
-Erik
2000-03-07 23:32:17 +00:00
Erik Andersen cbd0d625c7 Fix up some #define stuff to ensure the Right Thing(tm)
happens with all combinations of BB_KILL and BB_KILLALL
being defined.
 -Erik
2000-03-07 07:58:57 +00:00
Erik Andersen 06249f24f3 Add some description
-Erik
2000-03-07 07:48:53 +00:00
Erik Andersen ea6b67de65 Add a #define to make init extra quiet on boot.
-Erik
2000-03-07 07:47:10 +00:00
Erik Andersen 246cc6dddd Wrote killall.
Adjusted mount, ps, utility.c, etc to handle my nifty new kernel
patches the allow busybox to run perfectly without /proc.
 -Erik
2000-03-07 07:41:42 +00:00
Erik Andersen e916d24805 Fixed a bug where "sed 's/foo/bar/g'" (i.e. a script w/o a -e)
would go into an infinite loop.
 -Erik
2000-03-06 19:20:35 +00:00
Erik Andersen 9c5c29d442 Oops. I left debugging turned on...
-Erik
2000-03-06 18:34:48 +00:00
Erik Andersen 65fc1c70f7 Oops. Forgot to add in uptime when I added uptime.
Here it is in all its /proc free glory.
 -Erik
2000-03-05 08:16:03 +00:00
Erik Andersen fb002d0df0 Add in tr and dirname
-Erik
2000-03-05 08:07:00 +00:00
Erik Andersen 66be5e7e29 Wrote uptime. Doesn't use /proc. :)
-Erik
2000-03-05 07:52:05 +00:00
Erik Andersen 6437170cb3 Add in freeramdisk.c, which (duh) frees ramdisks. If you have any
ramdisks lying about and want to free up the memory they have used,
this baby is the answar you have been waiting for.
 -Erik
2000-03-04 22:23:27 +00:00
Erik Andersen 029011b9ee A few updates (including the cp fix the Craig has been looking for)
-Erik
2000-03-04 21:19:32 +00:00
Erik Andersen 7c4b2f3fe5 Minor makefile and todo updates
-Erik
2000-02-29 21:49:22 +00:00
Erik Andersen a51ecdd9e4 Minor tweak to argv[0] handling for linuxrc
-Erik
2000-02-24 18:09:58 +00:00
Erik Andersen 5b911ddd57 Fixed rebooting when init runs as /linuxrc
-Erik
2000-02-23 22:49:58 +00:00
John Beppu dc75a739ac + this is a small script for helping TargetWizard auto-generate
busybox.defs.h
2000-02-23 18:17:35 +00:00
Erik Andersen f7c49ef2d1 Sync up a few things. Add in a new telnet implementation (still
not perfect though).
 -Erik
2000-02-22 17:17:45 +00:00
Erik Andersen 3b9522f2af Add in a TODO item,
-Erik
2000-02-22 17:12:00 +00:00
Erik Andersen 6e769df47d Update the changelog
-Erik
2000-02-21 21:35:11 +00:00
Erik Andersen d07ee46919 Removed proc dependancies for init and free (which maintaining exactly
the same functionality).  /proc takes up 90k of kernel space, so it is
nice to avoid using it at all costs.  The only places where it is depended
on is for cetain optional mount/umount features, and for ps and lsmod.
 -Erik
2000-02-21 21:26:32 +00:00
Erik Andersen fa4718efcf Minor update for handling TERM with serial consoles.
-Erik
2000-02-21 19:25:12 +00:00
Erik Andersen 42387e4964 Forgot to add basename. More fixes to du from
Friedrich Vedder <fwv@myrtle.lahn.de>.
 -Erik
2000-02-21 17:27:17 +00:00
Erik Andersen 27fdd081ef Fixed du. Now behaves just like GNU du (only less so).
-Erik
2000-02-19 18:16:49 +00:00
Erik Andersen e272915e1f Some updates for the day,
-Erik
2000-02-18 21:34:17 +00:00
Erik Andersen bf5f009862 Formatting fix
-Erik
2000-02-14 18:44:33 +00:00
John Beppu 08c965a0a1 - I suspect the problem has something to do w/ symlinks.
- It's not completely in agreement w/ GNU/du, but
+ the answer is much closer than before.
- Some of the right-shifts seem to have mysteriously disappeared.
  I put them back in.
2000-02-13 04:10:57 +00:00
Erik Andersen 5e2b96345c Add this in
-Erik
2000-02-11 21:55:41 +00:00
Erik Andersen 9ffdaa647e Updates
-Erik
2000-02-11 21:55:04 +00:00
John Beppu 5e1b2ca116 + memory allocation/deallocation is less tolerant of evil. 2000-02-11 12:52:55 +00:00
John Beppu fa376f8034 fsck_minix.c lost fat. 2000-02-11 12:44:07 +00:00
John Beppu c1dc5d9473 reduced .bss size by dynmaically allocating a certain large
array instead of letting it be static.

objdump -t busybox	    \
| grep .bss		    \
| sed 's/^.*\.bss	//' \
| grep -v ABS		    \
#| perl -e 'while(<>) { @x = split; @y = reverse split(//, $x[0]); for ($i=0; $i<@y; $i++) { $s += $y[$i] * (16 ** $i); if ($y[$i] && $i > 2) { print "> $y[$i] * 16 ** $i $x[1]\n"; } } } print "$s\n";'
2000-02-11 12:43:20 +00:00
Erik Andersen 91f3df3c45 Fixed a bug,
-Erik
2000-02-10 22:58:40 +00:00
Erik Andersen 4d0543138e More minor touchups.
-Erik
2000-02-10 07:31:15 +00:00
Erik Andersen fb1793f03c Fix stupid typos -- thanks to Taketoshi Sano <kgh12351@nifty.ne.jp>
for noticing these bugs.
 -Erik
2000-02-09 16:37:08 +00:00
Erik Andersen 07f5604046 Fix a possible /linuxrc crash.
-Erik
2000-02-09 06:05:01 +00:00
Erik Andersen d7ce5e7802 Update the sample inittab to add the "ctrlaltdel" action.
Note a bug in busybox init that I need to fix.
 -Erik
2000-02-09 04:40:25 +00:00
Erik Andersen e132f4b09e Fixed the init problem where it wouldn't unmount filesystems
on reboot.  Also fixed swapoff -a so it works.
 -Erik
2000-02-09 04:16:43 +00:00
Erik Andersen e49d5ecbbe Some formatting updates (ran the code through indent)
-Erik
2000-02-08 19:58:47 +00:00
Erik Andersen c0bf817bbc mkdir -p had gotten broken. Fixed now.
-Erik
2000-02-08 06:19:29 +00:00
Erik Andersen d0480c26ab Forgot a semicolon.
-Erik
2000-02-07 20:35:14 +00:00
Erik Andersen 31cf8e0056 device_open is common code -- moved into utility.c
-Erik
2000-02-07 20:31:19 +00:00
Erik Andersen 79ac30da83 Forgot cp and mv are now cp_mv
-Erik
2000-02-07 05:53:48 +00:00
Erik Andersen d7cd21aed5 Remove the now obsolete test. Tests now
live in the tests directory.
 -Erik
2000-02-07 05:30:41 +00:00
Erik Andersen fac10d7c59 A few minor updates. ;-)
Seriously though, read the Changelog for busybox 0.42,
which this is about to become...
 -Erik
2000-02-07 05:29:42 +00:00
John Beppu 50bc101b7d made more robust and commented my code. 2000-01-30 09:47:16 +00:00
John Beppu b332e779e6 nslookup -- a work in progress... 2000-01-29 12:59:01 +00:00
Erik Andersen 04e97024e7 Clear up some ambiguity with old style assignments.
-Erik
2000-01-29 07:06:24 +00:00
Erik Andersen a6d0dbc86f Minor change. init now uses dup2.
-Erik
2000-01-29 06:29:32 +00:00
Erik Andersen 8e759aa31f copy fixes to simplify link copying and always do the right thing.
ping could segfault because I'm an idiot, and tried to put a value
in where I hadn't allocated storage.  choke.
 -Erik
2000-01-29 05:52:40 +00:00
Erik Andersen d7a44c76fe Forgot some debugging noise.
-Erik
2000-01-27 23:00:01 +00:00
Erik Andersen ce5b466bcc copyFile could call chmod on a symlink, changing the perms
of the pointed to file.  Minor fix to tar for directory handling.
 -Erik
2000-01-27 19:50:47 +00:00
Erik Andersen ccc7488615 Fixed ls formatting for 8 char user names.
-Erik
2000-01-27 02:40:21 +00:00
Erik Andersen de7965ca7e Shuffle location of generic code into utility.c
-Erik
2000-01-26 23:49:21 +00:00
Erik Andersen 5cbdd712f5 mount and umount could leak loop device allocations causing the system to
quickly run out.  Also disable init's SIGHUP handler during shutdown.
 -Erik
2000-01-26 20:06:48 +00:00
Erik Andersen 3fe39dce5d Some busybox updates. See the changelog for details if you care.
-Erik
2000-01-25 18:13:53 +00:00
John Beppu bf3a838aac put #if's around the lchown, because
older glibc versions don't have it.
2000-01-24 12:06:22 +00:00
Erik Andersen 5509af7073 * added (and documented) "-n" option for head -
contributed Friedrich Vedder <fwv@myrtle.lahn.de>
* Cleanup for a number of usage messages -- also
    contributed Friedrich Vedder <fwv@myrtle.lahn.de>
 -Erik
2000-01-23 18:19:02 +00:00
John Beppu 9bc7e89fc1 Making note of my changes 2000-01-23 13:54:15 +00:00
John Beppu a4a8fd05f4 Went ahead and fixed bug #301 (chown not working on symlinks)
in fileAction(), I changed the chown() to lchown(); Hopefully, that
	doesn't break anything.  (I don't think it does).

	nested ?:?:?: madness in chmod_chown_chgrp.c
2000-01-23 13:38:32 +00:00
Erik Andersen 06936df164 Fix a bug where tar could change perms and ownership of dirs pointed
to by symlink within a tarball.
 -Erik
2000-01-23 02:14:20 +00:00
Erik Andersen de552874d2 Some busybox updates. You no longer _have_ to put a "-" in front of tar
options, logger is better behaved and has a "-t" option now.  init now supports
the kernel chroot patch, so you can chroot to a new device and umount the old
root.
 -Erik
2000-01-23 01:34:05 +00:00
Erik Andersen f4acea8cf5 Better way to check for namespace aliasing.
-Erik
2000-01-22 04:55:32 +00:00
Erik Andersen b2660c703d Tell what I did
-Erik
2000-01-20 19:51:48 +00:00
Erik Andersen 8ad12e32c8 Fix a namespace aliasing problem wereby du and dutmp, or
rm and rmmod symlinks would be created when only du or rm
was included.
 -Erik
2000-01-20 19:32:32 +00:00
John Beppu 4581b4cdd9 foreach (@busybox_command) {
put_help_message_in_busybox_pod($_);
}
2000-01-19 15:04:41 +00:00
John Beppu 08fe43d3f9 added a little more content. 2000-01-19 12:39:16 +00:00
Erik Andersen a2f69e5485 Bug fix. grep wasn't printing file names they way it was supposed to.
-Erik
2000-01-19 04:30:37 +00:00
John Beppu 46a4e76243 fleshed out a bit more... just wanted to put the current
changes under version control.
2000-01-18 22:33:11 +00:00
John Beppu 3a1b6be7d8 the beginnings of a proper man page for busybox. 2000-01-18 15:45:59 +00:00
Erik Andersen 05100cd477 tar creation support is now optional.
-Erik
2000-01-16 01:30:52 +00:00
Erik Andersen 83865e3e90 Ready for release 2000-01-15 22:33:09 +00:00
Erik Andersen 3163821967 Sync up busybox with the latest and greatest. This is not stuff for
the Embedix release.
 -Erik
2000-01-15 22:28:50 +00:00
Erik Andersen b7cc49d992 * Added -o loop option for mount, and support in umount for loop
devices. Support is toggled by MOUNT_LOOP feature -- Ben Collins
    <bcollins@debian.org>

 -Erik
2000-01-13 06:38:14 +00:00
Erik Andersen 05df239ed9 Bug fixes.
-Erik
2000-01-13 04:43:48 +00:00
Erik Andersen 9a9a261569 Fix a logger bug.
-Erik
2000-01-09 06:49:08 +00:00
Erik Andersen ac6e71f0c4 Possible fixes...
-Erik
2000-01-08 22:04:33 +00:00
Erik Andersen 766f9c7a19 Oops. left debug on.
-Erik
2000-01-08 21:20:49 +00:00
Erik Andersen 1dbc17f630 Fix cp and mv so 'cp foo/README bar' where foo and bar are directories,
and README is a file.
 -Erik
2000-01-08 21:16:29 +00:00
Erik Andersen 5338ce19c8 foo 2000-01-07 23:30:07 +00:00
Erik Andersen 5f2df6ccb4 Remove some leftover debug noise.
-Erik
2000-01-07 23:11:00 +00:00
Erik Andersen 9b5c0b7611 More adjustments
-Erik
2000-01-07 18:33:06 +00:00
Erik Andersen 812d46667d More minor fixes.
-Erik
2000-01-07 18:30:40 +00:00
Erik Andersen 96e2abd084 Init is now even more perfect then before.
-Erik
2000-01-07 11:40:44 +00:00
Erik Andersen 286b0de74d Trivial type fix.
-Erik
2000-01-07 09:43:38 +00:00
Erik Andersen d38eaef70b foo 2000-01-07 02:55:55 +00:00
Erik Andersen 0e3782f7c3 Init is now _more_ perfect then before.
-Erik
2000-01-07 02:54:55 +00:00
John Beppu 9324b400ab making note of my changes. 2000-01-07 02:04:58 +00:00
John Beppu 9d83165d9e added uniq_usage message 2000-01-07 01:57:32 +00:00
John Beppu 96f1f33e56 did tedious stuff 2000-01-06 23:49:21 +00:00
Erik Andersen 3695052813 Add in sample inittab file
-Erik
2000-01-06 01:16:59 +00:00
Erik Andersen 9e7372584f inittab is now perfect. The universe will now submit to my
will. muhahahaha!!!  Phear!
 -Erik
2000-01-06 01:16:13 +00:00
Erik Andersen 0b874ed41f Cool. Beppu is doing uniq.
-Erik
2000-01-06 01:14:56 +00:00
John Beppu abb4772b28 i am busybox of borg. unix will be assimilated. 2000-01-06 00:48:21 +00:00
Erik Andersen 0881de706e The latest and greatest. init basically works, though needs
a minor inittab design change to accomodate specifying the device
to run each process on.
 -Erik
2000-01-05 09:34:26 +00:00
Erik Andersen f4a99cc02c heheh. Forgot the fix. Here it is:
* Grep -i previously failed on UPPER CASE patterns due to a silly
    regexp implementation bug that is now fixed.

 -Erik
2000-01-05 05:49:51 +00:00
Erik Andersen fb62e3225f * Grep -i previously failed on UPPER CASE patterns due to a silly
regexp implementation bug that is now fixed.

 -Erik
2000-01-05 05:47:11 +00:00
Erik Andersen 7dc160721e Bunches of fixes. Typos, bugs, etc.
Added 'gunzip -t'.  inittab support _almost_ works (but it isn't
ready for prime time useage yet).
 -Erik
2000-01-04 01:10:25 +00:00
Erik Andersen 9c88cac5cb First pass inittab parser written
-Erik
1999-12-30 09:25:17 +00:00
Erik Andersen 1266a13e1f * sed now supports addresses (numeric or regexp, with negation) and
has an append command, thanks to Marco Pantaleoni <panta@prosa.it>
* Fixed dmesg.  It wasn't parsing its options (-n or -s) properly.
* Some cosmetic fixes to ls output formatting to make it behave more
    like GNU ls.
 -Erik
1999-12-29 22:19:46 +00:00
Erik Andersen a89910829c Add the beginings of some regression testing. Add in the recently
contributed loadacm utility (for dealing with unicode fonts)
 -Erik
1999-12-29 03:34:00 +00:00
Erik Andersen f664c004db Fixed mv so it now does the right thing (same method used in cp). Removed
some cruft from cp.
 -Erik
1999-12-29 02:36:29 +00:00
Erik Andersen 2fe08c7afb Fixed cp so it works as God intended it to.
-Erik
1999-12-29 02:10:35 +00:00
Erik Andersen 00266d3df6 Fixed a bug where tar would not set the user and group on device
special files.
 -Erik
1999-12-28 00:17:46 +00:00
Erik Andersen 69ba6b2956 Added changelog
-Erik
1999-12-27 23:56:17 +00:00
Erik Andersen 98f67e35d8 chown(2) clears S_ISUID and S_ISGID, even when chown is
called as root.  Changed ordering of chown and chmod so
SGID and SUID file permissions don't get munged.
 -Erik
1999-12-27 23:48:33 +00:00
John Beppu 00417a38c1 sort is good to go. 1999-12-23 22:46:10 +00:00
John Beppu ee512a3f86 implemented numeric sort (sort -g) 1999-12-23 00:02:49 +00:00
John Beppu 568cb7b45f oops.. qsort(2) misunderstanding on my part.
it's ok, now.
1999-12-22 23:02:12 +00:00
John Beppu d19385e160 playing w/ $Log$ 1999-12-22 22:27:01 +00:00
John Beppu f3e59041b5 the base is nearly done.
need to implement various comparison functions, now.
1999-12-22 22:24:52 +00:00
John Beppu 019513a59f added hooks for sort 1999-12-22 17:57:31 +00:00
John Beppu 38efa7902e work in progress... 1999-12-22 00:30:29 +00:00
John Beppu c0ca473af9 this is my work in progress. 1999-12-21 20:00:35 +00:00
Erik Andersen 3fe2ecf0d9 Added grep -q, thanks to a patch from "Konstantin Boldyshev" <konst@voshod.com>
-Erik
1999-12-21 08:52:04 +00:00
Erik Andersen d387d01f11 Sync to my local tree 1999-12-21 02:55:11 +00:00
Erik Andersen f294a0288d Fix double quoting bug preventing ininit scripts from running 1999-12-21 02:54:37 +00:00
Erik Andersen 021043205c Add in first draft of insmod. Not yet working (but will Real Soon Now(tm))
-Erik
1999-12-17 18:57:34 +00:00
Erik Andersen 10c341af35 Make head --version do the right thing. Update TODO list
-Erik
1999-12-17 18:52:06 +00:00
Erik Andersen 4d1d0113fd Reworked the source so it will compile and run under glibc 2.0.7
and linux kernel 2.0.36 (though the dubious reasons why someone
would want to do that defy imagination ;)
 -Erik
1999-12-17 18:44:15 +00:00
Erik Andersen 6da0ae8183 Minor fixes to rmmod. First pass at insmod (not yet working).
-Erik
1999-12-17 01:08:27 +00:00
Mark Whitley c144e330c0 Fixed correctness of comment in rmmod.c - MKW 1999-12-17 00:01:46 +00:00
Erik Andersen 2129b146db Added an AUTHORS file to acknowledge the folks that have
done stuff.
 -Erik
1999-12-16 23:26:57 +00:00
Erik Andersen 3d7e3414da Wrote rmmod for busybox.
-Erik
1999-12-16 23:04:20 +00:00
John Beppu 0aa6118167 killed an elusive bug in du -s. 1999-12-16 21:16:47 +00:00
Erik Andersen 1c5b2589d1 Fix bugs in logger and syslogd. Add fbset.
-Erik
1999-12-16 20:59:36 +00:00
Erik Andersen 6f23cec5d0 Added lsmod
-Erik
1999-12-15 22:14:12 +00:00
John Beppu 935fb3886f made note of my recent changes 1999-12-15 19:35:02 +00:00
John Beppu 25ab653457 fixed an embarrasing segfault (head w/ no args
used to die (but now it lives))
1999-12-15 19:29:09 +00:00
John Beppu e1618e42a8 Implemented du -s 1999-12-15 18:52:17 +00:00
Erik Andersen 3cd5d2541f Turn off loadkmap and loadfont. We won't be needing those.
-Erik
1999-12-15 08:20:08 +00:00
Eric Andersen 0f0fcecf7f Added the list of available commands.
-Erik
1999-12-12 05:32:52 +00:00
Eric Andersen 664584b50e Fixed spelling of my name. Geez.
Ah kant evun spel mi nam.
 -Erik
1999-12-11 23:25:59 +00:00
Eric Andersen 19db07b3d4 Ok, so this is reallt 0.38...
-Erik
1999-12-11 08:41:28 +00:00
Eric Andersen 59248bad97 Set version to 0.39
-Erik
1999-12-11 04:21:50 +00:00
Eric Andersen 84b009256f Minor updates 1999-12-11 04:16:51 +00:00
John Beppu b52a218c95 Removed a redundant call du(); Save cpu cycles. 1999-12-10 15:23:47 +00:00
John Beppu 59017e80da damnit.
removed mkfifo from the TODO list.

    I didn't implement it, because I realized (too late) that
    mknod already existed, and it can do anything that mkfifo
    would have done.
1999-12-10 08:44:54 +00:00
Eric Andersen cf53687376 Fixed John's email address again.
John.  Your email address is "john@lineo.com" not @line.com. :)
 -Erik
1999-12-10 08:29:20 +00:00
Eric Andersen 2cb55077e2 Added poweroff (and adjusted init to use it). Inlined function
calls to code only called once in tee.  Made BB_KLOGD and option.
 -Erik
1999-12-10 08:25:07 +00:00
John Beppu c5ff0165ad less TODO 1999-12-10 07:48:34 +00:00
John Beppu 3157b1fba9 Implemented head(1).
tried to mimic GNU behaviour.
1999-12-10 07:42:50 +00:00
John Beppu a3e0d7928b changed tee_usage from being a function to a char[]
that gets used be usage();
1999-12-10 07:41:03 +00:00
John Beppu 9835541c54 Fixed bug when dealing with files specified
on the command line that didn't exist.
1999-12-10 07:40:08 +00:00
Eric Andersen 21818c8a80 Make sure the world knows who "beppu" is.
-Erik
1999-12-10 06:48:10 +00:00
Eric Andersen 70e2f0b111 Fix beppu's email address.
BTW, John, go to sleep.  It is late. :)
 -Erik
1999-12-10 06:45:42 +00:00
John Beppu 14c82b64c9 Fleshed out du_main().
I'm not sure which options to support.
1999-12-10 06:15:27 +00:00
John Beppu 2ad2afd05c less TODO 1999-12-10 06:14:28 +00:00
John Beppu 059f152a7a Implemented tee(1). 1999-12-10 05:27:16 +00:00
John Beppu 29fcc90f3e minor changelog update 1999-12-09 23:33:04 +00:00
Eric Andersen 6805d5d69e Adjustments for Johns init stuff,
-Erik
1999-12-09 22:39:55 +00:00
John Beppu f95ca97d1b findInitPid() has been implemented and it seems to work.
reboot has been changed to take advantage of findInitPid();
1999-12-09 22:10:18 +00:00
John Beppu 395b216a2e du is done 1999-12-09 18:37:56 +00:00
John Beppu 7a98606d85 Modified to include du 1999-12-09 18:29:29 +00:00
John Beppu 0f5e1ab949 This is my preliminary
du implementation.  It
    was written from scratch
    (doesn't use recursiveAction).
    I still need to flesh out
    du_main().
1999-12-09 18:23:54 +00:00
Eric Andersen f0758dd6ba * Fixed rebooting from init. I'd left some debugging code in
which blocked reboots.  Oops.
 -Erik
1999-12-09 07:57:58 +00:00
Eric Andersen 1792f8c489 Tail now works (costs 6k). Several other updates.
-Erik
1999-12-09 06:11:36 +00:00
Eric Andersen c24db7b591 Added an empty line for no reason.
-Erik
1999-12-09 01:29:12 +00:00
Eric Andersen 8cd6a1f9a2 Fixed spelling error
-Erik
1999-12-09 01:26:38 +00:00
Eric Andersen 48091fb3d3 * my_getid was leaking file descriptors, causing 'ls -l' on long
directories to fail
 -Erik
1999-12-09 01:15:52 +00:00
Eric Andersen abc0f4f8f9 Latest and greatest 1999-12-08 23:19:36 +00:00
Eric Andersen 2285f367e2 Stuf 1999-12-08 04:23:30 +00:00
Eric Andersen fcdb57a0fc Fixes 1999-12-08 04:13:59 +00:00
Eric Andersen d29edf34d6 Stuf 1999-12-08 04:13:44 +00:00
Eric Andersen 485b9550fd Stuf 1999-12-07 23:14:59 +00:00
Eric Andersen d00c262847 Stuf 1999-12-07 08:37:31 +00:00
Eric Andersen 0ecb54a0f3 Stuf 1999-12-05 23:24:55 +00:00
Eric Andersen 14ec6cf3c2 syslogd and klogd work now.
-Erik
1999-12-05 22:17:02 +00:00
Eric Andersen de1d61268e Fixes 1999-12-03 15:14:25 +00:00
Eric Andersen b186d980d6 Stuf 1999-12-03 09:19:54 +00:00
Eric Andersen 77619b9dda Sqtuf 1999-11-29 04:31:50 +00:00
Eric Andersen bb58702833 Fix up changelog 1999-11-29 04:30:12 +00:00
Eric Andersen 03018f7551 Fixed tar so uid/gud/permissions on extracted tarballs will be correct.
-Erik
1999-11-29 04:29:13 +00:00
Eric Andersen 1667fb4b63 Fixes 1999-11-27 20:34:28 +00:00
Eric Andersen c054b21f7d Stuf 1999-11-27 17:41:29 +00:00
Eric Andersen 4c78147755 Changes 1999-11-26 08:12:56 +00:00
Eric Andersen ec33d45e89 Stuf 1999-11-26 01:51:02 +00:00
Eric Andersen befda6e4ed Stuf 1999-11-25 08:06:22 +00:00
Eric Andersen 3843e96252 Stuf 1999-11-25 07:30:46 +00:00
Eric Andersen b99df0fd65 First draft 1999-11-24 09:04:33 +00:00
Eric Andersen 394f764e7d Stuf 1999-11-23 21:38:12 +00:00
Eric Andersen cb41c2e83b Bug fixes 1999-11-22 07:41:00 +00:00
Eric Andersen 5d44d1fda5 Stuf 1999-11-22 06:01:01 +00:00
Eric Andersen 0f4c0848c7 Fix bugs 1999-11-22 05:57:09 +00:00
Eric Andersen 0727458a97 Stuf 1999-11-21 21:50:07 +00:00
Eric Andersen fa213cd71e Latest n greatest 1999-11-19 06:24:35 +00:00
Eric Andersen e1850ddde4 Stuf 1999-11-19 05:42:32 +00:00
Eric Andersen 6a76e652aa Stuf 1999-11-19 05:31:45 +00:00
Eric Andersen 08b1034f4f Stuf 1999-11-19 02:38:58 +00:00
Eric Andersen ab746abfc0 Stuf 1999-11-18 20:33:45 +00:00
Eric Andersen 1c43d0c5af Stuff 1999-11-18 07:58:07 +00:00
Eric Andersen b052b47722 Forgot this. 1999-11-18 00:21:59 +00:00
291 changed files with 77538 additions and 20264 deletions

No files matched your search

+2
View File
@@ -1,2 +1,4 @@
busybox
busybox.links
_install
loop.h
Vendored
+33
View File
@@ -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
+69
View File
@@ -0,0 +1,69 @@
List of the authors of code contained in BusyBox.
If you have code in BusyBox, you should be listed here. If you should be
listed, or the description of what you have done needs more detail, or is
incorect, _please_ let me know.
-Erik
-----------
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
Brian Candler <B.Candler@pobox.com>
tiny-ls(ls)
Randolph Chung <tausq@debian.org>
fbset, ping, hostname, and mkfifo
Dave Cinege <dcinege@psychosis.com>
more(v2), makedevs, dutmp, modularization, auto links file,
various fixes, Linux Router Project maintenance
Karl M. Hegbloom <karlheg@debian.org>
cp_mv.c, the test suite, various fixes to utility.c, &c.
Daniel Jacobowitz <dan@debian.org>
mktemp.c
Matt Kraai <kraai@alumni.carnegiemellon.edu>
documentation, bugfixes
John Lombardo <john@deltanet.com>
dirname, tr
Glenn McGrath <bug1@netconnect.com.au>
ar.c
Bruce Perens <bruce@pixar.com>
Original author of BusyBox. His code is still in many apps.
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)
Enrique Zanardi <ezanardi@ull.es>
tarcat (since removed), loadkmap, various fixes, Debian maintenance
+648 -92
View File
@@ -1,46 +1,598 @@
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,
GNU libc 2.0 and 2.1, and various Linux kernels including
2.0.x, 2.2.x, and to 2.4.0-test*. (patch for 2.4.x kernels
to make /proc/mounts behave included in the kernel-patches dir).
* Fixed a _horrible_ bug where 'tar -tvf' could unlink
local files that matched tarball contents!!! Fix thanks
to Marius Groeger <mgroeger@sysgo.de>
* Fixed a nasty bug in tar when could mess up saved symlinks.
* Fixed tar creation support when reading from stdin ('tar -cf - . ')
thanks to Daniel Quinlan <quinlan@transmeta.com>
* Updates to handle Linux 2.4.0 kernels (kludged around the
"none" entries in /proc/mounts, added a hack to make sysinfo
work with both old and new kernels).
* Fixed insmod module option parsing for options lacking an '='.
Fix thanks to Marc Nijdam <marc_nijdam@hp.com>
* Fixed segfault with 'cut -f 1 -d:' and added 'cut -s' suport.
Fix thanks to Arne Bernin <arne@matrix.loopback.org>
* Several fixes from Marius Groeger <mag@sysgo.de>
- Added support for "sh -c command args..."
- Fixed globbing, i.e. 'echo * *' and 'echo "******"' now work.
- Added shell environment variable substitution
- Added the "read" shell builtin.
* Fixed cursor editing in cmdedit.c. The following keyboard sequence
used to create an infinite loop: ls, cursor up, left, down.
* Added support for being a login shell, so things like
'-su' or '-sh' (stuff where argv[0][0]=='-') will now always
invoke the shell. Now you can use BusyBox as a login shell.
* ls.c now ignores '-g', since some ftp clients like that sort
of thing. Patch thanks to David Vrabel <dvrabel@arcom.co.uk>
* Fix to init.c from Stuart Menefy <Stuart.Menefy@st.com> so that
it always sets the controlling terminal before running any programs
* Several fixes from Matt Kraai <kraai@alumni.carnegiemellon.edu>
- Fixed tr so it recognizes standard escape sequences.
Merged common escape seq. code from tr and echo into utility.c.
- Major work in updating/cleaning up the docs, and getting the
new SGML based docs into shape.
- cleanup of ar.c
- BusyBox should now poweroff when asked to do so.
- Fixed 'ln -n' and 'ln -s' so they both work properly.
* Reorganized signal names in kill.c for better architecture support
-- patch thanks to simon wood <simon@mungewell.uklinux.net>
* In 0.43, backspace and delete worked properly, but with 0.45,
it just echoed a ^? for backspace, and ^H for control-h. This
was due to a broken macro in init.c, that is now fixed.
* Removed sfdisk from BusyBox. It was buggy, fat, and we really
couldn't maintain it very well, so including it was not really
very appropriate. Those wanting an fdisk are invited to
grab a copy from util-linux.
* Added 'dumpkmap' to allow people to dump a binary keymap, which can
then be loaded in by 'loadkmap' -- submitted by
Arne Bernin <arne@matrix.loopback.org>
* Fixed NFS so it supports 2.4.x kernels and NFSv3.
* Brand, new versions of grep and sed which use libc regex routines,
thanks to Mark Whitley <markw@lineo.com>. The hand-tooled
"regexp.[ch]" files have been removed. Much help on these from
Matt Kraai as well.
-Erik Andersen, 11 July 2000
0.45
* Now compiles vs libc5 (which can save lots of space for
embedded systems).
* Added BB_FEATURE_TRIVIAL_HELP which compiles out most all of the
help messages (i.e --help). Saves 17k over a full compile.
* Added cut and tr from minix, since due to the license change,
we can now use minix code. Minix tr saves 4k.
* insmod now works. It costs 29k, but imagine an initrd with a
staticly linked busybox containing only insmod and sh, a few /dev
entries, and a kernel module or two... It doesn't get smaller
then this folks (I pity the fool that writes insmod in asm ;-).
Many kudos go to Ron Alder <alder@lineo.com> for finishing this off!
* Added a mini ar archive utility, especially written for BusyBox by
Glenn McGrath <bug1@netconnect.com.au>
* Added mktemp, contributed by Daniel Jacobowitz <dan@debian.org>
* Added setkeycodes, for those that have wierd keyboard buttons.
* Added md5sum, uuencode and uudecode -- thanks to Alfred M. Szmidt
<ams@trillian.itslinux.org> for contributing these.
* Added 'grep -v' option (inverted search) and updated
docs accordingly. -beppu
* Wrote which
* Replaced the telnet implementation with one written by
Tomi Ollila <too@iki.fi> It works great and costs 3k.
* BusyBox sh (lash) now supports being used as a standalone shell. When
BB_FEATURE_SH_STANDALONE_SHELL is defined, all the busybox commands may
be invoked as shell internals. Best used when compiling staticly
(i.e. DOSTATIC=true)
* BusyBox sh (lash) internals now behave as expected wrt pipes
and redirects.
* Fixed ping warnings -- fix from Sascha Ziemann <szi@aibon.ping.de>
* Fixed update segfault
* Fixed mknod -- minor number was always 0
* Fixed tar option parsing, so both "tar xvf foo.tar" and
"tar -xvf foo.tar" now work (i.e. no "-" before options)
(this was very broken in 0.43).
* Several contributions from Randolph Chung <tausq@debian.org>.
* cp/mv now accepts the -f flag
* tail can now accept -<num> commands (e.g. -10) for better
compatibility with the standard tail command
* added a simple id implementation; doesn't support sup. groups yet
* logname used getlogin(3) which uses utmp. Now it doesn't.
* whoami used getpwuid(3) which uses libc NSS. Now it behaves.
* Add support for "noatime" and "nodiratime" mount flags to mount.
* Changed 'umount -f' to mean force, and actually use umount2.
* Changed 'umount -l' to mean "Do not free loop device".
* Fixed basename to support stripping of suffixes. Patch thanks
to xiong jianxin <jxiong@uiuc.edu>
* cp -fa now works as expected for symlinks (it didn't before)
* zcat now works (wasn't working since option parsing was broken)
* Renamed "mnc" to the more correct "nc" (for netcat).
* Makefile intelligence updates
* Changed the way init parses /etc/inittab entries to avoid problems
with commands that contain colons in them. Fix thanks to
Pavel Roskin <proski@gnu.org>
* Fixed a warning in utility.c due to char being unsigned on Linux/PPC,
Fix thanks to Pavel Roskin <proski@gnu.org>
* Made "killall" complain (not error and exit) about processes that it
cannot find by name -- Pavel Roskin <proski@gnu.org>
* Fixed more and ps to have sensible terminal width defaults, thanks
to Pavel Roskin.
* Fixed all fatalError() calls lacking a "\n", thanks to Pavel Roskin.
* Fixed a segfault in yes when no args were given -- Pavel Roskin.
* Simplified freeramdisk and added argument checking -- Pavel Roskin.
* Fixed segfault caused by "touch -c"
* Fixed segfault caused by "rm -f"
* Fixed segfault caused by "ln -s -s" and similar abuses. Further fixes
and "--" support from Pavel Roskin.
* Fixed segfault caused by "cp -a -a" and similar abuses.
* Implemented "rm -- <foo>". Implementation fixed by Pavel Roskin.
* "which" rewritten to use stat(). Fixes to improve its compatability
with traditional implementations -- Pavel Roskin.
* "mount" now reports errors from nfsmount() and assumes NFS mount
if ':' is present in the device name - Pavel Roskin
* Fixed exit status for killall - Pavel Roskin
* Fixed 'swapon -a' and 'swapoff -a', which were broken.
* Fixed 'mount -a' so it works as expected.
* Implemented 'ls -R' (enabled by enabling BB_FEATURE_LS_RECURSIVE)
* Implemented "ping -s", fixed error messages and argument parsing -
Pavel Roskin
* Syslogd will not go to background if "-n" is given. Better help
and argument checking -- Pavel Roskin
* Fixed a small bug that could cause tar to emit warning messages
and not extract the first file in a directory in some cases
of nested directories. Thanks to Kevin Traas <kevin@netmaster.com>
for helping track this one down.
* More doc updates
* Fixed grep "Line too long" problem -- John Beppu
* Fixed 'grep -q -i B some_file' so it works
* math takes input from stdin if no args are given. -- John Beppu
* math was renamed to dc. Although it deviates from dc's behaviour,
this will probably be remedied in the future. -- John Beppu
-Erik Andersen, June 21, 2000
0.44
Previously, an erronous announcement of BusyBox 0.44 was made, so to
avoid possible confusion, we are skipping straight to 0.45, and calling
it good.
-Erik Andersen
0.43
* Major update to the provided documentation.
* Busybox now includes a shell! It currently costs 7.5 k (plus an
additional 2.5 k if you compile in command line editing). Handles
job control, has the usual set of builtins, and does everything
except for handling programming statements (if, while, etc...)
* Busybox can now work perfectly when /proc is disabled, thereby
saving a bunch of memory (kernel /proc support is not thin). This
is done by making use of some nice kernel patches I wrote up to
support the features that busybox requires and that /proc usually
provides. To enable this, turn on BB_FEATURE_USE_DEVPS_PATCH and
patch your kernel with the devps patch in the kernel-patches/
directory.
* Wrote basename, dirname, killall, and uptime.
* tar has been completely rewritten by me. Both tar creation and
extraction are now well behaved. Costs 7.6k with all optional
tar features enabled, and 5k for just tar extraction support.
* Added freeramdisk, which will free up all memory associated
with a ram disk. Contributed by Emanuele Caratti <wiz@iol.it>
and then adjusted a bit by me.
* Added tr from John Lombardo <john@deltanet.com>
* Added echo and test (from me).
* Added usleep contributed by Nicolas Pitre <nico@cam.org>
* BusyBox's bss size has been majorly reduced (was 384668, is now 28740).
* Several fixes from Pavel Roskin <proski@gnu.org>:
- When `tail' fails to open a file it now exits.
- When `syslogd' is given the `-n' option it should still use
fork() for running klogd.
* nslookup types are now changed to u_int32_t (instead of uint32_t)
changed per a patch from Pascal Bellard <pascal.bellard@ascend.com>
* Fixed "du" so it gives the same answers as GNU "du" (busybox du used
to count hard-linked files more then once). Many thanks to
Friedrich Vedder <fwv@myrtle.lahn.de> for the fix.
* Removed /proc dependancies for init and free (while maintaining
exactly the same functionality). /proc takes up 90k of kernel
space, so it is nice to avoid using it at all costs.
* init no longer tries to mount /proc (unless there is less the 1 meg
free). Use of /proc (or not) is policy that should be set up in
/etc/fstab (or in hardcoded scripts), not in init.
* Fixed rebooting when init runs as an initrd.
* Fixes and updates from Karl M. Hegbloom <karlheg@debian.org>
- update.c rewritten to look more like update-2.11
- moveed the inode hash out of du.c and into utility.c to make
it a common resource that can be used by other apps.
- cp_mv.c now checks inodes to see if a source and dest are
the same, and prints an error (instead of endlessly looping).
- mv now attempts to do a rename, and will fall back to doing
a copy only if the rename fails.
- Syslogd now supports multiple concurrent connections
* Several fixes from Pavel Roskin <proski@gnu.org>:
- Fixes to sort. Removed "-g", fixed and added "-r"
- Fixes to the makefile for handling "strip"
* An initial telnet implementation was added by
Randolph Chung <tausq@debian.org>.
* Fixed a bug where "sed 's/foo/bar/g'" (i.e. a script w/o a "-e")
* ps now supports BB_FEATURE_AUTOWIDTH, and can adjust its width
to match the terminal (defaults to width=79 when this is off).
* ps now accepts (and ignores) all options except for "--help" (which
as would be expected displays help).
* Fixed mount'ing loop devices when the filesystem type was not
specified. It used to revert to non-loop after the first try.
* all mallocs now use xmalloc (and so are OOM error safe), and
the common error handling saves a few bytes. Thanks to
Bob Tinsley <bob@earthrise.demon.co.uk> for the patch.
* Fix "+" parsing bug in date, from "Merle F. McClelland" <mfm@cts.com>.
* Fix symlink following bug in chmod -R and friends.
* Now allows SYSV style 'chown foo:bar' in addition to 'chown foo.bar'
* Fixed a bug in the busybox globbing routine such that 'find /dir -name [i]'
no longer segfaults.
-Erik Andersen
0.42
* Fairly massive restructuring of umount.c to deal with remounting
busy devices read-only. Adds a -r option to control that; it is
optionally compiled in with BB_FEATURE_REMOUNT
* Added a bunch of functions to mtab.c to interact with the
{get,set,end}mntent interface; as it turns out, those functions do
not appear to be re-entrant, and that causes a lot of problems with
the way umount was originally written.
* Makes init send TERM and KILL (instead of HUP and KILL) on reboot
to be more consistent with sysvinit
* Changes to init.c to use the new -r option to umount. Also increased
the sleep time between the time the TERM and KILL signals are sent
- Randolph Chung
* cp.c, mv.c: removed, replaced by cp_mv.c which has been
extensively rewritten from the original cp.c.
* Fixed cp and mv so if the source and destination are a the
same directory it will print an error and continue.
* Also added a warning message to the `mv' usage string saying that
this is not GNU mv, and it will break hard links. cp also breaks
hard links.
* ln.c: implemented `-n' switch, no-deref symlinks.
* include<sys/param.h>: and use PATH_MAX everywhere. busybox: File
* name buffer overrun guards to prevent future crashes.
- Always check exit status.
- Purge all use of `creat()', replace with `open()'.
* utility.c
- recursiveAction was overriding the value of followLinks thus
ignoring it.
- isDirectory now takes a followLinks boolean, updated all callers
- copyFile had the followLinks logic reversed.
* messages.c: New file. Put common error message strings all in
one place in an attempt to shrink the binary a little.
-Karl M. Hegbloom
* changed fsck_minix.c to reduce its .bss size significantly
-beppu -piptigger
* Made tar creation support in busybox tar optional. You no longer
* _have_ to put a "-" in front of tar options. Tar could inadvertently
* change permissions and ownership on
certain directories pointed to by symlinks.
* Made grep and grep -h do the right thing wrt printing
the file name (it failed to print files names in many cases).
* Fix a namespace aliasing problem wereby if du was built in, the
symlink for both du and dutmp would be installed, or then rm was
built in, the symlinks for both rm and rmmod would be installed.
* Added a closelog() to init.c after loging -- fix thanks to
Taketoshi Sano <kgh12351@nifty.ne.jp>
* Rewrote and simplified logger. Added the "-t" option, and made it
behave itself a bit better.
* Optional support contributed by Ben Collins <bcollins@debian.org>
for the kernel init chroot patch by Werner Almesberger, which
allows init to chroot to a new device, and umount the old one.
* Fixed bug that wouldn't let one chown a symlink -- it would
always dereference before. -beppu
* Fixed a bug where init could have reference already freed memory.
Found and fixed by Taketoshi Sano <kgh12351@nifty.ne.jp>
* Several contributions from Friedrich Vedder <fwv@myrtle.lahn.de>
* Added (and documented) "-n" option for head
* Cleanup for a number of usage messages -- also
contributed Friedrich Vedder <fwv@myrtle.lahn.de>
* Cosmetic fix to busybox.c (Don't print a comma at the
end of line if there are no more application names).
* Fixed a stupid bug in "head" option handling ("head -n"
would segfault).
* Moved commonly used functions "xmalloc()" and "exit()"
to utility.c (with proper #ifdef's).
* Created a tiny tail implementation, removing -c, -q, -v, and making
tail -f work only with a single file. This reduced tail from 6k to
2.4k. The bigger/more featured tail can still be had by disabling
BB_FEATURE_SIMPLE_TAIL in busybox.defs.h
* Ping now falls back to doing the right thing if /etc/protocols
turns up missing.
* Fixed mount and umount. Previously they could leak loop device
allocations, causing the system to quickly run out. Fix for umount
by Ben Collins <bcollins@debian.org>, and mount was fixed by me.
* ls formatting on eight charactor user names fixed by
Randolph Chung <tausq@debian.org>.
* cp could, when copying symlinks, change permissions of the
files pointed to by the symlinks.
* Several fixes from Pavel Roskin <proski@gnu.org>:
- `chown' with 1 argument displayed the error incorrectly
- `fdflush', `length' and `printf' crashed if run without arguments
- `fdflush' tried to flush itself using *argv
- added "skip" and "seek" to dd.
- ls no longer messus up output when combining files and
directories on the command line
* swapoff -a was not working. Now it is.
* init did not cleanly unmount filesystems on reboot. Now it does.
* "sed -ne s/foo/bar/" worked but "sed -n -e s/foo/bar/" didn't.
Now both work.
* Some architectures (PowerPc) assume chars are unsigned, so they could
not distinguish between EOF and '\0xFF' in sed. Sed now uses ints.
* Began converting error handling to use some common routines
in utility.c
* syslogd now has better message handling and ignores SIGHUP.
* install.sh had a bug preventing installation to the specified
target directory. Fix from Gilbert Coville <gilbert@mvista.com>
* You can now spefify alternative strip commands -- change
also from Gilbert Coville.
-Erik Andersen
0.41
* New Apps: wc, hostid, logname, tty, whoami, yes -- all contributed
by Edward Betts <edward@debian.org>
* Fixed a bug in both cp and mv preventing 'cp foo/README bar'
type commands (file in a directory to another directory) from
working.
* Fixed a logger bug that caused garbage to be written to the syslog
(unless you used busybox syslog, which hid the bug). Thanks to
Alex Holden <alex@linuxhacker.org> for the fix.
* /bin/true and /bin/false were echoing a blank line when run.
Now fixed.
* mkdir -p would print an error when asked to mkdir an existing dir
with no interveining subdirectories.
* Fixed "syslogd -O" so that it works. Added -o loop option for mount,
* and support in umount for loop
devices. Support is toggled by MOUNT_LOOP feature -- Ben Collins
<bcollins@debian.org>
* Several fixes from Marco Pantaleoni <panta@prosa.it> compile in
* fullWrite() not only if BB_TAR is defined, but also
if BB_CP or BB_MV are (fullWrite() is referenced by copyFile())
* add some compiler optimizations to further reduce executable size
(as a side note, on my machines the largest code is generated
by gcc 2.95.2 with -Os ! The smallest by plain gcc 2.7.2.3 with
-O2 -m386 ...)
* Compile now won't fail if busybox.def.h defines
BB_FEATURE_LINUXRC but not BB_INIT. (init_main used to be
referenced, but not compiled)
* Fixed a bug in setting TERM for serial console support. TERM now
defaults to "ansi" for serial consoles.
* Fixed a bug in handling the CONSOLE env. variable for serial
* consoles.
-Erik Andersen, Jan 15, 2000
0.40
* New Apps: sort, uniq. -beppu New Apps: lsmod, rmmod -erik New Apps:
* fbset contributed by Randolph Chung <tausq@debian.org>. New App::
* loadacm contributed by Peter Novodvorsky <petya@logic.ru>
for loading application character maps for Unicode fonts.
* Major init re-work. init now supports inittab (slightly different
but similar to sysvinit), allowing me to get all the policy out of
init and into the conf file. It works just fine without inittab
being present, but if you dont like the defautl behavior you can
now do something about it. Init is much cleaner as a result.
* Fixed an bug in syslogd causing it to stop after 20 minutes. -erik
* Fixed an embarrasing segfault in head -beppu Fixed the embarrasing
* failure of 'logger -p'. -erik Added the -s option to du -beppu
* Re-worked the source tree a bit so it will compile under glibc 2.0.7
with the 2.0.x Linux kernel.
* Added 'grep -q' thanks to a patch from "Konstantin Boldyshev"
<konst@voshod.com>.
* Grep -i previously failed on UPPER CASE patterns due to a silly
regexp implementation bug that is now fixed.
* Fixed a bug where tar would set, and then clear SGID and SUID bits.
* Fixed a bug where tar would not set the user and group on device
special files.
* Fixed a bug where tar would not restore the time to files. Fixed a
* major security problem with tar -- it changed ownership
of any file pointed to by a symlink to 777 (like say libc....)
Ouch!!!
* cp and mv were very broken when moving directories. I have rewritten
them so they should now work as expected.
* sed now supports addresses (numeric or regexp, with negation) and
has an append command, thanks to Marco Pantaleoni <panta@prosa.it>
* Fixed dmesg. It wasn't parsing its options (-n or -s) properly.
* Some cosmetic fixes to ls output formatting to make it behave more
like GNU ls.
* Fixed a stupid segfault in kill. Several fixes from Friedrich Vedder
* <fwv@myrtle.lahn.de>:
- Added gunzip -t, removed gunzip.c dead code,
- fixed several typos
- Glibc 2.0.7 and libc5 compile fixes
* Fixed a bug where 'mknod --help' would segfault.
-Erik Andersen, Jan 07, 2000
0.39
* New Apps: ping, hostname, and mkfifo contributed by Randolph Chung
<tausq@debian.org>. 3 items off the TODO list!
* I wrote free (just calls "cat /proc/meminfo"). Added tail, based on
* tail from GNU textutils-1.19, but adjusted
to suit my evil purposes. Costs 6k. I'll make it smaller
sometime.
* on reboot, init called 'umount -a -n', which caused errors
when BB_MTAB was not enabled. Changed to 'umount -a', which does
the right thing.
* init will now try to run /sbin/getty if it is present (for easy
integration with the about-to-be-released tinylogin.)
* kill now behaves itself properly, added 'kill -l' to list signals 'ls
* -l' was failing on long directories, since my_getid was leaking
one file descriptor per file. Oops.
* Fixed rebooting from init. I'd accidently left some debugging code
* in
which blocked reboots.
* Fixed reboot, halt (and added poweroff) such that they handle it when
init is not at PID 1 (like when running in an initrd).
* Added a prelinary du implementation. Some parameter parsing
stuff still needs to be added. -beppu (John Beppu
<beppu@lineo.com>)
* Implemented tee. -beppu Implemented head. -beppu
-Erik Andersen, Dec 10, 1999
0.38
* Fixed a segfault in 'umount -a' when a badly formed /etc/fstab
file existed.
* df will not exit on error, but will stat all mounted filesystems.
* Fixed tar so uid/gid/permissions on extracted tarballs will be
correct.
* Fixed find -name so it properly uses shell wildcard patterns
(i.e. `*', `?', and `[]') instead of regular expressions, which
was causing some confusing and unexpected behavior.
* Added klogd to syslogd, so now the log will contain both system and
kernel messages.
* syslogd now creates the /dev/log socket to make sure it is there, and
is actually a socket with the right permissions.
* I've taken a first step to making busybox not need the /proc
filesystem. Most apps don't need it. Those that _require_ it,
will complain if you enable them when you disable
BB_FEATURE_USE_PROCFS.
-Erik Andersen, Dec 5, 1999
0.37
* Wrote a micro syslogd, and a logger util (to log things to the syslog
from the command line or scripts) With both compiled in, costs 4k.
* Fixed 'make install' so symlinks are installed in their proper
* locations. Changed the build system slightly so that features can
* now be enabled
or disabled from the busybox.defs.h header file, without trying to
compile in a source file named after that featue (unless that file
exists).
* Several options are now moved into busybox.defs.h Now 'rm -R' and 'rm
* -r' both work. dd now properly handles input beyond 1 block from
* stdin. Fixed a bug where tar unpacked everything a directories.
* Moved some code
from createPath into mkdir where it belonged, thereby making tar
work properly.
* Fixed an off-by-one bug in cat. Given a list of file it wouldn't cat
* out the
last file in the list.
* Fixed 'ls -ln' so numeric group/uid are presented properly, and fixed
* 'ls -l'
so when uid/gid is not in /etc/{passwd,group} the numeric group/uid
are presented properly.
* Also added a TODO.
-Erik Andersen, Nov 25, 1999
0.36
* fixed dd so it properly defaults to stdin and stdout when no
if= and of= are set (fix thanks to Eric Delaunay).
* Don't try to close the file descriptor of a pipein tar. (fix also from
* Don't try to close the file descriptor of a pipein tar. (fix also
* from
Eric Delaunay).
* Made createPath be quiet (again thanks to Eric Delaunay).
* If BB_CONSOLE_CMD_IF_RC_SCRIPT_EXITS is defined, then whatever
* Made createPath be quiet (again thanks to Eric Delaunay). If
* BB_CONSOLE_CMD_IF_RC_SCRIPT_EXITS is defined, then whatever
command you define it as will be run if the init script exits.
* Updated install.sh to make it more robust (thanks to Adam Di Carlo)
* NFS support added to mount by Eric Delaunay. It costs 10k when compiled
* NFS support added to mount by Eric Delaunay. It costs 10k when
* compiled
in, but that is still a big win for those that use NFS.
* Made 'rm -f' be silent for non-existant files (thanks to Eric Delaunay).
* changed zcat.c to gunzip.c. It now obeys the principle of least surprise
and acts as god intended gunzip and zcat to act. They answer --help and
obey the '-c' flag.
* Fixed a bug in mv which caused it to not move files when the destination
* Made 'rm -f' be silent for non-existant files (thanks to Eric
* Delaunay). changed zcat.c to gunzip.c. It now obeys the principle
* of least surprise
and acts as god intended gunzip and zcat to act. They answer
--help and obey the '-c' flag.
* Fixed a bug in mv which caused it to not move files when the
* destination
was a directory.
* Fixed a decimal-instead-of-octal bug causing mkdir to make directories
* Fixed a decimal-instead-of-octal bug causing mkdir to make
* directories
with very wrong permissions.
* chmod would overwrite file permissions instead of modifying them.
Now it properly modifies permissions.
* Init now sends warnings destined for the console to /dev/console to ensure
they show up on whatever the active console it. Otherwise important
messages (for example that the system is rebooting) were not seen when
switched to a different VT.
* Init now sends warnings destined for the console to /dev/console to
* ensure
they show up on whatever the active console it. Otherwise
important messages (for example that the system is rebooting) were
not seen when switched to a different VT.
-Erik Andersen, Nov 17, 1999
0.35
* gzip now obeys the principle of least surprise and acts like god intended
(i.e. it accepts a file name, answers --help, and obeys the '-c' flag
and only then outputs to stdout).
* gzip now obeys the principle of least surprise and acts like god
* intended
(i.e. it accepts a file name, answers --help, and obeys the '-c'
flag and only then outputs to stdout).
* Fixed more.c to compile autowidth on sparc and set initial winsize
to 0,0 in case the TIOCGWINSZ ioctl fails. Fix thanks to Eric Delaunay.
to 0,0 in case the TIOCGWINSZ ioctl fails. Fix thanks to Eric
Delaunay.
* Fixed tar so it now works as expected (it had TRUE/FALSE backwards)
* tar now accepts --help
* chmod, chown, and chgrp usage now works
* General usage (i.e. --help) cleanups for most apps
* umount now parses options correctly
* tar can now unpack tarballs containing device special files,
sockets, and fifos (though it can't pack them up) thanks
to Matt Porter. Creating archives containing these is still
left to the interested student.
* tar now accepts --help chmod, chown, and chgrp usage now works
* General usage (i.e. --help) cleanups for most apps umount now parses
* options correctly tar can now unpack tarballs containing device
* special files,
sockets, and fifos (though it can't pack them up) thanks to Matt
Porter. Creating archives containing these is still left to the
interested student.
* fixed up the license in more.c to properly point to Bruce Perens.
-Erik Andersen, Nov 11, 1999
@@ -50,17 +602,17 @@
Patch thanks to Eric Delaunay
* init now properly handles sparc serial consoles and does a
better job of finding the real console device rather than using
/dev/console which doesn't support job control. Patch also
thanks to Eric Delaunay.
/dev/console which doesn't support job control. Patch also thanks
to Eric Delaunay.
* more started to read from stdin after the last file was finished, and
options were not parsed correctly (fix thanks to Eric Delaunay).
* more will now use the terminal size if BB_FEATURE_AUTOWIDTH is on.
* rm wouldn't remove a symlink unless the symlink was valid. This was
a side effect of the busybox 0.32 recursiveAction() fix. Things
a side effect of the busybox 0.32 recursiveAction() fix. Things
should now work correctly.
* grep wouldn't grep stdin. Now it does.
* sed wouldn't sed stdin. Now it does.
* sed was appending a \n to the end of lines with replacements.
* grep wouldn't grep stdin. Now it does. sed wouldn't sed stdin. Now
* it does. sed was appending a \n to the end of lines with
* replacements.
Now it doesn't do that.
* ls -l now bypasses libc6 nss when displaying user/group names.
Now uses my_getpwuid and my_getgrgid.
@@ -81,45 +633,45 @@
0.32
* More changes -- many thanks to Lineo for paying me to work on
busybox. If you have any problems please let me know ASAP
at andersen@lineo.com or andersee@debian.org
busybox. If you have any problems please let me know ASAP at
andersen@lineo.com or andersee@debian.org
* usage() now prints the BusyBox version. This will help folks
realize that they are not in Kansas anymore.
* Fixed mkdir -m option so that it works.
* kill segfaulted w/o any arguments. Now it doesn't do that.
* kill wasn't properly accepting signal names. It does now.
* Added new apps chvt and deallocvt (I should probably add open)
* Major rewrite of init.c. Code is now readable by mere mortals IMHO.
* Wrote sed -- weighs only 1.8k (5.8k with full regular expressions!).
* Fixed a stupid seg-fault in sync
* Fixed mount -- mount -a failed to parse and apply mount options
* Fixed umount -n (patch thanks to Matthew Grant <grantma@anathoth.gen.nz>)
* umount -a no longer umounts /proc
* Added BB_MTAB, allowing (at the cost of ~1.5k and the need for a rw /etc)
folks to use a real /etc/mtab file instead of a symlink to /proc/mounts.
mount, and umount will add/remove entries and df will now use /etc/mtab
if BB_MTAB is defined.
* Fixed mkdir -m option so that it works. kill segfaulted w/o any
* arguments. Now it doesn't do that. kill wasn't properly accepting
* signal names. It does now. Added new apps chvt and deallocvt (I
* should probably add open) Major rewrite of init.c. Code is now
* readable by mere mortals IMHO. Wrote sed -- weighs only 1.8k (5.8k
* with full regular expressions!). Fixed a stupid seg-fault in sync
* Fixed mount -- mount -a failed to parse and apply mount options Fixed
* umount -n (patch thanks to Matthew Grant <grantma@anathoth.gen.nz>)
* umount -a no longer umounts /proc Added BB_MTAB, allowing (at the
* cost of ~1.5k and the need for a rw /etc)
folks to use a real /etc/mtab file instead of a symlink to
/proc/mounts. mount, and umount will add/remove entries and df
will now use /etc/mtab if BB_MTAB is defined.
* Fixed a nice bug in recursiveAction() which caused it to infinitely
hunt through /proc/../fd/* creating new file descriptors if it
followed the /dev/fd link over to /proc. recursiveAction() now
lstat's the file when followLinks==FALSE so it won't follow links
as the name suggests. Fix thanks to Matt Porter <porter@debian.org>.
followed the /dev/fd link over to /proc. recursiveAction() now
lstat's the file when followLinks==FALSE so it won't follow links
as the name suggests. Fix thanks to Matt Porter
<porter@debian.org>.
-Erik Andersen, Nov 4, 1999
0.31
* I added a changelog for version 0.30.
* adjusted find internals to make it smaller, and removed
* I added a changelog for version 0.30. adjusted find internals to
* make it smaller, and removed
some redundancy.
* Fixed a segfault in ps when /etc/passwd or /etc/group
are absent. Now will warn you and carry on.
* Added in optional _real_ regular expression support (to be
the basis for a future sed utility). When compiled in
it adds 3.9k, but makes grep much more capable.
the basis for a future sed utility). When compiled in it adds
3.9k, but makes grep much more capable.
* Checked out using nftw(3) for recursive stuff, but unfortunatly
it wasn't supported before GNU libc 2.1, and some folks use
glibc 2.0.7 since it is much smaller than that latest and greatest.
it wasn't supported before GNU libc 2.1, and some folks use glibc
2.0.7 since it is much smaller than that latest and greatest.
-Erik Andersen, Oct 21, 1999
@@ -133,8 +685,8 @@
* busybox can now invoke apps in two ways: via symlinks to the
busybox binary, and as 'busybox [function] [arguments]...'
* When invoked as busybox, the list of currently compiled in
functions is printed out (no this is not bloat -- the list
has to be there anyway to map invocation name to function).
functions is printed out (no this is not bloat -- the list has
to be there anyway to map invocation name to function).
* busybox no longer parses command lines for apps or displays their
usage info. Each app gets to handle (or not handle) this for
itself.
@@ -145,9 +697,9 @@
* All shared code now lives in utility.c, and is properly
ifdef'ed to be only included for those apps requiring it.
* Eliminated struct FileInfo (the basis of monadic, dyadic, etc)
so now each app has the function prototype of (da-dum):
extern int foo_main(int argc, char** argv);
which speeds integration of new apps.
so now each app has the function prototype of (da-dum): extern
int foo_main(int argc, char** argv); which speeds integration
of new apps.
* Adjusted the Makefile to make it easier to
{en|dis}able debugging.
* Changed default compiler optimization to -Os
@@ -156,39 +708,43 @@
App Changes:
* To cope with the new app function prototype and the removal of
monadic, dyadic, etc, the following apps were re-written:
* cat - Works same as always.
* chgrp, chmod, chown - rewrite. Combined into a single
source file. Absorbed patches from Enrique Zanardi <ezanard@debian.org>
that removes the dependency on libc6 libnss* libraries.
* cat - Works same as always. chgrp, chmod, chown -
* rewrite. Combined into a single
source file. Absorbed patches from Enrique Zanardi
<ezanard@debian.org> that removes the dependency on
libc6 libnss* libraries.
* cp - Can now do 'cp -a' can can copy devices,
pipes, symlinks, as well as recursive or non-recursive dir copies.
* fdflush - adjusted to remove dependancy on struct FileInfo.
* find - Now includes some basic regexp matching
pipes, symlinks, as well as recursive or non-recursive
dir copies.
* fdflush - adjusted to remove dependancy on struct
* FileInfo. find - Now includes some basic regexp matching
which will be the basic of a future mini-sed.
* ln - Same functionality.
* mkdir - Added -p flag to feature set.
* mv - rewrite.
* rm - Added -f flag to feature set.
* rmdir - Same functionality.
* swapon, swapoff - Combined into a single binary. No longer
uses /etc/swaps. swap{on|off} -a uses /etc/fstab instead.
* touch - Same functionality.
* date - adjusted with a patch from Matthew Grant <grantma@anathoth.gen.nz>
to accomodate glibc timezone support. I then ripped out GNU getopt.
* mkswap -- new version merged from util-linux. Can now make >128Meg swaps.
* Replaced the old and star, unstar, and tarcat with the tar
implementation from sash. Now tar behaves as god intended
it to (i.e. tar -xvf <file> and tar -cf <file> <dir> work).
* dd -- rewritten. Can with with files, stdin, stdout.
* Added the following new apps:
* loadfont -- added from debian boot floppies
* chroot -- added based on a patch from Paolo Molaro <lupus@lettere.unipd.it>
* grep -- I just wrote it. Only matches simple strings
* ps -- I just wrote it. Has _no_ options at all, but works.
* fsck_minix, mkfs_minix -- added from util-linux, but I ripped out
* ln - Same functionality. mkdir - Added -p flag to
* feature set. mv - rewrite. rm - Added -f flag to
* feature set. rmdir - Same functionality. swapon,
* swapoff - Combined into a single binary. No longer
uses /etc/swaps. swap{on|off} -a uses /etc/fstab
instead.
* touch - Same functionality. date - adjusted with a patch
* from Matthew Grant <grantma@anathoth.gen.nz>
to accomodate glibc timezone support. I then ripped out GNU
getopt.
* mkswap -- new version merged from util-linux. Can now make
>128Meg swaps.
* Replaced the old and star, unstar, and tarcat with the tar
implementation from sash. Now tar behaves as god intended it
to (i.e. tar -xvf <file> and tar -cf <file> <dir> work).
* dd -- rewritten. Can with with files, stdin, stdout. Added the
* following new apps: loadfont -- added from debian boot floppies
* chroot -- added based on a patch from Paolo Molaro
* <lupus@lettere.unipd.it> grep -- I just wrote it. Only matches
* simple strings ps -- I just wrote it. Has _no_ options at all,
* but works. fsck_minix, mkfs_minix -- added from util-linux, but
* I ripped out
internationalization and such to make them smaller.
* sfdisk -- Added from util-linux (minus internationalization and such).
* Probably some other changes that I forgot to document...
* sfdisk -- Added from util-linux (minus
* internationalization and such). Probably some other
* changes that I forgot to document...
-Erik Andersen, Oct 20, 1999
+329
View File
@@ -0,0 +1,329 @@
/* vi: set sw=4 ts=4: */
// 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
#define BB_CLEAR
#define BB_CP_MV
#define BB_CUT
#define BB_DATE
#define BB_DC
#define BB_DD
#define BB_DEALLOCVT
#define BB_DF
#define BB_DIRNAME
#define BB_DMESG
#define BB_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
#define BB_HALT
#define BB_HEAD
#define BB_HOSTID
#define BB_HOSTNAME
#define BB_ID
#define BB_INIT
#define BB_INSMOD
#define BB_KILL
#define BB_KILLALL
#define BB_LENGTH
#define BB_LN
#define BB_LOADACM
#define BB_LOADFONT
#define BB_LOADKMAP
#define BB_LOGGER
#define BB_LOGNAME
#define BB_LS
#define BB_LSMOD
#define BB_MAKEDEVS
#define BB_MD5SUM
#define BB_MKDIR
#define BB_MKFIFO
#define BB_MKFS_MINIX
#define BB_MKNOD
#define BB_MKSWAP
#define BB_MKTEMP
#define BB_NC
#define BB_MORE
#define BB_MOUNT
#define BB_MT
#define BB_NSLOOKUP
#define BB_PING
#define BB_POWEROFF
#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
#define BB_SED
#define BB_SETKEYCODES
#define BB_SH
#define BB_SLEEP
#define BB_SORT
#define BB_SWAPONOFF
#define BB_SYNC
#define BB_SYSLOGD
#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_UNRPM
#define BB_UPTIME
#define BB_USLEEP
#define BB_WC
#define BB_WGET
#define BB_WHICH
#define BB_WHOAMI
#define BB_UUENCODE
#define BB_UUDECODE
#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
//
//
//
// ---------------------------------------------------------
// 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
//
// enable ls -L
#define BB_FEATURE_LS_FOLLOWLINKS
//
// 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
+326
View File
@@ -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
+1 -1
View File
@@ -26,7 +26,7 @@ Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
Please feed suggestions, bug reports, insults, and bribes back to:
Erik Andersen
<andersen@lineo.com>
<andersee@deban.org>
<andersee@debian.org>
+188 -70
View File
@@ -1,5 +1,8 @@
# Makefile for busybox
#
# Copyright (C) 1999-2000 Erik Andersen <andersee@debian.org>
# Copyright (C) 2000 Karl M. Hegbloom <karlheg@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
@@ -15,101 +18,216 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
PROG := busybox
VERSION := 0.47
BUILDTIME := $(shell TZ=UTC date --utc "+%Y.%m.%d-%H:%M%z")
export VERSION
PROG=busybox
VERSION=0.36
BUILDTIME=$(shell date "+%Y%m%d-%H%M")
# If you want a static binary, turn this on.
DOSTATIC = false
# Comment out the following to make a debuggable build
# Leave this off for production use.
DODEBUG=false
# If you want a static binary, turn this on. I can't think
# of many situations where anybody would ever want it static,
# but...
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 will choke on a non-debian system
ARCH=`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
# 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
GCCMAJVERSION=`$(CC) --version | sed -n "s/^\([0-9]\)\.\([0-9].*\)[\.].*/\1/p"`
GCCMINVERSION=`$(CC) --version | sed -n "s/^\([0-9]\)\.\([0-9].*\)[\.].*/\2/p"`
GCCSUPPORTSOPTSIZE=$(shell \
if ( test $(GCCMAJVERSION) -eq 2 ) ; then \
if ( test $(GCCMINVERSION) -ge 95 ) ; then \
echo "true"; \
else \
echo "false"; \
fi; \
else \
if ( test $(GCCMAJVERSION) -gt 2 ) ; then \
echo "true"; \
else \
echo "false"; \
fi; \
fi; )
# 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
ifeq ($(GCCSUPPORTSOPTSIZE), true)
OPTIMIZATION=-Os
else
OPTIMIZATION=-O2
# 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 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$(LIBCDIR)/include -I$(GCCINCDIR)
#LDFLAGS+=-nostdlib
#LIBRARIES = $(LIBCDIR)/libc.a
#--------------------------------------------------------
# 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
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 -DDEBUG_INIT
STRIP=
LDFLAGS=
CFLAGS += $(WARNINGS) -g -D_GNU_SOURCE
LDFLAGS +=
STRIP =
else
CFLAGS+=-Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
LDFLAGS= -s
STRIP= strip --remove-section=.note --remove-section=.comment $(PROG)
#Only staticly link when _not_ debugging
ifeq ($(DOSTATIC),true)
LDFLAGS+= --static
endif
CFLAGS += $(WARNINGS) $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE
LDFLAGS += -s
STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment $(PROG)
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`/busybox_install
PREFIX = `pwd`/_install
endif
LIBRARIES=
OBJECTS=$(shell ./busybox.sh)
CFLAGS+= -DBB_VER='"$(VERSION)"'
CFLAGS+= -DBB_BT='"$(BUILDTIME)"'
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
busybox: $(OBJECTS)
$(CC) $(LDFLAGS) -o $(PROG) $(OBJECTS) $(LIBRARIES)
all: busybox busybox.links doc
doc: olddoc
# Old Docs...
olddoc: docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
docs/BusyBox.txt: docs/busybox.pod
@echo
@echo BusyBox Documentation
@echo
- pod2text docs/busybox.pod > docs/BusyBox.txt
docs/BusyBox.1: docs/busybox.pod
- pod2man --center=BusyBox --release="version $(VERSION)" docs/busybox.pod > docs/BusyBox.1
docs/BusyBox.html: docs/busybox.lineo.com/BusyBox.html
- rm -f docs/BusyBox.html
- ln -s busybox.lineo.com/BusyBox.html docs/BusyBox.html
docs/busybox.lineo.com/BusyBox.html: docs/busybox.pod
- pod2html --noindex docs/busybox.pod > docs/busybox.lineo.com/BusyBox.html
- rm -f pod2html*
# New docs based on DOCBOOK SGML
newdoc: docs/busybox.txt docs/busybox.pdf docs/busybox/busyboxdocumentation.html
docs/busybox.txt: docs/busybox.sgml
@echo
@echo BusyBox Documentation
@echo
(cd docs; sgmltools -b txt busybox.sgml)
docs/busybox.dvi: docs/busybox.sgml
(cd docs; sgmltools -b dvi busybox.sgml)
docs/busybox.ps: docs/busybox.sgml
(cd docs; sgmltools -b ps busybox.sgml)
docs/busybox.pdf: docs/busybox.ps
(cd docs; ps2pdf busybox.ps)
docs/busybox/busyboxdocumentation.html: docs/busybox.sgml
(cd docs/busybox.lineo.com; sgmltools -b html ../busybox.sgml)
busybox: $(OBJECTS)
$(CC) $(LDFLAGS) -o $@ $^ $(LIBRARIES)
$(STRIP)
busybox.links:
busybox.links: Config.h
- ./busybox.mkll | sort >$@
nfsmount.o cmdedit.o: %.o: %.h
$(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 $(PROG) busybox.links *~ *.o core
- rm -rf busybox_install
cd tests && $(MAKE) clean
- rm -f docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html \
docs/busybox.lineo.com/BusyBox.html
- rm -f docs/busybox.txt docs/busybox.dvi docs/busybox.ps \
docs/busybox.pdf docs/busybox.lineo.com/busybox.html
- rm -rf docs/busybox _install
- rm -f busybox.links *~ *.o core
distclean: clean
- rm -f $(PROG)
- rm -f busybox
- cd tests && $(MAKE) distclean
force:
$(OBJECTS): busybox.def.h internal.h Makefile
install: busybox
install: busybox busybox.links
./install.sh $(PREFIX)
whichversion:
@echo $(VERSION)
install-hardlinks: busybox busybox.links
./install.sh $(PREFIX) --hardlinks
dist release: distclean doc
cd ..; \
rm -rf busybox-$(VERSION); \
cp -a busybox busybox-$(VERSION); \
\
find busybox-$(VERSION)/ -type d \
-name CVS \
-print \
| xargs rm -rf; \
\
find busybox-$(VERSION)/ -type f \
-name .cvsignore \
-print \
| xargs rm -f; \
\
find busybox-$(VERSION)/ -type f \
-name .\#* \
-print \
| xargs rm -f; \
\
tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)/;
dist: release
release: distclean
(cd .. ; rm -rf busybox-$(VERSION) ; cp -a busybox busybox-$(VERSION); rm -rf busybox-$(VERSION)/CVS busybox-$(VERSION)/.cvsignore ; tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION))
.PHONY: tags
tags:
ctags -R .
+62 -17
View File
@@ -1,26 +1,71 @@
Please see the LICENSE file for copyright information.
BusyBox combines tiny versions of many common UNIX utilities into a single
small executable. It provides minimalist replacements for most of the utilities
you usually find in fileutils, shellutils, findutils, textutils, grep, gzip,
tar, etc. BusyBox provides a fairly complete POSIX environment for any small or
emdedded system. The utilities in BusyBox generally have fewer options then
their full featured GNU cousins; however, the options that are included provide
the expected functionality and behave very much like their GNU counterparts.
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
provides a pretty complete POSIX environment in a very small package.
Just add a kernel, "ash" (Keith Almquists tiny Bourne shell clone), and
an editor such as "elvis-tiny" or "ae", and you have a working system.
Busybox was begun to support the Debian Rescue/Install disks, but it
also makes an excellent environment for any small or embedded system.
BusyBox has been written with size-optimization and limited resources in mind.
It is also extremely modular so you can easily include or exclude commands (or
features) at compile time. This makes it easy to customize your embedded
systems. To create a working system, just add a kernel, a shell (such as ash),
and an editor (such as elvis-tiny or ae).
As of version 0.20 there is a version number. : ) Also as of version
0.20, BB is now modularized to easily allow you to build of only the
BB parts you need, thereby reducing binary size. To turn off unwanted
Busybox components, simply edit the file busybox.def.h and comment out
the parts you do not need using C++ style (//) comments.
Busybox was originally written to support the Debian Rescue/Install disks, but
it also makes an excellent environment for any small or embedded system.
After the build is complete a busybox.links file is generated which is
then used by 'make install' to create symlinks to the busybox binary
for all compiled in functions. By default, 'make install' will place
the symlink forest into `pwd`/busybox_install unless you have defined
the PREFIX environment variable.
As of version 0.20 there is a version number. : ) Also as of version 0.20,
BusyBox is now modularized to easily allow you to build only the components you
need, thereby reducing binary size. To turn off unwanted Busybox components,
simply edit the file "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
used by 'make install' to create symlinks to the busybox binary for all
compiled in functions. By default, 'make install' will place the symlink
forest into `pwd`/_install unless you have defined the PREFIX environment
variable (i.e. make PREFIX="/tmp/foo" install)
----------------
Getting help:
When you find you need help, you can check out the BusyBox mailing list
archives at http://opensource.lineo.com/lists/busybox/ or even join
the mailing list if you are interested.
----------------
Bugs:
If you find bugs, follow the instructions at http://bugs.lineo.com/Reporting.html
and submit a bug report. This way, we can be sure nothing falls through the
cracks...
----------------
FTP:
Source for the latest released version can always be downloaded from
ftp://ftp.lineo.com/pub/busybox.
----------------
CVS:
BusyBox now has its own publically browsable CVS tree at:
http://opensource.lineo.com/cgi-bin/cvsweb/busybox/
Anonymous CVS access is available. For instructions, check out:
http://opensource.lineo.com/cvs_anon.html
For those that are actively contributing there is even CVS write access:
http://opensource.lineo.com/cvs_write.html
----------------
Please feed suggestions, bug reports, insults, and bribes back to:
Erik Andersen
<andersen@lineo.com>
<andersee@deban.org>
<andersee@debian.org>
<blatent plug>
Many thanks to go to Lineo for paying me to work on busybox.
</blatent plug>
+57
View File
@@ -0,0 +1,57 @@
TODO list for busybox in no particular order. Just because something
is listed here doesn't mean that it is going to be added to busybox,
or that doing so is even a good idea. It just means that I _might_ get
around to it some time. If you have any good ideas, please let me know.
* login/sulogin/passwd/getty/etc are part of tinylogin, and so are not
needed or wanted in busybox (or else I'd have to link to libcrypt).
* 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 (network logging) will remain in BusyBox.
-Erik
-----------
* dnsdomainname
* traceroute/netstat
* hwclock
* stty
* tftp
* ftp
* group/commonize strings, remove dups (for i18n, l10n)
-----------------------
Running the following:
rm -f busybox && make LDFLAGS+=-nostdlib 2>&1 | \
sed -ne 's/.*undefined reference to `\(.*\)..*/\1/gp' | sort | uniq
reveals the list of all external (i.e. libc) things that BusyBox depends on.
It would be a very nice thing to reduce this list to an absolute minimum, and
then create a microLibc to provide these functions. There is no good reason
for GNU libc to be so big. I'm sure it can be a lot better.
(BTW, this is more informative if BB_FEATURE_NFSMOUNT is turned off...)
Most wanted list:
[andersen@slag busybox]$ grep -l getgroups *.[ch]
test.c
Policy violation. getgroups uses libc nss, which is unlikely
to be present in an embedded system.
-----------------------
Compile with debugging on, run 'nm --size-sort ./busybox'
and then start with the biggest things and make them smaller...
-----------------------
du.c probably ought to have an -x switch like GNU du does...
------------------------------------------------------------------
+459 -163
View File
@@ -1,246 +1,542 @@
#include "internal.h"
/* vi: set sw=4 ts=4: */
#include "busybox.h"
#include <stdio.h>
#include <string.h>
#include <errno.h>
#define bb_need_full_version
#define BB_DECLARE_EXTERN
#include "messages.c"
static int been_there_done_that = 0;
static const struct Applet applets[] = {
const struct BB_applet applets[] = {
#ifdef BB_BUSYBOX //bin
{"busybox", busybox_main},
#ifdef BB_AR
{"ar", ar_main, _BB_DIR_USR_BIN, ar_usage},
#endif
#ifdef BB_BLOCK_DEVICE //sbin
{"block_device", block_device_main},
#ifdef BB_BASENAME
{"basename", basename_main, _BB_DIR_USR_BIN, basename_usage},
#endif
#ifdef BB_CAT //bin
{"cat", cat_main},
{"busybox", busybox_main, _BB_DIR_BIN, NULL},
#ifdef BB_CAT
{"cat", cat_main, _BB_DIR_BIN, cat_usage},
#endif
#ifdef BB_CHMOD_CHOWN_CHGRP //bin
{"chmod", chmod_chown_chgrp_main},
{"chown", chmod_chown_chgrp_main},
{"chgrp", chmod_chown_chgrp_main},
#ifdef BB_CHMOD_CHOWN_CHGRP
{"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN, chgrp_usage},
#endif
#ifdef BB_CHROOT //sbin
{"chroot", chroot_main},
#ifdef BB_CHMOD_CHOWN_CHGRP
{"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN, chmod_usage},
#endif
#ifdef BB_CLEAR //usr/bin
{"clear", clear_main},
#ifdef BB_CHMOD_CHOWN_CHGRP
{"chown", chmod_chown_chgrp_main, _BB_DIR_BIN, chown_usage},
#endif
#ifdef BB_CP //bin
{"cp", cp_main},
#ifdef BB_CHROOT
{"chroot", chroot_main, _BB_DIR_USR_SBIN, chroot_usage},
#endif
#ifdef BB_DATE //bin
{"date", date_main},
#ifdef BB_CLEAR
{"clear", clear_main, _BB_DIR_USR_BIN, clear_usage},
#endif
#ifdef BB_DD //bin
{"dd", dd_main},
#ifdef BB_CHVT
{"chvt", chvt_main, _BB_DIR_USR_BIN, chvt_usage},
#endif
#ifdef BB_DF //bin
{"df", df_main},
#ifdef BB_CP_MV
{"cp", cp_mv_main, _BB_DIR_BIN, cp_usage},
#endif
#ifdef BB_DMESG //bin
{"dmesg", dmesg_main},
#ifdef BB_CUT
{"cut", cut_main, _BB_DIR_USR_BIN, cut_usage},
#endif
#ifdef BB_DUTMP //usr/sbin
{"dutmp", dutmp_main},
#ifdef BB_DATE
{"date", date_main, _BB_DIR_BIN, date_usage},
#endif
#ifdef BB_FDFLUSH //bin
{"fdflush", fdflush_main},
#ifdef BB_DC
{"dc", dc_main, _BB_DIR_USR_BIN, dc_usage},
#endif
#ifdef BB_FIND //usr/bin
{"find", find_main},
#ifdef BB_DD
{"dd", dd_main, _BB_DIR_BIN, dd_usage},
#endif
#ifdef BB_CHVT //usr/bin
{"chvt", chvt_main},
#ifdef BB_DF
{"df", df_main, _BB_DIR_BIN, df_usage},
#endif
#ifdef BB_DEALLOCVT //usr/bin
{"deallocvt", deallocvt_main},
#ifdef BB_DIRNAME
{"dirname", dirname_main, _BB_DIR_USR_BIN, dirname_usage},
#endif
#ifdef BB_FSCK_MINIX //sbin
{"fsck.minix", fsck_minix_main},
#ifdef BB_DMESG
{"dmesg", dmesg_main, _BB_DIR_BIN, dmesg_usage},
#endif
#ifdef BB_MKFS_MINIX //sbin
{"mkfs.minix", mkfs_minix_main},
#ifdef BB_DOS2UNIX
{"dos2unix", dos2unix_main, _BB_DIR_USR_BIN, dos2unix_usage},
#endif
#ifdef BB_GREP //bin
{"grep", grep_main},
#ifdef BB_DU
{"du", du_main, _BB_DIR_USR_BIN, du_usage},
#endif
#ifdef BB_HALT //sbin
{"halt", halt_main},
#ifdef BB_DUMPKMAP
{"dumpkmap", dumpkmap_main, _BB_DIR_BIN, dumpkmap_usage},
#endif
#ifdef BB_INIT //sbin
{"init", init_main},
#ifdef BB_DUTMP
{"dutmp", dutmp_main, _BB_DIR_USR_SBIN, dutmp_usage},
#endif
#ifdef BB_KILL //bin
{"kill", kill_main},
#ifdef BB_ECHO
{"echo", echo_main, _BB_DIR_BIN, echo_usage},
#endif
#ifdef BB_LENGTH //usr/bin
{"length", length_main},
#ifdef BB_EXPR
{"expr", expr_main, _BB_DIR_USR_BIN, expr_usage},
#endif
#ifdef BB_LN //bin
{"ln", ln_main},
#ifdef BB_TRUE_FALSE
{"false", false_main, _BB_DIR_BIN, false_usage},
#endif
#ifdef BB_LOADFONT //usr/bin
{"loadfont", loadfont_main},
#ifdef BB_FBSET
{"fbset", fbset_main, _BB_DIR_USR_SBIN, NULL},
#endif
#ifdef BB_LOADKMAP //sbin
{"loadkmap", loadkmap_main},
#ifdef BB_FDFLUSH
{"fdflush", fdflush_main, _BB_DIR_BIN, fdflush_usage},
#endif
#ifdef BB_LS //bin
{"ls", ls_main},
#ifdef BB_FIND
{"find", find_main, _BB_DIR_USR_BIN, find_usage},
#endif
#ifdef BB_MAKEDEVS //sbin
{"makedevs", makedevs_main},
#ifdef BB_FREE
{"free", free_main, _BB_DIR_USR_BIN, free_usage},
#endif
#ifdef BB_MATH //usr/bin
{"math", math_main},
#ifdef BB_FREERAMDISK
{"freeramdisk", freeramdisk_main, _BB_DIR_SBIN, freeramdisk_usage},
#endif
#ifdef BB_MKDIR //bin
{"mkdir", mkdir_main},
#ifdef BB_DEALLOCVT
{"deallocvt", deallocvt_main, _BB_DIR_USR_BIN, deallocvt_usage},
#endif
#ifdef BB_MKNOD //bin
{"mknod", mknod_main},
#ifdef BB_FSCK_MINIX
{"fsck.minix", fsck_minix_main, _BB_DIR_SBIN, fsck_minix_usage},
#endif
#ifdef BB_MKSWAP //sbin
{"mkswap", mkswap_main},
#ifdef BB_GETOPT
{"getopt", getopt_main, _BB_DIR_BIN},
#endif
#ifdef BB_MNC //usr/bin
{"mnc", mnc_main},
#ifdef BB_GREP
{"grep", grep_main, _BB_DIR_BIN, grep_usage},
#endif
#ifdef BB_MORE //bin
{"more", more_main},
#ifdef BB_GUNZIP
{"gunzip", gunzip_main, _BB_DIR_BIN, gunzip_usage},
#endif
#ifdef BB_MOUNT //bin
{"mount", mount_main},
#ifdef BB_GZIP
{"gzip", gzip_main, _BB_DIR_BIN, gzip_usage},
#endif
#ifdef BB_MT //bin
{"mt", mt_main},
#ifdef BB_HALT
{"halt", halt_main, _BB_DIR_SBIN, halt_usage},
#endif
#ifdef BB_MV //bin
{"mv", mv_main},
#ifdef BB_HEAD
{"head", head_main, _BB_DIR_USR_BIN, head_usage},
#endif
#ifdef BB_PRINTF //usr/bin
{"printf", printf_main},
#ifdef BB_HOSTID
{"hostid", hostid_main, _BB_DIR_USR_BIN, hostid_usage},
#endif
#ifdef BB_PS //bin
{"ps", ps_main},
#ifdef BB_HOSTNAME
{"hostname", hostname_main, _BB_DIR_BIN, hostname_usage},
#endif
#ifdef BB_PWD //bin
{"pwd", pwd_main},
#ifdef BB_ID
{"id", id_main, _BB_DIR_USR_BIN, id_usage},
#endif
#ifdef BB_REBOOT //sbin
{"reboot", reboot_main},
#ifdef BB_INIT
{"init", init_main, _BB_DIR_SBIN, NULL},
#endif
#ifdef BB_RM //bin
{"rm", rm_main},
#ifdef BB_INSMOD
{"insmod", insmod_main, _BB_DIR_SBIN, insmod_usage},
#endif
#ifdef BB_RMDIR //bin
{"rmdir", rmdir_main},
#ifdef BB_KILL
{"kill", kill_main, _BB_DIR_BIN, kill_usage},
#endif
#ifdef BB_SFDISK //sbin
{"fdisk", sfdisk_main},
{"sfdisk", sfdisk_main},
#ifdef BB_KILLALL
{"killall", kill_main, _BB_DIR_USR_BIN, kill_usage},
#endif
#ifdef BB_SED //bin
{"sed", sed_main},
#ifdef BB_LENGTH
{"length", length_main, _BB_DIR_USR_BIN, length_usage},
#endif
#ifdef BB_SLEEP //bin
{"sleep", sleep_main},
#ifdef BB_LINUXRC
{"linuxrc", init_main, _BB_DIR_ROOT, NULL},
#endif
#ifdef BB_TAR //bin
{"tar", tar_main},
#ifdef BB_LN
{"ln", ln_main, _BB_DIR_BIN, ln_usage},
#endif
#ifdef BB_SWAPONOFF //sbin
{"swapon", swap_on_off_main},
{"swapoff", swap_on_off_main},
#ifdef BB_LOADACM
{"loadacm", loadacm_main, _BB_DIR_USR_BIN, loadacm_usage},
#endif
#ifdef BB_SYNC //bin
{"sync", sync_main},
#ifdef BB_LOADFONT
{"loadfont", loadfont_main, _BB_DIR_USR_BIN, loadfont_usage},
#endif
#ifdef BB_TOUCH //usr/bin
{"touch", touch_main},
#ifdef BB_LOADKMAP
{"loadkmap", loadkmap_main, _BB_DIR_SBIN, loadkmap_usage},
#endif
#ifdef BB_TRUE_FALSE //bin
{"true", true_main},
{"false", false_main},
#ifdef BB_LOGGER
{"logger", logger_main, _BB_DIR_USR_BIN, logger_usage},
#endif
#ifdef BB_UNAME //bin
{"uname", uname_main},
#ifdef BB_LOGNAME
{"logname", logname_main, _BB_DIR_USR_BIN, logname_usage},
#endif
#ifdef BB_UMOUNT //bin
{"umount", umount_main},
#ifdef BB_LS
{"ls", ls_main, _BB_DIR_BIN, ls_usage},
#endif
#ifdef BB_UPDATE //sbin
{"update", update_main},
#ifdef BB_LSMOD
{"lsmod", lsmod_main, _BB_DIR_SBIN, lsmod_usage},
#endif
#ifdef BB_GUNZIP //bin
{"zcat", gunzip_main},
{"gunzip", gunzip_main},
#ifdef BB_MAKEDEVS
{"makedevs", makedevs_main, _BB_DIR_SBIN, makedevs_usage},
#endif
#ifdef BB_GZIP //bin
{"gzip", gzip_main},
#ifdef BB_MD5SUM
{"md5sum", md5sum_main, _BB_DIR_USR_BIN, md5sum_usage},
#endif
{0}
#ifdef BB_MKDIR
{"mkdir", mkdir_main, _BB_DIR_BIN, mkdir_usage},
#endif
#ifdef BB_MKFIFO
{"mkfifo", mkfifo_main, _BB_DIR_USR_BIN, mkfifo_usage},
#endif
#ifdef BB_MKFS_MINIX
{"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN, mkfs_minix_usage},
#endif
#ifdef BB_MKNOD
{"mknod", mknod_main, _BB_DIR_BIN, mknod_usage},
#endif
#ifdef BB_MKSWAP
{"mkswap", mkswap_main, _BB_DIR_SBIN, mkswap_usage},
#endif
#ifdef BB_MKTEMP
{"mktemp", mktemp_main, _BB_DIR_BIN, mktemp_usage},
#endif
#ifdef BB_NC
{"nc", nc_main, _BB_DIR_USR_BIN, nc_usage},
#endif
#ifdef BB_MORE
{"more", more_main, _BB_DIR_BIN, more_usage},
#endif
#ifdef BB_MOUNT
{"mount", mount_main, _BB_DIR_BIN, mount_usage},
#endif
#ifdef BB_MT
{"mt", mt_main, _BB_DIR_BIN, mt_usage},
#endif
#ifdef BB_CP_MV
{"mv", cp_mv_main, _BB_DIR_BIN, mv_usage},
#endif
#ifdef BB_NSLOOKUP
{"nslookup", nslookup_main, _BB_DIR_USR_BIN, nslookup_usage},
#endif
#ifdef BB_PING
{"ping", ping_main, _BB_DIR_BIN, ping_usage},
#endif
#ifdef BB_POWEROFF
{"poweroff", poweroff_main, _BB_DIR_SBIN, poweroff_usage},
#endif
#ifdef BB_PRINTF
{"printf", printf_main, _BB_DIR_USR_BIN, printf_usage},
#endif
#ifdef BB_PS
{"ps", ps_main, _BB_DIR_BIN, ps_usage},
#endif
#ifdef BB_PWD
{"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_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_usage},
#endif
#ifdef BB_RMDIR
{"rmdir", rmdir_main, _BB_DIR_BIN, rmdir_usage},
#endif
#ifdef BB_RMMOD
{"rmmod", rmmod_main, _BB_DIR_SBIN, rmmod_usage},
#endif
#ifdef BB_SED
{"sed", sed_main, _BB_DIR_BIN, sed_usage},
#endif
#ifdef BB_SETKEYCODES
{"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN, setkeycodes_usage},
#endif
#ifdef BB_SH
{"sh", shell_main, _BB_DIR_BIN, shell_usage},
#endif
#ifdef BB_SLEEP
{"sleep", sleep_main, _BB_DIR_BIN, sleep_usage},
#endif
#ifdef BB_SORT
{"sort", sort_main, _BB_DIR_USR_BIN, sort_usage},
#endif
#ifdef BB_SYNC
{"sync", sync_main, _BB_DIR_BIN, sync_usage},
#endif
#ifdef BB_SYSLOGD
{"syslogd", syslogd_main, _BB_DIR_SBIN, syslogd_usage},
#endif
#ifdef BB_SWAPONOFF
{"swapon", swap_on_off_main, _BB_DIR_SBIN, swapon_usage},
#endif
#ifdef BB_SWAPONOFF
{"swapoff", swap_on_off_main, _BB_DIR_SBIN, swapoff_usage},
#endif
#ifdef BB_TAIL
{"tail", tail_main, _BB_DIR_USR_BIN, tail_usage},
#endif
#ifdef BB_TAR
{"tar", tar_main, _BB_DIR_BIN, tar_usage},
#endif
#ifdef BB_TELNET
{"telnet", telnet_main, _BB_DIR_USR_BIN, telnet_usage},
#endif
#ifdef BB_TEST
{"test", test_main, _BB_DIR_USR_BIN, test_usage},
#endif
#ifdef BB_TEE
{"tee", tee_main, _BB_DIR_USR_BIN, tee_usage},
#endif
#ifdef BB_TOUCH
{"touch", touch_main, _BB_DIR_BIN, touch_usage},
#endif
#ifdef BB_TR
{"tr", tr_main, _BB_DIR_USR_BIN, tr_usage},
#endif
#ifdef BB_TRUE_FALSE
{"true", true_main, _BB_DIR_BIN, true_usage},
#endif
#ifdef BB_TTY
{"tty", tty_main, _BB_DIR_USR_BIN, tty_usage},
#endif
#ifdef BB_UMOUNT
{"umount", umount_main, _BB_DIR_BIN, umount_usage},
#endif
#ifdef BB_UNAME
{"uname", uname_main, _BB_DIR_BIN, uname_usage},
#endif
#ifdef BB_UNIQ
{"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_usage},
#endif
#ifdef BB_UPTIME
{"uptime", uptime_main, _BB_DIR_USR_BIN, uptime_usage},
#endif
#ifdef BB_UUENCODE
{"uuencode", uuencode_main, _BB_DIR_USR_BIN, uuencode_usage},
#endif
#ifdef BB_UUDECODE
{"uudecode", uudecode_main, _BB_DIR_USR_BIN, uudecode_usage},
#endif
#ifdef BB_USLEEP
{"usleep", usleep_main, _BB_DIR_BIN, usleep_usage},
#endif
#ifdef BB_WC
{"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_usage},
#endif
#ifdef BB_WHOAMI
{"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_usage},
#endif
#ifdef BB_GUNZIP
{"zcat", gunzip_main, _BB_DIR_BIN, gunzip_usage},
#endif
#ifdef BB_TEST
{"[", test_main, _BB_DIR_USR_BIN, test_usage},
#endif
{0,NULL,0,NULL}
};
const char *applet_name;
#ifdef BB_FEATURE_INSTALLER
/*
* directory table
* this should be consistent w/ the enum, busybox.h::Location,
* or else...
*/
static char* install_dir[] = {
"/",
"/bin",
"/sbin",
"/usr/bin",
"/usr/sbin",
};
/* abstract link() */
typedef int (*__link_f)(const char *, const char *);
/*
* Where in the filesystem is this busybox?
* [return]
* malloc'd string w/ full pathname of busybox's location
* NULL on failure
*/
static char *busybox_fullpath()
{
pid_t pid;
char path[256];
char proc[256];
int len;
pid = getpid();
sprintf(proc, "/proc/%d/exe", pid);
len = readlink(proc, path, 256);
if (len != -1) {
path[len] = 0;
} else {
errorMsg("%s: %s\n", proc, strerror(errno));
return NULL;
}
return strdup(path);
}
/* create (sym)links for each applet */
static void install_links(const char *busybox, int use_symbolic_links)
{
__link_f Link = link;
char command[256];
int i;
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);
rc = Link(busybox, command);
if (rc) {
errorMsg("%s: %s\n", command, strerror(errno));
}
}
}
#endif /* BB_FEATURE_INSTALLER */
int main(int argc, char **argv)
{
char *s = argv[0];
char *name = argv[0];
const struct Applet *a = applets;
const char *s;
const struct BB_applet *a = applets;
applet_name = "busybox";
while (*s != '\0') {
if (*s++ == '/')
name = s;
}
#ifdef BB_FEATURE_INSTALLER
/*
* This style of argument parsing doesn't scale well
* in the event that busybox starts wanting more --options.
* If someone has a cleaner approach, by all means implement it.
*/
if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
int use_symbolic_links = 0;
int rc = 0;
char *busybox;
while (a->name != 0) {
if (strcmp(name, a->name) == 0) {
int status;
/* to use symlinks, or not to use symlinks... */
if (argc > 2) {
if ((strcmp(argv[2], "-s") == 0)) {
use_symbolic_links = 1;
}
}
status = ((*(a->main)) (argc, argv));
if (status < 0) {
fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
}
fprintf(stderr, "\n");
exit(status);
/* link */
busybox = busybox_fullpath();
if (busybox) {
install_links(busybox, use_symbolic_links);
free(busybox);
} else {
rc = 1;
}
return rc;
}
a++;
}
exit (busybox_main(argc, argv));
#endif /* BB_FEATURE_INSTALLER */
for (s = applet_name = argv[0]; *s != '\0';) {
if (*s++ == '/')
applet_name = s;
}
*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 == '-' && *(*argv+1)!= '-') {
exit(((*(shell_main)) (argc, argv)));
}
#endif
while (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++;
}
return(busybox_main(argc, argv));
}
int busybox_main(int argc, char **argv)
{
int col=0;
argc--;
argv++;
int col = 0;
if (been_there_done_that == 1 || argc < 1) {
const struct Applet *a = applets;
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
BB_VER, BB_BT);
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
fprintf(stderr, " or: [function] [arguments]...\n\n");
fprintf(stderr,
"\tMost people will create a symlink to busybox for each\n"
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
fprintf(stderr, "\nCurrently defined functions:\n");
argc--;
argv++;
while (a->name != 0) {
col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), (a++)->name);
if (col>60) {
fprintf(stderr, ",\n");
col=0;
}
if (been_there_done_that == 1 || argc < 1) {
const struct BB_applet *a = applets;
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", full_version);
while (a->name != 0) {
col +=
fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
(a++)->name);
if (col > 60 && a->name != 0) {
fprintf(stderr, ",\n");
col = 0;
}
}
fprintf(stderr, "\n\n");
exit(-1);
}
fprintf(stderr, "\n\n");
exit(-1);
} else {
/* If we've already been here once, exit now */
been_there_done_that = 1;
return (main(argc, argv));
}
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+12 -8
View File
@@ -1,15 +1,19 @@
#!/bin/sh
#Make busybox links list file
# Make busybox links list file.
DF="busybox.def.h"
DF="Config.h"
MF="busybox.c"
LIST="$(sed -n '/^#define/{s/^#define //p;}' $DF)"
LIST="$(gcc -E -dM $DF | sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/BB_\1/gp;' | sort)"
for def in ${LIST}; do
i=`sed -n 's/^#ifdef \<'$def'\>.*\/\/\(.*$\)/\/\1\//gp' $MF`
j=`sed -n '/^#ifdef '$def'.*/,/^#endif/{ s/.*\"\(.*\)\".*/\1/gp; }' $MF`
for k in $j; do
echo $i$k
done
i=`sed -n '/^#ifdef \<'$def'\>.*/,/^#endif/{ s/.*\"\(.*\)\".*\(_BB_DIR_[A-Z_]*\).*$/\2\/\1/gp; }' $MF`
for j in $i; do
if [ -z $j ] ; then
continue;
fi;
echo $j | sed -e 's/_BB_DIR_ROOT//g;s/_BB_DIR_BIN/\/bin/g;' \
-e 's/_BB_DIR_SBIN/\/sbin/g;s/_BB_DIR_USR_BIN/\/usr\/bin/g;' \
-e 's/_BB_DIR_USR_SBIN/\/usr\/sbin/g;'
done;
done
+8 -2
View File
@@ -1,4 +1,10 @@
#!/bin/sh
sed -n '/^#define/{s/.*BB_//; s/$/.o/p; }' busybox.def.h | \
tr [:upper:] [:lower:]
# 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 Config.h | \
sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/\1.c/gp;' \
| tr '[:upper:]' '[:lower:]' | sort
` 2>/dev/null | sed -e 's/\.c$/\.o/g'
+41 -14
View File
@@ -1,22 +1,49 @@
#!/bin/sh
set -e
if [ "$1" == "" ]; then
prefix=$1
if [ "$prefix" = "" ]; then
echo "No installation directory, aborting."
exit 1;
fi
# can't just use cat, rmdir is not unique
#h=`cat busybox.links`
if [ "$2" = "--hardlinks" ]; then
linkopts="-f"
else
linkopts="-fs"
fi
h=`sort busybox.links | uniq`
mkdir -p $1/bin
for i in $h ; do
[ ${verbose} ] && echo " making link to $i"
mkdir -p $1/`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\1/g' `
ln -s busybox $1/bin/`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\2/g' `
done
rm -f $1/bin/busybox
install -m 755 busybox $1/bin/busybox
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
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
exit 0
+1458
View File
File diff suppressed because it is too large. Load diff
+391
View File
@@ -0,0 +1,391 @@
/* vi: set sw=4 ts=4: */
/*
* Mini ar implementation for busybox
*
* Copyright (C) 2000 by Glenn McGrath
* Written by Glenn McGrath <bug1@netconnect.com.au> 1 June 2000
*
* Based in part on BusyBox tar, Debian dpkg-deb and GNU ar.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Last modified 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 <sys/stat.h>
#include <malloc.h>
#include "busybox.h"
#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 MAX_NAME_LENGTH 100
//#define BB_DECLARE_EXTERN
//#define bb_need_io_error
//#include "messages.c"
//#define BB_AR_EXPERIMENTAL_UNTAR
#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
/*
* identify Tar header (magic field) and reset srcFd to entry position
*/
static int checkTarMagic(int srcFd)
{
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);
}
static int readTarHeader(int srcFd, headerL_t *current)
{
rawTarHeader_t rawTarHeader;
unsigned char *temp = (unsigned char *) &rawTarHeader;
long sum = 0;
int i;
off_t initialOffset;
initialOffset = lseek(srcFd, 0, SEEK_CUR);
if (fullRead(srcFd, (char *) &rawTarHeader, 512) != 512) {
lseek(srcFd, initialOffset, SEEK_SET);
return(FALSE);
}
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);
}
/*
* get, check and correct the converted header
*/
static int readArEntry(int srcFd, headerL_t *entry)
{
size_t nameLength;
rawArHeader_t rawArHeader;
off_t initialOffset;
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);
}
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;
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';
/* 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);
}
}
}
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, opt=0;
int srcFd=0, dstFd=0;
headerL_t *header, *entry, *extractList;
while ((opt = getopt(argc, argv, "ovtpxR")) != -1) {
switch (opt) {
case 'o':
funct |= PRESERVE_DATE;
break;
case 'v':
funct |= VERBOSE;
break;
case 't':
funct |= DISPLAY;
break;
case 'x':
funct |= EXT_TO_FILE;
break;
case 'p':
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]);
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;
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);
}
+391
View File
@@ -0,0 +1,391 @@
/* vi: set sw=4 ts=4: */
/*
* Mini ar implementation for busybox
*
* Copyright (C) 2000 by Glenn McGrath
* Written by Glenn McGrath <bug1@netconnect.com.au> 1 June 2000
*
* Based in part on BusyBox tar, Debian dpkg-deb and GNU ar.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Last modified 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 <sys/stat.h>
#include <malloc.h>
#include "busybox.h"
#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 MAX_NAME_LENGTH 100
//#define BB_DECLARE_EXTERN
//#define bb_need_io_error
//#include "messages.c"
//#define BB_AR_EXPERIMENTAL_UNTAR
#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
/*
* identify Tar header (magic field) and reset srcFd to entry position
*/
static int checkTarMagic(int srcFd)
{
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);
}
static int readTarHeader(int srcFd, headerL_t *current)
{
rawTarHeader_t rawTarHeader;
unsigned char *temp = (unsigned char *) &rawTarHeader;
long sum = 0;
int i;
off_t initialOffset;
initialOffset = lseek(srcFd, 0, SEEK_CUR);
if (fullRead(srcFd, (char *) &rawTarHeader, 512) != 512) {
lseek(srcFd, initialOffset, SEEK_SET);
return(FALSE);
}
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);
}
/*
* get, check and correct the converted header
*/
static int readArEntry(int srcFd, headerL_t *entry)
{
size_t nameLength;
rawArHeader_t rawArHeader;
off_t initialOffset;
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);
}
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;
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';
/* 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);
}
}
}
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, opt=0;
int srcFd=0, dstFd=0;
headerL_t *header, *entry, *extractList;
while ((opt = getopt(argc, argv, "ovtpxR")) != -1) {
switch (opt) {
case 'o':
funct |= PRESERVE_DATE;
break;
case 'v':
funct |= VERBOSE;
break;
case 't':
funct |= DISPLAY;
break;
case 'x':
funct |= EXT_TO_FILE;
break;
case 'p':
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]);
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;
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);
}
+2195
View File
File diff suppressed because it is too large. Load diff
+1589 -1478
View File
File diff suppressed because it is too large. Load diff
+944 -1106
View File
File diff suppressed because it is too large. Load diff
+49
View File
@@ -0,0 +1,49 @@
/* vi: set sw=4 ts=4: */
/*
* Mini basename implementation for busybox
*
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "busybox.h"
#include <stdio.h>
extern int basename_main(int argc, char **argv)
{
int m, n;
char *s;
if ((argc < 2) || (**(argv + 1) == '-')) {
usage(basename_usage);
}
argv++;
s = get_last_path_component(*argv);
if (argc>2) {
argv++;
n = strlen(*argv);
m = strlen(s);
if (m>=n && strncmp(s+m-n, *argv, n)==0)
s[m-n] = '\0';
}
printf("%s\n", s);
return(TRUE);
}
+459 -163
View File
@@ -1,246 +1,542 @@
#include "internal.h"
/* vi: set sw=4 ts=4: */
#include "busybox.h"
#include <stdio.h>
#include <string.h>
#include <errno.h>
#define bb_need_full_version
#define BB_DECLARE_EXTERN
#include "messages.c"
static int been_there_done_that = 0;
static const struct Applet applets[] = {
const struct BB_applet applets[] = {
#ifdef BB_BUSYBOX //bin
{"busybox", busybox_main},
#ifdef BB_AR
{"ar", ar_main, _BB_DIR_USR_BIN, ar_usage},
#endif
#ifdef BB_BLOCK_DEVICE //sbin
{"block_device", block_device_main},
#ifdef BB_BASENAME
{"basename", basename_main, _BB_DIR_USR_BIN, basename_usage},
#endif
#ifdef BB_CAT //bin
{"cat", cat_main},
{"busybox", busybox_main, _BB_DIR_BIN, NULL},
#ifdef BB_CAT
{"cat", cat_main, _BB_DIR_BIN, cat_usage},
#endif
#ifdef BB_CHMOD_CHOWN_CHGRP //bin
{"chmod", chmod_chown_chgrp_main},
{"chown", chmod_chown_chgrp_main},
{"chgrp", chmod_chown_chgrp_main},
#ifdef BB_CHMOD_CHOWN_CHGRP
{"chgrp", chmod_chown_chgrp_main, _BB_DIR_BIN, chgrp_usage},
#endif
#ifdef BB_CHROOT //sbin
{"chroot", chroot_main},
#ifdef BB_CHMOD_CHOWN_CHGRP
{"chmod", chmod_chown_chgrp_main, _BB_DIR_BIN, chmod_usage},
#endif
#ifdef BB_CLEAR //usr/bin
{"clear", clear_main},
#ifdef BB_CHMOD_CHOWN_CHGRP
{"chown", chmod_chown_chgrp_main, _BB_DIR_BIN, chown_usage},
#endif
#ifdef BB_CP //bin
{"cp", cp_main},
#ifdef BB_CHROOT
{"chroot", chroot_main, _BB_DIR_USR_SBIN, chroot_usage},
#endif
#ifdef BB_DATE //bin
{"date", date_main},
#ifdef BB_CLEAR
{"clear", clear_main, _BB_DIR_USR_BIN, clear_usage},
#endif
#ifdef BB_DD //bin
{"dd", dd_main},
#ifdef BB_CHVT
{"chvt", chvt_main, _BB_DIR_USR_BIN, chvt_usage},
#endif
#ifdef BB_DF //bin
{"df", df_main},
#ifdef BB_CP_MV
{"cp", cp_mv_main, _BB_DIR_BIN, cp_usage},
#endif
#ifdef BB_DMESG //bin
{"dmesg", dmesg_main},
#ifdef BB_CUT
{"cut", cut_main, _BB_DIR_USR_BIN, cut_usage},
#endif
#ifdef BB_DUTMP //usr/sbin
{"dutmp", dutmp_main},
#ifdef BB_DATE
{"date", date_main, _BB_DIR_BIN, date_usage},
#endif
#ifdef BB_FDFLUSH //bin
{"fdflush", fdflush_main},
#ifdef BB_DC
{"dc", dc_main, _BB_DIR_USR_BIN, dc_usage},
#endif
#ifdef BB_FIND //usr/bin
{"find", find_main},
#ifdef BB_DD
{"dd", dd_main, _BB_DIR_BIN, dd_usage},
#endif
#ifdef BB_CHVT //usr/bin
{"chvt", chvt_main},
#ifdef BB_DF
{"df", df_main, _BB_DIR_BIN, df_usage},
#endif
#ifdef BB_DEALLOCVT //usr/bin
{"deallocvt", deallocvt_main},
#ifdef BB_DIRNAME
{"dirname", dirname_main, _BB_DIR_USR_BIN, dirname_usage},
#endif
#ifdef BB_FSCK_MINIX //sbin
{"fsck.minix", fsck_minix_main},
#ifdef BB_DMESG
{"dmesg", dmesg_main, _BB_DIR_BIN, dmesg_usage},
#endif
#ifdef BB_MKFS_MINIX //sbin
{"mkfs.minix", mkfs_minix_main},
#ifdef BB_DOS2UNIX
{"dos2unix", dos2unix_main, _BB_DIR_USR_BIN, dos2unix_usage},
#endif
#ifdef BB_GREP //bin
{"grep", grep_main},
#ifdef BB_DU
{"du", du_main, _BB_DIR_USR_BIN, du_usage},
#endif
#ifdef BB_HALT //sbin
{"halt", halt_main},
#ifdef BB_DUMPKMAP
{"dumpkmap", dumpkmap_main, _BB_DIR_BIN, dumpkmap_usage},
#endif
#ifdef BB_INIT //sbin
{"init", init_main},
#ifdef BB_DUTMP
{"dutmp", dutmp_main, _BB_DIR_USR_SBIN, dutmp_usage},
#endif
#ifdef BB_KILL //bin
{"kill", kill_main},
#ifdef BB_ECHO
{"echo", echo_main, _BB_DIR_BIN, echo_usage},
#endif
#ifdef BB_LENGTH //usr/bin
{"length", length_main},
#ifdef BB_EXPR
{"expr", expr_main, _BB_DIR_USR_BIN, expr_usage},
#endif
#ifdef BB_LN //bin
{"ln", ln_main},
#ifdef BB_TRUE_FALSE
{"false", false_main, _BB_DIR_BIN, false_usage},
#endif
#ifdef BB_LOADFONT //usr/bin
{"loadfont", loadfont_main},
#ifdef BB_FBSET
{"fbset", fbset_main, _BB_DIR_USR_SBIN, NULL},
#endif
#ifdef BB_LOADKMAP //sbin
{"loadkmap", loadkmap_main},
#ifdef BB_FDFLUSH
{"fdflush", fdflush_main, _BB_DIR_BIN, fdflush_usage},
#endif
#ifdef BB_LS //bin
{"ls", ls_main},
#ifdef BB_FIND
{"find", find_main, _BB_DIR_USR_BIN, find_usage},
#endif
#ifdef BB_MAKEDEVS //sbin
{"makedevs", makedevs_main},
#ifdef BB_FREE
{"free", free_main, _BB_DIR_USR_BIN, free_usage},
#endif
#ifdef BB_MATH //usr/bin
{"math", math_main},
#ifdef BB_FREERAMDISK
{"freeramdisk", freeramdisk_main, _BB_DIR_SBIN, freeramdisk_usage},
#endif
#ifdef BB_MKDIR //bin
{"mkdir", mkdir_main},
#ifdef BB_DEALLOCVT
{"deallocvt", deallocvt_main, _BB_DIR_USR_BIN, deallocvt_usage},
#endif
#ifdef BB_MKNOD //bin
{"mknod", mknod_main},
#ifdef BB_FSCK_MINIX
{"fsck.minix", fsck_minix_main, _BB_DIR_SBIN, fsck_minix_usage},
#endif
#ifdef BB_MKSWAP //sbin
{"mkswap", mkswap_main},
#ifdef BB_GETOPT
{"getopt", getopt_main, _BB_DIR_BIN},
#endif
#ifdef BB_MNC //usr/bin
{"mnc", mnc_main},
#ifdef BB_GREP
{"grep", grep_main, _BB_DIR_BIN, grep_usage},
#endif
#ifdef BB_MORE //bin
{"more", more_main},
#ifdef BB_GUNZIP
{"gunzip", gunzip_main, _BB_DIR_BIN, gunzip_usage},
#endif
#ifdef BB_MOUNT //bin
{"mount", mount_main},
#ifdef BB_GZIP
{"gzip", gzip_main, _BB_DIR_BIN, gzip_usage},
#endif
#ifdef BB_MT //bin
{"mt", mt_main},
#ifdef BB_HALT
{"halt", halt_main, _BB_DIR_SBIN, halt_usage},
#endif
#ifdef BB_MV //bin
{"mv", mv_main},
#ifdef BB_HEAD
{"head", head_main, _BB_DIR_USR_BIN, head_usage},
#endif
#ifdef BB_PRINTF //usr/bin
{"printf", printf_main},
#ifdef BB_HOSTID
{"hostid", hostid_main, _BB_DIR_USR_BIN, hostid_usage},
#endif
#ifdef BB_PS //bin
{"ps", ps_main},
#ifdef BB_HOSTNAME
{"hostname", hostname_main, _BB_DIR_BIN, hostname_usage},
#endif
#ifdef BB_PWD //bin
{"pwd", pwd_main},
#ifdef BB_ID
{"id", id_main, _BB_DIR_USR_BIN, id_usage},
#endif
#ifdef BB_REBOOT //sbin
{"reboot", reboot_main},
#ifdef BB_INIT
{"init", init_main, _BB_DIR_SBIN, NULL},
#endif
#ifdef BB_RM //bin
{"rm", rm_main},
#ifdef BB_INSMOD
{"insmod", insmod_main, _BB_DIR_SBIN, insmod_usage},
#endif
#ifdef BB_RMDIR //bin
{"rmdir", rmdir_main},
#ifdef BB_KILL
{"kill", kill_main, _BB_DIR_BIN, kill_usage},
#endif
#ifdef BB_SFDISK //sbin
{"fdisk", sfdisk_main},
{"sfdisk", sfdisk_main},
#ifdef BB_KILLALL
{"killall", kill_main, _BB_DIR_USR_BIN, kill_usage},
#endif
#ifdef BB_SED //bin
{"sed", sed_main},
#ifdef BB_LENGTH
{"length", length_main, _BB_DIR_USR_BIN, length_usage},
#endif
#ifdef BB_SLEEP //bin
{"sleep", sleep_main},
#ifdef BB_LINUXRC
{"linuxrc", init_main, _BB_DIR_ROOT, NULL},
#endif
#ifdef BB_TAR //bin
{"tar", tar_main},
#ifdef BB_LN
{"ln", ln_main, _BB_DIR_BIN, ln_usage},
#endif
#ifdef BB_SWAPONOFF //sbin
{"swapon", swap_on_off_main},
{"swapoff", swap_on_off_main},
#ifdef BB_LOADACM
{"loadacm", loadacm_main, _BB_DIR_USR_BIN, loadacm_usage},
#endif
#ifdef BB_SYNC //bin
{"sync", sync_main},
#ifdef BB_LOADFONT
{"loadfont", loadfont_main, _BB_DIR_USR_BIN, loadfont_usage},
#endif
#ifdef BB_TOUCH //usr/bin
{"touch", touch_main},
#ifdef BB_LOADKMAP
{"loadkmap", loadkmap_main, _BB_DIR_SBIN, loadkmap_usage},
#endif
#ifdef BB_TRUE_FALSE //bin
{"true", true_main},
{"false", false_main},
#ifdef BB_LOGGER
{"logger", logger_main, _BB_DIR_USR_BIN, logger_usage},
#endif
#ifdef BB_UNAME //bin
{"uname", uname_main},
#ifdef BB_LOGNAME
{"logname", logname_main, _BB_DIR_USR_BIN, logname_usage},
#endif
#ifdef BB_UMOUNT //bin
{"umount", umount_main},
#ifdef BB_LS
{"ls", ls_main, _BB_DIR_BIN, ls_usage},
#endif
#ifdef BB_UPDATE //sbin
{"update", update_main},
#ifdef BB_LSMOD
{"lsmod", lsmod_main, _BB_DIR_SBIN, lsmod_usage},
#endif
#ifdef BB_GUNZIP //bin
{"zcat", gunzip_main},
{"gunzip", gunzip_main},
#ifdef BB_MAKEDEVS
{"makedevs", makedevs_main, _BB_DIR_SBIN, makedevs_usage},
#endif
#ifdef BB_GZIP //bin
{"gzip", gzip_main},
#ifdef BB_MD5SUM
{"md5sum", md5sum_main, _BB_DIR_USR_BIN, md5sum_usage},
#endif
{0}
#ifdef BB_MKDIR
{"mkdir", mkdir_main, _BB_DIR_BIN, mkdir_usage},
#endif
#ifdef BB_MKFIFO
{"mkfifo", mkfifo_main, _BB_DIR_USR_BIN, mkfifo_usage},
#endif
#ifdef BB_MKFS_MINIX
{"mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN, mkfs_minix_usage},
#endif
#ifdef BB_MKNOD
{"mknod", mknod_main, _BB_DIR_BIN, mknod_usage},
#endif
#ifdef BB_MKSWAP
{"mkswap", mkswap_main, _BB_DIR_SBIN, mkswap_usage},
#endif
#ifdef BB_MKTEMP
{"mktemp", mktemp_main, _BB_DIR_BIN, mktemp_usage},
#endif
#ifdef BB_NC
{"nc", nc_main, _BB_DIR_USR_BIN, nc_usage},
#endif
#ifdef BB_MORE
{"more", more_main, _BB_DIR_BIN, more_usage},
#endif
#ifdef BB_MOUNT
{"mount", mount_main, _BB_DIR_BIN, mount_usage},
#endif
#ifdef BB_MT
{"mt", mt_main, _BB_DIR_BIN, mt_usage},
#endif
#ifdef BB_CP_MV
{"mv", cp_mv_main, _BB_DIR_BIN, mv_usage},
#endif
#ifdef BB_NSLOOKUP
{"nslookup", nslookup_main, _BB_DIR_USR_BIN, nslookup_usage},
#endif
#ifdef BB_PING
{"ping", ping_main, _BB_DIR_BIN, ping_usage},
#endif
#ifdef BB_POWEROFF
{"poweroff", poweroff_main, _BB_DIR_SBIN, poweroff_usage},
#endif
#ifdef BB_PRINTF
{"printf", printf_main, _BB_DIR_USR_BIN, printf_usage},
#endif
#ifdef BB_PS
{"ps", ps_main, _BB_DIR_BIN, ps_usage},
#endif
#ifdef BB_PWD
{"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_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_usage},
#endif
#ifdef BB_RMDIR
{"rmdir", rmdir_main, _BB_DIR_BIN, rmdir_usage},
#endif
#ifdef BB_RMMOD
{"rmmod", rmmod_main, _BB_DIR_SBIN, rmmod_usage},
#endif
#ifdef BB_SED
{"sed", sed_main, _BB_DIR_BIN, sed_usage},
#endif
#ifdef BB_SETKEYCODES
{"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN, setkeycodes_usage},
#endif
#ifdef BB_SH
{"sh", shell_main, _BB_DIR_BIN, shell_usage},
#endif
#ifdef BB_SLEEP
{"sleep", sleep_main, _BB_DIR_BIN, sleep_usage},
#endif
#ifdef BB_SORT
{"sort", sort_main, _BB_DIR_USR_BIN, sort_usage},
#endif
#ifdef BB_SYNC
{"sync", sync_main, _BB_DIR_BIN, sync_usage},
#endif
#ifdef BB_SYSLOGD
{"syslogd", syslogd_main, _BB_DIR_SBIN, syslogd_usage},
#endif
#ifdef BB_SWAPONOFF
{"swapon", swap_on_off_main, _BB_DIR_SBIN, swapon_usage},
#endif
#ifdef BB_SWAPONOFF
{"swapoff", swap_on_off_main, _BB_DIR_SBIN, swapoff_usage},
#endif
#ifdef BB_TAIL
{"tail", tail_main, _BB_DIR_USR_BIN, tail_usage},
#endif
#ifdef BB_TAR
{"tar", tar_main, _BB_DIR_BIN, tar_usage},
#endif
#ifdef BB_TELNET
{"telnet", telnet_main, _BB_DIR_USR_BIN, telnet_usage},
#endif
#ifdef BB_TEST
{"test", test_main, _BB_DIR_USR_BIN, test_usage},
#endif
#ifdef BB_TEE
{"tee", tee_main, _BB_DIR_USR_BIN, tee_usage},
#endif
#ifdef BB_TOUCH
{"touch", touch_main, _BB_DIR_BIN, touch_usage},
#endif
#ifdef BB_TR
{"tr", tr_main, _BB_DIR_USR_BIN, tr_usage},
#endif
#ifdef BB_TRUE_FALSE
{"true", true_main, _BB_DIR_BIN, true_usage},
#endif
#ifdef BB_TTY
{"tty", tty_main, _BB_DIR_USR_BIN, tty_usage},
#endif
#ifdef BB_UMOUNT
{"umount", umount_main, _BB_DIR_BIN, umount_usage},
#endif
#ifdef BB_UNAME
{"uname", uname_main, _BB_DIR_BIN, uname_usage},
#endif
#ifdef BB_UNIQ
{"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_usage},
#endif
#ifdef BB_UPTIME
{"uptime", uptime_main, _BB_DIR_USR_BIN, uptime_usage},
#endif
#ifdef BB_UUENCODE
{"uuencode", uuencode_main, _BB_DIR_USR_BIN, uuencode_usage},
#endif
#ifdef BB_UUDECODE
{"uudecode", uudecode_main, _BB_DIR_USR_BIN, uudecode_usage},
#endif
#ifdef BB_USLEEP
{"usleep", usleep_main, _BB_DIR_BIN, usleep_usage},
#endif
#ifdef BB_WC
{"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_usage},
#endif
#ifdef BB_WHOAMI
{"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_usage},
#endif
#ifdef BB_GUNZIP
{"zcat", gunzip_main, _BB_DIR_BIN, gunzip_usage},
#endif
#ifdef BB_TEST
{"[", test_main, _BB_DIR_USR_BIN, test_usage},
#endif
{0,NULL,0,NULL}
};
const char *applet_name;
#ifdef BB_FEATURE_INSTALLER
/*
* directory table
* this should be consistent w/ the enum, busybox.h::Location,
* or else...
*/
static char* install_dir[] = {
"/",
"/bin",
"/sbin",
"/usr/bin",
"/usr/sbin",
};
/* abstract link() */
typedef int (*__link_f)(const char *, const char *);
/*
* Where in the filesystem is this busybox?
* [return]
* malloc'd string w/ full pathname of busybox's location
* NULL on failure
*/
static char *busybox_fullpath()
{
pid_t pid;
char path[256];
char proc[256];
int len;
pid = getpid();
sprintf(proc, "/proc/%d/exe", pid);
len = readlink(proc, path, 256);
if (len != -1) {
path[len] = 0;
} else {
errorMsg("%s: %s\n", proc, strerror(errno));
return NULL;
}
return strdup(path);
}
/* create (sym)links for each applet */
static void install_links(const char *busybox, int use_symbolic_links)
{
__link_f Link = link;
char command[256];
int i;
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);
rc = Link(busybox, command);
if (rc) {
errorMsg("%s: %s\n", command, strerror(errno));
}
}
}
#endif /* BB_FEATURE_INSTALLER */
int main(int argc, char **argv)
{
char *s = argv[0];
char *name = argv[0];
const struct Applet *a = applets;
const char *s;
const struct BB_applet *a = applets;
applet_name = "busybox";
while (*s != '\0') {
if (*s++ == '/')
name = s;
}
#ifdef BB_FEATURE_INSTALLER
/*
* This style of argument parsing doesn't scale well
* in the event that busybox starts wanting more --options.
* If someone has a cleaner approach, by all means implement it.
*/
if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
int use_symbolic_links = 0;
int rc = 0;
char *busybox;
while (a->name != 0) {
if (strcmp(name, a->name) == 0) {
int status;
/* to use symlinks, or not to use symlinks... */
if (argc > 2) {
if ((strcmp(argv[2], "-s") == 0)) {
use_symbolic_links = 1;
}
}
status = ((*(a->main)) (argc, argv));
if (status < 0) {
fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
}
fprintf(stderr, "\n");
exit(status);
/* link */
busybox = busybox_fullpath();
if (busybox) {
install_links(busybox, use_symbolic_links);
free(busybox);
} else {
rc = 1;
}
return rc;
}
a++;
}
exit (busybox_main(argc, argv));
#endif /* BB_FEATURE_INSTALLER */
for (s = applet_name = argv[0]; *s != '\0';) {
if (*s++ == '/')
applet_name = s;
}
*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 == '-' && *(*argv+1)!= '-') {
exit(((*(shell_main)) (argc, argv)));
}
#endif
while (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++;
}
return(busybox_main(argc, argv));
}
int busybox_main(int argc, char **argv)
{
int col=0;
argc--;
argv++;
int col = 0;
if (been_there_done_that == 1 || argc < 1) {
const struct Applet *a = applets;
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
BB_VER, BB_BT);
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
fprintf(stderr, " or: [function] [arguments]...\n\n");
fprintf(stderr,
"\tMost people will create a symlink to busybox for each\n"
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
fprintf(stderr, "\nCurrently defined functions:\n");
argc--;
argv++;
while (a->name != 0) {
col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), (a++)->name);
if (col>60) {
fprintf(stderr, ",\n");
col=0;
}
if (been_there_done_that == 1 || argc < 1) {
const struct BB_applet *a = applets;
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", full_version);
while (a->name != 0) {
col +=
fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
(a++)->name);
if (col > 60 && a->name != 0) {
fprintf(stderr, ",\n");
col = 0;
}
}
fprintf(stderr, "\n\n");
exit(-1);
}
fprintf(stderr, "\n\n");
exit(-1);
} else {
/* If we've already been here once, exit now */
been_there_done_that = 1;
return (main(argc, argv));
}
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
-66
View File
@@ -1,66 +0,0 @@
/*
* This file is parsed by sed. You MUST use single line comments.
* IE //#define BB_BLAH
*/
#define BB_BUSYBOX
#define BB_CAT
#define BB_CHMOD_CHOWN_CHGRP
#define BB_CHROOT
#define BB_CLEAR
#define BB_CP
#define BB_DATE
#define BB_DD
#define BB_DF
#define BB_DMESG
//#define BB_DUTMP
//#define BB_FDFLUSH
#define BB_FIND
#define BB_FSCK_MINIX
#define BB_MKFS_MINIX
#define BB_CHVT
#define BB_DEALLOCVT
#define BB_GREP
//#define BB_HALT
#define BB_INIT
#define BB_KILL
//#define BB_LENGTH
#define BB_LN
#define BB_LOADFONT
#define BB_LOADKMAP
#define BB_LS
//#define BB_MAKEDEVS
//#define BB_MATH
#define BB_MKDIR
#define BB_MKNOD
#define BB_MKSWAP
//#define BB_MNC
#define BB_MORE
#define BB_MOUNT
#define BB_NFSMOUNT
//#define BB_MT
//#define BB_MTAB
#define BB_MV
//#define BB_PRINTF
#define BB_PS
#define BB_PWD
#define BB_REGEXP
#define BB_REBOOT
#define BB_RM
#define BB_RMDIR
//#define BB_SFDISK
#define BB_SED
#define BB_SLEEP
#define BB_SWAPONOFF
#define BB_SYNC
#define BB_TAR
#define BB_TOUCH
#define BB_TRUE_FALSE
#define BB_UMOUNT
#define BB_UPDATE
#define BB_UNAME
#define BB_GZIP
#define BB_GUNZIP
// Don't turn BB_UTILITY off. It contains support code
// that compiles to 0 if everything else if turned off.
#define BB_UTILITY
+468
View File
@@ -0,0 +1,468 @@
/* vi: set sw=4 ts=4: */
/*
* Busybox main internal header file
*
*
* 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
*
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
* Permission has been granted to redistribute this code under the GPL.
*
*/
#ifndef _BB_INTERNAL_H_
#define _BB_INTERNAL_H_ 1
#include "Config.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <mntent.h>
#include <regex.h>
/* for the _syscall() macros */
#include <sys/syscall.h>
#include <linux/unistd.h>
/* Some useful definitions */
#define FALSE ((int) 1)
#define TRUE ((int) 0)
/* for mtab.c */
#define MTAB_GETMOUNTPT '1'
#define MTAB_GETDEVICE '2'
#define BUF_SIZE 8192
#define EXPAND_ALLOC 1024
#define isBlank(ch) (((ch) == ' ') || ((ch) == '\t'))
#define isDecimal(ch) (((ch) >= '0') && ((ch) <= '9'))
#define isOctal(ch) (((ch) >= '0') && ((ch) <= '7'))
#define isWildCard(ch) (((ch) == '*') || ((ch) == '?') || ((ch) == '['))
/* Macros for min/max. */
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
/* I don't like nested includes, but the string and io functions are used
* too often
*/
#include <stdio.h>
#if !defined(NO_STRING_H) || defined(STDC_HEADERS)
# include <string.h>
# if !defined(STDC_HEADERS) && !defined(NO_MEMORY_H) && !defined(__GNUC__)
# include <memory.h>
# endif
# define memzero(s, n) memset ((void *)(s), 0, (n))
#else
# include <strings.h>
# define strchr index
# define strrchr rindex
# define memcpy(d, s, n) bcopy((s), (d), (n))
# define memcmp(s1, s2, n) bcmp((s1), (s2), (n))
# define memzero(s, n) bzero((s), (n))
#endif
enum Location {
_BB_DIR_ROOT = 0,
_BB_DIR_BIN,
_BB_DIR_SBIN,
_BB_DIR_USR_BIN,
_BB_DIR_USR_SBIN
};
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);
extern int chroot_main(int argc, char** argv);
extern int chvt_main(int argc, char** argv);
extern int clear_main(int argc, char** argv);
extern int cp_mv_main(int argc, char** argv);
extern int cut_main(int argc, char** argv);
extern int date_main(int argc, char** argv);
extern int dc_main(int argc, char** argv);
extern int dd_main(int argc, char** argv);
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);
extern int fdflush_main(int argc, char **argv);
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);
extern int halt_main(int argc, char** argv);
extern int head_main(int argc, char** argv);
extern int hostid_main(int argc, char** argv);
extern int hostname_main(int argc, char** argv);
extern int id_main(int argc, char** argv);
extern int init_main(int argc, char** argv);
extern int insmod_main(int argc, char** argv);
extern int kill_main(int argc, char** argv);
extern int length_main(int argc, char** argv);
extern int ln_main(int argc, char** argv);
extern int loadacm_main(int argc, char** argv);
extern int loadfont_main(int argc, char** argv);
extern int loadkmap_main(int argc, char** argv);
extern int losetup_main(int argc, char** argv);
extern int logger_main(int argc, char **argv);
extern int logname_main(int argc, char **argv);
extern int ls_main(int argc, char** argv);
extern int lsmod_main(int argc, char** argv);
extern int makedevs_main(int argc, char** argv);
extern int md5sum_main(int argc, char** argv);
extern int mkdir_main(int argc, char** argv);
extern int mkfifo_main(int argc, char **argv);
extern int mkfs_minix_main(int argc, char **argv);
extern int mknod_main(int argc, char** argv);
extern int mkswap_main(int argc, char** argv);
extern int mktemp_main(int argc, char **argv);
extern int nc_main(int argc, char** argv);
extern int more_main(int argc, char** argv);
extern int mount_main(int argc, char** argv);
extern int mt_main(int argc, char** argv);
extern int nslookup_main(int argc, char **argv);
extern int ping_main(int argc, char **argv);
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);
extern int sed_main(int argc, char** argv);
extern int sfdisk_main(int argc, char** argv);
extern int setkeycodes_main(int argc, char** argv);
extern int shell_main(int argc, char** argv);
extern int sleep_main(int argc, char** argv);
extern int sort_main(int argc, char** argv);
extern int swap_on_off_main(int argc, char** argv);
extern int sync_main(int argc, char** argv);
extern int syslogd_main(int argc, char **argv);
extern int tail_main(int argc, char** argv);
extern int tar_main(int argc, char** argv);
extern int tee_main(int argc, char** argv);
extern int test_main(int argc, char** argv);
extern int telnet_main(int argc, char** argv);
extern int touch_main(int argc, char** argv);
extern int tr_main(int argc, char** argv);
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 umount_main(int argc, char** argv);
extern int uname_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)));
extern void fatalError(const char *s, ...) __attribute__ ((noreturn, format (printf, 1, 2)));
const char *modeString(int mode);
const char *timeString(time_t timeVal);
int isDirectory(const char *name, const int followLinks, struct stat *statBuf);
int isDevice(const char *name);
typedef struct ino_dev_hash_bucket_struct {
struct ino_dev_hash_bucket_struct *next;
ino_t ino;
dev_t dev;
char name[1];
} ino_dev_hashtable_bucket_t;
int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name);
void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
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);
char *chunkstrdup(const char *str);
void freeChunks(void);
int fullWrite(int fd, const char *buf, int len);
int fullRead(int fd, char *buf, int len);
int recursiveAction(const char *fileName, int recurse, int followLinks, int depthFirst,
int (*fileAction) (const char *fileName, struct stat* statbuf, void* userData),
int (*dirAction) (const char *fileName, struct stat* statbuf, void* userData),
void* userData);
extern int createPath (const char *name, int mode);
extern int parse_mode( const char* s, mode_t* theMode);
extern int get_kernel_revision(void);
extern int get_console_fd(char* tty_name);
extern struct mntent *findMountPoint(const char *name, const char *table);
extern void write_mtab(char* blockDevice, char* directory,
char* filesystemType, long flags, char* string_flags);
extern void erase_mtab(const char * name);
extern void mtab_read(void);
extern char *mtab_first(void **iter);
extern char *mtab_next(void **iter);
extern char *mtab_getinfo(const char *match, const char which);
extern int check_wildcard_match(const char* text, const char* pattern);
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 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 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);
extern int device_open(char *device, int mode);
#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);
extern char *find_unused_loop_device (void);
#endif
#if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT)
extern int vdprintf(int d, const char *format, va_list ap);
#endif
#if defined BB_NFSMOUNT
int nfsmount(const char *spec, const char *node, int *flags,
char **extra_opts, char **mount_opts, int running_bg);
#endif
#ifndef RB_POWER_OFF
/* Stop system and switch power off if possible. */
#define RB_POWER_OFF 0x4321fedc
#endif
/* Include our own copy of struct sysinfo to avoid binary compatability
* problems with Linux 2.4, which changed things. Grumble, grumble. */
struct sysinfo {
long uptime; /* Seconds since boot */
unsigned long loads[3]; /* 1, 5, and 15 minute load averages */
unsigned long totalram; /* Total usable main memory size */
unsigned long freeram; /* Available memory size */
unsigned long sharedram; /* Amount of shared memory */
unsigned long bufferram; /* Memory used by buffers */
unsigned long totalswap; /* Total swap space size */
unsigned long freeswap; /* swap space still available */
unsigned short procs; /* Number of current processes */
unsigned long totalhigh; /* Total high memory size */
unsigned long freehigh; /* Available high memory size */
unsigned int mem_unit; /* Memory unit size in bytes */
char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */
};
extern int sysinfo (struct sysinfo* info);
/* Bit map related macros -- libc5 doens't provide these... sigh. */
#ifndef setbit
#define NBBY CHAR_BIT
#define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
#define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
#define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
#define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
#endif
#endif /* _BB_INTERNAL_H_ */
+12 -8
View File
@@ -1,15 +1,19 @@
#!/bin/sh
#Make busybox links list file
# Make busybox links list file.
DF="busybox.def.h"
DF="Config.h"
MF="busybox.c"
LIST="$(sed -n '/^#define/{s/^#define //p;}' $DF)"
LIST="$(gcc -E -dM $DF | sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/BB_\1/gp;' | sort)"
for def in ${LIST}; do
i=`sed -n 's/^#ifdef \<'$def'\>.*\/\/\(.*$\)/\/\1\//gp' $MF`
j=`sed -n '/^#ifdef '$def'.*/,/^#endif/{ s/.*\"\(.*\)\".*/\1/gp; }' $MF`
for k in $j; do
echo $i$k
done
i=`sed -n '/^#ifdef \<'$def'\>.*/,/^#endif/{ s/.*\"\(.*\)\".*\(_BB_DIR_[A-Z_]*\).*$/\2\/\1/gp; }' $MF`
for j in $i; do
if [ -z $j ] ; then
continue;
fi;
echo $j | sed -e 's/_BB_DIR_ROOT//g;s/_BB_DIR_BIN/\/bin/g;' \
-e 's/_BB_DIR_SBIN/\/sbin/g;s/_BB_DIR_USR_BIN/\/usr\/bin/g;' \
-e 's/_BB_DIR_USR_SBIN/\/usr\/sbin/g;'
done;
done
+8 -2
View File
@@ -1,4 +1,10 @@
#!/bin/sh
sed -n '/^#define/{s/.*BB_//; s/$/.o/p; }' busybox.def.h | \
tr [:upper:] [:lower:]
# 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 Config.h | \
sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/\1.c/gp;' \
| tr '[:upper:]' '[:lower:]' | sort
` 2>/dev/null | sed -e 's/\.c$/\.o/g'
+8 -7
View File
@@ -1,5 +1,5 @@
Name: busybox
Version: 0.36
Version: 0.47
Release: 1
Group: System/Utilities
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
@@ -10,12 +10,13 @@ Buildroot: /tmp/%{Name}-%{Version}
Source: %{Name}-%{Version}.tar.gz
%Description
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
provides a pretty complete POSIX environment in a very small package.
Just add a kernel, "ash" (Keith Almquists tiny Bourne shell clone), and
an editor such as "elvis-tiny" or "ae", and you have a full system. This
is makes an excellent environment for a "rescue" disk or any small or
embedded system.
BusyBox combines tiny versions of many common UNIX utilities into a single
small executable. It provides minimalist replacements for most of the utilities
you usually find in fileutils, shellutils, findutils, textutils, grep, gzip,
tar, etc. BusyBox provides a fairly complete POSIX environment for any small
or emdedded system. The utilities in BusyBox generally have fewer options then
their full featured GNU cousins; however, the options that are provided behave
very much like their GNU counterparts.
%Prep
%setup -q -n %{Name}-%{Version}
-11
View File
@@ -1,11 +0,0 @@
#ifndef __BUSYBOX_FUNCTIONS_H__
#define __BUSYBOX_FUNCTIONS_H__
int
mkswap(char *device_name, int pages, int check);
/* pages = 0 for autodetection */
int
fdflush(char *filename);
#endif /* __BUSYBOX_FUNCTIONS_H__ */
+24 -35
View File
@@ -1,7 +1,8 @@
/* vi: set sw=4 ts=4: */
/*
* Mini Cat implementation for busybox
*
* Copyright (C) 1999 by Lineo, inc.
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -20,43 +21,31 @@
*
*/
#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");
}
argc--;
argv++;
while (argc-- > 0) {
file = fopen(*argv, "r");
if (file == NULL) {
perror(*argv);
exit(FALSE);
if (argc == 1) {
print_file(stdin);
exit(TRUE);
}
print_file( file);
argc--;
argv++;
}
exit(TRUE);
while (--argc > 0) {
if(!(strcmp(*++argv, "-"))) {
print_file(stdin);
} else if (print_file_by_name(*argv) == FALSE) {
perror(*argv);
exit(FALSE);
}
}
return(TRUE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+124 -101
View File
@@ -1,8 +1,9 @@
/* vi: set sw=4 ts=4: */
/*
* Mini chown/chmod/chgrp implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -21,135 +22,157 @@
*
*/
#include "busybox.h"
#define BB_DECLARE_EXTERN
#define bb_need_invalid_option
#define bb_need_too_few_args
#include "messages.c"
#include <stdio.h>
#include <grp.h>
#include <pwd.h>
#include "internal.h"
static uid_t uid=-1;
static gid_t gid=-1;
static long uid = -1;
static long gid = -1;
static int whichApp;
static char* invocationName=NULL;
static char* theMode=NULL;
static char *theMode = NULL;
#define CHGRP_APP 1
#define CHOWN_APP 2
#define CHMOD_APP 3
static const char chgrp_usage[] = "chgrp [OPTION]... GROUP FILE...\n\n"
"Change the group membership of each FILE to GROUP.\n"
"\nOptions:\n\t-R\tchange files and directories recursively\n";
static const char chown_usage[] = "chown [OPTION]... OWNER[.[GROUP] FILE...\n\n"
"Change the owner and/or group of each FILE to OWNER and/or GROUP.\n"
"\nOptions:\n\t-R\tchange files and directories recursively\n";
static const char chmod_usage[] = "chmod [-R] MODE[,MODE]... FILE...\n\n"
"Each MODE is one or more of the letters ugoa, one of the symbols +-= and\n"
"one or more of the letters rwxst.\n\n"
"\nOptions:\n\t-R\tchange files and directories recursively.\n";
static int fileAction(const char *fileName, struct stat* statbuf)
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
{
switch (whichApp) {
switch (whichApp) {
case CHGRP_APP:
case CHOWN_APP:
if (chown(fileName, (whichApp==CHOWN_APP)? uid : statbuf->st_uid,
(gid==-1)? statbuf->st_gid : gid) == 0) {
return( TRUE);
}
break;
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
if (lchown
(fileName, (whichApp == CHOWN_APP) ? uid : statbuf->st_uid,
(gid == -1) ? statbuf->st_gid : gid) == 0)
#else
if (chown
(fileName, (whichApp == CHOWN_APP) ? uid : statbuf->st_uid,
(gid == -1) ? statbuf->st_gid : gid) == 0)
#endif
{
return (TRUE);
}
break;
case CHMOD_APP:
/* Parse the specified modes */
if ( parse_mode(theMode, &(statbuf->st_mode)) == FALSE ) {
fprintf(stderr, "%s: Unknown mode: %s\n", invocationName, theMode);
exit( FALSE);
}
if (chmod(fileName, statbuf->st_mode) == 0)
return( TRUE);
break;
}
perror(fileName);
return( FALSE);
/* Parse the specified modes */
if (parse_mode(theMode, &(statbuf->st_mode)) == FALSE) {
fatalError( "unknown mode: %s\n", theMode);
}
if (chmod(fileName, statbuf->st_mode) == 0)
return (TRUE);
break;
}
perror(fileName);
return (FALSE);
}
int chmod_chown_chgrp_main(int argc, char **argv)
{
int recursiveFlag=FALSE;
char *groupName;
const char *appUsage;
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)? CHMOD_APP : CHGRP_APP;
whichApp = (strcmp(applet_name, "chown") == 0)?
CHOWN_APP : (strcmp(applet_name, "chmod") == 0)?
CHMOD_APP : CHGRP_APP;
appUsage = (whichApp==CHOWN_APP)? chown_usage : (whichApp==CHMOD_APP)? chmod_usage : chgrp_usage;
appUsage = (whichApp == CHOWN_APP)?
chown_usage : (whichApp == CHMOD_APP) ? chmod_usage : chgrp_usage;
if (argc < 2)
usage( appUsage);
invocationName=*argv;
argc--;
argv++;
/* Parse options */
while (**argv == '-') {
while (*++(*argv)) switch (**argv) {
case 'R':
recursiveFlag = TRUE;
break;
default:
fprintf(stderr, "Unknown option: %c\n", **argv);
usage( appUsage);
}
argc--;
if (argc < 2)
usage(appUsage);
argv++;
}
if ( whichApp == CHMOD_APP ) {
theMode=*argv;
} else {
/* Find the selected group */
if ( whichApp==CHGRP_APP ) {
groupName = *argv;
gid = my_getgrnam(groupName);
if (gid == -1)
goto bad_group;
/* Parse options */
while (--argc >= 0 && *argv && (**argv == '-')) {
while (stopIt==FALSE && *++(*argv)) {
switch (**argv) {
case 'R':
recursiveFlag = TRUE;
break;
default:
theMode=*argv-1;
stopIt = TRUE;
}
}
if (stopIt==TRUE)
break;
argv++;
}
if (argc == 0 || *argv == NULL) {
errorMsg(too_few_args);
}
if (whichApp == CHMOD_APP) {
if (theMode==NULL)
theMode = *argv;
} else {
groupName = strchr(*argv, '.');
if (groupName) {
*groupName++ = '\0';
gid = my_getgrnam(groupName);
if (gid == -1)
goto bad_group;
} else
gid = -1;
/* Find the selected group */
if (whichApp == CHGRP_APP) {
groupName = *argv;
gid = strtoul(groupName, &p, 10); /* maybe it's already numeric */
if (groupName == p)
gid = my_getgrnam(groupName);
if (gid == -1)
goto bad_group;
} else {
groupName = strchr(*argv, '.');
if (groupName == NULL)
groupName = strchr(*argv, ':');
if (groupName) {
*groupName++ = '\0';
gid = strtoul(groupName, &p, 10);
if (groupName == p)
gid = my_getgrnam(groupName);
if (gid == -1)
goto bad_group;
} else
gid = -1;
}
/* Find the selected user (if appropriate) */
if (whichApp == CHOWN_APP) {
uid = strtoul(*argv, &p, 10); /* if numeric ... */
if (*argv == p)
uid = my_getpwnam(*argv);
if (uid == -1) {
fatalError( "unknown user name: %s\n", *argv);
}
}
}
/* Find the selected user (if appropriate) */
if (whichApp==CHOWN_APP) {
uid = my_getpwnam(*argv);
if (uid == -1) {
fprintf(stderr, "%s: Unknown user name: %s\n", invocationName, *argv);
exit( FALSE);
}
/* Ok, ready to do the deed now */
if (argc < 1) {
fatalError(too_few_args);
}
}
/* Ok, ready to do the deed now */
if (argc <= 1) {
fprintf(stderr, "%s: too few arguments", invocationName);
exit( FALSE);
}
while (argc-- > 1) {
if (recursiveAction( *(++argv), recursiveFlag, TRUE, FALSE, fileAction, fileAction)==FALSE)
exit( FALSE);
}
exit(TRUE);
while (argc-- > 1) {
if (recursiveAction (*(++argv), recursiveFlag, FALSE, FALSE,
fileAction, fileAction, NULL) == FALSE)
exit(FALSE);
}
exit(TRUE);
bad_group:
fprintf(stderr, "%s: Unknown group name: %s\n", invocationName, groupName);
exit( FALSE);
bad_group:
fatalError( "unknown group name: %s\n", groupName);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+40 -35
View File
@@ -1,8 +1,9 @@
/* vi: set sw=4 ts=4: */
/*
* Mini chroot implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -21,46 +22,50 @@
*
*/
#include "internal.h"
#include "busybox.h"
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n\n"
"Run COMMAND with root directory set to NEWROOT.\n";
int chroot_main(int argc, char **argv)
{
if ( (argc < 2) || (**(argv+1) == '-') ) {
usage( chroot_usage);
}
argc--;
argv++;
if (chroot (*argv) || (chdir ("/"))) {
fprintf(stderr, "chroot: cannot change root directory to %s: %s\n",
*argv, strerror(errno));
exit( FALSE);
}
argc--;
argv++;
if (argc >= 1) {
fprintf(stderr, "command: %s\n", *argv);
execvp (*argv, argv);
}
else {
char *prog;
prog = getenv ("SHELL");
if (!prog)
prog = "/bin/sh";
execlp (prog, prog, NULL);
}
fprintf(stderr, "chroot: cannot execute %s: %s\n",
*argv, strerror(errno));
exit( FALSE);
if ((argc < 2) || (**(argv + 1) == '-')) {
usage(chroot_usage);
}
argc--;
argv++;
if (chroot(*argv) || (chdir("/"))) {
fatalError("cannot change root directory to %s: %s\n", *argv, strerror(errno));
}
argc--;
argv++;
if (argc >= 1) {
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("cannot execute %s: %s\n", prog, strerror(errno));
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+30 -22
View File
@@ -1,36 +1,44 @@
/* vi: set sw=4 ts=4: */
/*
* chvt.c - aeb - 940227 - Change virtual terminal
*
* busyboxed by Erik Andersen
*/
#include "internal.h"
#include <sys/types.h>
#include <sys/ioctl.h>
#include <linux/vt.h>
#include "busybox.h"
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
extern int getfd(void);
/* From <linux/vt.h> */
#define VT_ACTIVATE 0x5606 /* make vt active */
#define VT_WAITACTIVE 0x5607 /* wait for vt active */
int
chvt_main(int argc, char** argv)
int chvt_main(int argc, char **argv)
{
int fd, num;
int fd, num;
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
usage ("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
}
fd = get_console_fd("/dev/console");
num = atoi(argv[1]);
if (ioctl(fd,VT_ACTIVATE,num)) {
perror("VT_ACTIVATE");
exit(FALSE);
}
if (ioctl(fd,VT_WAITACTIVE,num)) {
perror("VT_WAITACTIVE");
exit(FALSE);
}
exit( TRUE);
if ((argc != 2) || (**(argv + 1) == '-'))
usage (chvt_usage);
fd = get_console_fd("/dev/console");
num = atoi(argv[1]);
if (ioctl(fd, VT_ACTIVATE, num)) {
perror("VT_ACTIVATE");
exit(FALSE);
}
if (ioctl(fd, VT_WAITACTIVE, num)) {
perror("VT_WAITACTIVE");
exit(FALSE);
}
return(TRUE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+5 -5
View File
@@ -1,8 +1,9 @@
/* vi: set sw=4 ts=4: */
/*
* Mini clear implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -21,13 +22,12 @@
*
*/
#include "internal.h"
#include "busybox.h"
#include <stdio.h>
extern int
clear_main(int argc, char** argv)
extern int clear_main(int argc, char **argv)
{
printf("\033[H\033[J");
exit( TRUE);
return(TRUE);
}
+741
View File
@@ -0,0 +1,741 @@
/* vi: set sw=4 ts=4: */
/*
* Termios command line History and Editting, originally
* intended for NetBSD sh (ash)
* Copyright (c) 1999
* Main code: Adam Rogoyski <rogoyski@cs.utexas.edu>
* Etc: Dave Cinege <dcinege@psychosis.com>
* Majorly adjusted/re-written for busybox:
* Erik Andersen <andersee@debian.org>
*
* You may use this code as you wish, so long as the original author(s)
* are attributed in any redistributions of the source code.
* This code is 'as is' with no warranty.
* This code may safely be consumed by a BSD or GPL license.
*
* v 0.5 19990328 Initial release
*
* Future plans: Simple file and path name completion. (like BASH)
*
*/
/*
Usage and Known bugs:
Terminal key codes are not extensive, and more will probably
need to be added. This version was created on Debian GNU/Linux 2.x.
Delete, Backspace, Home, End, and the arrow keys were tested
to work in an Xterm and console. Ctrl-A also works as Home.
Ctrl-E also works as End. The binary size increase is <3K.
Editting will not display correctly for lines greater then the
terminal width. (more then one line.) However, history will.
*/
#include "busybox.h"
#ifdef BB_FEATURE_SH_COMMAND_EDITING
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <ctype.h>
#include <signal.h>
#define MAX_HISTORY 15 /* Maximum length of the linked list for the command line history */
#define ESC 27
#define DEL 127
#define member(c, s) ((c) ? ((char *)strchr ((s), (c)) != (char *)NULL) : 0)
#define whitespace(c) (((c) == ' ') || ((c) == '\t'))
static struct history *his_front = NULL; /* First element in command line list */
static struct history *his_end = NULL; /* Last element in command line list */
/* ED: sparc termios is broken: revert back to old termio handling. */
#ifdef BB_FEATURE_USE_TERMIOS
#if #cpu(sparc)
# include <termio.h>
# define termios termio
# define setTermSettings(fd,argp) ioctl(fd,TCSETAF,argp)
# define getTermSettings(fd,argp) ioctl(fd,TCGETA,argp)
#else
# include <termios.h>
# define setTermSettings(fd,argp) tcsetattr(fd,TCSANOW,argp)
# define getTermSettings(fd,argp) tcgetattr(fd, argp);
#endif
/* Current termio and the previous termio before starting sh */
struct termios initial_settings, new_settings;
#ifndef _POSIX_VDISABLE
#define _POSIX_VDISABLE '\0'
#endif
#endif
static int cmdedit_termw = 80; /* actual terminal width */
static int cmdedit_scroll = 27; /* width of EOL scrolling region */
static int history_counter = 0; /* Number of commands in history list */
static int reset_term = 0; /* Set to true if the terminal needs to be reset upon exit */
static int exithandler_set = 0; /* Set to true when atexit() has been called */
struct history {
char *s;
struct history *p;
struct history *n;
};
#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)
{
if (w > 20) {
cmdedit_termw = w;
cmdedit_scroll = w / 3;
} else {
errorMsg("\n*** Error: minimum screen width is 21\n");
}
}
void cmdedit_reset_term(void)
{
if (reset_term)
/* sparc and other have broken termios support: use old termio handling. */
setTermSettings(fileno(stdin), (void*) &initial_settings);
#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)
{
cmdedit_reset_term();
fprintf(stdout, "\n");
if (sig!=SIGINT)
exit(TRUE);
}
/* Go to HOME position */
void input_home(int outputFd, int *cursor)
{
while (*cursor > 0) {
xwrite(outputFd, "\b", 1);
--*cursor;
}
}
/* Go to END position */
void input_end(int outputFd, int *cursor, int len)
{
while (*cursor < len) {
xwrite(outputFd, "\033[C", 3);
++*cursor;
}
}
/* Delete the char in back of the cursor */
void input_backspace(char* command, int outputFd, int *cursor, int *len)
{
int j = 0;
/* Debug crap */
//fprintf(stderr, "\nerik: len=%d, cursor=%d, strlen(command)='%d'\n", *len, *cursor, strlen(command));
//xwrite(outputFd, command, *len);
//*cursor = *len;
if (*cursor > 0) {
xwrite(outputFd, "\b \b", 3);
--*cursor;
memmove(command + *cursor, command + *cursor + 1,
BUFSIZ - *cursor + 1);
for (j = *cursor; j < (BUFSIZ - 1); j++) {
if (!*(command + j))
break;
else
xwrite(outputFd, (command + j), 1);
}
xwrite(outputFd, " \b", 2);
while (j-- > *cursor)
xwrite(outputFd, "\b", 1);
--*len;
}
}
/* Delete the char in front of the cursor */
void input_delete(char* command, int outputFd, int cursor, int *len)
{
int j = 0;
if (cursor == *len)
return;
memmove(command + cursor, command + cursor + 1,
BUFSIZ - cursor - 1);
for (j = cursor; j < (BUFSIZ - 1); j++) {
if (!*(command + j))
break;
else
xwrite(outputFd, (command + j), 1);
}
xwrite(outputFd, " \b", 2);
while (j-- > cursor)
xwrite(outputFd, "\b", 1);
--*len;
}
/* Move forward one charactor */
void input_forward(int outputFd, int *cursor, int len)
{
if (*cursor < len) {
xwrite(outputFd, "\033[C", 3);
++*cursor;
}
}
/* Move back one charactor */
void input_backward(int outputFd, int *cursor)
{
if (*cursor > 0) {
xwrite(outputFd, "\033[D", 3);
--*cursor;
}
}
#ifdef BB_FEATURE_SH_TAB_COMPLETION
char** username_tab_completion(char* command, int *num_matches)
{
char **matches = (char **) NULL;
*num_matches=0;
fprintf(stderr, "\nin username_tab_completion\n");
return (matches);
}
#include <dirent.h>
char** exe_n_cwd_tab_completion(char* command, int *num_matches)
{
char *dirName;
char **matches;
DIR *dir;
struct dirent *next;
matches = xmalloc( sizeof(char*)*50);
/* Stick a wildcard onto the command, for later use */
strcat( command, "*");
/* Now wall the current directory */
dirName = get_current_dir_name();
dir = opendir(dirName);
if (!dir) {
/* Don't print an error, just shut up and return */
*num_matches=0;
return (matches);
}
while ((next = readdir(dir)) != NULL) {
/* Some quick sanity checks */
if ((strcmp(next->d_name, "..") == 0)
|| (strcmp(next->d_name, ".") == 0)) {
continue;
}
/* See if this matches */
if (check_wildcard_match(next->d_name, command) == TRUE) {
/* Cool, found a match. Add it to the list */
matches[*num_matches] = xmalloc(strlen(next->d_name)+1);
strcpy( matches[*num_matches], next->d_name);
++*num_matches;
//matches = realloc( matches, sizeof(char*)*(*num_matches));
}
}
return (matches);
}
void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len)
{
/* Do TAB completion */
static int num_matches=0;
static char **matches = (char **) NULL;
int pos = cursor;
if (lastWasTab == FALSE) {
char *tmp, *tmp1, *matchBuf;
/* For now, we will not bother with trying to distinguish
* whether the cursor is in/at a command extression -- we
* will always try all possible matches. If you don't like
* that then feel free to fix it.
*/
/* Make a local copy of the string -- up
* to the position of the cursor */
matchBuf = (char *) xcalloc(BUFSIZ, sizeof(char));
strncpy(matchBuf, command, cursor);
tmp=matchBuf;
/* skip past any command seperator tokens */
while (*tmp && (tmp1=strpbrk(tmp, ";|&{(`")) != NULL) {
tmp=++tmp1;
/* skip any leading white space */
while (*tmp && isspace(*tmp))
++tmp;
}
/* skip any leading white space */
while (*tmp && isspace(*tmp))
++tmp;
/* Free up any memory already allocated */
if (matches) {
free(matches);
matches = (char **) NULL;
}
/* If the word starts with `~' and there is no slash in the word,
* then try completing this word as a username. */
/* FIXME -- this check is broken! */
if (*tmp == '~' && !strchr(tmp, '/'))
matches = username_tab_completion(tmp, &num_matches);
/* Try to match any executable in our path and everything
* in the current working directory that matches. */
if (!matches)
matches = exe_n_cwd_tab_completion(tmp, &num_matches);
/* Don't leak memory */
free( matchBuf);
/* Did we find exactly one match? */
if (matches && num_matches==1) {
/* write out the matched command */
strncpy(command+pos, matches[0]+pos, strlen(matches[0])-pos);
len=strlen(command);
cursor=len;
xwrite(outputFd, matches[0]+pos, strlen(matches[0])-pos);
break;
}
} else {
/* Ok -- the last char was a TAB. Since they
* just hit TAB again, print a list of all the
* available choices... */
if ( matches && num_matches>0 ) {
int i, col;
/* Go to the next line */
xwrite(outputFd, "\n", 1);
/* Print the list of matches */
for (i=0,col=0; i<num_matches; i++) {
char foo[17];
sprintf(foo, "%-14s ", matches[i]);
col += xwrite(outputFd, foo, strlen(foo));
if (col > 60 && matches[i+1] != NULL) {
xwrite(outputFd, "\n", 1);
col = 0;
}
}
/* Go to the next line */
xwrite(outputFd, "\n", 1);
/* Rewrite the prompt */
xwrite(outputFd, prompt, strlen(prompt));
/* Rewrite the command */
xwrite(outputFd, command, len);
/* Put the cursor back to where it used to be */
for (cursor=len; cursor > pos; cursor--)
xwrite(outputFd, "\b", 1);
}
}
}
#endif
void get_previous_history(struct history **hp, char* command)
{
if ((*hp)->s)
free((*hp)->s);
(*hp)->s = strdup(command);
*hp = (*hp)->p;
}
void get_next_history(struct history **hp, char* command)
{
if ((*hp)->s)
free((*hp)->s);
(*hp)->s = strdup(command);
*hp = (*hp)->n;
}
/*
* This function is used to grab a character buffer
* from the input file descriptor and allows you to
* a string with full command editing (sortof like
* a mini readline).
*
* The following standard commands are not implemented:
* ESC-b -- Move back one word
* ESC-f -- Move forward one word
* ESC-d -- Delete back one word
* ESC-h -- Delete forward one word
* CTL-t -- Transpose two characters
*
* Furthermore, the "vi" command editing keys are not implemented.
*
* TODO: implement TAB command completion. :)
*/
extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
{
int inputFd=fileno(stdin);
int outputFd=fileno(stdout);
int nr = 0;
int len = 0;
int j = 0;
int cursor = 0;
int break_out = 0;
int ret = 0;
int lastWasTab = FALSE;
char c = 0;
struct history *hp = his_end;
if (!reset_term) {
getTermSettings(inputFd, (void*) &initial_settings);
memcpy(&new_settings, &initial_settings, sizeof(struct termios));
new_settings.c_cc[VMIN] = 1;
new_settings.c_cc[VTIME] = 0;
new_settings.c_cc[VINTR] = _POSIX_VDISABLE; /* Turn off CTRL-C, so we can trap it */
new_settings.c_lflag &= ~ICANON; /* unbuffered input */
new_settings.c_lflag &= ~(ECHO|ECHOCTL|ECHONL); /* Turn off echoing */
reset_term = 1;
}
setTermSettings(inputFd, (void*) &new_settings);
memset(command, 0, BUFSIZ);
while (1) {
if ((ret = read(inputFd, &c, 1)) < 1)
return;
//fprintf(stderr, "got a '%c' (%d)\n", c, c);
switch (c) {
case '\n':
case '\r':
/* Enter */
*(command + len++ + 1) = c;
xwrite(outputFd, &c, 1);
break_out = 1;
break;
case 1:
/* Control-a -- Beginning of line */
input_home(outputFd, &cursor);
case 2:
/* Control-b -- Move back one character */
input_backward(outputFd, &cursor);
break;
case 3:
/* Control-c -- leave the current line,
* and start over on the next line */
/* Go to the next line */
xwrite(outputFd, "\n", 1);
/* Rewrite the prompt */
xwrite(outputFd, prompt, strlen(prompt));
/* Reset the command string */
memset(command, 0, BUFSIZ);
len = cursor = 0;
break;
case 4:
/* Control-d -- Delete one character, or exit
* if the len=0 and no chars to delete */
if (len == 0) {
xwrite(outputFd, "exit", 4);
clean_up_and_die(0);
} else {
input_delete(command, outputFd, cursor, &len);
}
break;
case 5:
/* Control-e -- End of line */
input_end(outputFd, &cursor, len);
break;
case 6:
/* Control-f -- Move forward one character */
input_forward(outputFd, &cursor, len);
break;
case '\b':
case DEL:
/* Control-h and DEL */
input_backspace(command, outputFd, &cursor, &len);
break;
case '\t':
#ifdef BB_FEATURE_SH_TAB_COMPLETION
input_tab(command, prompt, outputFd, &cursor, &len);
#endif
break;
case 14:
/* Control-n -- Get next command in history */
if (hp && hp->n && hp->n->s) {
get_next_history(&hp, command);
goto rewrite_line;
} else {
xwrite(outputFd, "\007", 1);
}
break;
case 16:
/* Control-p -- Get previous command from history */
if (hp && hp->p) {
get_previous_history(&hp, command);
goto rewrite_line;
} else {
xwrite(outputFd, "\007", 1);
}
break;
case ESC:{
/* escape sequence follows */
if ((ret = read(inputFd, &c, 1)) < 1)
return;
if (c == '[') { /* 91 */
if ((ret = read(inputFd, &c, 1)) < 1)
return;
switch (c) {
case 'A':
/* Up Arrow -- Get previous command from history */
if (hp && hp->p) {
get_previous_history(&hp, command);
goto rewrite_line;
} else {
xwrite(outputFd, "\007", 1);
}
break;
case 'B':
/* Down Arrow -- Get next command in history */
if (hp && hp->n && hp->n->s) {
get_next_history(&hp, command);
goto rewrite_line;
} else {
xwrite(outputFd, "\007", 1);
}
break;
/* Rewrite the line with the selected history item */
rewrite_line:
/* erase old command from command line */
len = strlen(command)-strlen(hp->s);
while (len>cursor)
input_delete(command, outputFd, cursor, &len);
while (cursor>0)
input_backspace(command, outputFd, &cursor, &len);
input_home(outputFd, &cursor);
/* write new command */
strcpy(command, hp->s);
len = strlen(hp->s);
xwrite(outputFd, command, len);
cursor = len;
break;
case 'C':
/* Right Arrow -- Move forward one character */
input_forward(outputFd, &cursor, len);
break;
case 'D':
/* Left Arrow -- Move back one character */
input_backward(outputFd, &cursor);
break;
case '3':
/* Delete */
input_delete(command, outputFd, cursor, &len);
break;
case '1':
/* Home (Ctrl-A) */
input_home(outputFd, &cursor);
break;
case '4':
/* End (Ctrl-E) */
input_end(outputFd, &cursor, len);
break;
default:
xwrite(outputFd, "\007", 1);
}
if (c == '1' || c == '3' || c == '4')
if ((ret = read(inputFd, &c, 1)) < 1)
return; /* read 126 (~) */
}
if (c == 'O') {
/* 79 */
if ((ret = read(inputFd, &c, 1)) < 1)
return;
switch (c) {
case 'H':
/* Home (xterm) */
input_home(outputFd, &cursor);
break;
case 'F':
/* End (xterm) */
input_end(outputFd, &cursor, len);
break;
default:
xwrite(outputFd, "\007", 1);
}
}
c = 0;
break;
}
default: /* If it's regular input, do the normal thing */
if (!isprint(c)) { /* Skip non-printable characters */
break;
}
if (len >= (BUFSIZ - 2)) /* Need to leave space for enter */
break;
len++;
if (cursor == (len - 1)) { /* Append if at the end of the line */
*(command + cursor) = c;
} else { /* Insert otherwise */
memmove(command + cursor + 1, command + cursor,
len - cursor - 1);
*(command + cursor) = c;
for (j = cursor; j < len; j++)
xwrite(outputFd, command + j, 1);
for (; j > cursor; j--)
xwrite(outputFd, "\033[D", 3);
}
cursor++;
xwrite(outputFd, &c, 1);
break;
}
if (c == '\t')
lastWasTab = TRUE;
else
lastWasTab = FALSE;
if (break_out) /* Enter is the command terminator, no more input. */
break;
}
nr = len + 1;
setTermSettings(inputFd, (void *) &initial_settings);
reset_term = 0;
/* Handle command history log */
if (*(command)) {
struct history *h = his_end;
if (!h) {
/* No previous history -- 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);
h->n->p = h;
h->n->n = NULL;
h->n->s = NULL;
his_end = h->n;
history_counter++;
} else {
/* Add a new history command -- this memory is never freed */
h->n = xmalloc(sizeof(struct history));
h->n->p = h;
h->n->n = NULL;
h->n->s = NULL;
h->s = strdup(command);
his_end = h->n;
/* After max history, remove the oldest command */
if (history_counter >= MAX_HISTORY) {
struct history *p = his_front->n;
p->p = NULL;
free(his_front->s);
free(his_front);
his_front = p;
} else {
history_counter++;
}
}
}
return;
}
extern void cmdedit_init(void)
{
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 */
+38
View File
@@ -0,0 +1,38 @@
#ifndef CMDEDIT_H
#define CMDEDIT_H
/* unix systems can #define POSIX to use termios, otherwise
* the bsd or sysv interface will be used
*/
#ifdef __STDC__
#include <stddef.h>
typedef size_t (*cmdedit_strwidth_proc)(char *);
void cmdedit_init(void);
void cmdedit_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 */
void cmdedit_strwidth(cmdedit_strwidth_proc); /* to bind cmdedit_strlen */
extern int (*cmdedit_in_hook)(char *);
extern int (*cmdedit_out_hook)(char *);
extern int (*cmdedit_tab_hook)(char *, int, int *);
#else /* not __STDC__ */
void cmdedit_init(void);
void cmdedit_read_input(char* promptStr, char* command);
void cmdedit_setwidth();
void cmdedit_histadd();
void cmdedit_strwidth();
extern int (*cmdedit_in_hook)();
extern int (*cmdedit_out_hook)();
extern int (*cmdedit_tab_hook)();
#endif /* __STDC__ */
#endif /* CMDEDIT_H */
+30 -22
View File
@@ -1,36 +1,44 @@
/* vi: set sw=4 ts=4: */
/*
* chvt.c - aeb - 940227 - Change virtual terminal
*
* busyboxed by Erik Andersen
*/
#include "internal.h"
#include <sys/types.h>
#include <sys/ioctl.h>
#include <linux/vt.h>
#include "busybox.h"
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
extern int getfd(void);
/* From <linux/vt.h> */
#define VT_ACTIVATE 0x5606 /* make vt active */
#define VT_WAITACTIVE 0x5607 /* wait for vt active */
int
chvt_main(int argc, char** argv)
int chvt_main(int argc, char **argv)
{
int fd, num;
int fd, num;
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
usage ("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
}
fd = get_console_fd("/dev/console");
num = atoi(argv[1]);
if (ioctl(fd,VT_ACTIVATE,num)) {
perror("VT_ACTIVATE");
exit(FALSE);
}
if (ioctl(fd,VT_WAITACTIVE,num)) {
perror("VT_WAITACTIVE");
exit(FALSE);
}
exit( TRUE);
if ((argc != 2) || (**(argv + 1) == '-'))
usage (chvt_usage);
fd = get_console_fd("/dev/console");
num = atoi(argv[1]);
if (ioctl(fd, VT_ACTIVATE, num)) {
perror("VT_ACTIVATE");
exit(FALSE);
}
if (ioctl(fd, VT_WAITACTIVE, num)) {
perror("VT_WAITACTIVE");
exit(FALSE);
}
return(TRUE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+5 -5
View File
@@ -1,8 +1,9 @@
/* vi: set sw=4 ts=4: */
/*
* Mini clear implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -21,13 +22,12 @@
*
*/
#include "internal.h"
#include "busybox.h"
#include <stdio.h>
extern int
clear_main(int argc, char** argv)
extern int clear_main(int argc, char **argv)
{
printf("\033[H\033[J");
exit( TRUE);
return(TRUE);
}
+34 -36
View File
@@ -1,50 +1,48 @@
/* vi: set sw=4 ts=4: */
/*
* 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>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <linux/vt.h>
#include <stdio.h>
extern int getfd(void);
char *progname;
/* From <linux/vt.h> */
#define VT_DISALLOCATE 0x5608 /* free memory associated to vt */
int
deallocvt_main(int argc, char *argv[]) {
int fd, num, i;
int deallocvt_main(int argc, char *argv[])
{
int fd, num, i;
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
usage ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
}
//if ((argc > 2) || ((argv == 2) && (**(argv + 1) == '-')))
if (argc > 2)
usage(deallocvt_usage);
progname = argv[0];
fd = get_console_fd("/dev/console");
fd = get_console_fd("/dev/console");
if (argc == 1) {
/* deallocate all unused consoles */
if (ioctl(fd,VT_DISALLOCATE,0)) {
perror("VT_DISALLOCATE");
exit(1);
}
} else
for (i = 1; i < argc; i++) {
num = atoi(argv[i]);
if (num == 0)
fprintf(stderr, "%s: 0: illegal VT number\n", progname);
else if (num == 1)
fprintf(stderr, "%s: VT 1 cannot be deallocated\n", progname);
else
if (ioctl(fd,VT_DISALLOCATE,num)) {
perror("VT_DISALLOCATE");
fprintf(stderr, "%s: could not deallocate console %d\n",
progname, num);
exit(1);
}
}
exit(0);
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)
errorMsg("0: illegal VT number\n");
else if (num == 1)
errorMsg("VT 1 cannot be deallocated\n");
else if (ioctl(fd, VT_DISALLOCATE, num)) {
perror("VT_DISALLOCATE");
fatalError("could not deallocate console %d\n", num);
}
}
printf("erik: C\n");
return( TRUE);
}
+92
View File
@@ -0,0 +1,92 @@
/* vi: set sw=4 ts=4: */
/*
* Mini dumpkmap implementation for busybox
*
* Copyright (C) Arne Bernin <arne@matrix.loopback.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "busybox.h"
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
/* From <linux/kd.h> */
struct kbentry {
unsigned char kb_table;
unsigned char kb_index;
unsigned short kb_value;
};
#define KDGKBENT 0x4B46 /* gets one entry in translation table */
/* From <linux/keyboard.h> */
#define NR_KEYS 128
#define MAX_NR_KEYMAPS 256
int dumpkmap_main(int argc, char **argv)
{
struct kbentry ke;
int i, j, fd;
char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap";
if (argc>=2 && *argv[1]=='-') {
usage(dumpkmap_usage);
}
fd = open("/dev/tty0", O_RDWR);
if (fd < 0) {
errorMsg("Error opening /dev/tty0: %s\n", strerror(errno));
return 1;
}
write(1, magic, 7);
for (i=0; i < MAX_NR_KEYMAPS; i++) flags[i]=0;
flags[0]=1;
flags[1]=1;
flags[2]=1;
flags[4]=1;
flags[5]=1;
flags[6]=1;
flags[8]=1;
flags[9]=1;
flags[10]=1;
flags[12]=1;
/* dump flags */
for (i=0; i < MAX_NR_KEYMAPS; i++) write(1,&flags[i],1);
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
if (flags[i] == 1) {
for (j = 0; j < NR_KEYS; j++) {
ke.kb_index = j;
ke.kb_table = i;
if (ioctl(fd, KDGKBENT, &ke) < 0) {
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,(void*)&ke.kb_value,2);
}
}
}
}
close(fd);
return 0;
}
+406
View File
@@ -0,0 +1,406 @@
/* vi: set sw=4 ts=4: */
/*
* Derived from
* mapscrn.c - version 0.92
*
* Was taken from console-tools and adapted by
* Peter Novodvorsky <petya@logic.ru>
*/
#include "busybox.h"
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
#include <errno.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/kd.h>
typedef unsigned short unicode;
static long int ctoi(unsigned char *s, int *is_unicode);
int old_screen_map_read_ascii(FILE * fp, unsigned char buf[]);
int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode);
unicode utf8_to_ucs2(char *buf);
int screen_map_load(int fd, FILE * fp);
int loadacm_main(int argc, char **argv)
{
int fd;
if (argc>=2 && *argv[1]=='-') {
usage(loadacm_usage);
}
fd = open("/dev/tty", O_RDWR);
if (fd < 0) {
errorMsg("Error opening /dev/tty1: %s\n", strerror(errno));
return( FALSE);
}
if (screen_map_load(fd, stdin)) {
errorMsg("Error loading acm: %s\n", strerror(errno));
return( FALSE);
}
write(fd, "\033(K", 3);
return( TRUE);
}
int screen_map_load(int fd, FILE * fp)
{
struct stat stbuf;
unicode wbuf[E_TABSZ];
unsigned char buf[E_TABSZ];
int parse_failed = 0;
int is_unicode;
if (fstat(fileno(fp), &stbuf))
perror("Cannot stat map file"), exit(1);
/* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */
if (!
(parse_failed =
(-1 == uni_screen_map_read_ascii(fp, wbuf, &is_unicode)))
|| (S_ISREG(stbuf.st_mode) && (stbuf.st_size == (sizeof(unicode) * E_TABSZ)))) { /* test for binary UTF map by size */
if (parse_failed) {
if (-1 == fseek(fp, 0, SEEK_SET)) {
if (errno == ESPIPE)
errorMsg("16bit screen-map MUST be a regular file.\n"),
exit(1);
else
perror("fseek failed reading binary 16bit screen-map"),
exit(1);
}
if (fread(wbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1)
perror("Cannot read [new] map from file"), exit(1);
#if 0
else
errorMsg("Input screen-map is binary.\n");
#endif
}
/* if it was effectively a 16-bit ASCII, OK, else try to read as 8-bit map */
/* same if it was binary, ie. if parse_failed */
if (parse_failed || is_unicode) {
if (ioctl(fd, PIO_UNISCRNMAP, wbuf))
perror("PIO_UNISCRNMAP ioctl"), exit(1);
else
return 0;
}
}
/* rewind... */
if (-1 == fseek(fp, 0, SEEK_SET)) {
if (errno == ESPIPE)
errorMsg("Assuming 8bit screen-map - MUST be a regular file.\n"),
exit(1);
else
perror("fseek failed assuming 8bit screen-map"), exit(1);
}
/* ... and try an old 8-bit screen-map */
if (!(parse_failed = (-1 == old_screen_map_read_ascii(fp, buf))) ||
(S_ISREG(stbuf.st_mode) && (stbuf.st_size == E_TABSZ))) { /* test for binary old 8-bit map by size */
if (parse_failed) {
if (-1 == fseek(fp, 0, SEEK_SET)) {
if (errno == ESPIPE)
/* should not - it succedeed above */
errorMsg("fseek() returned ESPIPE !\n"),
exit(1);
else
perror("fseek for binary 8bit screen-map"), exit(1);
}
if (fread(buf, E_TABSZ, 1, fp) != 1)
perror("Cannot read [old] map from file"), exit(1);
#if 0
else
errorMsg("Input screen-map is binary.\n");
#endif
}
if (ioctl(fd, PIO_SCRNMAP, buf))
perror("PIO_SCRNMAP ioctl"), exit(1);
else
return 0;
}
errorMsg("Error parsing symbolic map\n");
return(1);
}
/*
* - reads `fp' as a 16-bit ASCII SFM file.
* - returns -1 on error.
* - returns it in `unicode' in an E_TABSZ-elements array.
* - sets `*is_unicode' flagiff there were any non-8-bit
* (ie. real 16-bit) mapping.
*
* FIXME: ignores everything after second word
*/
int uni_screen_map_read_ascii(FILE * fp, unicode buf[], int *is_unicode)
{
char buffer[256]; /* line buffer reading file */
char *p, *q; /* 1st + 2nd words in line */
int in, on; /* the same, as numbers */
int tmp_is_unicode; /* tmp for is_unicode calculation */
int i; /* loop index - result holder */
int ret_code = 0; /* return code */
sigset_t sigset, old_sigset;
assert(is_unicode);
*is_unicode = 0;
/* first 128 codes defaults to ASCII */
for (i = 0; i < 128; i++)
buf[i] = i;
/* remaining defaults to replacement char (usually E_TABSZ = 256) */
for (; i < E_TABSZ; i++)
buf[i] = 0xfffd;
/* block SIGCHLD */
sigemptyset(&sigset);
sigaddset(&sigset, SIGCHLD);
sigprocmask(SIG_BLOCK, &sigset, &old_sigset);
do {
if (NULL == fgets(buffer, sizeof(buffer), fp)) {
if (feof(fp))
break;
else {
perror("uni_screen_map_read_ascii() can't read line");
exit(2);
}
}
/* get "charset-relative charcode", stripping leading spaces */
p = strtok(buffer, " \t\n");
/* skip empty lines and comments */
if (!p || *p == '#')
continue;
/* get unicode mapping */
q = strtok(NULL, " \t\n");
if (q) {
in = ctoi(p, NULL);
if (in < 0 || in > 255) {
ret_code = -1;
break;
}
on = ctoi(q, &tmp_is_unicode);
if (in < 0 && on > 65535) {
ret_code = -1;
break;
}
*is_unicode |= tmp_is_unicode;
buf[in] = on;
} else {
ret_code = -1;
break;
}
}
while (1); /* terminated by break on feof() */
/* restore sig mask */
sigprocmask(SIG_SETMASK, &old_sigset, NULL);
return ret_code;
}
int old_screen_map_read_ascii(FILE * fp, unsigned char buf[])
{
char buffer[256];
int in, on;
char *p, *q;
for (in = 0; in < 256; in++)
buf[in] = in;
while (fgets(buffer, sizeof(buffer) - 1, fp)) {
p = strtok(buffer, " \t\n");
if (!p || *p == '#')
continue;
q = strtok(NULL, " \t\n#");
if (q) {
in = ctoi(p, NULL);
if (in < 0 || in > 255)
return -1;
on = ctoi(q, NULL);
if (in < 0 && on > 255)
return -1;
buf[in] = on;
} else
return -1;
}
return (0);
}
/*
* - converts a string into an int.
* - supports dec and hex bytes, hex UCS2, single-quoted byte and UTF8 chars.
* - returns the converted value
* - if `is_unicode != NULL', use it to tell whether it was unicode
*
* CAVEAT: will report valid UTF mappings using only 1 byte as 8-bit ones.
*/
long int ctoi(unsigned char *s, int *is_unicode)
{
int i;
size_t ls;
ls = strlen(s);
if (is_unicode)
*is_unicode = 0;
/* hex-specified UCS2 */
if ((strncmp(s, "U+", 2) == 0) &&
(strspn(s + 2, "0123456789abcdefABCDEF") == ls - 2)) {
sscanf(s + 2, "%x", &i);
if (is_unicode)
*is_unicode = 1;
}
/* hex-specified byte */
else if ((ls <= 4) && (strncmp(s, "0x", 2) == 0) &&
(strspn(s + 2, "0123456789abcdefABCDEF") == ls - 2))
sscanf(s + 2, "%x", &i);
/* oct-specified number (byte) */
else if ((*s == '0') && (strspn(s, "01234567") == ls))
sscanf(s, "%o", &i);
/* dec-specified number (byte) */
else if (strspn(s, "0123456789") == ls)
sscanf(s, "%d", &i);
/* single-byte quoted char */
else if ((strlen(s) == 3) && (s[0] == '\'') && (s[2] == '\''))
i = s[1];
/* multi-byte UTF8 quoted char */
else if ((s[0] == '\'') && (s[ls - 1] == '\'')) {
s[ls - 1] = 0; /* ensure we'll not "parse UTF too far" */
i = utf8_to_ucs2(s + 1);
if (is_unicode)
*is_unicode = 1;
} else
return (-1);
return (i);
}
void saveoldmap(int fd, char *omfil)
{
FILE *fp;
char buf[E_TABSZ];
#ifdef GIO_UNISCRNMAP
unicode xbuf[E_TABSZ];
int is_old_map = 0;
if (ioctl(fd, GIO_UNISCRNMAP, xbuf)) {
perror("GIO_UNISCRNMAP ioctl error");
#endif
if (ioctl(fd, GIO_SCRNMAP, buf)) {
perror("GIO_SCRNMAP ioctl error");
exit(1);
} else
is_old_map = 1;
#ifdef GIO_UNISCRNMAP
}
#endif
if ((fp = fopen(omfil, "w")) == NULL) {
perror(omfil);
exit(1);
}
#ifdef GIO_UNISCRNMAP
if (is_old_map) {
#endif
if (fwrite(buf, E_TABSZ, 1, fp) != 1) {
perror("Error writing map to file");
exit(1);
}
#ifdef GIO_UNISCRNMAP
} else if (fwrite(xbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1) {
perror("Error writing map to file");
exit(1);
}
#endif
fclose(fp);
}
unicode utf8_to_ucs2(char *buf)
{
int utf_count = 0;
long utf_char = 0;
unicode tc = 0;
unsigned char c;
do {
c = *buf;
buf++;
/* if byte should be part of multi-byte sequence */
if (c & 0x80) {
/* if we have already started to parse a UTF8 sequence */
if (utf_count > 0 && (c & 0xc0) == 0x80) {
utf_char = (utf_char << 6) | (c & 0x3f);
utf_count--;
if (utf_count == 0)
tc = utf_char;
else
continue;
} else { /* Possibly 1st char of a UTF8 sequence */
if ((c & 0xe0) == 0xc0) {
utf_count = 1;
utf_char = (c & 0x1f);
} else if ((c & 0xf0) == 0xe0) {
utf_count = 2;
utf_char = (c & 0x0f);
} else if ((c & 0xf8) == 0xf0) {
utf_count = 3;
utf_char = (c & 0x07);
} else if ((c & 0xfc) == 0xf8) {
utf_count = 4;
utf_char = (c & 0x03);
} else if ((c & 0xfe) == 0xfc) {
utf_count = 5;
utf_char = (c & 0x01);
} else
utf_count = 0;
continue;
}
} else { /* not part of multi-byte sequence - treat as ASCII
* this makes incomplete sequences to be ignored
*/
tc = c;
utf_count = 0;
}
}
while (utf_count);
return tc;
}
+103 -107
View File
@@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/*
* loadfont.c - Eugene Crosser & Andries Brouwer
*
@@ -6,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>
@@ -14,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>
@@ -29,73 +29,71 @@
#define PSF_MAXMODE 0x03
#define PSF_SEPARATOR 0xFFFF
static const char loadfont_usage[] = "loadfont\n"
"\n"
"\tLoad a console font from standard input.\n"
"\n";
struct psf_header
{
unsigned char magic1, magic2; /* Magic number */
unsigned char mode; /* PSF font mode */
unsigned char charsize; /* Character size */
struct psf_header {
unsigned char magic1, magic2; /* Magic number */
unsigned char mode; /* PSF font mode */
unsigned char charsize; /* Character size */
};
#define PSF_MAGIC_OK(x) ((x).magic1 == PSF_MAGIC1 && (x).magic2 == PSF_MAGIC2)
static void loadnewfont(int fd);
extern int
loadfont_main(int argc, char **argv)
extern int loadfont_main(int argc, char **argv)
{
int fd;
if (argc>=2 && *argv[1]=='-') {
usage(loadfont_usage);
}
fd = open("/dev/tty0", O_RDWR);
if (fd < 0) {
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
return 1;
errorMsg("Error opening /dev/tty0: %s\n", strerror(errno));
return( FALSE);
}
loadnewfont(fd);
return 0;
return( TRUE);
}
static void
do_loadfont(int fd, char *inbuf, int unit, int fontsize) {
static void do_loadfont(int fd, char *inbuf, int unit, int fontsize)
{
char buf[16384];
int i;
memset(buf,0,sizeof(buf));
memset(buf, 0, sizeof(buf));
if (unit < 1 || unit > 32) {
fprintf(stderr, "Bad character size %d\n", unit);
exit(1);
errorMsg("Bad character size %d\n", unit);
exit(1);
}
for (i = 0; i < fontsize; i++)
memcpy(buf+(32*i), inbuf+(unit*i), unit);
memcpy(buf + (32 * i), inbuf + (unit * i), unit);
#if defined( PIO_FONTX ) && !defined( __sparc__ )
{
struct consolefontdesc cfd;
struct consolefontdesc cfd;
cfd.charcount = fontsize;
cfd.charheight = unit;
cfd.chardata = buf;
cfd.charcount = fontsize;
cfd.charheight = unit;
cfd.chardata = buf;
if (ioctl(fd, PIO_FONTX, &cfd) == 0)
return; /* success */
perror("PIO_FONTX ioctl error (trying PIO_FONT)");
if (ioctl(fd, PIO_FONTX, &cfd) == 0)
return; /* success */
perror("PIO_FONTX ioctl error (trying PIO_FONT)");
}
#endif
if (ioctl(fd, PIO_FONT, buf)) {
perror("PIO_FONT ioctl error");
exit(1);
perror("PIO_FONT ioctl error");
exit(1);
}
}
static void
do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) {
do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
{
struct unimapinit advice;
struct unimapdesc ud;
struct unipair *up;
@@ -103,23 +101,20 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) {
int glyph;
u_short unicode;
maxct = tailsz; /* more than enough */
up = (struct unipair *) malloc(maxct * sizeof(struct unipair));
if (!up) {
fprintf(stderr, "Out of memory?\n");
exit(1);
}
maxct = tailsz; /* more than enough */
up = (struct unipair *) xmalloc(maxct * sizeof(struct unipair));
for (glyph = 0; glyph < fontsize; glyph++) {
while (tailsz >= 2) {
unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
tailsz -= 2;
inbuf += 2;
if (unicode == PSF_SEPARATOR)
break;
up[ct].unicode = unicode;
up[ct].fontpos = glyph;
ct++;
}
while (tailsz >= 2) {
unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
tailsz -= 2;
inbuf += 2;
if (unicode == PSF_SEPARATOR)
break;
up[ct].unicode = unicode;
up[ct].fontpos = glyph;
ct++;
}
}
/* Note: after PIO_UNIMAPCLR and before PIO_UNIMAP
@@ -128,34 +123,34 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) {
advice.advised_hashsize = 0;
advice.advised_hashstep = 0;
advice.advised_hashlevel = 0;
if(ioctl(fd, PIO_UNIMAPCLR, &advice)) {
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");
} else
if (errno == ENOIOCTLCMD) {
errorMsg("It seems this kernel is older than 1.1.92\n");
errorMsg("No Unicode mapping table loaded.\n");
} else
#endif
perror("PIO_UNIMAPCLR");
exit(1);
perror("PIO_UNIMAPCLR");
exit(1);
}
ud.entry_ct = ct;
ud.entries = up;
if(ioctl(fd, PIO_UNIMAP, &ud)) {
if (ioctl(fd, PIO_UNIMAP, &ud)) {
#if 0
if (errno == ENOMEM) {
/* change advice parameters */
}
if (errno == ENOMEM) {
/* change advice parameters */
}
#endif
perror("PIO_UNIMAP");
exit(1);
perror("PIO_UNIMAP");
exit(1);
}
}
static void
loadnewfont(int fd) {
static void loadnewfont(int fd)
{
int unit;
char inbuf[32768]; /* primitive */
int inputlth, offset;
char inbuf[32768]; /* primitive */
unsigned int inputlth, offset;
/*
* We used to look at the length of the input file
@@ -178,57 +173,58 @@ loadnewfont(int fd) {
/* test for psf first */
{
struct psf_header psfhdr;
int fontsize;
int hastable;
int head0, head;
struct psf_header psfhdr;
int fontsize;
int hastable;
unsigned int head0, head;
if (inputlth < sizeof(struct psf_header))
goto no_psf;
if (inputlth < sizeof(struct psf_header))
goto no_psf;
psfhdr = * (struct psf_header *) &inbuf[0];
psfhdr = *(struct psf_header *) &inbuf[0];
if (!PSF_MAGIC_OK(psfhdr))
goto no_psf;
if (!PSF_MAGIC_OK(psfhdr))
goto no_psf;
if (psfhdr.mode > PSF_MAXMODE) {
fprintf(stderr, "Unsupported psf file mode\n");
exit(1);
}
fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256);
if (psfhdr.mode > PSF_MAXMODE) {
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");
exit(1);
}
if (fontsize != 256) {
errorMsg("Only fontsize 256 supported\n");
exit(1);
}
#endif
hastable = (psfhdr.mode & PSF_MODEHASTAB);
unit = psfhdr.charsize;
head0 = sizeof(struct psf_header);
head = head0 + fontsize*unit;
if (head > inputlth || (!hastable && head != inputlth)) {
fprintf(stderr, "Input file: bad length\n");
exit(1);
}
do_loadfont(fd, inbuf + head0, unit, fontsize);
if (hastable)
do_loadtable(fd, inbuf + head, inputlth-head, fontsize);
return;
hastable = (psfhdr.mode & PSF_MODEHASTAB);
unit = psfhdr.charsize;
head0 = sizeof(struct psf_header);
head = head0 + fontsize * unit;
if (head > inputlth || (!hastable && head != inputlth)) {
errorMsg("Input file: bad length\n");
exit(1);
}
do_loadfont(fd, inbuf + head0, unit, fontsize);
if (hastable)
do_loadtable(fd, inbuf + head, inputlth - head, fontsize);
return;
}
no_psf:
no_psf:
/* file with three code pages? */
if (inputlth == 9780) {
offset = 40;
unit = 16;
offset = 40;
unit = 16;
} else {
/* bare font */
if (inputlth & 0377) {
fprintf(stderr, "Bad input file size\n");
exit(1);
}
offset = 0;
unit = inputlth/256;
/* bare font */
if (inputlth & 0377) {
errorMsg("Bad input file size\n");
exit(1);
}
offset = 0;
unit = inputlth / 256;
}
do_loadfont(fd, inbuf+offset, unit, 256);
do_loadfont(fd, inbuf + offset, unit, 256);
}
+65 -58
View File
@@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/*
* Mini loadkmap implementation for busybox
*
@@ -19,71 +20,77 @@
*
*/
#include "internal.h"
#include "busybox.h"
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <linux/kd.h>
#include <linux/keyboard.h>
#include <sys/ioctl.h>
/* From <linux/kd.h> */
struct kbentry {
unsigned char kb_table;
unsigned char kb_index;
unsigned short kb_value;
};
#define KDSKBENT 0x4B47 /* sets one entry in translation table */
static const char loadkmap_usage[] = "loadkmap\n"
"\n"
"\tLoad a binary keyboard translation table from standard input.\n"
"\n";
/* From <linux/keyboard.h> */
#define NR_KEYS 128
#define MAX_NR_KEYMAPS 256
int loadkmap_main(int argc, char **argv)
{
struct kbentry ke;
u_short *ibuff;
int i, j, fd, readsz, pos, ibuffsz = NR_KEYS * sizeof(u_short);
char flags[MAX_NR_KEYMAPS], magic[] = "bkeymap", buff[7];
int
loadkmap_main(int argc, char * * argv)
{
struct kbentry ke;
u_short *ibuff;
int i,j,fd,readsz,pos,ibuffsz=NR_KEYS * sizeof(u_short);
char flags[MAX_NR_KEYMAPS],magic[]="bkeymap",buff[7];
fd = open("/dev/tty0", O_RDWR);
if (fd < 0) {
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
return 1;
}
read(0,buff,7);
if (0 != strncmp(buff,magic,7)) {
fprintf(stderr, "This is not a valid binary keymap.\n");
return 1;
}
if ( MAX_NR_KEYMAPS != read(0,flags,MAX_NR_KEYMAPS) ) {
fprintf(stderr, "Error reading keymap flags: %s\n", strerror(errno));
return 1;
}
ibuff=(u_short *) malloc(ibuffsz);
if (!ibuff) {
fprintf(stderr, "Out of memory.\n");
return 1;
}
for(i=0; i<MAX_NR_KEYMAPS; i++) {
if (flags[i]==1){
pos=0;
while (pos < ibuffsz) {
if ( (readsz = read(0,(char *)ibuff+pos,ibuffsz-pos)) < 0 ) {
fprintf(stderr, "Error reading keymap: %s\n",
strerror(errno));
return 1;
}
pos += readsz;
}
for(j=0; j<NR_KEYS; j++) {
ke.kb_index = j;
ke.kb_table = i;
ke.kb_value = ibuff[j];
ioctl(fd, KDSKBENT, &ke);
}
if (argc>=2 && *argv[1]=='-') {
usage(loadkmap_usage);
}
}
close (fd);
return 0;
fd = open("/dev/tty0", O_RDWR);
if (fd < 0) {
errorMsg("Error opening /dev/tty0: %s\n", strerror(errno));
exit(FALSE);
}
read(0, buff, 7);
if (0 != strncmp(buff, magic, 7)) {
errorMsg("This is not a valid binary keymap.\n");
exit(FALSE);
}
if (MAX_NR_KEYMAPS != read(0, flags, MAX_NR_KEYMAPS)) {
errorMsg("Error reading keymap flags: %s\n",
strerror(errno));
exit(FALSE);
}
ibuff = (u_short *) xmalloc(ibuffsz);
for (i = 0; i < MAX_NR_KEYMAPS; i++) {
if (flags[i] == 1) {
pos = 0;
while (pos < ibuffsz) {
if ((readsz = read(0, (char *) ibuff + pos, ibuffsz - pos))
< 0) {
errorMsg("Error reading keymap: %s\n",
strerror(errno));
exit(FALSE);
}
pos += readsz;
}
for (j = 0; j < NR_KEYS; j++) {
ke.kb_index = j;
ke.kb_table = i;
ke.kb_value = ibuff[j];
ioctl(fd, KDSKBENT, &ke);
}
}
}
/* Don't bother to close files. Exit does that
* automagically, so we can save a few bytes */
/* close(fd); */
return(TRUE);
}
+34
View File
@@ -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);
}
+72
View File
@@ -0,0 +1,72 @@
/* vi: set sw=4 ts=4: */
/*
* setkeycodes
*
* Copyright (C) 1994-1998 Andries E. Brouwer <aeb@cwi.nl>
*
* Adjusted for BusyBox by Erik Andersen <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "busybox.h"
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
/* From <linux/kd.h> */
struct kbkeycode {
unsigned int scancode, keycode;
};
#define KDSETKEYCODE 0x4B4D /* write kernel keycode table entry */
extern int
setkeycodes_main(int argc, char** argv)
{
char *ep;
int fd, sc;
struct kbkeycode a;
if (argc % 2 != 1 || argc < 2) {
usage(setkeycodes_usage);
}
fd = get_console_fd("/dev/console");
while (argc > 2) {
a.keycode = atoi(argv[2]);
a.scancode = sc = strtol(argv[1], &ep, 16);
if (*ep) {
fatalError("error reading SCANCODE: '%s'\n", argv[1]);
}
if (a.scancode > 127) {
a.scancode -= 0xe000;
a.scancode += 128;
}
if (a.scancode > 255 || a.keycode > 127) {
fatalError("SCANCODE or KEYCODE outside bounds\n");
}
if (ioctl(fd,KDSETKEYCODE,&a)) {
perror("KDSETKEYCODE");
fatalError("failed to set SCANCODE %x to KEYCODE %d\n", sc, a.keycode);
}
argc -= 2;
argv += 2;
}
return( TRUE);
}
+49
View File
@@ -0,0 +1,49 @@
/* vi: set sw=4 ts=4: */
/*
* Mini basename implementation for busybox
*
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "busybox.h"
#include <stdio.h>
extern int basename_main(int argc, char **argv)
{
int m, n;
char *s;
if ((argc < 2) || (**(argv + 1) == '-')) {
usage(basename_usage);
}
argv++;
s = get_last_path_component(*argv);
if (argc>2) {
argv++;
n = strlen(*argv);
m = strlen(s);
if (m>=n && strncmp(s+m-n, *argv, n)==0)
s[m-n] = '\0';
}
printf("%s\n", s);
return(TRUE);
}
+24 -35
View File
@@ -1,7 +1,8 @@
/* vi: set sw=4 ts=4: */
/*
* Mini Cat implementation for busybox
*
* Copyright (C) 1999 by Lineo, inc.
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -20,43 +21,31 @@
*
*/
#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");
}
argc--;
argv++;
while (argc-- > 0) {
file = fopen(*argv, "r");
if (file == NULL) {
perror(*argv);
exit(FALSE);
if (argc == 1) {
print_file(stdin);
exit(TRUE);
}
print_file( file);
argc--;
argv++;
}
exit(TRUE);
while (--argc > 0) {
if(!(strcmp(*++argv, "-"))) {
print_file(stdin);
} else if (print_file_by_name(*argv) == FALSE) {
perror(*argv);
exit(FALSE);
}
}
return(TRUE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+40 -35
View File
@@ -1,8 +1,9 @@
/* vi: set sw=4 ts=4: */
/*
* Mini chroot implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -21,46 +22,50 @@
*
*/
#include "internal.h"
#include "busybox.h"
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n\n"
"Run COMMAND with root directory set to NEWROOT.\n";
int chroot_main(int argc, char **argv)
{
if ( (argc < 2) || (**(argv+1) == '-') ) {
usage( chroot_usage);
}
argc--;
argv++;
if (chroot (*argv) || (chdir ("/"))) {
fprintf(stderr, "chroot: cannot change root directory to %s: %s\n",
*argv, strerror(errno));
exit( FALSE);
}
argc--;
argv++;
if (argc >= 1) {
fprintf(stderr, "command: %s\n", *argv);
execvp (*argv, argv);
}
else {
char *prog;
prog = getenv ("SHELL");
if (!prog)
prog = "/bin/sh";
execlp (prog, prog, NULL);
}
fprintf(stderr, "chroot: cannot execute %s: %s\n",
*argv, strerror(errno));
exit( FALSE);
if ((argc < 2) || (**(argv + 1) == '-')) {
usage(chroot_usage);
}
argc--;
argv++;
if (chroot(*argv) || (chdir("/"))) {
fatalError("cannot change root directory to %s: %s\n", *argv, strerror(errno));
}
argc--;
argv++;
if (argc >= 1) {
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("cannot execute %s: %s\n", prog, strerror(errno));
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
-117
View File
@@ -1,117 +0,0 @@
/*
* Mini cp implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <time.h>
#include <utime.h>
#include <dirent.h>
static const char cp_usage[] = "cp [OPTION]... SOURCE DEST\n"
" or: cp [OPTION]... SOURCE... DIRECTORY\n\n"
"Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n"
"\n"
"\t-a\tsame as -dpR\n"
"\t-d\tpreserve links\n"
"\t-p\tpreserve file attributes if possable\n"
"\t-R\tcopy directories recursively\n";
static int recursiveFlag = FALSE;
static int followLinks = FALSE;
static int preserveFlag = FALSE;
static const char *srcName;
static const char *destName;
static const char *skipName;
static int dirFlag = FALSE;
static int fileAction(const char *fileName, struct stat* statbuf)
{
char newdestName[NAME_MAX];
strcpy(newdestName, destName);
if (dirFlag==TRUE) {
strcat(newdestName, "/");
if ( skipName != NULL)
strcat(newdestName, strstr(fileName, skipName));
else
strcat(newdestName, srcName);
}
return (copyFile(fileName, newdestName, preserveFlag, followLinks));
}
extern int cp_main(int argc, char **argv)
{
if (argc < 3) {
usage (cp_usage);
}
argc--;
argv++;
/* Parse any options */
while (**argv == '-') {
while (*++(*argv))
switch (**argv) {
case 'a':
followLinks = TRUE;
preserveFlag = TRUE;
recursiveFlag = TRUE;
break;
case 'd':
followLinks = TRUE;
break;
case 'p':
preserveFlag = TRUE;
break;
case 'R':
recursiveFlag = TRUE;
break;
default:
usage (cp_usage);
}
argc--;
argv++;
}
destName = argv[argc - 1];
dirFlag = isDirectory(destName);
if ((argc > 3) && dirFlag==FALSE) {
fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE);
}
while (argc-- > 1) {
srcName = *(argv++);
skipName = strrchr(srcName, '/');
if (skipName)
skipName++;
if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE,
fileAction, fileAction) == FALSE) {
exit( FALSE);
}
}
exit( TRUE);
}
+232
View File
@@ -0,0 +1,232 @@
/*
* cut.c - minimalist version of cut
*
* 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
* 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 <stdio.h>
#include <stdlib.h>
#include <unistd.h> /* getopt */
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include "busybox.h"
/* globals from other files */
extern int optind;
extern char *optarg;
/* 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;
/*
* 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;
}
+203 -233
View File
@@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/*
* Mini date implementation for busybox
*
@@ -19,13 +20,18 @@
*
*/
#include "internal.h"
#include "busybox.h"
#define BB_DECLARE_EXTERN
#define bb_need_invalid_date
#define bb_need_memory_exhausted
#include "messages.c"
#include <stdlib.h>
#include <errno.h>
#include <sys/time.h>
#include <unistd.h>
#include <time.h>
#include <stdio.h>
#include <getopt.h>
/* This 'date' command supports only 2 time setting formats,
@@ -34,254 +40,218 @@
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\n"
"Display the current time in the given FORMAT, or set the system date.\n"
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
"\t-s\t\tset time described by STRING\n"
"\t-u\t\tprint or set Coordinated Universal Time\n";
/* Input parsing code is always bulky - used heavy duty libc stuff as
much as possible, missed out a lot of bounds checking */
/* Default input handling to save suprising some people */
struct tm *
date_conv_time(struct tm *tm_time, const char *t_string) {
int nr;
struct tm *date_conv_time(struct tm *tm_time, const char *t_string)
{
int nr;
nr = sscanf(t_string, "%2d%2d%2d%2d%d",
&(tm_time->tm_mon),
&(tm_time->tm_mday),
&(tm_time->tm_hour),
&(tm_time->tm_min),
&(tm_time->tm_year));
nr = sscanf(t_string, "%2d%2d%2d%2d%d",
&(tm_time->tm_mon),
&(tm_time->tm_mday),
&(tm_time->tm_hour),
&(tm_time->tm_min), &(tm_time->tm_year));
if(nr < 4 || nr > 5) {
fprintf(stderr, "date: invalid date `%s'\n", t_string);
exit( FALSE);
}
if (nr < 4 || nr > 5) {
fatalError(invalid_date, t_string);
}
/* correct for century - minor Y2K problem here? */
if(tm_time->tm_year >= 1900)
tm_time->tm_year -= 1900;
/* adjust date */
tm_time->tm_mon -= 1;
return(tm_time);
/* correct for century - minor Y2K problem here? */
if (tm_time->tm_year >= 1900)
tm_time->tm_year -= 1900;
/* adjust date */
tm_time->tm_mon -= 1;
return (tm_time);
}
/* The new stuff for LRP */
struct tm *
date_conv_ftime(struct tm *tm_time, const char *t_string) {
struct tm itm_time, jtm_time, ktm_time, \
ltm_time, mtm_time, ntm_time;
itm_time = *tm_time;
jtm_time = *tm_time;
ktm_time = *tm_time;
ltm_time = *tm_time;
mtm_time = *tm_time;
ntm_time = *tm_time;
/* Parse input and assign appropriately to tm_time */
if(sscanf(t_string, "%d:%d:%d",
&itm_time.tm_hour,
&itm_time.tm_min,
&itm_time.tm_sec) == 3 ) {
*tm_time = itm_time;
return(tm_time);
} else if (sscanf(t_string, "%d:%d",
&jtm_time.tm_hour,
&jtm_time.tm_min) == 2) {
*tm_time = jtm_time;
return(tm_time);
} else if (sscanf(t_string, "%d.%d-%d:%d:%d",
&ktm_time.tm_mon,
&ktm_time.tm_mday,
&ktm_time.tm_hour,
&ktm_time.tm_min,
&ktm_time.tm_sec) == 5) {
ktm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
*tm_time = ktm_time;
return(tm_time);
} else if (sscanf(t_string, "%d.%d-%d:%d",
&ltm_time.tm_mon,
&ltm_time.tm_mday,
&ltm_time.tm_hour,
&ltm_time.tm_min) == 4) {
ltm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
*tm_time = ltm_time;
return(tm_time);
} else if (sscanf(t_string, "%d.%d.%d-%d:%d:%d",
&mtm_time.tm_year,
&mtm_time.tm_mon,
&mtm_time.tm_mday,
&mtm_time.tm_hour,
&mtm_time.tm_min,
&mtm_time.tm_sec) == 6) {
mtm_time.tm_year -= 1900; /* Adjust years */
mtm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
*tm_time = mtm_time;
return(tm_time);
} else if (sscanf(t_string, "%d.%d.%d-%d:%d",
&ntm_time.tm_year,
&ntm_time.tm_mon,
&ntm_time.tm_mday,
&ntm_time.tm_hour,
&ntm_time.tm_min) == 5) {
ntm_time.tm_year -= 1900; /* Adjust years */
ntm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
*tm_time = ntm_time;
return(tm_time);
}
fprintf(stderr, "date: invalid date `%s'\n", t_string);
exit( FALSE);
}
int
date_main(int argc, char * * argv)
struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
{
char *date_str = NULL;
char *date_fmt = NULL;
char *t_buff;
int i;
int set_time = 0;
int rfc822 = 0;
int utc = 0;
int use_arg = 0;
time_t tm;
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 = optarg;
break;
case 'u':
utc = 1;
if (putenv ("TZ=UTC0") != 0) {
fprintf(stderr,"date: memory exhausted\n");
exit( FALSE);
}
/* Look ma, no break. Don't fix it either. */
case 'd':
use_arg = 1;
if(date_str != NULL) usage ( date_usage);
date_str = optarg;
break;
case '-':
usage ( date_usage);
}
} else {
if ( (date_fmt == NULL) && (strcmp(*argv, "+")==0) )
date_fmt=*argv;
else if (date_str == NULL) {
set_time = 1;
date_str=*argv;
} else {
usage ( date_usage);
}
struct tm itm_time, jtm_time, ktm_time, ltm_time, mtm_time, ntm_time;
itm_time = *tm_time;
jtm_time = *tm_time;
ktm_time = *tm_time;
ltm_time = *tm_time;
mtm_time = *tm_time;
ntm_time = *tm_time;
/* Parse input and assign appropriately to tm_time */
if (sscanf(t_string, "%d:%d:%d",
&itm_time.tm_hour, &itm_time.tm_min, &itm_time.tm_sec) == 3) {
*tm_time = itm_time;
return (tm_time);
} else if (sscanf(t_string, "%d:%d",
&jtm_time.tm_hour, &jtm_time.tm_min) == 2) {
*tm_time = jtm_time;
return (tm_time);
} else if (sscanf(t_string, "%d.%d-%d:%d:%d",
&ktm_time.tm_mon,
&ktm_time.tm_mday,
&ktm_time.tm_hour,
&ktm_time.tm_min, &ktm_time.tm_sec) == 5) {
ktm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
*tm_time = ktm_time;
return (tm_time);
} else if (sscanf(t_string, "%d.%d-%d:%d",
&ltm_time.tm_mon,
&ltm_time.tm_mday,
&ltm_time.tm_hour, &ltm_time.tm_min) == 4) {
ltm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
*tm_time = ltm_time;
return (tm_time);
} else if (sscanf(t_string, "%d.%d.%d-%d:%d:%d",
&mtm_time.tm_year,
&mtm_time.tm_mon,
&mtm_time.tm_mday,
&mtm_time.tm_hour,
&mtm_time.tm_min, &mtm_time.tm_sec) == 6) {
mtm_time.tm_year -= 1900; /* Adjust years */
mtm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
*tm_time = mtm_time;
return (tm_time);
} else if (sscanf(t_string, "%d.%d.%d-%d:%d",
&ntm_time.tm_year,
&ntm_time.tm_mon,
&ntm_time.tm_mday,
&ntm_time.tm_hour, &ntm_time.tm_min) == 5) {
ntm_time.tm_year -= 1900; /* Adjust years */
ntm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
*tm_time = ntm_time;
return (tm_time);
}
i--;
argv++;
}
/* Now we have parsed all the information except the date format
which depends on whether the clock is being set or read */
time(&tm);
memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
/* Zero out fields - take her back to midnight!*/
if(date_str != NULL) {
tm_time.tm_sec = 0;
tm_time.tm_min = 0;
tm_time.tm_hour = 0;
}
/* Process any date input to UNIX time since 1 Jan 1970 */
if(date_str != NULL) {
if(strchr(date_str, ':') != NULL) {
date_conv_ftime(&tm_time, date_str);
} else {
date_conv_time(&tm_time, date_str);
}
/* Correct any day of week and day of year etc fields */
tm = mktime(&tm_time);
if (tm < 0 ) {
fprintf(stderr, "date: invalid date `%s'\n", date_str);
exit( FALSE);
}
/* if setting time, set it */
if(set_time) {
if( stime(&tm) < 0) {
fprintf(stderr, "date: can't set date.\n");
exit( FALSE);
}
}
}
/* Display output */
/* Deal with format string */
if(date_fmt == NULL) {
date_fmt = (rfc822
? (utc
? "%a, %_d %b %Y %H:%M:%S GMT"
: "%a, %_d %b %Y %H:%M:%S %z")
: "%a %b %e %H:%M:%S %Z %Y");
} else if ( *date_fmt == '\0' ) {
/* Imitate what GNU 'date' does with NO format string! */
printf ("\n");
exit( TRUE);
}
/* Handle special conversions */
if( strncmp( date_fmt, "%f", 2) == 0 ) {
date_fmt = "%Y.%m.%d-%H:%M:%S";
}
/* Print OUTPUT (after ALL that!) */
t_buff = malloc(201);
strftime(t_buff, 200, date_fmt, &tm_time);
printf("%s\n", t_buff);
exit( TRUE);
fatalError(invalid_date, t_string);
}
int date_main(int argc, char **argv)
{
char *date_str = NULL;
char *date_fmt = NULL;
char *t_buff;
int c;
int set_time = 0;
int rfc822 = 0;
int utc = 0;
int use_arg = 0;
time_t tm;
struct tm tm_time;
/* Interpret command line args */
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);
}
}
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 */
time(&tm);
memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
/* Zero out fields - take her back to midnight! */
if (date_str != NULL) {
tm_time.tm_sec = 0;
tm_time.tm_min = 0;
tm_time.tm_hour = 0;
}
/* Process any date input to UNIX time since 1 Jan 1970 */
if (date_str != NULL) {
if (strchr(date_str, ':') != NULL) {
date_conv_ftime(&tm_time, date_str);
} else {
date_conv_time(&tm_time, date_str);
}
/* Correct any day of week and day of year etc fields */
tm = mktime(&tm_time);
if (tm < 0)
fatalError(invalid_date, date_str);
/* if setting time, set it */
if (set_time) {
if (stime(&tm) < 0) {
fatalError("can't set date.\n");
}
}
}
/* Display output */
/* Deal with format string */
if (date_fmt == NULL) {
date_fmt = (rfc822
? (utc
? "%a, %_d %b %Y %H:%M:%S GMT"
: "%a, %_d %b %Y %H:%M:%S %z")
: "%a %b %e %H:%M:%S %Z %Y");
} else if (*date_fmt == '\0') {
/* Imitate what GNU 'date' does with NO format string! */
printf("\n");
exit(TRUE);
}
/* Handle special conversions */
if (strncmp(date_fmt, "%f", 2) == 0) {
date_fmt = "%Y.%m.%d-%H:%M:%S";
}
/* Print OUTPUT (after ALL that!) */
t_buff = xmalloc(201);
strftime(t_buff, 200, date_fmt, &tm_time);
printf("%s\n", t_buff);
return(TRUE);
}
+124 -188
View File
@@ -1,13 +1,14 @@
/* vi: set sw=4 ts=4: */
/*
* Mini dd implementation for busybox
*
* Copyright (C) 1999 by Lineo, inc.
* Copyright (C) 1999, 2000 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
* based in part on code taken from sash.
*
* Copyright (c) 1999 by David I. Bell
* Permission is granted to use, distribute, or modify this source,
* provided that this copyright notice remains intact.
* Based in part on code taken from sash.
* Copyright (c) 1999 by David I. Bell
* Permission is granted to use, distribute, or modify this source,
* provided that this copyright notice remains intact.
*
* Permission to distribute this code under the GPL has been granted.
*
@@ -28,204 +29,139 @@
*/
#include "internal.h"
#include "busybox.h"
#include <features.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
static const char dd_usage[] =
"dd [if=name] [of=name] [bs=n] [count=n]\n\n"
"Copy 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 stout\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"
"\n"
"BYTES may be suffixed: by k for x1024, b for x512, and w for x2.\n";
/*
* Read a number with a possible multiplier.
* Returns -1 if the number format is illegal.
*/
static long getNum (const char *cp)
{
long value;
if (!isDecimal (*cp))
return -1;
value = 0;
while (isDecimal (*cp))
value = value * 10 + *cp++ - '0';
switch (*cp++) {
case 'k':
value *= 1024;
break;
case 'b':
value *= 512;
break;
case 'w':
value *= 2;
break;
case '\0':
return value;
default:
return -1;
}
if (*cp)
return -1;
return value;
}
extern int dd_main (int argc, char **argv)
{
const char *inFile;
const char *outFile;
char *cp;
int inFd;
int outFd;
int inCc = 0;
int outCc;
int skipBlocks;
int blockSize;
long count;
long intotal;
long outTotal;
unsigned char *buf;
inFile = NULL;
outFile = NULL;
blockSize = 512;
skipBlocks = 0;
count = 1;
argc--;
argv++;
/* Parse any options */
while (argc) {
if (inFile == NULL && (strncmp(*argv, "if", 2) == 0))
inFile=((strchr(*argv, '='))+1);
else if (outFile == NULL && (strncmp(*argv, "of", 2) == 0))
outFile=((strchr(*argv, '='))+1);
else if (strncmp("count", *argv, 5) == 0) {
count = getNum ((strchr(*argv, '='))+1);
if (count <= 0) {
fprintf (stderr, "Bad count value %ld\n", count);
goto usage;
}
}
else if (strncmp(*argv, "bs", 2) == 0) {
blockSize = getNum ((strchr(*argv, '='))+1);
if (blockSize <= 0) {
fprintf (stderr, "Bad block size value %d\n", blockSize);
goto usage;
}
}
#if 0
else if (strncmp(*argv, "skip", 4) == 0) {
skipBlocks = atoi( *argv);
if (skipBlocks <= 0) {
fprintf (stderr, "Bad skip value %d\n", skipBlocks);
goto usage;
}
}
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
#include <inttypes.h>
#else
typedef unsigned long long int uintmax_t;
#endif
else {
goto usage;
}
extern int dd_main(int argc, char **argv)
{
char *inFile = NULL;
char *outFile = NULL;
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 = 0;
uintmax_t outTotal = 0;
uintmax_t totalSize;
uintmax_t readSize;
unsigned char buf[BUFSIZ];
char *keyword = NULL;
argc--;
argv++;
}
buf = malloc (blockSize);
if (buf == NULL) {
fprintf (stderr, "Cannot allocate buffer\n");
exit( FALSE);
}
/* Parse any options */
while (argc) {
if (inFile == NULL && (strncmp(*argv, "if", 2) == 0))
inFile = ((strchr(*argv, '=')) + 1);
else if (outFile == NULL && (strncmp(*argv, "of", 2) == 0))
outFile = ((strchr(*argv, '=')) + 1);
else if (strncmp("count", *argv, 5) == 0) {
count = getNum((strchr(*argv, '=')) + 1);
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) {
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) {
errorMsg("Bad skip value %s\n", *argv);
goto usage;
}
intotal = 0;
outTotal = 0;
if (inFile == NULL)
inFd = STDIN;
else
inFd = open (inFile, 0);
if (inFd < 0) {
perror (inFile);
free (buf);
exit( FALSE);
}
if (outFile == NULL)
outFd = STDOUT;
else
outFd = creat (outFile, 0666);
if (outFd < 0) {
perror (outFile);
close (inFd);
free (buf);
exit( FALSE);
}
//lseek(inFd, skipBlocks*blockSize, SEEK_SET);
while (outTotal < count * blockSize) {
inCc = read (inFd, buf, blockSize);
if (inCc < 0) {
perror (inFile);
goto cleanup;
} else if (strncmp(*argv, "seek", 4) == 0) {
seekBlocks = getNum((strchr(*argv, '=')) + 1);
if (seekBlocks <= 0) {
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;
}
argc--;
argv++;
}
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;
}
if (inFile == NULL)
inFd = fileno(stdin);
else
inFd = open(inFile, 0);
inCc -= outCc;
cp += outCc;
outTotal += outCc;
if (inFd < 0) {
/* Note that we are not freeing buf or closing
* files here to save a few bytes. This exits
* here anyways... */
/* free(buf); */
fatalError( inFile);
}
}
if (inCc < 0)
perror (inFile);
if (outFile == NULL)
outFd = fileno(stdout);
else
outFd = open(outFile, O_WRONLY | O_CREAT, 0666);
cleanup:
close (inFd);
close (outFd);
free (buf);
if (outFd < 0) {
/* Note that we are not freeing buf or closing
* files here to save a few bytes. This exits
* here anyways... */
printf ("%ld+%d records in\n", intotal / blockSize,
(intotal % blockSize) != 0);
printf ("%ld+%d records out\n", outTotal / blockSize,
(outTotal % blockSize) != 0);
exit( TRUE);
/* close(inFd);
free(buf); */
fatalError( outFile);
}
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));
}
/* Note that we are not freeing memory or closing
* files here, to save a few bytes. */
#ifdef BB_FEATURE_CLEAN_UP
close(inFd);
close(outFd);
#endif
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);
usage:
usage( dd_usage);
usage(dd_usage);
}
+69 -70
View File
@@ -1,7 +1,8 @@
/* vi: set sw=4 ts=4: */
/*
* Mini df implementation for busybox
*
* Copyright (C) 1999 by Lineo, inc.
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
* based on original code by (I think) Bruce Perens <bruce@pixar.com>.
*
@@ -21,94 +22,92 @@
*
*/
#include "internal.h"
#include "busybox.h"
#include <stdio.h>
#include <mntent.h>
#include <sys/stat.h>
#include <sys/vfs.h>
#include <fstab.h>
static const char df_usage[] = "df [filesystem ...]\n"
"\n" "\tPrint the filesystem space used and space available.\n";
extern const char mtab_file[]; /* Defined in utility.c */
extern const char mtab_file[]; /* Defined in utility.c */
static int df(char *device, const char *mountPoint)
{
struct statfs s;
long blocks_used;
long blocks_percent_used;
struct fstab* fstabItem;
struct statfs s;
long blocks_used;
long blocks_percent_used;
if (statfs(mountPoint, &s) != 0) {
perror(mountPoint);
return FALSE;
}
if (s.f_blocks > 0) {
blocks_used = s.f_blocks - s.f_bfree;
blocks_percent_used = (long)
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
if (strcmp (device, "/dev/root") == 0) {
fstabItem = getfsfile ("/");
if (fstabItem != NULL)
device = fstabItem->fs_spec;
if (statfs(mountPoint, &s) != 0) {
perror(mountPoint);
return FALSE;
}
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
device,
(long) (s.f_blocks * (s.f_bsize / 1024.0)),
(long) ((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)),
(long) (s.f_bavail * (s.f_bsize / 1024.0)),
blocks_percent_used, mountPoint);
}
if (s.f_blocks > 0) {
blocks_used = s.f_blocks - s.f_bfree;
blocks_percent_used = (long)
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
if (strcmp(device, "/dev/root") == 0) {
/* Adjusts device to be the real root device,
* or leaves device alone if it can't find it */
find_real_root_device_name( device);
}
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
device,
(long) (s.f_blocks * (s.f_bsize / 1024.0)),
(long) ((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)),
(long) (s.f_bavail * (s.f_bsize / 1024.0)),
blocks_percent_used, mountPoint);
return TRUE;
}
return TRUE;
}
extern int df_main(int argc, char **argv)
{
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
/* Only compiled in if BB_MTAB is not defined */
whine_if_fstab_is_missing();
if (argc > 1) {
struct mntent *mountEntry;
int status;
if (argc > 1) {
struct mntent *mountEntry;
int status;
if (**(argv + 1) == '-') {
usage(df_usage);
}
while (argc > 1) {
if ((mountEntry = findMountPoint(argv[1], mtab_file)) == 0) {
errorMsg("%s: can't find mount point.\n", argv[1]);
exit(FALSE);
}
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
if (status != 0)
exit(status);
argc--;
argv++;
}
exit(TRUE);
} else {
FILE *mountTable;
struct mntent *mountEntry;
while (argc > 1) {
if ((mountEntry = findMountPoint(argv[1], mtab_file)) ==
0) {
fprintf(stderr, "%s: can't find mount point.\n", argv[1]);
exit( FALSE);
}
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
if (status != 0)
exit( status);
argc--;
argv++;
}
exit( TRUE);
} else {
FILE *mountTable;
struct mntent *mountEntry;
mountTable = setmntent(mtab_file, "r");
if (mountTable == 0) {
perror(mtab_file);
exit(FALSE);
}
mountTable = setmntent(mtab_file, "r");
if (mountTable == 0) {
perror(mtab_file);
exit(FALSE);
while ((mountEntry = getmntent(mountTable))) {
df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
}
endmntent(mountTable);
}
while ((mountEntry = getmntent(mountTable))) {
int status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
if (status)
exit( status);
}
endmntent(mountTable);
}
exit( TRUE);
return(TRUE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+44
View File
@@ -0,0 +1,44 @@
/* vi: set sw=4 ts=4: */
/*
* Mini dirname implementation for busybox
*
* Copyright (C) 2000 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "busybox.h"
#include <stdio.h>
extern int dirname_main(int argc, char **argv)
{
char* s;
if ((argc < 2) || (**(argv + 1) == '-'))
usage(dirname_usage);
argv++;
s=*argv+strlen(*argv)-1;
while (s && *s == '/') {
*s = '\0';
s=*argv+strlen(*argv)-1;
}
s = strrchr(*argv, '/');
if (s && *s)
*s = '\0';
printf("%s\n", (s)? *argv : ".");
return(TRUE);
}
+45
View File
@@ -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;
}
+173
View File
@@ -0,0 +1,173 @@
/* vi: set sw=4 ts=4: */
/*
* Mini du implementation for busybox
*
*
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by John Beppu <beppu@lineo.com>
*
* This program is free software; you can redistribute it and/or modify
* 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"
#define BB_DECLARE_EXTERN
#define bb_need_name_too_long
#include "messages.c"
#include <sys/types.h>
#include <fcntl.h>
#include <dirent.h>
#include <stdio.h>
#include <errno.h>
typedef void (Display) (long, char *);
static int du_depth = 0;
static int count_hardlinks = 0;
static Display *print;
static void print_normal(long size, char *filename)
{
fprintf(stdout, "%ld\t%s\n", size, filename);
}
static void print_summary(long size, char *filename)
{
if (du_depth == 1) {
print_normal(size, filename);
}
}
/* tiny recursive du */
static long du(char *filename)
{
struct stat statbuf;
long sum;
int len;
if ((lstat(filename, &statbuf)) != 0) {
printf("du: %s: %s\n", filename, strerror(errno));
return 0;
}
du_depth++;
sum = (statbuf.st_blocks >> 1);
/* Don't add in stuff pointed to by symbolic links */
if (S_ISLNK(statbuf.st_mode)) {
sum = 0L;
if (du_depth == 1)
print(sum, filename);
}
if (S_ISDIR(statbuf.st_mode)) {
DIR *dir;
struct dirent *entry;
dir = opendir(filename);
if (!dir) {
du_depth--;
return 0;
}
len = strlen(filename);
if (filename[len - 1] == '/')
filename[--len] = '\0';
while ((entry = readdir(dir))) {
char newfile[BUFSIZ + 1];
char *name = entry->d_name;
if ((strcmp(name, "..") == 0)
|| (strcmp(name, ".") == 0)) {
continue;
}
if (len + strlen(name) + 1 > BUFSIZ) {
errorMsg(name_too_long);
du_depth--;
return 0;
}
sprintf(newfile, "%s/%s", filename, name);
sum += du(newfile);
}
closedir(dir);
print(sum, filename);
}
else if (statbuf.st_nlink > 1 && !count_hardlinks) {
/* Add files with hard links only once */
if (is_in_ino_dev_hashtable(&statbuf, NULL)) {
sum = 0L;
if (du_depth == 1)
print(sum, filename);
}
else {
add_to_ino_dev_hashtable(&statbuf, NULL);
}
}
du_depth--;
return sum;
}
int du_main(int argc, char **argv)
{
int i;
int c;
/* default behaviour */
print = print_normal;
/* parse argv[] */
while ((c = getopt(argc, argv, "sl")) != EOF) {
switch (c) {
case 's':
print = print_summary;
break;
case 'l':
count_hardlinks = 1;
break;
default:
usage(du_usage);
}
}
/* go through remaining args (if any) */
if (optind >= argc) {
du(".");
} else {
long sum;
for (i=optind; i < argc; i++) {
sum = du(argv[i]);
if (sum && isDirectory(argv[i], FALSE, NULL)) {
print_normal(sum, argv[i]);
}
reset_ino_dev_hashtable();
}
}
return(0);
}
/* $Id: du.c,v 1.25 2000/09/25 21:45:57 andersen Exp $ */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+112
View File
@@ -0,0 +1,112 @@
/* vi: set sw=4 ts=4: */
/*
* echo implementation for busybox
*
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Original copyright notice is retained at the end of this file.
*/
#include "busybox.h"
#include <stdio.h>
extern int
echo_main(int argc, char** argv)
{
register char **ap;
char *p;
int c;
int nflag = 0;
int eflag = 0;
while ((c = getopt(argc, argv, "neE")) != EOF) {
switch (c) {
case 'n':
nflag = 1;
break;
case 'e':
eflag = 1;
break;
case 'E':
eflag = 0;
break;
default:
usage(echo_usage);
}
}
ap = &argv[optind];
while ((p = *ap++) != NULL) {
while ((c = *p++) != '\0') {
if (c == '\\' && eflag) {
if (*p == 'c')
exit(0);
else
c = process_escape_sequence(&p);
}
putchar(c);
}
if (*ap)
putchar(' ');
}
if (! nflag)
putchar('\n');
fflush(stdout);
return( 0);
}
/*-
* Copyright (c) 1991, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Kenneth Almquist.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)echo.c 8.1 (Berkeley) 5/31/93
*/
+531
View File
@@ -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;
}
+103
View File
@@ -0,0 +1,103 @@
/* vi: set sw=4 ts=4: */
/*
* Mini head implementation for busybox
*
*
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by John Beppu <beppu@lineo.com>
*
* This program is free software; you can redistribute it and/or modify
* 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 <errno.h>
#include <stdio.h>
int head(int len, FILE * src)
{
int i;
char buffer[1024];
for (i = 0; i < len; i++) {
fgets(buffer, 1024, src);
if (feof(src)) {
break;
}
fputs(buffer, stdout);
}
return 0;
}
/* BusyBoxed head(1) */
int head_main(int argc, char **argv)
{
char opt;
int len = 10, tmplen, i;
/* parse argv[] */
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
opt = argv[i][1];
switch (opt) {
case 'n':
tmplen = 0;
if (++i < argc)
tmplen = atoi(argv[i]);
if (tmplen < 1)
usage(head_usage);
len = tmplen;
break;
case '-':
case 'h':
usage(head_usage);
default:
errorMsg("invalid option -- %c\n", opt);
usage(head_usage);
}
} else {
break;
}
}
/* get rest of argv[] or stdin if nothing's left */
if (i >= argc) {
head(len, stdin);
} else {
int need_headers = ((argc - i) > 1);
for (; i < argc; i++) {
FILE *src;
src = fopen(argv[i], "r");
if (!src) {
errorMsg("%s: %s\n", argv[i], strerror(errno));
} else {
/* emulating GNU behaviour */
if (need_headers) {
fprintf(stdout, "==> %s <==\n", argv[i]);
}
head(len, src);
if (i < argc - 1) {
fprintf(stdout, "\n");
}
}
}
}
return(0);
}
/* $Id: head.c,v 1.14 2000/09/25 21:45:57 andersen Exp $ */
+30
View File
@@ -0,0 +1,30 @@
/* vi: set sw=4 ts=4: */
/*
* Mini hostid implementation for busybox
*
* 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
*
*/
#include "busybox.h"
#include <stdio.h>
extern int hostid_main(int argc, char **argv)
{
printf("%lx\n", gethostid());
return(TRUE);
}
+93
View File
@@ -0,0 +1,93 @@
/* vi: set sw=4 ts=4: */
/*
* Mini id implementation for busybox
*
* Copyright (C) 2000 by Randolph Chung <tausq@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "busybox.h"
#include <stdio.h>
#include <unistd.h>
#include <pwd.h>
#include <grp.h>
#include <getopt.h>
#include <sys/types.h>
extern int id_main(int argc, char **argv)
{
int no_user = 0, no_group = 0, print_real = 0;
char *cp, *user, *group;
long gid;
long pwnam, grnam;
int opt;
cp = user = group = NULL;
gid = 0;
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);
}
}
if (no_user && no_group) usage(id_usage);
user = argv[optind];
if (user == NULL) {
user = xcalloc(9, sizeof(char));
group = xcalloc(9, sizeof(char));
if (print_real) {
my_getpwuid(user, getuid());
my_getgrgid(group, getgid());
} else {
my_getpwuid(user, geteuid());
my_getgrgid(group, getegid());
}
} else {
group = xcalloc(9, sizeof(char));
gid = my_getpwnamegid(user);
my_getgrgid(group, gid);
}
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=%ld(%s) gid=%ld(%s)\n", pwnam, user, grnam, group);
return(0);
}
/* END CODE */
+7 -8
View File
@@ -1,14 +1,13 @@
#include "internal.h"
/* vi: set sw=4 ts=4: */
#include "busybox.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
extern int
length_main(int argc, char * * argv)
extern int length_main(int argc, char **argv)
{
if ( **(argv+1) == '-' ) {
usage("length string\n");
}
printf("%d\n", strlen(argv[1]));
return( TRUE);
if (argc != 2 || **(argv + 1) == '-')
usage(length_usage);
printf("%lu\n", (long)strlen(argv[1]));
return (TRUE);
}
+94 -58
View File
@@ -1,8 +1,8 @@
/* vi: set sw=4 ts=4: */
/*
* Mini ln implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -21,75 +21,111 @@
*
*/
#include "internal.h"
#include "busybox.h"
#define BB_DECLARE_EXTERN
#define bb_need_not_a_directory
#include "messages.c"
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n"
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n"
"Options:\n"
"\t-s\tmake symbolic links instead of hard links\n"
"\t-f\tremove existing destination files\n";
static int symlinkFlag = FALSE;
static int removeoldFlag = FALSE;
static int followLinks = TRUE;
extern int ln_main(int argc, char **argv)
{
int status;
static char* linkName;
char *linkName, *dirName=NULL;
int linkIntoDirFlag;
int stopIt = FALSE;
if (argc < 3) {
usage (ln_usage);
}
argc--;
argv++;
/* Parse any options */
while (**argv == '-') {
while (*++(*argv))
switch (**argv) {
case 's':
symlinkFlag = TRUE;
break;
case 'f':
removeoldFlag = TRUE;
break;
default:
usage (ln_usage);
}
argc--;
argv++;
}
linkName = argv[argc - 1];
if ((argc > 3) && !(isDirectory(linkName))) {
fprintf(stderr, "%s: not a directory\n", linkName);
exit (FALSE);
}
while (argc-- >= 2) {
if (removeoldFlag==TRUE ) {
status = ( unlink(linkName) && errno != ENOENT );
if ( status != 0 ) {
perror(linkName);
exit( FALSE);
}
/* Parse any options */
while (argc > 0 && stopIt == FALSE) {
if (**argv == '-') {
while (*++(*argv))
switch (**argv) {
case 's':
symlinkFlag = TRUE;
break;
case 'f':
removeoldFlag = TRUE;
break;
case 'n':
followLinks = FALSE;
break;
case '-':
stopIt = TRUE;
break;
default:
usage(ln_usage);
}
argc--;
argv++;
}
else
break;
}
if ( symlinkFlag==TRUE)
status = symlink(*argv, linkName);
else
status = link(*argv, linkName);
if ( status != 0 ) {
perror(linkName);
exit( FALSE);
if (argc < 2) {
usage(ln_usage);
}
}
exit( TRUE);
linkName = argv[argc - 1];
linkIntoDirFlag = isDirectory(linkName, followLinks, NULL);
if ((argc >= 3) && linkIntoDirFlag == FALSE) {
errorMsg(not_a_directory, linkName);
exit FALSE;
}
if (linkIntoDirFlag == TRUE)
dirName = linkName;
while (argc-- >= 2) {
int status;
if (linkIntoDirFlag == TRUE) {
char *baseName = get_last_path_component(*argv);
linkName = (char *)xmalloc(strlen(dirName)+strlen(baseName)+2);
strcpy(linkName, dirName);
if(dirName[strlen(dirName)-1] != '/')
strcat(linkName, "/");
strcat(linkName,baseName);
}
if (removeoldFlag == TRUE) {
status = (unlink(linkName) && errno != ENOENT);
if (status != 0) {
perror(linkName);
exit FALSE;
}
}
if (symlinkFlag == TRUE)
status = symlink(*argv, linkName);
else
status = link(*argv, linkName);
if (status != 0) {
perror(linkName);
exit FALSE;
}
if (linkIntoDirFlag == TRUE)
free(linkName);
argv++;
}
return( TRUE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+40
View File
@@ -0,0 +1,40 @@
/* vi: set sw=4 ts=4: */
/*
* Mini logname implementation for busybox
*
* 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
*
*/
#include "busybox.h"
#include <stdio.h>
extern int logname_main(int argc, char **argv)
{
char *user = xmalloc(9);
if (argc > 1)
usage(logname_usage);
my_getpwuid(user, geteuid());
if (user) {
puts(user);
exit(TRUE);
}
errorMsg("no login name\n");
return(FALSE);
}
+738 -399
View File
File diff suppressed because it is too large. Load diff
+1004
View File
File diff suppressed because it is too large. Load diff
+67 -65
View File
@@ -1,8 +1,8 @@
/* vi: set sw=4 ts=4: */
/*
* Mini mkdir implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -21,17 +21,13 @@
*
*/
#include "internal.h"
#include "busybox.h"
#define bb_need_name_too_long
#define BB_DECLARE_EXTERN
#include "messages.c"
#include <stdio.h>
#include <errno.h>
#include <sys/param.h>
static const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n\n"
"Create 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";
static int parentFlag = FALSE;
static mode_t mode = 0777;
@@ -39,64 +35,70 @@ static mode_t mode = 0777;
extern int mkdir_main(int argc, char **argv)
{
int i=FALSE;
argc--;
argv++;
int i = FALSE;
/* Parse any options */
while (argc > 0 && **argv == '-') {
while (i==FALSE && *++(*argv)) {
switch (**argv) {
case 'm':
if (--argc == 0)
usage( mkdir_usage);
/* Find the specified modes */
mode = 0;
if ( parse_mode(*(++argv), &mode) == FALSE ) {
fprintf(stderr, "Unknown mode: %s\n", *argv);
exit( FALSE);
argc--;
argv++;
/* Parse any options */
while (argc > 0 && **argv == '-') {
while (i == FALSE && *++(*argv)) {
switch (**argv) {
case 'm':
if (--argc == 0)
usage(mkdir_usage);
/* Find the specified modes */
mode = 0;
if (parse_mode(*(++argv), &mode) == FALSE) {
errorMsg("Unknown mode: %s\n", *argv);
exit FALSE;
}
/* Set the umask for this process so it doesn't
* screw up whatever the user just entered. */
umask(0);
i = TRUE;
break;
case 'p':
parentFlag = TRUE;
break;
default:
usage(mkdir_usage);
}
}
/* Set the umask for this process so it doesn't
* screw up whatever the user just entered. */
umask(0);
i=TRUE;
break;
case 'p':
parentFlag = TRUE;
break;
default:
usage( mkdir_usage);
}
argc--;
argv++;
}
argc--;
argv++;
}
if (argc < 1) {
usage( mkdir_usage);
}
while (argc > 0) {
int status;
struct stat statBuf;
status=stat(*argv, &statBuf);
if (status != -1 && status != ENOENT ) {
fprintf(stderr, "%s: File exists\n", *argv);
exit( FALSE);
if (argc < 1) {
usage(mkdir_usage);
}
if (parentFlag == TRUE)
createPath(*argv, mode);
else {
if (mkdir (*argv, mode) != 0) {
perror(*argv);
exit( FALSE);
}
while (argc > 0) {
int status;
struct stat statBuf;
char buf[BUFSIZ + 1];
if (strlen(*argv) > BUFSIZ - 1) {
errorMsg(name_too_long);
exit FALSE;
}
strcpy(buf, *argv);
status = stat(buf, &statBuf);
if (parentFlag == FALSE && status != -1 && errno != ENOENT) {
errorMsg("%s: File exists\n", buf);
exit FALSE;
}
if (parentFlag == TRUE) {
strcat(buf, "/");
createPath(buf, mode);
} else {
if (mkdir(buf, mode) != 0 && parentFlag == FALSE) {
perror(buf);
exit FALSE;
}
}
argc--;
argv++;
}
argc--;
argv++;
}
exit( TRUE);
return( TRUE);
}
+61
View File
@@ -0,0 +1,61 @@
/* vi: set sw=4 ts=4: */
/*
* Mini mkfifo implementation for busybox
*
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "busybox.h"
#include <stdio.h>
#include <sys/types.h>
#include <errno.h>
extern int mkfifo_main(int argc, char **argv)
{
char *thisarg;
mode_t mode = 0666;
argc--;
argv++;
/* Parse any options */
while (argc > 1) {
if (**argv != '-')
usage(mkfifo_usage);
thisarg = *argv;
thisarg++;
switch (*thisarg) {
case 'm':
argc--;
argv++;
parse_mode(*argv, &mode);
break;
default:
usage(mkfifo_usage);
}
argc--;
argv++;
}
if (argc < 1 || *argv[0] == '-')
usage(mkfifo_usage);
if (mkfifo(*argv, mode) < 0) {
perror("mkfifo");
exit(255);
}
return(TRUE);
}
+44 -26
View File
@@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/*
* Mini mknod implementation for busybox
*
@@ -19,28 +20,46 @@
*
*/
#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 [OPTION]... NAME TYPE MAJOR MINOR\n\n"
"Make block or character special files.\n\n"
"Options:\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";
int
mknod_main(int argc, char** argv)
int mknod_main(int argc, char **argv)
{
mode_t mode = 0;
dev_t dev = 0;
char *thisarg;
mode_t mode = 0;
mode_t perm = 0666;
dev_t dev = 0;
switch(argv[2][0]) {
argc--;
argv++;
/* Parse any options */
while (argc > 1) {
if (**argv != '-')
break;
thisarg = *argv;
thisarg++;
switch (*thisarg) {
case 'm':
argc--;
argv++;
parse_mode(*argv, &perm);
umask(0);
break;
default:
usage(mknod_usage);
}
argc--;
argv++;
}
if (argc != 4 && argc != 2) {
usage(mknod_usage);
}
switch (argv[1][0]) {
case 'c':
case 'u':
mode = S_IFCHR;
@@ -50,23 +69,22 @@ mknod_main(int argc, char** argv)
break;
case 'p':
mode = S_IFIFO;
if (argc!=2) {
usage(mknod_usage);
}
break;
default:
usage (mknod_usage);
usage(mknod_usage);
}
if ( mode == S_IFCHR || mode == S_IFBLK ) {
dev = (atoi(argv[3]) << 8) | atoi(argv[4]);
if ( argc != 5 ) {
usage (mknod_usage);
}
if (mode == S_IFCHR || mode == S_IFBLK) {
dev = (atoi(argv[2]) << 8) | atoi(argv[3]);
}
mode |= 0666;
mode |= perm;
if ( mknod(argv[1], mode, dev) != 0 ) {
perror(argv[1]);
return( FALSE);
}
return( TRUE);
if (mknod(argv[0], mode, dev) != 0)
fatalError("%s: %s\n", argv[0], strerror(errno));
return (TRUE);
}
-85
View File
@@ -1,85 +0,0 @@
/*
* Mini mv implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <time.h>
#include <utime.h>
#include <dirent.h>
static const char mv_usage[] = "mv SOURCE DEST\n"
" or: mv SOURCE... DIRECTORY\n\n"
"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n";
static const char *srcName;
static const char *destName;
static const char *skipName;
static int dirFlag = FALSE;
extern int mv_main(int argc, char **argv)
{
char newdestName[NAME_MAX];
if (argc < 3) {
usage (mv_usage);
}
argc--;
argv++;
destName = argv[argc - 1];
dirFlag = isDirectory(destName);
if ((argc > 3) && dirFlag==FALSE) {
fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE);
}
while (argc-- > 1) {
srcName = *(argv++);
skipName = strrchr(srcName, '/');
if (skipName)
skipName++;
strcpy(newdestName, destName);
if (dirFlag==TRUE) {
strcat(newdestName, "/");
if ( skipName != NULL)
strcat(newdestName, strstr(srcName, skipName));
else
strcat(newdestName, srcName);
fprintf(stderr, "srcName='%s'\n", srcName);
fprintf(stderr, "skipName='%s'\n", skipName);
fprintf(stderr, "newdestName='%s'\n", newdestName);
}
if (copyFile(srcName, newdestName, FALSE, FALSE) == FALSE) {
exit( FALSE);
}
if (unlink (srcName) < 0) {
perror (srcName);
exit( FALSE);
}
}
exit( TRUE);
}
+279 -334
View File
@@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/* printf - format and print data
Copyright (C) 90, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
@@ -42,22 +43,19 @@
to convert all of the given arguments.
David MacKenzie <djm@gnu.ai.mit.edu> */
// 19990508 Busy Boxed! Dave Cinege
#include "internal.h"
#include "busybox.h"
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <getopt.h>
#include <sys/stat.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <ctype.h>
#include <libintl.h>
#ifndef S_IFMT
@@ -84,11 +82,11 @@
#if !defined(S_ISSOCK) && defined(S_IFSOCK)
# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
#endif
#if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
#if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
# define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
# define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
#endif
#if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
#if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
# define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
#endif
@@ -121,409 +119,356 @@
#define hextobin(c) ((c)>='a'&&(c)<='f' ? (c)-'a'+10 : (c)>='A'&&(c)<='F' ? (c)-'A'+10 : (c)-'0')
#define octtobin(c) ((c) - '0')
char *xmalloc ();
static double xstrtod __P((char *s));
static int print_esc __P((char *escstart));
static int print_formatted __P((char *format, int argc, char **argv));
static long xstrtol __P((char *s));
static unsigned long xstrtoul __P((char *s));
static void print_direc
__P(
static double xstrtod __P ((char *s));
static int print_esc __P ((char *escstart));
static int print_formatted __P ((char *format, int argc, char **argv));
static long xstrtol __P ((char *s));
static unsigned long xstrtoul __P ((char *s));
static void print_direc __P ((char *start, size_t length, int field_width, int precision, char *argument));
static void print_esc_char __P ((int c));
static void print_esc_string __P ((char *str));
static void verify __P ((char *s, char *end));
(char *start, size_t length, int field_width, int precision,
char *argument));
static void print_esc_char __P((int c));
static void print_esc_string __P((char *str));
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";
int
printf_main(int argc, char** argv)
int printf_main(int argc, char **argv)
{
char *format;
int args_used;
char *format;
int args_used;
exit_status = 0;
if ( **(argv+1) == '-' ) {
usage (printf_usage);
}
exit_status = 0;
if (argc <= 1 || **(argv + 1) == '-') {
usage(printf_usage);
}
format = argv[1];
argc -= 2;
argv += 2;
format = argv[1];
argc -= 2;
argv += 2;
do
{
args_used = print_formatted (format, argc, argv);
argc -= args_used;
argv += args_used;
}
while (args_used > 0 && argc > 0);
do {
args_used = print_formatted(format, argc, argv);
argc -= args_used;
argv += args_used;
}
while (args_used > 0 && argc > 0);
/*
if (argc > 0)
fprintf(stderr, "excess args ignored");
*/
exit (exit_status);
return(exit_status);
}
/* Print the text in FORMAT, using ARGV (with ARGC elements) for
arguments to any `%' directives.
Return the number of elements of ARGV used. */
static int
print_formatted (char *format, int argc, char **argv)
static int print_formatted(char *format, int argc, char **argv)
{
int save_argc = argc; /* Preserve original value. */
char *f; /* Pointer into `format'. */
char *direc_start; /* Start of % directive. */
size_t direc_length; /* Length of % directive. */
int field_width; /* Arg to first '*', or -1 if none. */
int precision; /* Arg to second '*', or -1 if none. */
int save_argc = argc; /* Preserve original value. */
char *f; /* Pointer into `format'. */
char *direc_start; /* Start of % directive. */
size_t direc_length; /* Length of % directive. */
int field_width; /* Arg to first '*', or -1 if none. */
int precision; /* Arg to second '*', or -1 if none. */
for (f = format; *f; ++f)
{
switch (*f)
{
case '%':
direc_start = f++;
direc_length = 1;
field_width = precision = -1;
if (*f == '%')
{
putchar ('%');
break;
}
if (*f == 'b')
{
if (argc > 0)
{
print_esc_string (*argv);
++argv;
--argc;
}
break;
}
if (strchr ("-+ #", *f))
{
++f;
++direc_length;
}
if (*f == '*')
{
++f;
++direc_length;
if (argc > 0)
{
field_width = xstrtoul (*argv);
++argv;
--argc;
}
else
field_width = 0;
}
else
while (ISDIGIT (*f))
{
++f;
++direc_length;
}
if (*f == '.')
{
++f;
++direc_length;
if (*f == '*')
{
++f;
++direc_length;
if (argc > 0)
{
precision = xstrtoul (*argv);
++argv;
--argc;
}
else
precision = 0;
}
else
while (ISDIGIT (*f))
{
++f;
++direc_length;
}
}
if (*f == 'l' || *f == 'L' || *f == 'h')
{
++f;
++direc_length;
}
/*
if (!strchr ("diouxXfeEgGcs", *f))
fprintf(stderr, "%%%c: invalid directive", *f);
*/
++direc_length;
if (argc > 0)
{
print_direc (direc_start, direc_length, field_width,
precision, *argv);
++argv;
--argc;
}
else
print_direc (direc_start, direc_length, field_width,
precision, "");
break;
for (f = format; *f; ++f) {
switch (*f) {
case '%':
direc_start = f++;
direc_length = 1;
field_width = precision = -1;
if (*f == '%') {
putchar('%');
break;
}
if (*f == 'b') {
if (argc > 0) {
print_esc_string(*argv);
++argv;
--argc;
}
break;
}
if (strchr("-+ #", *f)) {
++f;
++direc_length;
}
if (*f == '*') {
++f;
++direc_length;
if (argc > 0) {
field_width = xstrtoul(*argv);
++argv;
--argc;
} else
field_width = 0;
} else
while (ISDIGIT(*f)) {
++f;
++direc_length;
}
if (*f == '.') {
++f;
++direc_length;
if (*f == '*') {
++f;
++direc_length;
if (argc > 0) {
precision = xstrtoul(*argv);
++argv;
--argc;
} else
precision = 0;
} else
while (ISDIGIT(*f)) {
++f;
++direc_length;
}
}
if (*f == 'l' || *f == 'L' || *f == 'h') {
++f;
++direc_length;
}
/*
if (!strchr ("diouxXfeEgGcs", *f))
fprintf(stderr, "%%%c: invalid directive", *f);
*/
++direc_length;
if (argc > 0) {
print_direc(direc_start, direc_length, field_width,
precision, *argv);
++argv;
--argc;
} else
print_direc(direc_start, direc_length, field_width,
precision, "");
break;
case '\\':
f += print_esc (f);
break;
case '\\':
f += print_esc(f);
break;
default:
putchar (*f);
default:
putchar(*f);
}
}
}
return save_argc - argc;
return save_argc - argc;
}
/* Print a \ escape sequence starting at ESCSTART.
Return the number of characters in the escape sequence
besides the backslash. */
static int
print_esc (char *escstart)
static int print_esc(char *escstart)
{
register char *p = escstart + 1;
int esc_value = 0; /* Value of \nnn escape. */
int esc_length; /* Length of \nnn escape. */
register char *p = escstart + 1;
int esc_value = 0; /* Value of \nnn escape. */
int esc_length; /* Length of \nnn escape. */
/* \0ooo and \xhhh escapes have maximum length of 3 chars. */
if (*p == 'x')
{
for (esc_length = 0, ++p;
esc_length < 3 && ISXDIGIT (*p);
++esc_length, ++p)
esc_value = esc_value * 16 + hextobin (*p);
/* \0ooo and \xhhh escapes have maximum length of 3 chars. */
if (*p == 'x') {
for (esc_length = 0, ++p;
esc_length < 3 && ISXDIGIT(*p); ++esc_length, ++p)
esc_value = esc_value * 16 + hextobin(*p);
/* if (esc_length == 0)
fprintf(stderr, "missing hex in esc");
*/
putchar (esc_value);
}
else if (*p == '0')
{
for (esc_length = 0, ++p;
esc_length < 3 && isodigit (*p);
++esc_length, ++p)
esc_value = esc_value * 8 + octtobin (*p);
putchar (esc_value);
}
else if (strchr ("\"\\abcfnrtv", *p))
print_esc_char (*p++);
putchar(esc_value);
} else if (*p == '0') {
for (esc_length = 0, ++p;
esc_length < 3 && isodigit(*p); ++esc_length, ++p)
esc_value = esc_value * 8 + octtobin(*p);
putchar(esc_value);
} else if (strchr("\"\\abcfnrtv", *p))
print_esc_char(*p++);
/* else
fprintf(stderr, "\\%c: invalid esc", *p);
*/
return p - escstart - 1;
return p - escstart - 1;
}
/* Output a single-character \ escape. */
static void
print_esc_char (int c)
static void print_esc_char(int c)
{
switch (c)
{
case 'a': /* Alert. */
putchar (7);
break;
case 'b': /* Backspace. */
putchar (8);
break;
case 'c': /* Cancel the rest of the output. */
exit (0);
break;
case 'f': /* Form feed. */
putchar (12);
break;
case 'n': /* New line. */
putchar (10);
break;
case 'r': /* Carriage return. */
putchar (13);
break;
case 't': /* Horizontal tab. */
putchar (9);
break;
case 'v': /* Vertical tab. */
putchar (11);
break;
default:
putchar (c);
break;
}
switch (c) {
case 'a': /* Alert. */
putchar(7);
break;
case 'b': /* Backspace. */
putchar(8);
break;
case 'c': /* Cancel the rest of the output. */
exit(0);
break;
case 'f': /* Form feed. */
putchar(12);
break;
case 'n': /* New line. */
putchar(10);
break;
case 'r': /* Carriage return. */
putchar(13);
break;
case 't': /* Horizontal tab. */
putchar(9);
break;
case 'v': /* Vertical tab. */
putchar(11);
break;
default:
putchar(c);
break;
}
}
/* Print string STR, evaluating \ escapes. */
static void
print_esc_string (char *str)
static void print_esc_string(char *str)
{
for (; *str; str++)
if (*str == '\\')
str += print_esc (str);
else
putchar (*str);
for (; *str; str++)
if (*str == '\\')
str += print_esc(str);
else
putchar(*str);
}
static void
print_direc (char *start, size_t length, int field_width, int precision, char *argument)
print_direc(char *start, size_t length, int field_width, int precision,
char *argument)
{
char *p; /* Null-terminated copy of % directive. */
char *p; /* Null-terminated copy of % directive. */
p = xmalloc ((unsigned) (length + 1));
strncpy (p, start, length);
p[length] = 0;
p = xmalloc((unsigned) (length + 1));
strncpy(p, start, length);
p[length] = 0;
switch (p[length - 1])
{
case 'd':
case 'i':
if (field_width < 0)
{
if (precision < 0)
printf (p, xstrtol (argument));
else
printf (p, precision, xstrtol (argument));
}
else
{
if (precision < 0)
printf (p, field_width, xstrtol (argument));
else
printf (p, field_width, precision, xstrtol (argument));
}
break;
switch (p[length - 1]) {
case 'd':
case 'i':
if (field_width < 0) {
if (precision < 0)
printf(p, xstrtol(argument));
else
printf(p, precision, xstrtol(argument));
} else {
if (precision < 0)
printf(p, field_width, xstrtol(argument));
else
printf(p, field_width, precision, xstrtol(argument));
}
break;
case 'o':
case 'u':
case 'x':
case 'X':
if (field_width < 0)
{
if (precision < 0)
printf (p, xstrtoul (argument));
else
printf (p, precision, xstrtoul (argument));
}
else
{
if (precision < 0)
printf (p, field_width, xstrtoul (argument));
else
printf (p, field_width, precision, xstrtoul (argument));
}
break;
case 'o':
case 'u':
case 'x':
case 'X':
if (field_width < 0) {
if (precision < 0)
printf(p, xstrtoul(argument));
else
printf(p, precision, xstrtoul(argument));
} else {
if (precision < 0)
printf(p, field_width, xstrtoul(argument));
else
printf(p, field_width, precision, xstrtoul(argument));
}
break;
case 'f':
case 'e':
case 'E':
case 'g':
case 'G':
if (field_width < 0)
{
if (precision < 0)
printf (p, xstrtod (argument));
else
printf (p, precision, xstrtod (argument));
}
else
{
if (precision < 0)
printf (p, field_width, xstrtod (argument));
else
printf (p, field_width, precision, xstrtod (argument));
}
break;
case 'f':
case 'e':
case 'E':
case 'g':
case 'G':
if (field_width < 0) {
if (precision < 0)
printf(p, xstrtod(argument));
else
printf(p, precision, xstrtod(argument));
} else {
if (precision < 0)
printf(p, field_width, xstrtod(argument));
else
printf(p, field_width, precision, xstrtod(argument));
}
break;
case 'c':
printf (p, *argument);
break;
case 'c':
printf(p, *argument);
break;
case 's':
if (field_width < 0)
{
if (precision < 0)
printf (p, argument);
else
printf (p, precision, argument);
case 's':
if (field_width < 0) {
if (precision < 0)
printf(p, argument);
else
printf(p, precision, argument);
} else {
if (precision < 0)
printf(p, field_width, argument);
else
printf(p, field_width, precision, argument);
}
break;
}
else
{
if (precision < 0)
printf (p, field_width, argument);
else
printf (p, field_width, precision, argument);
}
break;
}
free (p);
free(p);
}
static unsigned long
xstrtoul (char *s)
static unsigned long xstrtoul(char *s)
{
char *end;
unsigned long val;
char *end;
unsigned long val;
errno = 0;
val = strtoul (s, &end, 0);
verify (s, end);
return val;
errno = 0;
val = strtoul(s, &end, 0);
verify(s, end);
return val;
}
static long
xstrtol (char *s)
static long xstrtol(char *s)
{
char *end;
long val;
char *end;
long val;
errno = 0;
val = strtol (s, &end, 0);
verify (s, end);
return val;
errno = 0;
val = strtol(s, &end, 0);
verify(s, end);
return val;
}
static double
xstrtod (char *s)
static double xstrtod(char *s)
{
char *end;
double val;
char *end;
double val;
errno = 0;
val = strtod (s, &end);
verify (s, end);
return val;
errno = 0;
val = strtod(s, &end);
verify(s, end);
return val;
}
static void
verify (char *s, char *end)
static void verify(char *s, char *end)
{
if (errno)
{
fprintf(stderr, "%s", s);
exit_status = 1;
}
else if (*end)
{
/*
if (s == end)
fprintf(stderr, "%s: expected numeric", s);
else
fprintf(stderr, "%s: not completely converted", s);
*/
exit_status = 1;
}
if (errno) {
fprintf(stderr, "%s", s);
exit_status = 1;
} else if (*end) {
/*
if (s == end)
fprintf(stderr, "%s: expected numeric", s);
else
fprintf(stderr, "%s: not completely converted", s);
*/
exit_status = 1;
}
}
+8 -9
View File
@@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/*
* Mini pwd implementation for busybox
*
@@ -20,20 +21,18 @@
*
*/
#include "internal.h"
#include "busybox.h"
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
extern int
pwd_main(int argc, char * * argv)
extern int pwd_main(int argc, char **argv)
{
char buf[NAME_MAX];
char buf[BUFSIZ + 1];
if ( getcwd(buf, sizeof(buf)) == NULL ) {
perror("get working directory");
exit( FALSE);
}
if (getcwd(buf, sizeof(buf)) == NULL)
fatalError("%s\n", strerror(errno));
printf("%s\n", buf);
exit( TRUE);
return(TRUE);
}
+62 -53
View File
@@ -1,8 +1,9 @@
/* vi: set sw=4 ts=4: */
/*
* Mini rm implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -21,81 +22,89 @@
*
*/
#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\n"
"Remove (unlink) the FILE(s).\n\n"
"Options:\n"
"\t-f\tremove existing destinations, never prompt\n"
"\t-r\tremove the contents of directories recursively\n";
static int recursiveFlag = FALSE;
static int forceFlag = FALSE;
static const char *srcName;
static int fileAction(const char *fileName, struct stat* statbuf)
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
{
if (unlink( fileName) < 0 ) {
perror( fileName);
return ( FALSE);
}
return ( TRUE);
if (unlink(fileName) < 0) {
perror(fileName);
return (FALSE);
}
return (TRUE);
}
static int dirAction(const char *fileName, struct stat* statbuf)
static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
{
if (rmdir( fileName) < 0 ) {
perror( fileName);
return ( FALSE);
}
return ( TRUE);
if (recursiveFlag == FALSE) {
errno = EISDIR;
perror(fileName);
return (FALSE);
}
if (rmdir(fileName) < 0) {
perror(fileName);
return (FALSE);
}
return (TRUE);
}
extern int rm_main(int argc, char **argv)
{
struct stat statbuf;
int stopIt=FALSE;
struct stat statbuf;
if (argc < 2) {
usage( rm_usage);
}
argc--;
argv++;
/* Parse any options */
while (**argv == '-') {
while (*++(*argv))
switch (**argv) {
case 'r':
recursiveFlag = TRUE;
break;
case 'f':
forceFlag = TRUE;
break;
default:
usage( rm_usage);
}
argc--;
argv++;
}
while (argc-- > 0) {
srcName = *(argv++);
if (forceFlag == TRUE && lstat(srcName, &statbuf) != 0 && errno == ENOENT) {
/* do not reports errors for non-existent files if -f, just skip them */
/* Parse any options */
while (argc > 0 && stopIt == FALSE) {
if (**argv == '-') {
while (*++(*argv))
switch (**argv) {
case 'R':
case 'r':
recursiveFlag = TRUE;
break;
case 'f':
forceFlag = TRUE;
break;
case '-':
stopIt = TRUE;
break;
default:
usage(rm_usage);
}
argc--;
argv++;
}
else
break;
}
else {
if (recursiveAction( srcName, recursiveFlag, FALSE,
TRUE, fileAction, dirAction) == FALSE) {
exit( FALSE);
}
if (argc < 1 && forceFlag == FALSE) {
usage(rm_usage);
}
}
exit( TRUE);
while (argc-- > 0) {
srcName = *(argv++);
if (forceFlag == TRUE && lstat(srcName, &statbuf) != 0
&& errno == ENOENT) {
/* do not reports errors for non-existent files if -f, just skip them */
} else {
if (recursiveAction(srcName, recursiveFlag, FALSE,
TRUE, fileAction, dirAction, NULL) == FALSE) {
exit(FALSE);
}
}
}
return(TRUE);
}
+11 -12
View File
@@ -1,8 +1,9 @@
/* vi: set sw=4 ts=4: */
/*
* Mini rmdir implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -21,22 +22,20 @@
*
*/
#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\nRemove the DIRECTORY(ies), if they are empty.\n");
}
if (argc == 1 || **(argv + 1) == '-')
usage(rmdir_usage);
while (--argc > 0) {
if ( rmdir(*(++argv)) == -1 ) {
fprintf(stderr, "%s: %s\n", *argv, strerror(errno));
exit(FALSE);
while (--argc > 0) {
if (rmdir(*(++argv)) == -1) {
errorMsg("%s\n", strerror(errno));
exit(FALSE);
}
}
}
exit(TRUE);
return(TRUE);
}
+10 -13
View File
@@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/*
* Mini sleep implementation for busybox
*
@@ -20,22 +21,18 @@
*
*/
#include "internal.h"
#include "busybox.h"
#include <stdio.h>
const char sleep_usage[] = "sleep N\n\n"
"Pause for N seconds.\n";
extern int
sleep_main(int argc, char * * argv)
extern int sleep_main(int argc, char **argv)
{
if ( (argc < 2) || (**(argv+1) == '-') ) {
usage( sleep_usage );
if ((argc < 2) || (**(argv + 1) == '-')) {
usage(sleep_usage);
}
if ( sleep(atoi(*(++argv))) != 0 ) {
perror( "sleep");
exit (FALSE);
} else
exit (TRUE);
if (sleep(atoi(*(++argv))) != 0) {
perror("sleep");
exit(FALSE);
}
return(TRUE);
}
+291
View File
@@ -0,0 +1,291 @@
/* vi: set sw=4 ts=4: */
/*
* Mini sort implementation for busybox
*
*
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by John Beppu <beppu@lineo.com>
*
* This program is free software; you can redistribute it and/or modify
* 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 <sys/types.h>
#include <fcntl.h>
#include <dirent.h>
#include <stdio.h>
#include <errno.h>
#ifdef BB_FEATURE_SORT_REVERSE
#define APPLY_REVERSE(x) (reverse ? -(x) : (x))
static int reverse = 0;
#else
#define APPLY_REVERSE(x) (x)
#endif
/* typedefs _______________________________________________________________ */
/* line node */
typedef struct Line {
char *data; /* line data */
struct Line *next; /* pointer to next line node */
} Line;
/* singly-linked list of lines */
typedef struct {
int len; /* number of Lines */
Line **sorted; /* array fed to qsort */
Line *head; /* head of List */
Line *current; /* current Line */
} List;
/* comparison function */
typedef int (Compare) (const void *, const void *);
/* methods ________________________________________________________________ */
static const int max = 1024;
/* mallocate Line */
static Line *line_alloc()
{
Line *self;
self = xmalloc(1 * sizeof(Line));
return self;
}
/* Construct Line from FILE* */
static Line *line_newFromFile(FILE * src)
{
Line *self;
char *cstring = NULL;
if ((cstring = get_line_from_file(src))) {
self = line_alloc();
self->data = cstring;
self->next = NULL;
return self;
}
return NULL;
}
/* Line destructor */
static Line *line_release(Line * self)
{
if (self->data) {
free(self->data);
free(self);
}
return self;
}
/* Comparison */
/* ascii order */
static int compare_ascii(const void *a, const void *b)
{
Line **doh;
Line *x, *y;
doh = (Line **) a;
x = *doh;
doh = (Line **) b;
y = *doh;
// fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data);
return APPLY_REVERSE(strcmp(x->data, y->data));
}
/* numeric order */
static int compare_numeric(const void *a, const void *b)
{
Line **doh;
Line *x, *y;
int xint, yint;
doh = (Line **) a;
x = *doh;
doh = (Line **) b;
y = *doh;
xint = strtoul(x->data, NULL, 10);
yint = strtoul(y->data, NULL, 10);
return APPLY_REVERSE(xint - yint);
}
/* List */
/* */
static List *list_init(List * self)
{
self->len = 0;
self->sorted = NULL;
self->head = NULL;
self->current = NULL;
return self;
}
/* for simplicity, the List gains ownership of the line */
static List *list_insert(List * self, Line * line)
{
if (line == NULL) {
return NULL;
}
/* first insertion */
if (self->head == NULL) {
self->head = line;
self->current = line;
/* all subsequent insertions */
} else {
self->current->next = line;
self->current = line;
}
self->len++;
return self;
}
/* order the list according to compare() */
static List *list_sort(List * self, Compare * compare)
{
int i;
Line *line;
/* mallocate array of Line*s */
self->sorted = (Line **) xmalloc(self->len * sizeof(Line *));
/* fill array w/ List's contents */
i = 0;
line = self->head;
while (line) {
self->sorted[i++] = line;
line = line->next;
}
/* apply qsort */
qsort(self->sorted, self->len, sizeof(Line *), compare);
return self;
}
/* precondition: list must be sorted */
static List *list_writeToFile(List * self, FILE * dst)
{
int i;
Line **line = self->sorted;
if (self->sorted == NULL) {
return NULL;
}
for (i = 0; i < self->len; i++) {
fprintf(dst, "%s", line[i]->data);
}
return self;
}
/* deallocate */
static void list_release(List * self)
{
Line *i;
Line *die;
i = self->head;
while (i) {
die = i;
i = die->next;
line_release(die);
}
}
int sort_main(int argc, char **argv)
{
int i;
char opt;
List list;
Line *l;
Compare *compare;
/* init */
compare = compare_ascii;
list_init(&list);
/* parse argv[] */
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
opt = argv[i][1];
switch (opt) {
case 'h':
usage(sort_usage);
break;
case 'n':
/* numeric comparison */
compare = compare_numeric;
break;
#ifdef BB_FEATURE_SORT_REVERSE
case 'r':
/* reverse */
reverse = 1;
break;
#endif
default:
errorMsg("invalid option -- %c\n", opt);
usage(sort_usage);
}
} else {
break;
}
}
/* this could be factored better */
/* work w/ stdin */
if (i >= argc) {
while ((l = line_newFromFile(stdin))) {
list_insert(&list, l);
}
list_sort(&list, compare);
list_writeToFile(&list, stdout);
list_release(&list);
/* work w/ what's left in argv[] */
} else {
FILE *src;
for (; i < argc; i++) {
src = fopen(argv[i], "r");
if (src == NULL) {
break;
}
while ((l = line_newFromFile(src))) {
list_insert(&list, l);
}
fclose(src);
}
list_sort(&list, compare);
list_writeToFile(&list, stdout);
list_release(&list);
}
return(0);
}
/* $Id: sort.c,v 1.22 2000/09/25 21:45:58 andersen Exp $ */
+6 -8
View File
@@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/*
* Mini sync implementation for busybox
*
@@ -20,15 +21,12 @@
*
*/
#include "internal.h"
#include "busybox.h"
#include <stdio.h>
extern int
sync_main(int argc, char * * argv)
extern int sync_main(int argc, char **argv)
{
if ( argc>1 && **(argv+1) == '-' ) {
usage( "sync\n\nWrite all buffered filesystem blocks to disk.\n");
}
exit( sync());
if (argc > 1 && **(argv + 1) == '-')
usage(sync_usage);
return(sync());
}
+339
View File
@@ -0,0 +1,339 @@
/* vi: set sw=4 ts=4: */
/* tail -- output the last part of file(s)
Copyright (C) 89, 90, 91, 95, 1996 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Original version by Paul Rubin <phr@ocf.berkeley.edu>.
Extensions by David MacKenzie <djm@gnu.ai.mit.edu>.
tail -f for multiple files by Ian Lance Taylor <ian@airs.com>.
Rewrote the option parser, removed locales support,
and generally busyboxed, Erik Andersen <andersen@lineo.com>
Removed superfluous options and associated code ("-c", "-n", "-q").
Removed "tail -f" support for multiple files.
Both changes by Friedrich Vedder <fwv@myrtle.lahn.de>.
Compleate Rewrite to correctly support "-NUM", "+NUM", and "-s" by
E.Allen Soard (esp@espsw.net).
*/
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <getopt.h>
#include "busybox.h"
#define STDIN "standard input"
#define LINES 0
#define BYTES 1
static int n_files = 0;
static char **files = NULL;
static char * buffer;
static ssize_t bytes_read=0;
static ssize_t bs;
static ssize_t filelocation=0;
static char pip;
#ifdef BB_FEATURE_SIMPLE_TAIL
static const char unit_type=LINES;
#else
static char unit_type=LINES;
static char verbose = 0;
#endif
static off_t units=0;
int tail_stream(int fd)
{
ssize_t startpoint;
ssize_t endpoint=0;
ssize_t count=0;
ssize_t filesize=0;
int direction=1;
filelocation=0;
startpoint=bs=BUFSIZ;
filesize=lseek(fd, -1, SEEK_END)+1;
pip=(filesize<=0);
if(units>=0)
lseek(fd,0,SEEK_SET);
else {
direction=-1;
count=1;
}
while(units != 0) {
if (pip) {
char * line;
ssize_t f_size=0;
bs=BUFSIZ;
line=xmalloc(bs);
while(1) {
bytes_read=read(fd,line,bs);
if(bytes_read<=0)
break;
buffer=xrealloc(buffer,f_size+bytes_read);
memcpy(&buffer[f_size],line,bytes_read);
filelocation=f_size+=bytes_read;
}
bs=f_size;
if(direction<0)
bs--;
if (line)
free(line);
} else {
filelocation = lseek(fd, 0, SEEK_CUR);
if(direction<0) {
if(filelocation<bs)
bs=filelocation;
filelocation = lseek(fd, -bs, SEEK_CUR);
}
bytes_read = read(fd, buffer, bs);
if (bytes_read <= 0)
break;
bs=bytes_read;
}
startpoint=bs;
if(direction>0) {
endpoint=startpoint;
startpoint=0;
}
for(;startpoint!=endpoint;startpoint+=direction) {
#ifndef BB_FEATURE_SIMPLE_TAIL
if(unit_type==BYTES)
count++;
else
#endif
if(buffer[startpoint-1]=='\n')
count++;
if (!pip)
filelocation=lseek(fd,0,SEEK_CUR);
if(count==units*direction)
break;
}
if((count==units*direction) | pip)
break;
if(direction<0){
filelocation = lseek(fd, -bytes_read, SEEK_CUR);
if(filelocation==0)
break;
}
}
if(pip && (direction<0))
bs++;
bytes_read=bs-startpoint;
memcpy(&buffer[0],&buffer[startpoint],bytes_read);
return 0;
}
void add_file(char *name)
{
++n_files;
files = xrealloc(files, n_files);
files[n_files - 1] = (char *) xmalloc(strlen(name) + 1);
strcpy(files[n_files - 1], name);
}
void checknumbers(const char* name)
{
int test=atoi(name);
if(test){
units=test;
if(units<0)
units=units-1;
} else {
fatalError("Unrecognised number '%s'\n", name);
}
}
int tail_main(int argc, char **argv)
{
int show_headers = 1;
int test;
int opt;
char follow=0;
int sleep_int=1;
int *fd;
opterr = 0;
while ((opt=getopt(argc,argv,"c:fhn:s:q:v123456789+")) >0) {
switch (opt) {
case '1':case '2':case '3':case '4':case '5':
case '6':case '7':case '8':case '9':case '0':
checknumbers(argv[optind-1]);
break;
#ifndef BB_FEATURE_SIMPLE_TAIL
case 'c':
unit_type = BYTES;
test = atoi(optarg);
if(test==0)
usage(tail_usage);
if(optarg[strlen(optarg)-1]>'9') {
switch (optarg[strlen(optarg)-1]) {
case 'b':
test *= 512;
break;
case 'k':
test *= 1024;
break;
case 'm':
test *= (1024 * 1024);
break;
default:
fprintf(stderr,"Size must be b,k, or m.");
usage(tail_usage);
}
}
if(optarg[0]=='+')
units=test+1;
else
units=-(test+1);
break;
case 'q':
show_headers = 0;
break;
case 's':
sleep_int = atoi(optarg);
if(sleep_int<1)
sleep_int=1;
break;
case 'v':
verbose = 1;
break;
#endif
case 'f':
follow = 1;
break;
case 'h':
usage(tail_usage);
break;
case 'n':
test = atoi(optarg);
if (test) {
if (optarg[0] == '+')
units = test;
else
units = -(test+1);
} else
usage(tail_usage);
break;
default:
errorMsg("\nUnknown arg: %c.\n\n",optopt);
usage(tail_usage);
}
}
while (optind <= argc) {
if(optind==argc) {
if (n_files==0)
add_file(STDIN);
else
break;
}else {
if (*argv[optind] == '+') {
checknumbers(argv[optind]);
}
else if (!strcmp(argv[optind], "-")) {
add_file(STDIN);
} else {
add_file(argv[optind]);
}
optind++;
}
}
if(units==0)
units=-11;
if(units>0)
units--;
fd=xmalloc(sizeof(int)*n_files);
if (n_files == 1)
#ifndef BB_FEATURE_SIMPLE_TAIL
if (!verbose)
#endif
show_headers = 0;
buffer=xmalloc(BUFSIZ);
for (test = 0; test < n_files; test++) {
if (show_headers)
printf("==> %s <==\n", files[test]);
if (!strcmp(files[test], STDIN))
fd[test] = 0;
else
fd[test] = open(files[test], O_RDONLY);
if (fd[test] == -1)
fatalError("Unable to open file %s.\n", files[test]);
tail_stream(fd[test]);
bs=BUFSIZ;
while (1) {
if((filelocation>0 || pip)){
write(1,buffer,bytes_read);
}
bytes_read = read(fd[test], buffer, bs);
filelocation+=bytes_read;
if (bytes_read <= 0) {
break;
}
usleep(sleep_int * 1000);
}
if(n_files>1)
printf("\n");
}
while(1){
for (test = 0; test < n_files; test++) {
if(!follow){
close(fd[test]);
continue;
} else {
sleep(sleep_int);
bytes_read = read(fd[test], buffer, bs);
if(bytes_read>0) {
if (show_headers)
printf("==> %s <==\n", files[test]);
write(1,buffer,bytes_read);
if(n_files>1)
printf("\n");
}
}
}
if(!follow)
break;
}
if (fd)
free(fd);
if (buffer)
free(buffer);
if(files)
free(files);
return 0;
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+68
View File
@@ -0,0 +1,68 @@
/* vi: set sw=4 ts=4: */
/*
* Mini tee implementation for busybox
*
* Copyright (C) 1999,2000 by Lineo, inc.
* 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
* 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 <getopt.h>
#include <stdio.h>
int
tee_main(int argc, char **argv)
{
char *mode = "w";
int c, i, status = 0, nfiles = 0;
FILE **files;
while ((c = getopt(argc, argv, "a")) != EOF) {
switch (c) {
case 'a':
mode = "a";
break;
default:
usage(tee_usage);
}
}
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;
}
}
while ((c = getchar()) != EOF)
for (i = 0; i < nfiles; i++)
putc(c, files[i]);
return status;
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+582
View File
@@ -0,0 +1,582 @@
/* vi: set sw=4 ts=4: */
/*
* test implementation for busybox
*
* Copyright (c) by a whole pile of folks:
*
* test(1); version 7-like -- author Erik Baalbergen
* modified by Eric Gisin to be used as built-in.
* modified by Arnold Robbins to add SVR3 compatibility
* (-x -c -b -p -u -g -k) plus Korn's -L -nt -ot -ef and new -S (socket).
* modified by J.T. Conklin for NetBSD.
* modified by Herbert Xu to be used as built-in in ash.
* modified by Erik Andersen <andersee@debian.org> to be used
* in busybox.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Original copyright notice states:
* "This program is in the Public Domain."
*/
#include "busybox.h"
#include <sys/types.h>
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#define BB_DECLARE_EXTERN
#define bb_need_help
#include "messages.c"
/* test(1) accepts the following grammar:
oexpr ::= aexpr | aexpr "-o" oexpr ;
aexpr ::= nexpr | nexpr "-a" aexpr ;
nexpr ::= primary | "!" primary
primary ::= unary-operator operand
| operand binary-operator operand
| operand
| "(" oexpr ")"
;
unary-operator ::= "-r"|"-w"|"-x"|"-f"|"-d"|"-c"|"-b"|"-p"|
"-u"|"-g"|"-k"|"-s"|"-t"|"-z"|"-n"|"-o"|"-O"|"-G"|"-L"|"-S";
binary-operator ::= "="|"!="|"-eq"|"-ne"|"-ge"|"-gt"|"-le"|"-lt"|
"-nt"|"-ot"|"-ef";
operand ::= <any legal UNIX file name>
*/
enum token {
EOI,
FILRD,
FILWR,
FILEX,
FILEXIST,
FILREG,
FILDIR,
FILCDEV,
FILBDEV,
FILFIFO,
FILSOCK,
FILSYM,
FILGZ,
FILTT,
FILSUID,
FILSGID,
FILSTCK,
FILNT,
FILOT,
FILEQ,
FILUID,
FILGID,
STREZ,
STRNZ,
STREQ,
STRNE,
STRLT,
STRGT,
INTEQ,
INTNE,
INTGE,
INTGT,
INTLE,
INTLT,
UNOT,
BAND,
BOR,
LPAREN,
RPAREN,
OPERAND
};
enum token_types {
UNOP,
BINOP,
BUNOP,
BBINOP,
PAREN
};
struct t_op {
const char *op_text;
short op_num, op_type;
} const ops [] = {
{"-r", FILRD, UNOP},
{"-w", FILWR, UNOP},
{"-x", FILEX, UNOP},
{"-e", FILEXIST,UNOP},
{"-f", FILREG, UNOP},
{"-d", FILDIR, UNOP},
{"-c", FILCDEV,UNOP},
{"-b", FILBDEV,UNOP},
{"-p", FILFIFO,UNOP},
{"-u", FILSUID,UNOP},
{"-g", FILSGID,UNOP},
{"-k", FILSTCK,UNOP},
{"-s", FILGZ, UNOP},
{"-t", FILTT, UNOP},
{"-z", STREZ, UNOP},
{"-n", STRNZ, UNOP},
{"-h", FILSYM, UNOP}, /* for backwards compat */
{"-O", FILUID, UNOP},
{"-G", FILGID, UNOP},
{"-L", FILSYM, UNOP},
{"-S", FILSOCK,UNOP},
{"=", STREQ, BINOP},
{"!=", STRNE, BINOP},
{"<", STRLT, BINOP},
{">", STRGT, BINOP},
{"-eq", INTEQ, BINOP},
{"-ne", INTNE, BINOP},
{"-ge", INTGE, BINOP},
{"-gt", INTGT, BINOP},
{"-le", INTLE, BINOP},
{"-lt", INTLT, BINOP},
{"-nt", FILNT, BINOP},
{"-ot", FILOT, BINOP},
{"-ef", FILEQ, BINOP},
{"!", UNOT, BUNOP},
{"-a", BAND, BBINOP},
{"-o", BOR, BBINOP},
{"(", LPAREN, PAREN},
{")", RPAREN, PAREN},
{0, 0, 0}
};
char **t_wp;
struct t_op const *t_wp_op;
static gid_t *group_array = NULL;
static int ngroups;
static enum token t_lex();
static int oexpr();
static int aexpr();
static int nexpr();
static int binop();
static int primary();
static int filstat();
static int getn();
static int newerf();
static int olderf();
static int equalf();
static void syntax();
static int test_eaccess();
static int is_a_group_member();
static void initialize_group_array();
extern int
test_main(int argc, char** argv)
{
int res;
if (strcmp(applet_name, "[") == 0) {
if (strcmp(argv[--argc], "]"))
fatalError("missing ]\n");
argv[argc] = NULL;
}
/* Implement special cases from POSIX.2, section 4.62.4 */
switch (argc) {
case 1:
exit( 1);
case 2:
exit (*argv[1] == '\0');
case 3:
if (argv[1][0] == '!' && argv[1][1] == '\0') {
exit (!(*argv[2] == '\0'));
}
break;
case 4:
if (argv[1][0] != '!' || argv[1][1] != '\0') {
if (t_lex(argv[2]),
t_wp_op && t_wp_op->op_type == BINOP) {
t_wp = &argv[1];
exit (binop() == 0);
}
}
break;
case 5:
if (argv[1][0] == '!' && argv[1][1] == '\0') {
if (t_lex(argv[3]),
t_wp_op && t_wp_op->op_type == BINOP) {
t_wp = &argv[2];
exit (!(binop() == 0));
}
}
break;
}
t_wp = &argv[1];
res = !oexpr(t_lex(*t_wp));
if (*t_wp != NULL && *++t_wp != NULL)
syntax(*t_wp, "unknown operand");
return( res);
}
static void
syntax(op, msg)
char *op;
char *msg;
{
if (op && *op)
fatalError("%s: %s\n", op, msg);
else
fatalError("%s\n", msg);
}
static int
oexpr(n)
enum token n;
{
int res;
res = aexpr(n);
if (t_lex(*++t_wp) == BOR)
return oexpr(t_lex(*++t_wp)) || res;
t_wp--;
return res;
}
static int
aexpr(n)
enum token n;
{
int res;
res = nexpr(n);
if (t_lex(*++t_wp) == BAND)
return aexpr(t_lex(*++t_wp)) && res;
t_wp--;
return res;
}
static int
nexpr(n)
enum token n; /* token */
{
if (n == UNOT)
return !nexpr(t_lex(*++t_wp));
return primary(n);
}
static int
primary(n)
enum token n;
{
int res;
if (n == EOI)
syntax(NULL, "argument expected");
if (n == LPAREN) {
res = oexpr(t_lex(*++t_wp));
if (t_lex(*++t_wp) != RPAREN)
syntax(NULL, "closing paren expected");
return res;
}
if (t_wp_op && t_wp_op->op_type == UNOP) {
/* unary expression */
if (*++t_wp == NULL)
syntax(t_wp_op->op_text, "argument expected");
switch (n) {
case STREZ:
return strlen(*t_wp) == 0;
case STRNZ:
return strlen(*t_wp) != 0;
case FILTT:
return isatty(getn(*t_wp));
default:
return filstat(*t_wp, n);
}
}
if (t_lex(t_wp[1]), t_wp_op && t_wp_op->op_type == BINOP) {
return binop();
}
return strlen(*t_wp) > 0;
}
static int
binop()
{
const char *opnd1, *opnd2;
struct t_op const *op;
opnd1 = *t_wp;
(void) t_lex(*++t_wp);
op = t_wp_op;
if ((opnd2 = *++t_wp) == (char *)0)
syntax(op->op_text, "argument expected");
switch (op->op_num) {
case STREQ:
return strcmp(opnd1, opnd2) == 0;
case STRNE:
return strcmp(opnd1, opnd2) != 0;
case STRLT:
return strcmp(opnd1, opnd2) < 0;
case STRGT:
return strcmp(opnd1, opnd2) > 0;
case INTEQ:
return getn(opnd1) == getn(opnd2);
case INTNE:
return getn(opnd1) != getn(opnd2);
case INTGE:
return getn(opnd1) >= getn(opnd2);
case INTGT:
return getn(opnd1) > getn(opnd2);
case INTLE:
return getn(opnd1) <= getn(opnd2);
case INTLT:
return getn(opnd1) < getn(opnd2);
case FILNT:
return newerf (opnd1, opnd2);
case FILOT:
return olderf (opnd1, opnd2);
case FILEQ:
return equalf (opnd1, opnd2);
}
/* NOTREACHED */
return 1;
}
static int
filstat(nm, mode)
char *nm;
enum token mode;
{
struct stat s;
unsigned int i;
if (mode == FILSYM) {
#ifdef S_IFLNK
if (lstat(nm, &s) == 0) {
i = S_IFLNK;
goto filetype;
}
#endif
return 0;
}
if (stat(nm, &s) != 0)
return 0;
switch (mode) {
case FILRD:
return test_eaccess(nm, R_OK) == 0;
case FILWR:
return test_eaccess(nm, W_OK) == 0;
case FILEX:
return test_eaccess(nm, X_OK) == 0;
case FILEXIST:
return 1;
case FILREG:
i = S_IFREG;
goto filetype;
case FILDIR:
i = S_IFDIR;
goto filetype;
case FILCDEV:
i = S_IFCHR;
goto filetype;
case FILBDEV:
i = S_IFBLK;
goto filetype;
case FILFIFO:
#ifdef S_IFIFO
i = S_IFIFO;
goto filetype;
#else
return 0;
#endif
case FILSOCK:
#ifdef S_IFSOCK
i = S_IFSOCK;
goto filetype;
#else
return 0;
#endif
case FILSUID:
i = S_ISUID;
goto filebit;
case FILSGID:
i = S_ISGID;
goto filebit;
case FILSTCK:
i = S_ISVTX;
goto filebit;
case FILGZ:
return s.st_size > 0L;
case FILUID:
return s.st_uid == geteuid();
case FILGID:
return s.st_gid == getegid();
default:
return 1;
}
filetype:
return ((s.st_mode & S_IFMT) == i);
filebit:
return ((s.st_mode & i) != 0);
}
static enum token
t_lex(s)
char *s;
{
struct t_op const *op = ops;
if (s == 0) {
t_wp_op = (struct t_op *)0;
return EOI;
}
while (op->op_text) {
if (strcmp(s, op->op_text) == 0) {
t_wp_op = op;
return op->op_num;
}
op++;
}
t_wp_op = (struct t_op *)0;
return OPERAND;
}
/* atoi with error detection */
static int
getn(s)
char *s;
{
char *p;
long r;
errno = 0;
r = strtol(s, &p, 10);
if (errno != 0)
fatalError("%s: out of range\n", s);
while (isspace(*p))
p++;
if (*p)
fatalError("%s: bad number\n", s);
return (int) r;
}
static int
newerf (f1, f2)
char *f1, *f2;
{
struct stat b1, b2;
return (stat (f1, &b1) == 0 &&
stat (f2, &b2) == 0 &&
b1.st_mtime > b2.st_mtime);
}
static int
olderf (f1, f2)
char *f1, *f2;
{
struct stat b1, b2;
return (stat (f1, &b1) == 0 &&
stat (f2, &b2) == 0 &&
b1.st_mtime < b2.st_mtime);
}
static int
equalf (f1, f2)
char *f1, *f2;
{
struct stat b1, b2;
return (stat (f1, &b1) == 0 &&
stat (f2, &b2) == 0 &&
b1.st_dev == b2.st_dev &&
b1.st_ino == b2.st_ino);
}
/* Do the same thing access(2) does, but use the effective uid and gid,
and don't make the mistake of telling root that any file is
executable. */
static int
test_eaccess (path, mode)
char *path;
int mode;
{
struct stat st;
unsigned int euid = geteuid();
if (stat (path, &st) < 0)
return (-1);
if (euid == 0) {
/* Root can read or write any file. */
if (mode != X_OK)
return (0);
/* Root can execute any file that has any one of the execute
bits set. */
if (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH))
return (0);
}
if (st.st_uid == euid) /* owner */
mode <<= 6;
else if (is_a_group_member (st.st_gid))
mode <<= 3;
if (st.st_mode & mode)
return (0);
return (-1);
}
static void
initialize_group_array ()
{
ngroups = getgroups(0, NULL);
group_array = xrealloc(group_array, ngroups * sizeof(gid_t));
getgroups(ngroups, group_array);
}
/* Return non-zero if GID is one that we have in our groups list. */
static int
is_a_group_member (gid)
gid_t gid;
{
register int i;
/* Short-circuit if possible, maybe saving a call to getgroups(). */
if (gid == getgid() || gid == getegid())
return (1);
if (ngroups == 0)
initialize_group_array ();
/* Search through the list looking for GID. */
for (i = 0; i < ngroups; i++)
if (gid == group_array[i])
return (1);
return (0);
}
+40 -52
View File
@@ -1,8 +1,9 @@
/* vi: set sw=4 ts=4: */
/*
* Mini touch implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
@@ -21,66 +22,53 @@
*
*/
#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\n"
"Update the last-modified date on the given file[s].\n";
extern int
touch_main(int argc, char **argv)
extern int touch_main(int argc, char **argv)
{
int fd;
int create=TRUE;
int fd;
int create = TRUE;
if (argc < 2) {
usage( touch_usage);
}
argc--;
argv++;
/* Parse options */
while (**argv == '-') {
while (*++(*argv)) switch (**argv) {
case 'c':
create = FALSE;
break;
default:
usage( touch_usage);
exit( FALSE);
/* Parse options */
while (--argc > 0 && **(++argv) == '-') {
while (*(++(*argv))) {
switch (**argv) {
case 'c':
create = FALSE;
break;
default:
usage(touch_usage);
exit(FALSE);
}
}
}
argc--;
argv++;
}
fd = open (*argv, (create==FALSE)? O_RDWR : O_RDWR | O_CREAT, 0644);
if (fd < 0 ) {
if (create==FALSE && errno == ENOENT)
exit( TRUE);
else {
perror("touch");
exit( FALSE);
if (argc < 1) {
usage(touch_usage);
}
}
close( fd);
if (utime (*argv, NULL)) {
perror("touch");
exit( FALSE);
}
else
exit( TRUE);
while (argc > 0) {
fd = open(*argv, (create == FALSE) ? O_RDWR : O_RDWR | O_CREAT,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
if (fd < 0) {
if (create == FALSE && errno == ENOENT)
exit(TRUE);
else {
fatalError("%s", strerror(errno));
}
}
close(fd);
if (utime(*argv, NULL)) {
fatalError("%s", strerror(errno));
}
argc--;
argv++;
}
return(TRUE);
}
+231
View File
@@ -0,0 +1,231 @@
/* vi: set sw=4 ts=4: */
/*
* Mini tr implementation for busybox
*
* Copyright (c) Michiel Huisjes
*
* This version of tr is adapted from Minix tr and was modified
* by Erik Andersen <andersee@debian.org> to be used in busybox.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Original copyright notice is retained at the end of this file.
*/
#include "busybox.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#define BB_DECLARE_EXTERN
#define bb_need_write_error
#include "messages.c"
#ifdef TRUE
#undef TRUE
#undef FALSE
#define TRUE 1
#define FALSE 0
#endif
#define ASCII 0377
/* some glabals shared across this file */
static char com_fl, del_fl, sq_fl;
static unsigned char output[BUFSIZ], input[BUFSIZ];
static unsigned char vector[ASCII + 1];
static char invec[ASCII + 1], outvec[ASCII + 1];
static short in_index, out_index;
static void convert()
{
short read_chars = 0;
short c, coded;
short last = -1;
for (;;) {
if (in_index == read_chars) {
if ((read_chars = read(0, (char *) input, BUFSIZ)) <= 0) {
if (write(1, (char *) output, out_index) != out_index)
write(2, write_error, strlen(write_error));
exit(0);
}
in_index = 0;
}
c = input[in_index++];
coded = vector[c];
if (del_fl && invec[c])
continue;
if (sq_fl && last == coded && outvec[coded])
continue;
output[out_index++] = last = coded;
if (out_index == BUFSIZ) {
if (write(1, (char *) output, out_index) != out_index) {
write(2, write_error, strlen(write_error));
exit(1);
}
out_index = 0;
}
}
/* NOTREACHED */
}
static void map(register unsigned char *string1, unsigned int string1_len,
register unsigned char *string2, unsigned int string2_len)
{
unsigned char last = '0';
unsigned int i, j;
for (j = 0, i = 0; i < string1_len; i++) {
if (string2_len <= j)
vector[string1[i]] = last;
else
vector[string1[i]] = last = string2[j++];
}
}
static unsigned int expand(char *arg, register unsigned char *buffer)
{
unsigned char *buffer_start = buffer;
int i, ac;
while (*arg) {
if (*arg == '\\') {
arg++;
*buffer++ = process_escape_sequence(&arg);
} else if (*arg == '[') {
arg++;
i = *arg++;
if (*arg++ != '-') {
*buffer++ = '[';
arg -= 2;
continue;
}
ac = *arg++;
while (i <= ac)
*buffer++ = i++;
arg++; /* Skip ']' */
} else
*buffer++ = *arg++;
}
return (buffer - buffer_start);
}
static int complement(unsigned char *buffer, int buffer_len)
{
register short i, j, index;
char conv[ASCII + 2];
index = 0;
for (i = 0; i <= ASCII; i++) {
for (j = 0; j < buffer_len; j++)
if (buffer[j] == i)
break;
if (j == buffer_len)
conv[index++] = i & ASCII;
}
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;
int i;
if (argc > 1 && argv[index][0] == '-') {
for (ptr = (unsigned char *) &argv[index][1]; *ptr; ptr++) {
switch (*ptr) {
case 'c':
com_fl = TRUE;
break;
case 'd':
del_fl = TRUE;
break;
case 's':
sq_fl = TRUE;
break;
default:
usage(tr_usage);
}
}
index++;
}
for (i = 0; i <= ASCII; i++) {
vector[i] = i;
invec[i] = outvec[i] = FALSE;
}
if (argv[index] != NULL) {
input_length = expand(argv[index++], input);
if (com_fl)
input_length = complement(input, input_length);
if (argv[index] != NULL) {
if (*argv[index] == '\0')
fatalError("STRING2 cannot be empty\n");
output_length = expand(argv[index], output);
map(input, input_length, output, output_length);
}
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);
}
/*
* 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.
*
*/
+42
View File
@@ -0,0 +1,42 @@
/* vi: set sw=4 ts=4: */
/*
* Mini tty implementation for busybox
*
* 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
*
*/
#include "busybox.h"
#include <stdio.h>
#include <sys/types.h>
extern int tty_main(int argc, char **argv)
{
char *tty;
if (argc > 1) {
if (argv[1][0] != '-' || argv[1][1] != 's')
usage(tty_usage);
} else {
tty = ttyname(0);
if (tty)
puts(tty);
else
puts("not a tty");
}
return(isatty(0) ? TRUE : FALSE);
}
+60 -72
View File
@@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/* uname -- print system information
Copyright (C) 1989-1999 Free Software Foundation, Inc.
@@ -30,7 +31,7 @@
/* Busyboxed by Erik Andersen */
#include "internal.h"
#include "busybox.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/utsname.h>
@@ -39,20 +40,6 @@
# include <sys/systeminfo.h>
#endif
static const char uname_usage[] =
"uname [OPTION]...\n\n"
"Print 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";
static void print_element(unsigned int mask, char *element);
/* Values that are bitwise or'd into `toprint'. */
@@ -80,77 +67,78 @@ static unsigned char toprint;
int uname_main(int argc, char **argv)
{
struct utsname name;
char processor[256];
struct utsname name;
char processor[256];
#if defined(__sparc__) && defined(__linux__)
char *fake_sparc = getenv("FAKE_SPARC");
char *fake_sparc = getenv("FAKE_SPARC");
#endif
toprint = 0;
toprint = 0;
/* Parse any options */
//fprintf(stderr, "argc=%d, argv=%s\n", argc, *argv);
while (--argc > 0 && **(++argv) == '-') {
while (*(++(*argv))) {
switch (**argv) {
case 's':
toprint |= PRINT_SYSNAME;
break;
case 'n':
toprint |= PRINT_NODENAME;
break;
case 'r':
toprint |= PRINT_RELEASE;
break;
case 'v':
toprint |= PRINT_VERSION;
break;
case 'm':
toprint |= PRINT_MACHINE;
break;
case 'p':
toprint |= PRINT_PROCESSOR;
break;
case 'a':
toprint = (PRINT_SYSNAME | PRINT_NODENAME | PRINT_RELEASE |
PRINT_PROCESSOR | PRINT_VERSION |
PRINT_MACHINE);
break;
default:
usage(uname_usage);
}
/* Parse any options */
//fprintf(stderr, "argc=%d, argv=%s\n", argc, *argv);
while (--argc > 0 && **(++argv) == '-') {
while (*(++(*argv))) {
switch (**argv) {
case 's':
toprint |= PRINT_SYSNAME;
break;
case 'n':
toprint |= PRINT_NODENAME;
break;
case 'r':
toprint |= PRINT_RELEASE;
break;
case 'v':
toprint |= PRINT_VERSION;
break;
case 'm':
toprint |= PRINT_MACHINE;
break;
case 'p':
toprint |= PRINT_PROCESSOR;
break;
case 'a':
toprint = (PRINT_SYSNAME | PRINT_NODENAME | PRINT_RELEASE |
PRINT_PROCESSOR | PRINT_VERSION |
PRINT_MACHINE);
break;
default:
usage(uname_usage);
}
}
}
}
if (toprint == 0)
toprint = PRINT_SYSNAME;
if (toprint == 0)
toprint = PRINT_SYSNAME;
if (uname(&name) == -1)
perror("cannot get system name");
if (uname(&name) == -1)
perror("cannot get system name");
#if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE)
if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1)
perror("cannot get processor type");
if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1)
perror("cannot get processor type");
}
#else
strcpy(processor, "unknown");
strcpy(processor, "unknown");
#endif
#if defined(__sparc__) && defined(__linux__)
if (fake_sparc != NULL
&& (fake_sparc[0] == 'y'
|| fake_sparc[0] == 'Y')) strcpy(name.machine, "sparc");
if (fake_sparc != NULL
&& (fake_sparc[0] == 'y'
|| fake_sparc[0] == 'Y')) strcpy(name.machine, "sparc");
#endif
print_element(PRINT_SYSNAME, name.sysname);
print_element(PRINT_NODENAME, name.nodename);
print_element(PRINT_RELEASE, name.release);
print_element(PRINT_VERSION, name.version);
print_element(PRINT_MACHINE, name.machine);
print_element(PRINT_PROCESSOR, processor);
print_element(PRINT_SYSNAME, name.sysname);
print_element(PRINT_NODENAME, name.nodename);
print_element(PRINT_RELEASE, name.release);
print_element(PRINT_VERSION, name.version);
print_element(PRINT_MACHINE, name.machine);
print_element(PRINT_PROCESSOR, processor);
exit(TRUE);
return(TRUE);
}
/* If the name element set in MASK is selected for printing in `toprint',
@@ -159,8 +147,8 @@ int uname_main(int argc, char **argv)
static void print_element(unsigned int mask, char *element)
{
if (toprint & mask) {
toprint &= ~mask;
printf("%s%c", element, toprint ? ' ' : '\n');
}
if (toprint & mask) {
toprint &= ~mask;
printf("%s%c", element, toprint ? ' ' : '\n');
}
}
+182
View File
@@ -0,0 +1,182 @@
/* vi: set sw=4 ts=4: */
/*
* Mini uniq implementation for busybox
*
*
* Copyright (C) 1999,2000 by Lineo, inc.
* Written by John Beppu <beppu@lineo.com>
*
* This program is free software; you can redistribute it and/or modify
* 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>
#include <string.h>
#include <errno.h>
/* max chars in line */
#define UNIQ_MAX 4096
typedef void (Print) (FILE *, const char *);
typedef int (Decide) (const char *, const char *);
/* container for two lines to be compared */
typedef struct {
char *a;
char *b;
int recurrence;
FILE *in;
FILE *out;
void *func;
} Subject;
/* set up all the variables of a uniq operation */
static Subject *subject_init(Subject * self, FILE * in, FILE * out,
void *func)
{
self->a = NULL;
self->b = NULL;
self->in = in;
self->out = out;
self->func = func;
self->recurrence = 0;
return self;
}
/* point a and b to the appropriate lines;
* count the recurrences (if any) of a string;
*/
static Subject *subject_next(Subject * self)
{
/* tmp line holders */
static char line[2][UNIQ_MAX];
static int alternator = 0;
if (fgets(line[alternator], UNIQ_MAX, self->in)) {
self->a = self->b;
self->b = line[alternator];
alternator ^= 1;
return self;
}
return NULL;
}
static Subject *subject_last(Subject * self)
{
self->a = self->b;
self->b = NULL;
return self;
}
static Subject *subject_study(Subject * self)
{
if (self->a == NULL) {
return self;
}
if (self->b == NULL) {
fprintf(self->out, "%s", self->a);
return self;
}
if (strcmp(self->a, self->b) == 0) {
self->recurrence++;
} else {
fprintf(self->out, "%s", self->a);
self->recurrence = 0;
}
return self;
}
static int
set_file_pointers(int schema, FILE ** in, FILE ** out, char **argv)
{
switch (schema) {
case 0:
*in = stdin;
*out = stdout;
break;
case 1:
*in = fopen(argv[0], "r");
*out = stdout;
break;
case 2:
*in = fopen(argv[0], "r");
*out = fopen(argv[1], "w");
break;
}
if (*in == NULL) {
errorMsg("%s: %s\n", argv[0], strerror(errno));
return errno;
}
if (*out == NULL) {
errorMsg("%s: %s\n", argv[1], strerror(errno));
return errno;
}
return 0;
}
/* one variable is the decision algo */
/* another variable is the printing algo */
/* I don't think I have to have more than a 1 line memory
this is the one constant */
/* it seems like GNU/uniq only takes one or two files as an option */
/* ________________________________________________________________________ */
int uniq_main(int argc, char **argv)
{
int i;
char opt;
FILE *in, *out;
Subject s;
/* parse argv[] */
for (i = 1; i < argc; i++) {
if (argv[i][0] == '-') {
opt = argv[i][1];
switch (opt) {
case '-':
case 'h':
usage(uniq_usage);
default:
usage(uniq_usage);
}
} else {
break;
}
}
/* 0 src: stdin; dst: stdout */
/* 1 src: file; dst: stdout */
/* 2 src: file; dst: file */
if (set_file_pointers((argc - 1), &in, &out, &argv[i])) {
exit(1);
}
subject_init(&s, in, out, NULL);
while (subject_next(&s)) {
subject_study(&s);
}
subject_last(&s);
subject_study(&s);
return(0);
}
/* $Id: uniq.c,v 1.14 2000/09/25 21:45:58 andersen Exp $ */
+36
View File
@@ -0,0 +1,36 @@
/* vi: set sw=4 ts=4: */
/*
* Mini usleep implementation for busybox
*
*
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "busybox.h"
#include <stdlib.h>
#include <unistd.h>
extern int usleep_main(int argc, char **argv)
{
if ((argc < 2) || (**(argv + 1) == '-')) {
usage(usleep_usage);
}
usleep(atoi(*(++argv))); /* return void */
return(TRUE);
}
+342
View File
@@ -0,0 +1,342 @@
/* uudecode.c -- uudecode utility.
* Copyright (C) 1994, 1995 Free Software Foundation, Inc.
*
* This product is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This product is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this product; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
/* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* Reworked to GNU style by Ian Lance Taylor, ian@airs.com, August 93. */
#include "busybox.h"
#include <stdio.h>
#include <errno.h>
#include <getopt.h>
#include <pwd.h>
/*struct passwd *getpwnam();*/
/* Single character decode. */
#define DEC(Char) (((Char) - ' ') & 077)
static int read_stduu (const char *inname)
{
char buf[2 * BUFSIZ];
while (1) {
int n;
char *p;
if (fgets (buf, sizeof(buf), stdin) == NULL) {
errorMsg("%s: Short file\n", inname);
return FALSE;
}
p = buf;
/* N is used to avoid writing out all the characters at the end of
the file. */
n = DEC (*p);
if (n <= 0)
break;
for (++p; n > 0; p += 4, n -= 3) {
char ch;
if (n >= 3) {
ch = DEC (p[0]) << 2 | DEC (p[1]) >> 4;
putchar (ch);
ch = DEC (p[1]) << 4 | DEC (p[2]) >> 2;
putchar (ch);
ch = DEC (p[2]) << 6 | DEC (p[3]);
putchar (ch);
} else {
if (n >= 1) {
ch = DEC (p[0]) << 2 | DEC (p[1]) >> 4;
putchar (ch);
}
if (n >= 2) {
ch = DEC (p[1]) << 4 | DEC (p[2]) >> 2;
putchar (ch);
}
}
}
}
if (fgets (buf, sizeof(buf), stdin) == NULL
|| strcmp (buf, "end\n")) {
errorMsg("%s: No `end' line\n", inname);
return FALSE;
}
return TRUE;
}
static int read_base64 (const char *inname)
{
static const char b64_tab[256] = {
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*000-007*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*010-017*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*020-027*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*030-037*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*040-047*/
'\177', '\177', '\177', '\76', '\177', '\177', '\177', '\77', /*050-057*/
'\64', '\65', '\66', '\67', '\70', '\71', '\72', '\73', /*060-067*/
'\74', '\75', '\177', '\177', '\177', '\100', '\177', '\177', /*070-077*/
'\177', '\0', '\1', '\2', '\3', '\4', '\5', '\6', /*100-107*/
'\7', '\10', '\11', '\12', '\13', '\14', '\15', '\16', /*110-117*/
'\17', '\20', '\21', '\22', '\23', '\24', '\25', '\26', /*120-127*/
'\27', '\30', '\31', '\177', '\177', '\177', '\177', '\177', /*130-137*/
'\177', '\32', '\33', '\34', '\35', '\36', '\37', '\40', /*140-147*/
'\41', '\42', '\43', '\44', '\45', '\46', '\47', '\50', /*150-157*/
'\51', '\52', '\53', '\54', '\55', '\56', '\57', '\60', /*160-167*/
'\61', '\62', '\63', '\177', '\177', '\177', '\177', '\177', /*170-177*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*200-207*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*210-217*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*220-227*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*230-237*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*240-247*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*250-257*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*260-267*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*270-277*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*300-307*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*310-317*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*320-327*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*330-337*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*340-347*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*350-357*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*360-367*/
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*370-377*/
};
unsigned char buf[2 * BUFSIZ];
while (1) {
int last_data = 0;
unsigned char *p;
if (fgets (buf, sizeof(buf), stdin) == NULL) {
errorMsg("%s: Short file\n", inname);
return FALSE;
}
p = buf;
if (memcmp (buf, "====", 4) == 0)
break;
if (last_data != 0) {
errorMsg("%s: data following `=' padding character\n", inname);
return FALSE;
}
/* The following implementation of the base64 decoding might look
a bit clumsy but I only try to follow the POSIX standard:
``All line breaks or other characters not found in the table
[with base64 characters] shall be ignored by decoding
software.'' */
while (*p != '\n') {
char c1, c2, c3;
while ((b64_tab[*p] & '\100') != 0)
if (*p == '\n' || *p++ == '=')
break;
if (*p == '\n')
/* This leaves the loop. */
continue;
c1 = b64_tab[*p++];
while ((b64_tab[*p] & '\100') != 0)
if (*p == '\n' || *p++ == '=') {
errorMsg("%s: illegal line\n", inname);
return FALSE;
}
c2 = b64_tab[*p++];
while (b64_tab[*p] == '\177')
if (*p++ == '\n') {
errorMsg("%s: illegal line\n", inname);
return FALSE;
}
if (*p == '=') {
putchar (c1 << 2 | c2 >> 4);
last_data = 1;
break;
}
c3 = b64_tab[*p++];
while (b64_tab[*p] == '\177')
if (*p++ == '\n') {
errorMsg("%s: illegal line\n", inname);
return FALSE;
}
putchar (c1 << 2 | c2 >> 4);
putchar (c2 << 4 | c3 >> 2);
if (*p == '=') {
last_data = 1;
break;
}
else
putchar (c3 << 6 | b64_tab[*p++]);
}
}
return TRUE;
}
static int decode (const char *inname,
const char *forced_outname)
{
struct passwd *pw;
register int n;
register char *p;
int mode, n1;
char buf[2 * BUFSIZ];
char *outname;
int do_base64 = 0;
/* Search for header line. */
while (1) {
if (fgets (buf, sizeof (buf), stdin) == NULL) {
errorMsg("%s: No `begin' line\n", inname);
return FALSE;
}
if (strncmp (buf, "begin", 5) == 0) {
if (sscanf (buf, "begin-base64 %o %s", &mode, buf) == 2) {
do_base64 = 1;
break;
} else if (sscanf (buf, "begin %o %s", &mode, buf) == 2)
break;
}
}
/* If the output file name is given on the command line this rules. */
if (forced_outname != NULL)
outname = (char *) forced_outname;
else {
/* Handle ~user/file format. */
if (buf[0] != '~')
outname = buf;
else {
p = buf + 1;
while (*p != '/')
++p;
if (*p == '\0') {
errorMsg("%s: Illegal ~user\n", inname);
return FALSE;
}
*p++ = '\0';
pw = getpwnam (buf + 1);
if (pw == NULL) {
errorMsg("%s: No user `%s'\n", inname, buf + 1);
return FALSE;
}
n = strlen (pw->pw_dir);
n1 = strlen (p);
outname = (char *) alloca ((size_t) (n + n1 + 2));
memcpy (outname + n + 1, p, (size_t) (n1 + 1));
memcpy (outname, pw->pw_dir, (size_t) n);
outname[n] = '/';
}
}
/* Create output file and set mode. */
if (strcmp (outname, "/dev/stdout") != 0 && strcmp (outname, "-") != 0
&& (freopen (outname, "w", stdout) == NULL
|| chmod (outname, mode & (S_IRWXU | S_IRWXG | S_IRWXO))
)) {
errorMsg("%s: %s %s\n", outname, inname, strerror(errno)); /* */
return FALSE;
}
/* We differenciate decoding standard UU encoding and base64. A
common function would only slow down the program. */
/* For each input line: */
if (do_base64)
return read_base64 (inname);
else
return read_stduu (inname);
}
int uudecode_main (int argc,
char **argv)
{
int opt;
int exit_status;
const char *outname;
outname = NULL;
while ((opt = getopt(argc, argv, "o:")) != EOF) {
switch (opt) {
case 0:
break;
case 'o':
outname = optarg;
break;
default:
usage(uudecode_usage);
}
}
if (optind == argc)
exit_status = decode ("stdin", outname) == 0 ? TRUE : FALSE;
else {
exit_status = TRUE;
do {
if (freopen (argv[optind], "r", stdin) != NULL) {
if (decode (argv[optind], outname) != 0)
exit_status = FALSE;
} else {
errorMsg("%s: %s\n", argv[optind], strerror(errno));
exit_status = FALSE;
}
optind++;
}
while (optind < argc);
}
return(exit_status);
}
+236
View File
@@ -0,0 +1,236 @@
/* uuencode.c -- uuencode utility.
* Copyright (C) 1994, 1995 Free Software Foundation, Inc.
*
* This product is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This product is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this product; see the file COPYING. If not, write to
* the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
/* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* Reworked to GNU style by Ian Lance Taylor, ian@airs.com, August 93. */
/* Hacked to work with BusyBox by Alfred M. Szmidt */
#include "busybox.h"
#include <stdio.h>
#include <errno.h>
#include <getopt.h>
#include <pwd.h>
#define RW (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
static void encode __P ((void));
/* Pointer to the translation table we currently use. */
const char *trans_ptr;
/* The two currently defined translation tables. The first is the
standard uuencoding, the second is base64 encoding. */
const char uu_std[64] = {
'`', '!', '"', '#', '$', '%', '&', '\'',
'(', ')', '*', '+', ',', '-', '.', '/',
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', ':', ';', '<', '=', '>', '?',
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '[', '\\', ']', '^', '_'
};
const char uu_base64[64] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'
};
/* ENC is the basic 1 character encoding function to make a char printing. */
#define ENC(Char) (trans_ptr[(Char) & 077])
/* Copy from IN to OUT, encoding as you go along. */
static void encode()
{
register int ch, n;
char *p = NULL;
char buf[80];
while (1) {
n = 0;
do {
register int m = fread (buf, 1, 45 - n, stdin);
if (m == 0)
break;
n += m;
}
while (n < 45);
if (n == 0)
break;
if (trans_ptr == uu_std)
if (putchar (ENC (n)) == EOF)
break;
for (p = buf; n > 2; n -= 3, p += 3) {
ch = *p >> 2;
ch = ENC (ch);
if (putchar (ch) == EOF)
break;
ch = ((*p << 4) & 060) | ((p[1] >> 4) & 017);
ch = ENC (ch);
if (putchar (ch) == EOF)
break;
ch = ((p[1] << 2) & 074) | ((p[2] >> 6) & 03);
ch = ENC (ch);
if (putchar (ch) == EOF)
break;
ch = p[2] & 077;
ch = ENC (ch);
if (putchar (ch) == EOF)
break;
}
if (n != 0)
break;
if (putchar ('\n') == EOF)
break;
}
while (n != 0) {
char c1 = *p;
char c2 = n == 1 ? 0 : p[1];
ch = c1 >> 2;
ch = ENC (ch);
if (putchar (ch) == EOF)
break;
ch = ((c1 << 4) & 060) | ((c2 >> 4) & 017);
ch = ENC (ch);
if (putchar (ch) == EOF)
break;
if (n == 1)
ch = trans_ptr == uu_std ? ENC ('\0') : '=';
else {
ch = (c2 << 2) & 074;
ch = ENC (ch);
}
if (putchar (ch) == EOF)
break;
ch = trans_ptr == uu_std ? ENC ('\0') : '=';
if (putchar (ch) == EOF)
break;
putchar ('\n');
break;
}
if (ferror (stdin))
errorMsg("Read error\n");
if (trans_ptr == uu_std) {
putchar (ENC ('\0'));
putchar ('\n');
}
}
int uuencode_main (int argc,
char **argv)
{
int opt;
struct stat sb;
int mode;
trans_ptr = uu_std; /* Standard encoding is old uu format */
/* Parse any options */
while ((opt = getopt (argc, argv, "m")) != EOF) {
switch (opt) {
case 'm':
trans_ptr = uu_base64;
break;
case 0:
break;
default:
usage(uuencode_usage);
}
}
switch (argc - optind) {
case 2:
/* Optional first argument is input file. */
if (!freopen (argv[optind], "r", stdin) || fstat (fileno (stdin), &sb)) {
errorMsg("%s: %s\n", argv[optind], strerror(errno));
exit FALSE;
}
mode = sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
optind++;
break;
case 1:
mode = RW & ~umask (RW);
break;
case 0:
default:
usage(uuencode_usage);
}
printf("begin%s %o %s\n", trans_ptr == uu_std ? "" : "-base64",
mode, argv[optind]);
encode();
printf(trans_ptr == uu_std ? "end\n" : "====\n");
if (ferror (stdout)) {
errorMsg("Write error\n");
exit FALSE;
}
return( TRUE);
}
+155
View File
@@ -0,0 +1,155 @@
/* vi: set sw=4 ts=4: */
/*
* Mini wc implementation for busybox
*
* 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
*
*/
#include "busybox.h"
#include <stdio.h>
#include <getopt.h>
static int total_lines, total_words, total_chars, max_length;
static int print_lines, print_words, print_chars, print_length;
void print_counts(int lines, int words, int chars, int length,
const char *name)
{
char const *space = "";
if (print_lines) {
printf("%7d", lines);
space = " ";
}
if (print_words) {
printf("%s%7d", space, words);
space = " ";
}
if (print_chars) {
printf("%s%7d", space, chars);
space = " ";
}
if (print_length)
printf("%s%7d", space, length);
if (*name)
printf(" %s", name);
putchar('\n');
}
static void wc_file(FILE * file, const char *name)
{
int lines, words, chars, length;
int in_word = 0, linepos = 0;
int c;
lines = words = chars = length = 0;
while ((c = getc(file)) != EOF) {
chars++;
switch (c) {
case '\n':
lines++;
case '\r':
case '\f':
if (linepos > length)
length = linepos;
linepos = 0;
goto word_separator;
case '\t':
linepos += 8 - (linepos % 8);
goto word_separator;
case ' ':
linepos++;
case '\v':
word_separator:
if (in_word) {
in_word = 0;
words++;
}
break;
default:
linepos++;
in_word = 1;
break;
}
}
if (linepos > length)
length = linepos;
if (in_word)
words++;
print_counts(lines, words, chars, length, name);
total_lines += lines;
total_words += words;
total_chars += chars;
if (length > max_length)
max_length = length;
fclose(file);
fflush(stdout);
}
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 ((opt = getopt(argc, argv, "clLw")) > 0) {
switch (opt) {
case 'c':
print_chars = 1;
break;
case 'l':
print_lines = 1;
break;
case 'L':
print_length = 1;
break;
case 'w':
print_words = 1;
break;
default:
usage(wc_usage);
}
}
if (!print_lines && !print_words && !print_chars && !print_length)
print_lines = print_words = print_chars = 1;
if (argv[optind] == NULL || strcmp(argv[optind], "-") == 0) {
wc_file(stdin, "");
exit(TRUE);
} else {
while (optind < argc) {
file = fopen(argv[optind], "r");
if (file == NULL) {
fatalError(argv[optind]);
}
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 0 ;
}
+42
View File
@@ -0,0 +1,42 @@
/* vi: set sw=4 ts=4: */
/*
* Mini whoami implementation for busybox
*
* 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
*
*/
#include "busybox.h"
#include <stdio.h>
#include <pwd.h>
extern int whoami_main(int argc, char **argv)
{
char *user = xmalloc(9);
uid_t uid = geteuid();
if (argc > 1)
usage(whoami_usage);
my_getpwuid(user, uid);
if (user) {
puts(user);
exit(TRUE);
}
errorMsg("cannot find username for UID %u\n", (unsigned) uid);
return(FALSE);
}
+50
View File
@@ -0,0 +1,50 @@
/* vi: set sw=4 ts=4: */
/*
* Mini yes implementation for busybox
*
* 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
*
*/
#include "busybox.h"
#include <stdio.h>
extern int yes_main(int argc, char **argv)
{
int i;
if (argc >= 2 && *argv[1] == '-')
usage(yes_usage);
if (argc == 1) {
while (1)
if (puts("y") == EOF) {
perror("yes");
return EXIT_FAILURE;
}
}
while (1)
for (i = 1; i < argc; i++)
if (fputs(argv[i], stdout) == EOF
|| putchar(i == argc - 1 ? '\n' : ' ') == EOF) {
perror("yes");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
-117
View File
@@ -1,117 +0,0 @@
/*
* Mini cp implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <time.h>
#include <utime.h>
#include <dirent.h>
static const char cp_usage[] = "cp [OPTION]... SOURCE DEST\n"
" or: cp [OPTION]... SOURCE... DIRECTORY\n\n"
"Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n"
"\n"
"\t-a\tsame as -dpR\n"
"\t-d\tpreserve links\n"
"\t-p\tpreserve file attributes if possable\n"
"\t-R\tcopy directories recursively\n";
static int recursiveFlag = FALSE;
static int followLinks = FALSE;
static int preserveFlag = FALSE;
static const char *srcName;
static const char *destName;
static const char *skipName;
static int dirFlag = FALSE;
static int fileAction(const char *fileName, struct stat* statbuf)
{
char newdestName[NAME_MAX];
strcpy(newdestName, destName);
if (dirFlag==TRUE) {
strcat(newdestName, "/");
if ( skipName != NULL)
strcat(newdestName, strstr(fileName, skipName));
else
strcat(newdestName, srcName);
}
return (copyFile(fileName, newdestName, preserveFlag, followLinks));
}
extern int cp_main(int argc, char **argv)
{
if (argc < 3) {
usage (cp_usage);
}
argc--;
argv++;
/* Parse any options */
while (**argv == '-') {
while (*++(*argv))
switch (**argv) {
case 'a':
followLinks = TRUE;
preserveFlag = TRUE;
recursiveFlag = TRUE;
break;
case 'd':
followLinks = TRUE;
break;
case 'p':
preserveFlag = TRUE;
break;
case 'R':
recursiveFlag = TRUE;
break;
default:
usage (cp_usage);
}
argc--;
argv++;
}
destName = argv[argc - 1];
dirFlag = isDirectory(destName);
if ((argc > 3) && dirFlag==FALSE) {
fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE);
}
while (argc-- > 1) {
srcName = *(argv++);
skipName = strrchr(srcName, '/');
if (skipName)
skipName++;
if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE,
fileAction, fileAction) == FALSE) {
exit( FALSE);
}
}
exit( TRUE);
}
+330
View File
@@ -0,0 +1,330 @@
/* vi: set sw=4 ts=4: */
/*
* Mini `cp' and `mv' implementation for BusyBox.
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* Copyright (C) 2000 by BitterSweet Enterprises, LLC. (GPL)
* Extensively modified and rewritten by Karl M. Hegbloom <karlheg@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "busybox.h"
#define BB_DECLARE_EXTERN
#define bb_need_name_too_long
#define bb_need_omitting_directory
#define bb_need_not_a_directory
#include "messages.c"
#include <stdio.h>
#include <time.h>
#include <utime.h>
#include <dirent.h>
#include <sys/param.h>
#include <setjmp.h>
#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 *cp_mv_usage[] = /* .rodata */
{
cp_usage,
mv_usage
};
static int recursiveFlag;
static int followLinks;
static int preserveFlag;
static int forceFlag;
static const char *baseSrcName;
static int srcDirFlag;
static struct stat srcStatBuf;
static char baseDestName[BUFSIZ + 1];
static size_t baseDestLen;
static int destDirFlag;
static struct stat destStatBuf;
static jmp_buf catch;
static volatile int mv_Action_first_time;
static void name_too_long__exit (void) __attribute__((noreturn));
static
void name_too_long__exit (void)
{
fatalError(name_too_long);
}
static void
fill_baseDest_buf(char *_buf, size_t * _buflen) {
const char *srcBasename;
if ((srcBasename = strrchr(baseSrcName, '/')) == NULL) {
srcBasename = baseSrcName;
if (_buf[*_buflen - 1] != '/') {
if (++(*_buflen) > BUFSIZ)
name_too_long__exit();
strcat(_buf, "/");
}
}
if (*_buflen + strlen(srcBasename) > BUFSIZ)
name_too_long__exit();
strcat(_buf, srcBasename);
return;
}
static int
cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
{
char destName[BUFSIZ + 1];
size_t destLen;
const char *srcBasename;
char *name;
strcpy(destName, baseDestName);
destLen = strlen(destName);
if (srcDirFlag == TRUE) {
if (recursiveFlag == FALSE) {
errorMsg(omitting_directory, baseSrcName);
return TRUE;
}
srcBasename = (strstr(fileName, baseSrcName)
+ strlen(baseSrcName));
if (destLen + strlen(srcBasename) > BUFSIZ) {
errorMsg(name_too_long);
return FALSE;
}
strcat(destName, srcBasename);
}
else if (destDirFlag == TRUE) {
fill_baseDest_buf(&destName[0], &destLen);
}
else {
srcBasename = baseSrcName;
}
if (mv_Action_first_time && (dz_i == is_mv)) {
mv_Action_first_time = errno = 0;
if (rename(fileName, destName) < 0 && errno != EXDEV) {
errorMsg("rename(%s, %s): %s\n", fileName, destName,
strerror(errno));
goto do_copyFile; /* Try anyway... */
}
else if (errno == EXDEV)
goto do_copyFile;
else
longjmp(catch, 1); /* succeeded with rename() */
}
do_copyFile:
if (preserveFlag == TRUE && statbuf->st_nlink > 1) {
if (is_in_ino_dev_hashtable(statbuf, &name)) {
if (link(name, destName) < 0) {
errorMsg("link(%s, %s): %s\n", name, destName, strerror(errno));
return FALSE;
}
return TRUE;
}
else {
add_to_ino_dev_hashtable(statbuf, destName);
}
}
return copyFile(fileName, destName, preserveFlag, followLinks, forceFlag);
}
static int
rm_Action(const char *fileName, struct stat *statbuf, void* junk)
{
int status = TRUE;
if (S_ISDIR(statbuf->st_mode)) {
if (rmdir(fileName) < 0) {
errorMsg("rmdir(%s): %s\n", fileName, strerror(errno));
status = FALSE;
}
} else if (unlink(fileName) < 0) {
errorMsg("unlink(%s): %s\n", fileName, strerror(errno));
status = FALSE;
}
return status;
}
extern int cp_mv_main(int argc, char **argv)
{
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]);
if (dz_i == is_cp) {
recursiveFlag = preserveFlag = forceFlag = FALSE;
followLinks = TRUE;
while ((c = getopt(argc, argv, "adpRf")) != EOF) {
switch (c) {
case 'a':
followLinks = FALSE;
preserveFlag = TRUE;
recursiveFlag = TRUE;
break;
case 'd':
followLinks = FALSE;
break;
case 'p':
preserveFlag = TRUE;
break;
case 'R':
recursiveFlag = TRUE;
break;
case 'f':
forceFlag = TRUE;
break;
default:
usage(cp_mv_usage[is_cp]);
}
}
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) {
errorMsg(name_too_long);
goto exit_false;
}
strcpy(baseDestName, argv[argc - 1]);
baseDestLen = strlen(baseDestName);
if (baseDestLen == 0)
goto exit_false;
destDirFlag = isDirectory(baseDestName, TRUE, &destStatBuf);
if (argc - optind > 2 && destDirFlag == FALSE) {
errorMsg(not_a_directory, baseDestName);
goto exit_false;
}
for (i = optind; i < (argc-1); i++) {
size_t srcLen;
volatile int flags_memo;
int status;
baseSrcName=argv[i];
if ((srcLen = strlen(baseSrcName)) > BUFSIZ)
name_too_long__exit();
if (srcLen == 0) continue; /* "" */
srcDirFlag = isDirectory(baseSrcName, followLinks, &srcStatBuf);
if ((flags_memo = (recursiveFlag == TRUE &&
srcDirFlag == TRUE && destDirFlag == TRUE))) {
struct stat sb;
int state = 0;
char *pushd, *d, *p;
if ((pushd = getcwd(NULL, BUFSIZ + 1)) == NULL) {
errorMsg("getcwd(): %s\n", strerror(errno));
continue;
}
if (chdir(baseDestName) < 0) {
errorMsg("chdir(%s): %s\n", baseSrcName, strerror(errno));
continue;
}
if ((d = getcwd(NULL, BUFSIZ + 1)) == NULL) {
errorMsg("getcwd(): %s\n", strerror(errno));
continue;
}
while (!state && *d != '\0') {
if (stat(d, &sb) < 0) { /* stat not lstat - always dereference targets */
errorMsg("stat(%s): %s\n", d, strerror(errno));
state = -1;
continue;
}
if ((sb.st_ino == srcStatBuf.st_ino) &&
(sb.st_dev == srcStatBuf.st_dev)) {
errorMsg("Cannot %s `%s' into a subdirectory of itself, "
"`%s/%s'\n", applet_name, baseSrcName,
baseDestName, baseSrcName);
state = -1;
continue;
}
if ((p = strrchr(d, '/')) != NULL) {
*p = '\0';
}
}
if (chdir(pushd) < 0) {
errorMsg("chdir(%s): %s\n", pushd, strerror(errno));
free(pushd);
free(d);
continue;
}
free(pushd);
free(d);
if (state < 0)
continue;
else
fill_baseDest_buf(baseDestName, &baseDestLen);
}
status = setjmp(catch);
if (status == 0) {
mv_Action_first_time = 1;
if (recursiveAction(baseSrcName,
recursiveFlag, followLinks, FALSE,
cp_mv_Action, cp_mv_Action, NULL) == FALSE) goto exit_false;
if (dz_i == is_mv &&
recursiveAction(baseSrcName,
recursiveFlag, followLinks, TRUE,
rm_Action, rm_Action, NULL) == FALSE) goto exit_false;
}
if (flags_memo)
*(baseDestName + baseDestLen) = '\0';
}
return( TRUE);
exit_false:
return( FALSE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/
+232
View File
@@ -0,0 +1,232 @@
/*
* cut.c - minimalist version of cut
*
* 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
* 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 <stdio.h>
#include <stdlib.h>
#include <unistd.h> /* getopt */
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include "busybox.h"
/* globals from other files */
extern int optind;
extern char *optarg;
/* 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;
/*
* 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;
}
+203 -233
View File
@@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/*
* Mini date implementation for busybox
*
@@ -19,13 +20,18 @@
*
*/
#include "internal.h"
#include "busybox.h"
#define BB_DECLARE_EXTERN
#define bb_need_invalid_date
#define bb_need_memory_exhausted
#include "messages.c"
#include <stdlib.h>
#include <errno.h>
#include <sys/time.h>
#include <unistd.h>
#include <time.h>
#include <stdio.h>
#include <getopt.h>
/* This 'date' command supports only 2 time setting formats,
@@ -34,254 +40,218 @@
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\n"
"Display the current time in the given FORMAT, or set the system date.\n"
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
"\t-s\t\tset time described by STRING\n"
"\t-u\t\tprint or set Coordinated Universal Time\n";
/* Input parsing code is always bulky - used heavy duty libc stuff as
much as possible, missed out a lot of bounds checking */
/* Default input handling to save suprising some people */
struct tm *
date_conv_time(struct tm *tm_time, const char *t_string) {
int nr;
struct tm *date_conv_time(struct tm *tm_time, const char *t_string)
{
int nr;
nr = sscanf(t_string, "%2d%2d%2d%2d%d",
&(tm_time->tm_mon),
&(tm_time->tm_mday),
&(tm_time->tm_hour),
&(tm_time->tm_min),
&(tm_time->tm_year));
nr = sscanf(t_string, "%2d%2d%2d%2d%d",
&(tm_time->tm_mon),
&(tm_time->tm_mday),
&(tm_time->tm_hour),
&(tm_time->tm_min), &(tm_time->tm_year));
if(nr < 4 || nr > 5) {
fprintf(stderr, "date: invalid date `%s'\n", t_string);
exit( FALSE);
}
if (nr < 4 || nr > 5) {
fatalError(invalid_date, t_string);
}
/* correct for century - minor Y2K problem here? */
if(tm_time->tm_year >= 1900)
tm_time->tm_year -= 1900;
/* adjust date */
tm_time->tm_mon -= 1;
return(tm_time);
/* correct for century - minor Y2K problem here? */
if (tm_time->tm_year >= 1900)
tm_time->tm_year -= 1900;
/* adjust date */
tm_time->tm_mon -= 1;
return (tm_time);
}
/* The new stuff for LRP */
struct tm *
date_conv_ftime(struct tm *tm_time, const char *t_string) {
struct tm itm_time, jtm_time, ktm_time, \
ltm_time, mtm_time, ntm_time;
itm_time = *tm_time;
jtm_time = *tm_time;
ktm_time = *tm_time;
ltm_time = *tm_time;
mtm_time = *tm_time;
ntm_time = *tm_time;
/* Parse input and assign appropriately to tm_time */
if(sscanf(t_string, "%d:%d:%d",
&itm_time.tm_hour,
&itm_time.tm_min,
&itm_time.tm_sec) == 3 ) {
*tm_time = itm_time;
return(tm_time);
} else if (sscanf(t_string, "%d:%d",
&jtm_time.tm_hour,
&jtm_time.tm_min) == 2) {
*tm_time = jtm_time;
return(tm_time);
} else if (sscanf(t_string, "%d.%d-%d:%d:%d",
&ktm_time.tm_mon,
&ktm_time.tm_mday,
&ktm_time.tm_hour,
&ktm_time.tm_min,
&ktm_time.tm_sec) == 5) {
ktm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
*tm_time = ktm_time;
return(tm_time);
} else if (sscanf(t_string, "%d.%d-%d:%d",
&ltm_time.tm_mon,
&ltm_time.tm_mday,
&ltm_time.tm_hour,
&ltm_time.tm_min) == 4) {
ltm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
*tm_time = ltm_time;
return(tm_time);
} else if (sscanf(t_string, "%d.%d.%d-%d:%d:%d",
&mtm_time.tm_year,
&mtm_time.tm_mon,
&mtm_time.tm_mday,
&mtm_time.tm_hour,
&mtm_time.tm_min,
&mtm_time.tm_sec) == 6) {
mtm_time.tm_year -= 1900; /* Adjust years */
mtm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
*tm_time = mtm_time;
return(tm_time);
} else if (sscanf(t_string, "%d.%d.%d-%d:%d",
&ntm_time.tm_year,
&ntm_time.tm_mon,
&ntm_time.tm_mday,
&ntm_time.tm_hour,
&ntm_time.tm_min) == 5) {
ntm_time.tm_year -= 1900; /* Adjust years */
ntm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
*tm_time = ntm_time;
return(tm_time);
}
fprintf(stderr, "date: invalid date `%s'\n", t_string);
exit( FALSE);
}
int
date_main(int argc, char * * argv)
struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
{
char *date_str = NULL;
char *date_fmt = NULL;
char *t_buff;
int i;
int set_time = 0;
int rfc822 = 0;
int utc = 0;
int use_arg = 0;
time_t tm;
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 = optarg;
break;
case 'u':
utc = 1;
if (putenv ("TZ=UTC0") != 0) {
fprintf(stderr,"date: memory exhausted\n");
exit( FALSE);
}
/* Look ma, no break. Don't fix it either. */
case 'd':
use_arg = 1;
if(date_str != NULL) usage ( date_usage);
date_str = optarg;
break;
case '-':
usage ( date_usage);
}
} else {
if ( (date_fmt == NULL) && (strcmp(*argv, "+")==0) )
date_fmt=*argv;
else if (date_str == NULL) {
set_time = 1;
date_str=*argv;
} else {
usage ( date_usage);
}
struct tm itm_time, jtm_time, ktm_time, ltm_time, mtm_time, ntm_time;
itm_time = *tm_time;
jtm_time = *tm_time;
ktm_time = *tm_time;
ltm_time = *tm_time;
mtm_time = *tm_time;
ntm_time = *tm_time;
/* Parse input and assign appropriately to tm_time */
if (sscanf(t_string, "%d:%d:%d",
&itm_time.tm_hour, &itm_time.tm_min, &itm_time.tm_sec) == 3) {
*tm_time = itm_time;
return (tm_time);
} else if (sscanf(t_string, "%d:%d",
&jtm_time.tm_hour, &jtm_time.tm_min) == 2) {
*tm_time = jtm_time;
return (tm_time);
} else if (sscanf(t_string, "%d.%d-%d:%d:%d",
&ktm_time.tm_mon,
&ktm_time.tm_mday,
&ktm_time.tm_hour,
&ktm_time.tm_min, &ktm_time.tm_sec) == 5) {
ktm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
*tm_time = ktm_time;
return (tm_time);
} else if (sscanf(t_string, "%d.%d-%d:%d",
&ltm_time.tm_mon,
&ltm_time.tm_mday,
&ltm_time.tm_hour, &ltm_time.tm_min) == 4) {
ltm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
*tm_time = ltm_time;
return (tm_time);
} else if (sscanf(t_string, "%d.%d.%d-%d:%d:%d",
&mtm_time.tm_year,
&mtm_time.tm_mon,
&mtm_time.tm_mday,
&mtm_time.tm_hour,
&mtm_time.tm_min, &mtm_time.tm_sec) == 6) {
mtm_time.tm_year -= 1900; /* Adjust years */
mtm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
*tm_time = mtm_time;
return (tm_time);
} else if (sscanf(t_string, "%d.%d.%d-%d:%d",
&ntm_time.tm_year,
&ntm_time.tm_mon,
&ntm_time.tm_mday,
&ntm_time.tm_hour, &ntm_time.tm_min) == 5) {
ntm_time.tm_year -= 1900; /* Adjust years */
ntm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
*tm_time = ntm_time;
return (tm_time);
}
i--;
argv++;
}
/* Now we have parsed all the information except the date format
which depends on whether the clock is being set or read */
time(&tm);
memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
/* Zero out fields - take her back to midnight!*/
if(date_str != NULL) {
tm_time.tm_sec = 0;
tm_time.tm_min = 0;
tm_time.tm_hour = 0;
}
/* Process any date input to UNIX time since 1 Jan 1970 */
if(date_str != NULL) {
if(strchr(date_str, ':') != NULL) {
date_conv_ftime(&tm_time, date_str);
} else {
date_conv_time(&tm_time, date_str);
}
/* Correct any day of week and day of year etc fields */
tm = mktime(&tm_time);
if (tm < 0 ) {
fprintf(stderr, "date: invalid date `%s'\n", date_str);
exit( FALSE);
}
/* if setting time, set it */
if(set_time) {
if( stime(&tm) < 0) {
fprintf(stderr, "date: can't set date.\n");
exit( FALSE);
}
}
}
/* Display output */
/* Deal with format string */
if(date_fmt == NULL) {
date_fmt = (rfc822
? (utc
? "%a, %_d %b %Y %H:%M:%S GMT"
: "%a, %_d %b %Y %H:%M:%S %z")
: "%a %b %e %H:%M:%S %Z %Y");
} else if ( *date_fmt == '\0' ) {
/* Imitate what GNU 'date' does with NO format string! */
printf ("\n");
exit( TRUE);
}
/* Handle special conversions */
if( strncmp( date_fmt, "%f", 2) == 0 ) {
date_fmt = "%Y.%m.%d-%H:%M:%S";
}
/* Print OUTPUT (after ALL that!) */
t_buff = malloc(201);
strftime(t_buff, 200, date_fmt, &tm_time);
printf("%s\n", t_buff);
exit( TRUE);
fatalError(invalid_date, t_string);
}
int date_main(int argc, char **argv)
{
char *date_str = NULL;
char *date_fmt = NULL;
char *t_buff;
int c;
int set_time = 0;
int rfc822 = 0;
int utc = 0;
int use_arg = 0;
time_t tm;
struct tm tm_time;
/* Interpret command line args */
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);
}
}
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 */
time(&tm);
memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
/* Zero out fields - take her back to midnight! */
if (date_str != NULL) {
tm_time.tm_sec = 0;
tm_time.tm_min = 0;
tm_time.tm_hour = 0;
}
/* Process any date input to UNIX time since 1 Jan 1970 */
if (date_str != NULL) {
if (strchr(date_str, ':') != NULL) {
date_conv_ftime(&tm_time, date_str);
} else {
date_conv_time(&tm_time, date_str);
}
/* Correct any day of week and day of year etc fields */
tm = mktime(&tm_time);
if (tm < 0)
fatalError(invalid_date, date_str);
/* if setting time, set it */
if (set_time) {
if (stime(&tm) < 0) {
fatalError("can't set date.\n");
}
}
}
/* Display output */
/* Deal with format string */
if (date_fmt == NULL) {
date_fmt = (rfc822
? (utc
? "%a, %_d %b %Y %H:%M:%S GMT"
: "%a, %_d %b %Y %H:%M:%S %z")
: "%a %b %e %H:%M:%S %Z %Y");
} else if (*date_fmt == '\0') {
/* Imitate what GNU 'date' does with NO format string! */
printf("\n");
exit(TRUE);
}
/* Handle special conversions */
if (strncmp(date_fmt, "%f", 2) == 0) {
date_fmt = "%Y.%m.%d-%H:%M:%S";
}
/* Print OUTPUT (after ALL that!) */
t_buff = xmalloc(201);
strftime(t_buff, 200, date_fmt, &tm_time);
printf("%s\n", t_buff);
return(TRUE);
}
+186
View File
@@ -0,0 +1,186 @@
/* vi: set sw=4 ts=4: */
#include "busybox.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
/* Tiny RPN calculator, because "expr" didn't give me bitwise operations. */
static double stack[100];
static unsigned int pointer;
static void push(double a)
{
if (pointer >= (sizeof(stack) / sizeof(*stack))) {
errorMsg("stack overflow\n");
exit(-1);
} else
stack[pointer++] = a;
}
static double pop()
{
if (pointer == 0) {
errorMsg("stack underflow\n");
exit(-1);
}
return stack[--pointer];
}
static void add()
{
push(pop() + pop());
}
static void sub()
{
double subtrahend = pop();
push(pop() - subtrahend);
}
static void mul()
{
push(pop() * pop());
}
static void divide()
{
double divisor = pop();
push(pop() / divisor);
}
static void and()
{
push((unsigned int) pop() & (unsigned int) pop());
}
static void or()
{
push((unsigned int) pop() | (unsigned int) pop());
}
static void eor()
{
push((unsigned int) pop() ^ (unsigned int) pop());
}
static void not()
{
push(~(unsigned int) pop());
}
static void print()
{
printf("%g\n", pop());
}
struct op {
const char *name;
void (*function) ();
};
static const struct op operators[] = {
{"+", add},
{"add", add},
{"-", sub},
{"sub", sub},
{"*", mul},
{"mul", mul},
{"/", divide},
{"div", divide},
{"and", and},
{"or", or},
{"not", not},
{"eor", eor},
{0, 0}
};
static void stack_machine(const char *argument)
{
char *endPointer = 0;
double d;
const struct op *o = operators;
if (argument == 0) {
print();
return;
}
d = strtod(argument, &endPointer);
if (endPointer != argument) {
push(d);
return;
}
while (o->name != 0) {
if (strcmp(o->name, argument) == 0) {
(*(o->function)) ();
return;
}
o++;
}
errorMsg("%s: syntax error.\n", argument);
exit(-1);
}
/* return pointer to next token in buffer and set *buffer to one char
* past the end of the above mentioned token
*/
static char *get_token(char **buffer)
{
char *start = NULL;
char *current = *buffer;
while (isspace(*current)) { current++; }
if (*current != 0) {
start = current;
while (!isspace(*current) && current != 0) { current++; }
*buffer = current;
}
return start;
}
/* In Perl one might say, scalar m|\s*(\S+)\s*|g */
static int number_of_tokens(char *buffer)
{
int i = 0;
char *b = buffer;
while (get_token(&b)) { i++; }
return i;
}
int dc_main(int argc, char **argv)
{
/* take stuff from stdin if no args are given */
if (argc <= 1) {
int i, len;
char *line = NULL;
char *cursor = NULL;
char *token = NULL;
while ((line = get_line_from_file(stdin))) {
cursor = line;
len = number_of_tokens(line);
for (i = 0; i < len; i++) {
token = get_token(&cursor);
*cursor++ = 0;
stack_machine(token);
}
free(line);
}
} else {
if (*argv[1]=='-')
usage(dc_usage);
while (argc >= 2) {
stack_machine(argv[1]);
argv++;
argc--;
}
}
stack_machine(0);
return( TRUE);
}
+124 -188
View File
@@ -1,13 +1,14 @@
/* vi: set sw=4 ts=4: */
/*
* Mini dd implementation for busybox
*
* Copyright (C) 1999 by Lineo, inc.
* Copyright (C) 1999, 2000 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
* based in part on code taken from sash.
*
* Copyright (c) 1999 by David I. Bell
* Permission is granted to use, distribute, or modify this source,
* provided that this copyright notice remains intact.
* Based in part on code taken from sash.
* Copyright (c) 1999 by David I. Bell
* Permission is granted to use, distribute, or modify this source,
* provided that this copyright notice remains intact.
*
* Permission to distribute this code under the GPL has been granted.
*
@@ -28,204 +29,139 @@
*/
#include "internal.h"
#include "busybox.h"
#include <features.h>
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
static const char dd_usage[] =
"dd [if=name] [of=name] [bs=n] [count=n]\n\n"
"Copy 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 stout\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"
"\n"
"BYTES may be suffixed: by k for x1024, b for x512, and w for x2.\n";
/*
* Read a number with a possible multiplier.
* Returns -1 if the number format is illegal.
*/
static long getNum (const char *cp)
{
long value;
if (!isDecimal (*cp))
return -1;
value = 0;
while (isDecimal (*cp))
value = value * 10 + *cp++ - '0';
switch (*cp++) {
case 'k':
value *= 1024;
break;
case 'b':
value *= 512;
break;
case 'w':
value *= 2;
break;
case '\0':
return value;
default:
return -1;
}
if (*cp)
return -1;
return value;
}
extern int dd_main (int argc, char **argv)
{
const char *inFile;
const char *outFile;
char *cp;
int inFd;
int outFd;
int inCc = 0;
int outCc;
int skipBlocks;
int blockSize;
long count;
long intotal;
long outTotal;
unsigned char *buf;
inFile = NULL;
outFile = NULL;
blockSize = 512;
skipBlocks = 0;
count = 1;
argc--;
argv++;
/* Parse any options */
while (argc) {
if (inFile == NULL && (strncmp(*argv, "if", 2) == 0))
inFile=((strchr(*argv, '='))+1);
else if (outFile == NULL && (strncmp(*argv, "of", 2) == 0))
outFile=((strchr(*argv, '='))+1);
else if (strncmp("count", *argv, 5) == 0) {
count = getNum ((strchr(*argv, '='))+1);
if (count <= 0) {
fprintf (stderr, "Bad count value %ld\n", count);
goto usage;
}
}
else if (strncmp(*argv, "bs", 2) == 0) {
blockSize = getNum ((strchr(*argv, '='))+1);
if (blockSize <= 0) {
fprintf (stderr, "Bad block size value %d\n", blockSize);
goto usage;
}
}
#if 0
else if (strncmp(*argv, "skip", 4) == 0) {
skipBlocks = atoi( *argv);
if (skipBlocks <= 0) {
fprintf (stderr, "Bad skip value %d\n", skipBlocks);
goto usage;
}
}
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
#include <inttypes.h>
#else
typedef unsigned long long int uintmax_t;
#endif
else {
goto usage;
}
extern int dd_main(int argc, char **argv)
{
char *inFile = NULL;
char *outFile = NULL;
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 = 0;
uintmax_t outTotal = 0;
uintmax_t totalSize;
uintmax_t readSize;
unsigned char buf[BUFSIZ];
char *keyword = NULL;
argc--;
argv++;
}
buf = malloc (blockSize);
if (buf == NULL) {
fprintf (stderr, "Cannot allocate buffer\n");
exit( FALSE);
}
/* Parse any options */
while (argc) {
if (inFile == NULL && (strncmp(*argv, "if", 2) == 0))
inFile = ((strchr(*argv, '=')) + 1);
else if (outFile == NULL && (strncmp(*argv, "of", 2) == 0))
outFile = ((strchr(*argv, '=')) + 1);
else if (strncmp("count", *argv, 5) == 0) {
count = getNum((strchr(*argv, '=')) + 1);
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) {
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) {
errorMsg("Bad skip value %s\n", *argv);
goto usage;
}
intotal = 0;
outTotal = 0;
if (inFile == NULL)
inFd = STDIN;
else
inFd = open (inFile, 0);
if (inFd < 0) {
perror (inFile);
free (buf);
exit( FALSE);
}
if (outFile == NULL)
outFd = STDOUT;
else
outFd = creat (outFile, 0666);
if (outFd < 0) {
perror (outFile);
close (inFd);
free (buf);
exit( FALSE);
}
//lseek(inFd, skipBlocks*blockSize, SEEK_SET);
while (outTotal < count * blockSize) {
inCc = read (inFd, buf, blockSize);
if (inCc < 0) {
perror (inFile);
goto cleanup;
} else if (strncmp(*argv, "seek", 4) == 0) {
seekBlocks = getNum((strchr(*argv, '=')) + 1);
if (seekBlocks <= 0) {
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;
}
argc--;
argv++;
}
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;
}
if (inFile == NULL)
inFd = fileno(stdin);
else
inFd = open(inFile, 0);
inCc -= outCc;
cp += outCc;
outTotal += outCc;
if (inFd < 0) {
/* Note that we are not freeing buf or closing
* files here to save a few bytes. This exits
* here anyways... */
/* free(buf); */
fatalError( inFile);
}
}
if (inCc < 0)
perror (inFile);
if (outFile == NULL)
outFd = fileno(stdout);
else
outFd = open(outFile, O_WRONLY | O_CREAT, 0666);
cleanup:
close (inFd);
close (outFd);
free (buf);
if (outFd < 0) {
/* Note that we are not freeing buf or closing
* files here to save a few bytes. This exits
* here anyways... */
printf ("%ld+%d records in\n", intotal / blockSize,
(intotal % blockSize) != 0);
printf ("%ld+%d records out\n", outTotal / blockSize,
(outTotal % blockSize) != 0);
exit( TRUE);
/* close(inFd);
free(buf); */
fatalError( outFile);
}
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));
}
/* Note that we are not freeing memory or closing
* files here, to save a few bytes. */
#ifdef BB_FEATURE_CLEAN_UP
close(inFd);
close(outFd);
#endif
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);
usage:
usage( dd_usage);
usage(dd_usage);
}
+34 -36
View File
@@ -1,50 +1,48 @@
/* vi: set sw=4 ts=4: */
/*
* 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>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <linux/vt.h>
#include <stdio.h>
extern int getfd(void);
char *progname;
/* From <linux/vt.h> */
#define VT_DISALLOCATE 0x5608 /* free memory associated to vt */
int
deallocvt_main(int argc, char *argv[]) {
int fd, num, i;
int deallocvt_main(int argc, char *argv[])
{
int fd, num, i;
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
usage ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
}
//if ((argc > 2) || ((argv == 2) && (**(argv + 1) == '-')))
if (argc > 2)
usage(deallocvt_usage);
progname = argv[0];
fd = get_console_fd("/dev/console");
fd = get_console_fd("/dev/console");
if (argc == 1) {
/* deallocate all unused consoles */
if (ioctl(fd,VT_DISALLOCATE,0)) {
perror("VT_DISALLOCATE");
exit(1);
}
} else
for (i = 1; i < argc; i++) {
num = atoi(argv[i]);
if (num == 0)
fprintf(stderr, "%s: 0: illegal VT number\n", progname);
else if (num == 1)
fprintf(stderr, "%s: VT 1 cannot be deallocated\n", progname);
else
if (ioctl(fd,VT_DISALLOCATE,num)) {
perror("VT_DISALLOCATE");
fprintf(stderr, "%s: could not deallocate console %d\n",
progname, num);
exit(1);
}
}
exit(0);
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)
errorMsg("0: illegal VT number\n");
else if (num == 1)
errorMsg("VT 1 cannot be deallocated\n");
else if (ioctl(fd, VT_DISALLOCATE, num)) {
perror("VT_DISALLOCATE");
fatalError("could not deallocate console %d\n", num);
}
}
printf("erik: C\n");
return( TRUE);
}
+10
View File
@@ -0,0 +1,10 @@
BusyBox for Debian
----------------------
BusyBox is being developed and maintained by Erik Andersen
<andersee@debian.org>.
If you have a problem with BusyBox, send email to the Debian bug tracking
system that lives at <submit@bugs.lineo.com>
Erik Andersen <andersee@debian.org>, Sun, 18 Jun 2000 21:52:00 -0600
+30
View File
@@ -0,0 +1,30 @@
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.
-- Erik Andersen <andersee@debian.org> Tue, 11 Jul 2000 12:15:44 -0600
busybox (0.45-1) unstable; urgency=low
* First attempt at packaging BusyBox as a .deb. This has been in
in the Debian boot-floppies CVS tree forever. Hopefully, having it as a
standalone app will make life easier for me, the debian-installer team, and
everyone else as well...
* I have created a busybox-static that can be used as a rescue shell when you
hose your system. Just invoke "busybox sh" to fir up the shell. This has
every app provided by busybox staically linked in. There have been several
times in the past that I would have loved to have this sitting on my system
(i.e. when libc gets screwed up.)
-- Erik Andersen <andersee@debian.org> Tue, 27 Jun 2000 12:26:41 -0600
Local variables:
mode: debian-changelog
add-log-mailing-address: "andersee@debian.org"
End:
+46
View File
@@ -0,0 +1,46 @@
Source: busybox
Priority: optional
Maintainer: Erik Andersen <andersee@debian.org>
Build-Depends: debhelper
Standards-Version: 3.1.1
Package: busybox
Architecture: any
Depends: ${shlibs:Depends}
Conflicts: binutils, bsdutils, console-tools, cpio, debianutils, dnsutils, dpkg, fbset, fdflush, fileutils, grep, gzip, hostname, modutils, mount, netbase, procps, psmisc, sed, sharutils, shellutils, sysklogd, sysvinit, tar, textutils, update, util-linux
Replaces: netbase
Section: utils
Description: Tiny utilities for the debian-installer and for embedded systems.
BusyBox combines tiny versions of many common UNIX utilities into a single
small executable. It provides minimalist replacements for the most common
utilities you would usually find on your desktop system (i.e. ls, cp, mv,
mount, tar, etc). The utilities in BusyBox generally have fewer options than
their full-featured GNU cousins; however, the options that are included
provide the expected functionality and behave very much like their GNU
counterparts.
.
BusyBox is used by the debian-installer. Installing BusyBox onto your Debian
system is not recommended, unless you are intended to make a very small
embedded system. Chances are good that for embedded systems, you will want to
recompile to only include the tools and utilities you wish to include.
Package: busybox-static
Architecture: any
Depends: ${shlibs:Depends}
Section: shells
Description: Provides a stand alone rescue shell with tons of builtin utilities.
BusyBox combines tiny versions of many common UNIX utilities into a single
small executable. It provides minimalist replacements for the most common
utilities you would usually find on your desktop system (i.e. ls, cp, mv,
mount, tar, etc). The utilities in BusyBox generally have fewer options than
their full-featured GNU cousins; however, the options that are included
provide the expected functionality and behave very much like their GNU
counterparts.
.
BusyBox-static provides you with a statically linked simple stand alone shell
that provides all the utilities available in BusyBox. This package is
intended to be used as a rescue shell, in the event that you screw up your
system. Invoke "busybox sh" and you have a standalone shell ready to save
your system from certain destruction. Invoke "busybox", and it will list the
available builtin commands.
Loaded 100 of 291 files, more files were not shown because too many files have changed in this diff. Show more