Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4a971aef59 | ||
|
|
3c37598dc2 | ||
|
|
a29dec28cb | ||
|
|
ccd32cbb61 | ||
|
|
9d9610b8de | ||
|
|
6f9985e2f2 | ||
|
|
addc9c28ad | ||
|
|
4fa84e6b54 | ||
|
|
c6cdf58747 | ||
|
|
07edff4ba4 | ||
|
|
45087b1010 | ||
|
|
766c012975 | ||
|
|
c5c5e3d144 | ||
|
|
afa0662860 | ||
|
|
1a804e4b3c | ||
|
|
f929641c51 | ||
|
|
feb47c024a | ||
|
|
f7a01951fb | ||
|
|
7ac06a3ff1 | ||
|
|
0021679b0d | ||
|
|
b405dfa54d | ||
|
|
c03525475e | ||
|
|
e63ad9ba06 | ||
|
|
28c88a9430 | ||
|
|
339b892313 | ||
|
|
4eb1b30411 | ||
|
|
bd4a75f6c8 | ||
|
|
bb245ba0c2 | ||
|
|
9ca57d377e | ||
|
|
e1e23eecab | ||
|
|
5e29c6ffce | ||
|
|
a15cd0be34 | ||
|
|
b7362e36a8 | ||
|
|
67e32304b1 | ||
|
|
be5023a84d | ||
|
|
b610615be9 | ||
|
|
dbb3019d0d | ||
|
|
30f0f2d040 | ||
|
|
b108a5b780 | ||
|
|
110fc0cacc | ||
|
|
74c66ad06e | ||
|
|
98cd53e86d | ||
|
|
852ff13fc4 | ||
|
|
b991395405 | ||
|
|
2e965239ee | ||
|
|
3f75503fa0 | ||
|
|
28c70b3a16 | ||
|
|
e97da40079 | ||
|
|
1af7ed5573 | ||
|
|
3c709b45b3 | ||
|
|
d84990eb1f | ||
|
|
854e11581f | ||
|
|
2b6ab3cbf8 | ||
|
|
053b1462b7 | ||
|
|
baf22bff21 | ||
|
|
c7ccfc99fc | ||
|
|
9f16d61408 | ||
|
|
44760d058c | ||
|
|
5db60a7a7a | ||
|
|
0c6a970eb2 | ||
|
|
b3d235f63b | ||
|
|
b3cf9baeb9 | ||
|
|
049b706591 | ||
|
|
da10ec0eaa | ||
|
|
0024abcbbc | ||
|
|
0b66577368 | ||
|
|
a42982e8f5 | ||
|
|
1f6262b8e2 | ||
|
|
fb8ba506bb | ||
|
|
3232203226 | ||
|
|
d05e3ce5c2 | ||
|
|
eec2f63b3f | ||
|
|
700a5aed75 | ||
|
|
517cab761f | ||
|
|
6ca28ba65c | ||
|
|
680d65a646 | ||
|
|
68480dc30f | ||
|
|
815e904470 | ||
|
|
c389d91181 | ||
|
|
82c0ac7e4f | ||
|
|
f2fffefe49 | ||
|
|
36fe1a30b1 | ||
|
|
926e0e3465 | ||
|
|
afeb683459 | ||
|
|
46a38dbb9b | ||
|
|
ef4268efa7 | ||
|
|
832000f7f3 | ||
|
|
f0c30b71be | ||
|
|
5a0a2aa00b | ||
|
|
808d03ec19 | ||
|
|
9c8ffa02f4 | ||
|
|
3199bda52e | ||
|
|
6082917e34 | ||
|
|
380e58a05f | ||
|
|
ec480c49c2 | ||
|
|
86ab8a32bd | ||
|
|
4062268bc7 | ||
|
|
08e9289ab3 | ||
|
|
b6c6d87a99 | ||
|
|
77bd2db325 | ||
|
|
1624813459 | ||
|
|
b83e0ed3a1 | ||
|
|
89960b8af2 | ||
|
|
b5966368d7 | ||
|
|
deb0331eb6 | ||
|
|
108a44345c | ||
|
|
e511e7c116 | ||
|
|
8ea7d8cdaf | ||
|
|
330fd2b576 | ||
|
|
d356c6e9d1 | ||
|
|
5b46d792f1 | ||
|
|
499f65fb98 | ||
|
|
969f9b0486 | ||
|
|
67a0dd8f3c | ||
|
|
c3f5c9c2ee | ||
|
|
bcd6177853 | ||
|
|
73c8c9cf9a | ||
|
|
23dea9b712 | ||
|
|
7ab9c7ee52 | ||
|
|
3d427ac5ef | ||
|
|
59b9e87024 | ||
|
|
ac130e1dca | ||
|
|
0a027e6880 | ||
|
|
691f49d3c1 | ||
|
|
0e713cef9d | ||
|
|
6c5f2c6021 | ||
|
|
9b15e50835 | ||
|
|
a59d7094a6 | ||
|
|
0a704e8ff6 | ||
|
|
a19bc64653 | ||
|
|
e31c06608e | ||
|
|
03ccce6e30 | ||
|
|
5afc864422 | ||
|
|
3c1217cfad | ||
|
|
8f8d6d5f2d | ||
|
|
d16665810d | ||
|
|
12d1b378be | ||
|
|
9b7d964581 | ||
|
|
f378fced43 | ||
|
|
4625240674 | ||
|
|
94f5e0ba7c | ||
|
|
28c49b6c9c | ||
|
|
25c44c623d | ||
|
|
923ef599f3 | ||
|
|
6ed02a0ee0 | ||
|
|
abc199eb0c | ||
|
|
4f3f757d56 | ||
|
|
227a59b05d | ||
|
|
f93a95de69 | ||
|
|
e90f4045af | ||
|
|
1d1d95051a | ||
|
|
cf8d38a3eb | ||
|
|
7d6ba57bba | ||
|
|
e3ed156eeb |
No files matched your search
@@ -12,9 +12,6 @@ Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
Tons of new stuff, major rewrite of most of the
|
||||
core apps, tons of new apps as noted in header files.
|
||||
|
||||
Bruce Perens <bruce@pixar.com>
|
||||
Original author of BusyBox. His code is still in many apps.
|
||||
|
||||
John Beppu <beppu@lineo.com>
|
||||
du, head, nslookup, sort, tee, uniq
|
||||
|
||||
@@ -28,8 +25,23 @@ 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
|
||||
|
||||
John Lombardo <john@deltanet.com>
|
||||
dirname, tr
|
||||
dirname, tr
|
||||
|
||||
Glenn McGrath <bug1@netconnect.com.au>
|
||||
ar.c
|
||||
|
||||
Bruce Perens <bruce@pixar.com>
|
||||
Original author of BusyBox. His code is still in many apps.
|
||||
|
||||
Pavel Roskin <proski@gnu.org>
|
||||
Lots of bugs fixes and patches.
|
||||
|
||||
Linus Torvalds <torvalds@transmeta.com>
|
||||
mkswap, fsck.minix, mkfs.minix
|
||||
@@ -40,5 +52,4 @@ Charles P. Wright <cpwright@villagenet.com>
|
||||
Enrique Zanardi <ezanardi@ull.es>
|
||||
tarcat (since removed), loadkmap, various fixes, Debian maintenance
|
||||
|
||||
Karl M. Hegbloom <karlheg@debian.org>
|
||||
cp_mv.c, the test suite, various fixes to utility.c, &c.
|
||||
|
||||
@@ -1,3 +1,107 @@
|
||||
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_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
|
||||
@@ -22,7 +126,7 @@
|
||||
* 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 <pavel_roskin@geocities.com>:
|
||||
* 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.
|
||||
@@ -47,7 +151,7 @@
|
||||
- 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 <pavel_roskin@geocities.com>:
|
||||
* 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
|
||||
@@ -157,7 +261,7 @@
|
||||
Randolph Chung <tausq@debian.org>.
|
||||
* cp could, when copying symlinks, change permissions of the
|
||||
files pointed to by the symlinks.
|
||||
* Several fixes from Pavel Roskin <pavel_roskin@geocities.com>:
|
||||
* Several fixes from Pavel Roskin <proski@gnu.org>:
|
||||
- `chown' with 1 argument displayed the error incorrectly
|
||||
- `fdflush', `length' and `printf' crashed if run without arguments
|
||||
- `fdflush' tried to flush itself using *argv
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#
|
||||
|
||||
PROG := busybox
|
||||
VERSION := 0.43
|
||||
VERSION := 0.45
|
||||
BUILDTIME := $(shell TZ=UTC date --utc "+%Y.%m.%d-%H:%M%z")
|
||||
export VERSION
|
||||
|
||||
@@ -31,55 +31,47 @@ DODEBUG = false
|
||||
# If you want a static binary, turn this on.
|
||||
DOSTATIC = false
|
||||
|
||||
# This will choke on a non-debian system
|
||||
ARCH =`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
|
||||
# To compile vs an alternative libc, you may need to use/adjust
|
||||
# the following lines to meet your needs. This is how I did it...
|
||||
#CFLAGS+=-nostdinc -I/home/andersen/CVS/uC-libc/include -I/usr/include/linux
|
||||
#LDFLAGS+=-nostdlib
|
||||
#LIBRARIES = /home/andersen/CVS/uC-libc/libc.a
|
||||
|
||||
|
||||
CC = gcc
|
||||
|
||||
GCCMAJVERSION = $(shell $(CC) --version | sed -n "s/^[^0-9]*\([0-9]\)\.\([0-9].*\)[\.].*/\1/p")
|
||||
GCCMINVERSION = $(shell $(CC) --version | sed -n "s/^[^0-9]*\([0-9]\)\.\([0-9].*\)[\.].*/\2/p")
|
||||
# use '-Os' optimization if available, else use -O2
|
||||
OPTIMIZATION = $(shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
|
||||
then echo "-Os"; else echo "-O2" ; fi)
|
||||
|
||||
|
||||
GCCSUPPORTSOPTSIZE = $(shell \
|
||||
if ( test $(GCCMAJVERSION) -eq 2 ) ; then \
|
||||
if ( test $(GCCMINVERSION) -ge 66 ) ; then \
|
||||
echo "true"; \
|
||||
else \
|
||||
echo "false"; \
|
||||
fi; \
|
||||
else \
|
||||
if ( test $(GCCMAJVERSION) -gt 2 ) ; then \
|
||||
echo "true"; \
|
||||
else \
|
||||
echo "false"; \
|
||||
fi; \
|
||||
fi; )
|
||||
|
||||
|
||||
ifeq ($(GCCSUPPORTSOPTSIZE), true)
|
||||
OPTIMIZATION = -Os
|
||||
else
|
||||
OPTIMIZATION = -O2
|
||||
endif
|
||||
|
||||
# Allow alternative stripping tools to be used...
|
||||
ifndef $(STRIPTOOL)
|
||||
STRIPTOOL = strip
|
||||
endif
|
||||
|
||||
|
||||
# -D_GNU_SOURCE is needed because environ is used in init.c
|
||||
ifeq ($(DODEBUG),true)
|
||||
CFLAGS += -Wall -g -D_GNU_SOURCE
|
||||
LDFLAGS =
|
||||
CFLAGS += -Wall -g -fno-builtin -D_GNU_SOURCE
|
||||
LDFLAGS +=
|
||||
STRIP =
|
||||
else
|
||||
CFLAGS += -Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
|
||||
LDFLAGS = -s
|
||||
LDFLAGS += -s
|
||||
STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment $(PROG)
|
||||
#Only staticly link when _not_ debugging
|
||||
ifeq ($(DOSTATIC),true)
|
||||
LDFLAGS += --static
|
||||
#
|
||||
#use '-ffunction-sections -fdata-sections' and '--gc-sections' if they work
|
||||
#to try and strip out any unused junk. Doesn't do much for me, but you may
|
||||
#want to give it a shot...
|
||||
#
|
||||
#ifeq ($(shell $(CC) -ffunction-sections -fdata-sections -S \
|
||||
# -o /dev/null -xc /dev/null 2>/dev/null && $(LD) --gc-sections -v >/dev/null && echo 1),1)
|
||||
# CFLAGS += -ffunction-sections -fdata-sections
|
||||
# LDFLAGS += --gc-sections
|
||||
#endif
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -87,7 +79,7 @@ ifndef $(PREFIX)
|
||||
PREFIX = `pwd`/_install
|
||||
endif
|
||||
|
||||
LIBRARIES =
|
||||
|
||||
OBJECTS = $(shell ./busybox.sh) busybox.o messages.o utility.o
|
||||
CFLAGS += -DBB_VER='"$(VERSION)"'
|
||||
CFLAGS += -DBB_BT='"$(BUILDTIME)"'
|
||||
@@ -95,17 +87,35 @@ ifdef BB_INIT_SCRIPT
|
||||
CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
|
||||
endif
|
||||
|
||||
all: busybox busybox.links
|
||||
all: busybox busybox.links doc
|
||||
|
||||
doc: 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 docs/busybox.pod > docs/busybox.lineo.com/BusyBox.html
|
||||
- rm -f pod2html*
|
||||
|
||||
busybox: $(OBJECTS)
|
||||
$(CC) $(LDFLAGS) -o $@ $^ $(LIBRARIES)
|
||||
$(STRIP)
|
||||
$(MAKE) -C docs
|
||||
|
||||
|
||||
busybox.links: busybox.def.h
|
||||
- ./busybox.mkll | sort >$@
|
||||
|
||||
regexp.o nfsmount.o: %.o: %.h
|
||||
regexp.o nfsmount.o cmdedit.o: %.o: %.h
|
||||
$(OBJECTS): %.o: busybox.def.h internal.h %.c Makefile
|
||||
|
||||
test tests:
|
||||
@@ -115,6 +125,8 @@ clean:
|
||||
- rm -f busybox.links *~ *.o core
|
||||
- rm -rf _install
|
||||
- cd tests && $(MAKE) clean
|
||||
- rm -f docs/BusyBox.html docs/busybox.lineo.com/BusyBox.html \
|
||||
docs/BusyBox.1 docs/BusyBox.txt pod2html*
|
||||
|
||||
distclean: clean
|
||||
- rm -f busybox
|
||||
@@ -123,8 +135,7 @@ distclean: clean
|
||||
install: busybox busybox.links
|
||||
./install.sh $(PREFIX)
|
||||
|
||||
dist release: distclean
|
||||
$(MAKE) -C docs
|
||||
dist release: distclean doc
|
||||
cd ..; \
|
||||
rm -rf busybox-$(VERSION); \
|
||||
cp -a busybox busybox-$(VERSION); \
|
||||
|
||||
@@ -1,23 +1,64 @@
|
||||
Please see the LICENSE file for copyright information.
|
||||
|
||||
BusyBox combines tiny versions of many common UNIX utilities into a single
|
||||
small executable. It provides minimalist replacements for most of the utilities
|
||||
you usually find in fileutils, shellutils, findutils, textutils, grep, gzip,
|
||||
tar, etc. BusyBox provides a fairly complete POSIX environment for any small or
|
||||
emdedded system. The utilities in BusyBox generally have fewer options then
|
||||
their full featured GNU cousins; however, the options that are included provide
|
||||
the expected functionality and behave very much like their GNU counterparts.
|
||||
|
||||
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
|
||||
provides a pretty complete POSIX environment in a very small package.
|
||||
Just add a kernel, "ash" (Keith Almquists tiny Bourne shell clone), and
|
||||
an editor such as "elvis-tiny" or "ae", and you have a working system.
|
||||
Busybox was begun to support the Debian Rescue/Install disks, but it
|
||||
also makes an excellent environment for any small or embedded system.
|
||||
BusyBox has been written with size-optimization and limited resources in mind.
|
||||
It is also extremely modular so you can easily include or exclude commands (or
|
||||
features) at compile time. This makes it easy to customize your embedded
|
||||
systems. To create a working system, just add a kernel, a shell (such as ash),
|
||||
and an editor (such as elvis-tiny or ae).
|
||||
|
||||
As of version 0.20 there is a version number. : ) Also as of version 0.20, BB
|
||||
is now modularized to easily allow you to build only the BB parts you need,
|
||||
thereby reducing binary size. To turn off unwanted Busybox components, simply
|
||||
edit the file busybox.def.h and comment out the parts you do not need using C++
|
||||
style (//) comments.
|
||||
Busybox was originally written to support the Debian Rescue/Install disks, but
|
||||
it also makes an excellent environment for any small or embedded system.
|
||||
|
||||
After the build is complete a busybox.links file is generated which is
|
||||
then used by 'make install' to create symlinks to the busybox binary
|
||||
for all compiled in functions. By default, 'make install' will place
|
||||
the symlink forest into `pwd`/_install unless you have defined the
|
||||
PREFIX environment variable (i.e. make PREFIX="/tmp/foo" install)
|
||||
As of version 0.20 there is a version number. : ) Also as of version 0.20,
|
||||
BusyBox is now modularized to easily allow you to build only the components you
|
||||
need, thereby reducing binary size. To turn off unwanted Busybox components,
|
||||
simply edit the file busybox.def.h and comment out the components you do not
|
||||
need using C++ style (//) comments.
|
||||
|
||||
After the build is complete a busybox.links file is generated which is then
|
||||
used by 'make install' to create symlinks to the busybox binary for all
|
||||
compiled in functions. By default, 'make install' will place the symlink
|
||||
forest into `pwd`/_install unless you have defined the PREFIX environment
|
||||
variable (i.e. make PREFIX="/tmp/foo" install)
|
||||
|
||||
----------------
|
||||
Getting help:
|
||||
When you find you need help, you can check out the BusyBox mailing list
|
||||
archives at http://opensource.lineo.com/lists/busybox/ or even join
|
||||
the mailing list if you are interested.
|
||||
|
||||
----------------
|
||||
Bugs:
|
||||
If you find bugs, follow the instructions at http://bugs.lineo.com/Reporting.html
|
||||
and submit a bug report. This way, we can be sure nothing falls through the
|
||||
cracks...
|
||||
|
||||
----------------
|
||||
FTP:
|
||||
Source for the latest released version can always be downloaded from
|
||||
ftp://ftp.lineo.com/pub/busybox.
|
||||
|
||||
----------------
|
||||
CVS:
|
||||
BusyBox now has its own publically browsable CVS tree at:
|
||||
http://opensource.lineo.com/cgi-bin/cvsweb/busybox/
|
||||
|
||||
Anonymous CVS access is available. For instructions, check out:
|
||||
http://opensource.lineo.com/cvs_anon.html
|
||||
|
||||
For those that are actively contributing there is even CVS write access:
|
||||
http://opensource.lineo.com/cvs_write.html
|
||||
|
||||
|
||||
----------------
|
||||
|
||||
Please feed suggestions, bug reports, insults, and bribes back to:
|
||||
Erik Andersen
|
||||
|
||||
@@ -4,34 +4,105 @@ or that doing so is even a good idea. It just means that I _might_ get
|
||||
around to it some time. If you have any good ideas, please let me know.
|
||||
|
||||
* login/sulogin/passwd/getty/etc are part of tinylogin, and so are not
|
||||
needed or wanted in busybox (or else I'd have to link in libcrypt).
|
||||
needed or wanted in busybox (or else I'd have to link to libcrypt).
|
||||
|
||||
* Networking apps are probably going to be split out some time soon into a
|
||||
separate package (named perhaps tiny-netkit?). This currently includes
|
||||
hostid, hostname, mnc, and ping.
|
||||
|
||||
separate package (named perhaps netkit-tiny?). This would remove the
|
||||
following items from BusyBox: hostid, hostname, nc, nslookup, telnet,
|
||||
and ping. nfs mounting and syslogd (when it supports network logging)
|
||||
will remain in BusyBox.
|
||||
|
||||
-Erik
|
||||
|
||||
-----------
|
||||
|
||||
Bugs that need fixing:
|
||||
|
||||
- 'ln -n' has been disabled for this release, till we can fix a memory
|
||||
corruption bug.
|
||||
- fix 'cp' (or test suite script) so that it passes the last item in
|
||||
the test suite.
|
||||
- ps dirent race bug (need to stat the file before attempting chdir)
|
||||
- Make 'ln -s /tmp/file .' work the way GNU ln does (i.e. makes a link to
|
||||
/tmp/file in the current directory, rather then trying and failing to create
|
||||
a symlink named "." in the current working directory).
|
||||
- Prune sfdisk, graft in std fdisk instead
|
||||
|
||||
|
||||
We will rework these to use libc regex functions instead (as per the mailing
|
||||
list discussion):
|
||||
- 'grep foo$ file' doesn't work
|
||||
- 'grep *foo file' segfaults
|
||||
|
||||
|
||||
-----------
|
||||
|
||||
Linux 2.4.x kernels
|
||||
|
||||
BusyBox 0.45 currently will not work with the Linux 2.4.x kernels.
|
||||
I know of the following problems:
|
||||
|
||||
1) The sysinfo syscall has changed what it does (binary incompatable), breaking
|
||||
init and free.
|
||||
2) BusyBox NFS support is broken with 2.4.x (needs to be adjusted for NFSv3 and
|
||||
kernel header changes).
|
||||
3) mount,umount,and df are all broken by the "none" entries for fake filesystems
|
||||
such as the shared mem one. Al Viro claims these will be disappearing soon...
|
||||
|
||||
I made a kernel patch that reverts the sysinfo changes
|
||||
http://kernelnotes.org/lnxlists/linux-kernel/lk_0006_01/msg00619.html
|
||||
|
||||
and I have been fighting with Alan Cox to get these changes fixed in a binary
|
||||
compatable way, but Alan has so far not been very receptive. I am planning on
|
||||
appealing to Linus (when he gets back from vacation) and then going with
|
||||
whatever he decides...
|
||||
|
||||
So my thought is, 2.4.x just isn't ready for BusyBox to target it, and even if
|
||||
it was, BusyBox isn't ready yet either. Seems to me like this will not be
|
||||
ready for a while, and we should just not worry about it yet.
|
||||
|
||||
As long as I have BB_FEATURE_NFSMOUNT turned off, everything compiles cleanly
|
||||
for me with linux2.4.0test1-ac22-riel (i.e. I don't see the freeramdisk.c
|
||||
problem you reported). I use Debian potato (gcc 2.95.2, GNU libc 2.1.3).
|
||||
Of course, as noted above, compiling != working.
|
||||
|
||||
-----------
|
||||
|
||||
* Make insmod actually work
|
||||
* dnsdomainname
|
||||
* traceroute/netstat
|
||||
* rdate
|
||||
* hwclock
|
||||
* stty
|
||||
* cut
|
||||
* expr
|
||||
* wget (or whatever I call it)
|
||||
* tftp
|
||||
* ftp
|
||||
|
||||
* group/commonize strings, remove dups (for i18n, l10n)
|
||||
* consider making a unified option parser (if it can be done
|
||||
modular, small, etc.)
|
||||
|
||||
-----------------------
|
||||
|
||||
Add a compile option to turn off all the compiled in help
|
||||
and usage information. Some folks don't need or want it...
|
||||
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.
|
||||
|
||||
-----------------------
|
||||
|
||||
@@ -76,6 +147,10 @@ I'll add this to the TODO list,
|
||||
|
||||
------------------------------------------------------------------
|
||||
|
||||
An interesting email listing some apps that use /proc. BusyBox
|
||||
tries to avoid /proc as mush as is possible, so this stuff is
|
||||
interesting (to me at least):
|
||||
|
||||
|
||||
Date: Fri, 25 Feb 2000 08:23:12 +0000 (GMT)
|
||||
From: Riley Williams <rhw@MemAlpha.CX>
|
||||
|
||||
@@ -30,14 +30,15 @@ int atexit(void (*__func) (void))
|
||||
void *__libc_stack_end;
|
||||
#endif
|
||||
|
||||
static const struct Applet applets[] = {
|
||||
const struct BB_applet applets[] = {
|
||||
|
||||
#ifdef BB_AR
|
||||
{"ar", ar_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_BASENAME
|
||||
{"basename", basename_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_BUSYBOX
|
||||
{"busybox", busybox_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_BLOCK_DEVICE
|
||||
{"block_device", block_device_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
@@ -65,9 +66,15 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_CP_MV
|
||||
{"cp", cp_mv_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CUT
|
||||
{"cut", cut_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DATE
|
||||
{"date", date_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DC
|
||||
{"dc", dc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DD
|
||||
{"dd", dd_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
@@ -134,6 +141,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_HOSTNAME
|
||||
{"hostname", hostname_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_ID
|
||||
{"id", id_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_INIT
|
||||
{"init", init_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
@@ -179,8 +189,8 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_MAKEDEVS
|
||||
{"makedevs", makedevs_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_MATH
|
||||
{"math", math_main, _BB_DIR_USR_BIN},
|
||||
#ifdef BB_MD5SUM
|
||||
{"md5sum", md5sum_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKDIR
|
||||
{"mkdir", mkdir_main, _BB_DIR_BIN},
|
||||
@@ -197,8 +207,11 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_MKSWAP
|
||||
{"mkswap", mkswap_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_MNC
|
||||
{"mnc", mnc_main, _BB_DIR_USR_BIN},
|
||||
#ifdef BB_MKTEMP
|
||||
{"mktemp", mktemp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_NC
|
||||
{"nc", nc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MORE
|
||||
{"more", more_main, _BB_DIR_BIN},
|
||||
@@ -245,12 +258,15 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_SED
|
||||
{"sed", sed_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SH
|
||||
{"sh", shell_main, _BB_DIR_BIN},
|
||||
#ifdef BB_SETKEYCODES
|
||||
{"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SFDISK
|
||||
{"sfdisk", sfdisk_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_SH
|
||||
{"sh", shell_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SLEEP
|
||||
{"sleep", sleep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
@@ -311,12 +327,21 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_UPTIME
|
||||
{"uptime", uptime_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UUENCODE
|
||||
{"uuencode", uuencode_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UUDECODE
|
||||
{"uudecode", uudecode_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_USLEEP
|
||||
{"usleep", usleep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WC
|
||||
{"wc", wc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WHICH
|
||||
{"which", which_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WHOAMI
|
||||
{"whoami", whoami_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
@@ -338,7 +363,7 @@ int main(int argc, char **argv)
|
||||
{
|
||||
char *s;
|
||||
char *name;
|
||||
const struct Applet *a = applets;
|
||||
const struct BB_applet *a = applets;
|
||||
|
||||
for (s = name = argv[0]; *s != '\0';) {
|
||||
if (*s++ == '/')
|
||||
@@ -349,18 +374,11 @@ int main(int argc, char **argv)
|
||||
|
||||
while (a->name != 0) {
|
||||
if (strcmp(name, a->name) == 0) {
|
||||
int status;
|
||||
|
||||
status = ((*(a->main)) (argc, argv));
|
||||
if (status < 0) {
|
||||
fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
exit(status);
|
||||
exit(((*(a->main)) (argc, argv)));
|
||||
}
|
||||
a++;
|
||||
}
|
||||
exit(busybox_main(argc, argv));
|
||||
return(busybox_main(argc, argv));
|
||||
}
|
||||
|
||||
|
||||
@@ -372,18 +390,16 @@ int busybox_main(int argc, char **argv)
|
||||
argv++;
|
||||
|
||||
if (been_there_done_that == 1 || argc < 1) {
|
||||
const struct Applet *a = applets;
|
||||
const struct BB_applet *a = applets;
|
||||
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
|
||||
BB_VER, BB_BT);
|
||||
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
|
||||
fprintf(stderr, " or: [function] [arguments]...\n\n");
|
||||
fprintf(stderr,
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n"
|
||||
"Usage: busybox [function] [arguments]...\n"
|
||||
" or: [function] [arguments]...\n\n"
|
||||
"\tBusyBox is a multi-call binary that combines many common Unix\n"
|
||||
"\tutilities into a single executable. Most people will create a\n"
|
||||
"\tlink to busybox for each function they wish to use, and BusyBox\n"
|
||||
"\twill act like whatever it was invoked as.\n");
|
||||
fprintf(stderr, "\nCurrently defined functions:\n");
|
||||
"\twill act like whatever it was invoked as.\n"
|
||||
"\nCurrently defined functions:\n", BB_VER, BB_BT);
|
||||
|
||||
while (a->name != 0) {
|
||||
col +=
|
||||
@@ -396,11 +412,10 @@ int busybox_main(int argc, char **argv)
|
||||
}
|
||||
fprintf(stderr, "\n\n");
|
||||
exit(-1);
|
||||
} else {
|
||||
/* If we've already been here once, exit now */
|
||||
been_there_done_that = 1;
|
||||
return (main(argc, argv));
|
||||
}
|
||||
/* If we've already been here once, exit now */
|
||||
been_there_done_that = 1;
|
||||
return (main(argc, argv));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -0,0 +1,332 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini ar implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 by Glenn McGrath
|
||||
* Written by Glenn McGrath <bug1@netconnect.com.au> 1 June 2000
|
||||
*
|
||||
* Based in part on BusyBox tar, Debian dpkg-deb and GNU ar.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Last modified 10 June 2000
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <sys/types.h>
|
||||
#include "internal.h"
|
||||
|
||||
#define AR_BLOCK_SIZE 60
|
||||
#define AR_PRESERVE_DATE 1
|
||||
#define AR_VERBOSE 2
|
||||
#define AR_DISPLAY 4
|
||||
#define AR_EXT_TO_FILE 8
|
||||
#define AR_EXT_TO_STDOUT 16
|
||||
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_io_error
|
||||
#include "messages.c"
|
||||
|
||||
struct ArHeader { /* Byte Offset */
|
||||
char ar_name[16]; /* 0-15 */
|
||||
char ar_date[12]; /* 16-27 */
|
||||
char ar_uid[6], ar_gid[6]; /* 28-39 */
|
||||
char ar_mode[8]; /* 40-47 */
|
||||
char ar_size[10]; /* 48-57 */
|
||||
char ar_fmag[2]; /* 58-59 */
|
||||
};
|
||||
typedef struct ArHeader ArHeader;
|
||||
|
||||
struct ArInfo {
|
||||
char name[17]; /* File name */
|
||||
time_t date; /* long int, No of seconds since epoch */
|
||||
uid_t uid; /* unsigned int, Numeric UID */
|
||||
gid_t gid; /* unsigned int, Numeric GID */
|
||||
mode_t mode; /* unsigned int, Unix mode */
|
||||
size_t size; /* int, Size of the file */
|
||||
};
|
||||
typedef struct ArInfo ArInfo;
|
||||
|
||||
static const char ar_usage[] = "ar [optxvV] archive [filenames] \n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nExtract or list files from an ar archive.\n\n"
|
||||
"Options:\n"
|
||||
"\to\t\tpreserve original dates\n"
|
||||
"\tp\t\textract to stdout\n"
|
||||
"\tt\t\tlist\n"
|
||||
"\tx\t\textract\n"
|
||||
"\tv\t\tverbosely list files processed\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
/*
|
||||
* Display details of a file, verbosly if funct=2
|
||||
*/
|
||||
static void displayEntry(struct ArInfo *entry, int funct)
|
||||
{
|
||||
/* TODO convert mode to string */
|
||||
if ((funct & AR_VERBOSE) == AR_VERBOSE)
|
||||
printf("%i %i/%i %8i %s ", entry->mode, entry->uid, entry->gid,
|
||||
entry->size, timeString(entry->date));
|
||||
printf("%s\n", entry->name);
|
||||
}
|
||||
|
||||
/* this is from tar.c remove later*/
|
||||
static long getOctal(const char *cp, int size)
|
||||
{
|
||||
long val = 0;
|
||||
|
||||
for(;(size > 0) && (*cp == ' '); cp++, size--);
|
||||
if ((size == 0) || !isOctal(*cp))
|
||||
return -1;
|
||||
for(; (size > 0) && isOctal(*cp); size--) {
|
||||
val = val * 8 + *cp++ - '0';
|
||||
}
|
||||
for (;(size > 0) && (*cp == ' '); cp++, size--);
|
||||
if ((size > 0) && *cp)
|
||||
return -1;
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts from the char based struct to a new struct with stricter types
|
||||
*/
|
||||
static int processArHeader(struct ArHeader *rawHeader, struct ArInfo *header)
|
||||
{
|
||||
int count2;
|
||||
int count;
|
||||
|
||||
/* check end of header marker is valid */
|
||||
if ((rawHeader->ar_fmag[0]!='`') || (rawHeader->ar_fmag[1]!='\n'))
|
||||
return(FALSE);
|
||||
|
||||
/* convert filename */
|
||||
for (count = 0; count < 16; count++) {
|
||||
/* allow spaces in filename except at the end */
|
||||
if (rawHeader->ar_name[count] == ' ') {
|
||||
for (count2 = count; count2 < 16; count2++)
|
||||
if (!isspace(rawHeader->ar_name[count2]))
|
||||
break;
|
||||
if (count2 >= 16)
|
||||
break;
|
||||
}
|
||||
/* GNU ar uses '/' as an end of filename marker */
|
||||
if (rawHeader->ar_name[count] == '/')
|
||||
break;
|
||||
header->name[count] = rawHeader->ar_name[count];
|
||||
}
|
||||
header->name[count] = '\0';
|
||||
header->date = atoi(rawHeader->ar_date);
|
||||
header->uid = atoi(rawHeader->ar_uid);
|
||||
header->gid = atoi(rawHeader->ar_gid);
|
||||
header->mode = getOctal(rawHeader->ar_mode, sizeof(rawHeader->ar_mode));
|
||||
header->size = atoi(rawHeader->ar_size);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy size bytes from current position if srcFd to current position in dstFd
|
||||
* taken from tarExtractRegularFile in tar.c, remove later
|
||||
*/
|
||||
static int copySubFile(int srcFd, int dstFd, int copySize)
|
||||
{
|
||||
int readSize, writeSize, doneSize;
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
while (copySize > 0) {
|
||||
if (copySize > BUFSIZ)
|
||||
readSize = BUFSIZ;
|
||||
else
|
||||
readSize = copySize;
|
||||
writeSize = fullRead(srcFd, buffer, readSize);
|
||||
if (writeSize <= 0) {
|
||||
errorMsg(io_error, "copySubFile :", strerror(errno));
|
||||
return (FALSE);
|
||||
}
|
||||
doneSize = fullWrite(dstFd, buffer, writeSize);
|
||||
if (doneSize <= 0) {
|
||||
errorMsg(io_error, "copySubFile :", strerror(errno));
|
||||
return (FALSE);
|
||||
}
|
||||
copySize -= doneSize;
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract the file described in ArInfo to the specified path
|
||||
* set the new files uid, gid and mode
|
||||
*/
|
||||
static int extractToFile(struct ArInfo *file, int funct, int srcFd, const char *path)
|
||||
{
|
||||
int dstFd, temp;
|
||||
struct stat tmpStat;
|
||||
char *pathname = NULL;
|
||||
struct utimbuf newtime;
|
||||
|
||||
if ((temp = isDirectory(path, TRUE, &tmpStat)) != TRUE) {
|
||||
if (!createPath(path, 0777)) {
|
||||
fatalError("Cannot extract to specified path");
|
||||
return (FALSE);
|
||||
}
|
||||
}
|
||||
temp = (strlen(path) + 16);
|
||||
pathname = (char *) xmalloc(temp);
|
||||
pathname = strcpy(pathname, path);
|
||||
pathname = strcat(pathname, file->name);
|
||||
dstFd = device_open(pathname, O_WRONLY | O_CREAT);
|
||||
temp = copySubFile(srcFd, dstFd, file->size);
|
||||
fchown(dstFd, file->uid, file->gid);
|
||||
fchmod(dstFd, file->mode);
|
||||
close(dstFd);
|
||||
if ((funct&AR_PRESERVE_DATE)==AR_PRESERVE_DATE)
|
||||
newtime.modtime=file->date;
|
||||
else
|
||||
newtime.modtime=time(0);
|
||||
newtime.actime=time(0);
|
||||
temp = utime(pathname, &newtime);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a file descriptor for the specified file and do error checks
|
||||
*/
|
||||
static int getArFd(char *filename)
|
||||
{
|
||||
int arFd;
|
||||
char arVersion[8];
|
||||
|
||||
arFd = open(filename, O_RDONLY);
|
||||
if (arFd < 0) {
|
||||
errorMsg("Error opening '%s': %s\n", filename, strerror(errno));
|
||||
return (FALSE);
|
||||
}
|
||||
if (fullRead(arFd, arVersion, 8) <= 0) {
|
||||
errorMsg( "ar: Unexpected EOF in archive\n");
|
||||
return (FALSE);
|
||||
}
|
||||
if (strncmp(arVersion,"!<arch>",7) != 0) {
|
||||
errorMsg("ar header fails check ");
|
||||
return(FALSE);
|
||||
}
|
||||
return arFd;
|
||||
}
|
||||
|
||||
/*
|
||||
* Step through the ar file and process it one entry at a time
|
||||
* fileList[0] is the name of the ar archive
|
||||
* fileList[1] and up are filenames to extract from the archive
|
||||
* funct contains flags to specify the actions to be performed
|
||||
*/
|
||||
static int readArFile(char *fileList[16], int fileListSize, int funct)
|
||||
{
|
||||
int arFd, status, extFileFlag, i, lastOffset=0;
|
||||
ArHeader rawArHeader;
|
||||
ArInfo arEntry;
|
||||
|
||||
/* open the ar archive */
|
||||
arFd=getArFd(fileList[0]);
|
||||
|
||||
/* read the first header, then loop until ono more headers */
|
||||
while ((status = fullRead(arFd, (char *) &rawArHeader, AR_BLOCK_SIZE))
|
||||
== AR_BLOCK_SIZE) {
|
||||
|
||||
/* check the header is valid, if not try reading the header
|
||||
agian with an offset of 1, needed as some ar archive end
|
||||
with a '\n' which isnt counted in specified file size */
|
||||
if ((status=processArHeader(&rawArHeader, &arEntry))==FALSE ) {
|
||||
if ((i=lseek(arFd, 0, SEEK_CUR))==(lastOffset+60))
|
||||
lseek(arFd, lastOffset+1, SEEK_SET);
|
||||
else
|
||||
return(FALSE);
|
||||
}
|
||||
else {
|
||||
extFileFlag=0;
|
||||
|
||||
if (funct&AR_DISPLAY)
|
||||
displayEntry(&arEntry, funct);
|
||||
|
||||
/* check file was specified to be extracted only if
|
||||
some file were specified */
|
||||
if ((funct&AR_EXT_TO_FILE) || (funct&AR_EXT_TO_STDOUT)){
|
||||
if (fileListSize==1)
|
||||
extFileFlag=1;
|
||||
else {
|
||||
for( i=1; i<=fileListSize; i++)
|
||||
if ((status=(strcmp(fileList[i],arEntry.name)))==0)
|
||||
extFileFlag=1;
|
||||
}
|
||||
}
|
||||
if (extFileFlag==1) {
|
||||
if (funct&AR_EXT_TO_FILE)
|
||||
extractToFile(&arEntry, funct, arFd, "./");
|
||||
else
|
||||
copySubFile(arFd,fileno(stdout),arEntry.size);
|
||||
}
|
||||
else
|
||||
lseek(arFd, arEntry.size, SEEK_CUR);
|
||||
lastOffset=lseek(arFd, 0, SEEK_CUR);
|
||||
} /* if processArHeader */
|
||||
} /* while */
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
extern int ar_main(int argc, char **argv)
|
||||
{
|
||||
int funct = 0, ret=0, i=0;
|
||||
char *fileList[16], c, *opt_ptr;
|
||||
|
||||
if (argc < 2)
|
||||
usage(ar_usage);
|
||||
|
||||
opt_ptr = argv[1];
|
||||
if (*opt_ptr == '-')
|
||||
++opt_ptr;
|
||||
while ((c = *opt_ptr++) != '\0') {
|
||||
switch (c) {
|
||||
case 'o': /* preserver original dates */
|
||||
funct = funct | 1;
|
||||
break;
|
||||
case 'p': /* extract to stdout */
|
||||
funct = funct | 16;
|
||||
break;
|
||||
case 't': /* display contents */
|
||||
funct = funct | 4;
|
||||
break;
|
||||
case 'x': /* extract contents of archive */
|
||||
funct = funct | 8;
|
||||
break;
|
||||
case 'v': /* be verbose */
|
||||
funct = funct | 2;
|
||||
break;
|
||||
default:
|
||||
usage(ar_usage);
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0; i<(argc-2); i++)
|
||||
fileList[i]=argv[i+2];
|
||||
|
||||
if (funct > 3)
|
||||
ret = readArFile(fileList, (argc-2), funct);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
@@ -0,0 +1,332 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini ar implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 by Glenn McGrath
|
||||
* Written by Glenn McGrath <bug1@netconnect.com.au> 1 June 2000
|
||||
*
|
||||
* Based in part on BusyBox tar, Debian dpkg-deb and GNU ar.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Last modified 10 June 2000
|
||||
*/
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <sys/types.h>
|
||||
#include "internal.h"
|
||||
|
||||
#define AR_BLOCK_SIZE 60
|
||||
#define AR_PRESERVE_DATE 1
|
||||
#define AR_VERBOSE 2
|
||||
#define AR_DISPLAY 4
|
||||
#define AR_EXT_TO_FILE 8
|
||||
#define AR_EXT_TO_STDOUT 16
|
||||
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_io_error
|
||||
#include "messages.c"
|
||||
|
||||
struct ArHeader { /* Byte Offset */
|
||||
char ar_name[16]; /* 0-15 */
|
||||
char ar_date[12]; /* 16-27 */
|
||||
char ar_uid[6], ar_gid[6]; /* 28-39 */
|
||||
char ar_mode[8]; /* 40-47 */
|
||||
char ar_size[10]; /* 48-57 */
|
||||
char ar_fmag[2]; /* 58-59 */
|
||||
};
|
||||
typedef struct ArHeader ArHeader;
|
||||
|
||||
struct ArInfo {
|
||||
char name[17]; /* File name */
|
||||
time_t date; /* long int, No of seconds since epoch */
|
||||
uid_t uid; /* unsigned int, Numeric UID */
|
||||
gid_t gid; /* unsigned int, Numeric GID */
|
||||
mode_t mode; /* unsigned int, Unix mode */
|
||||
size_t size; /* int, Size of the file */
|
||||
};
|
||||
typedef struct ArInfo ArInfo;
|
||||
|
||||
static const char ar_usage[] = "ar [optxvV] archive [filenames] \n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nExtract or list files from an ar archive.\n\n"
|
||||
"Options:\n"
|
||||
"\to\t\tpreserve original dates\n"
|
||||
"\tp\t\textract to stdout\n"
|
||||
"\tt\t\tlist\n"
|
||||
"\tx\t\textract\n"
|
||||
"\tv\t\tverbosely list files processed\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
/*
|
||||
* Display details of a file, verbosly if funct=2
|
||||
*/
|
||||
static void displayEntry(struct ArInfo *entry, int funct)
|
||||
{
|
||||
/* TODO convert mode to string */
|
||||
if ((funct & AR_VERBOSE) == AR_VERBOSE)
|
||||
printf("%i %i/%i %8i %s ", entry->mode, entry->uid, entry->gid,
|
||||
entry->size, timeString(entry->date));
|
||||
printf("%s\n", entry->name);
|
||||
}
|
||||
|
||||
/* this is from tar.c remove later*/
|
||||
static long getOctal(const char *cp, int size)
|
||||
{
|
||||
long val = 0;
|
||||
|
||||
for(;(size > 0) && (*cp == ' '); cp++, size--);
|
||||
if ((size == 0) || !isOctal(*cp))
|
||||
return -1;
|
||||
for(; (size > 0) && isOctal(*cp); size--) {
|
||||
val = val * 8 + *cp++ - '0';
|
||||
}
|
||||
for (;(size > 0) && (*cp == ' '); cp++, size--);
|
||||
if ((size > 0) && *cp)
|
||||
return -1;
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
* Converts from the char based struct to a new struct with stricter types
|
||||
*/
|
||||
static int processArHeader(struct ArHeader *rawHeader, struct ArInfo *header)
|
||||
{
|
||||
int count2;
|
||||
int count;
|
||||
|
||||
/* check end of header marker is valid */
|
||||
if ((rawHeader->ar_fmag[0]!='`') || (rawHeader->ar_fmag[1]!='\n'))
|
||||
return(FALSE);
|
||||
|
||||
/* convert filename */
|
||||
for (count = 0; count < 16; count++) {
|
||||
/* allow spaces in filename except at the end */
|
||||
if (rawHeader->ar_name[count] == ' ') {
|
||||
for (count2 = count; count2 < 16; count2++)
|
||||
if (!isspace(rawHeader->ar_name[count2]))
|
||||
break;
|
||||
if (count2 >= 16)
|
||||
break;
|
||||
}
|
||||
/* GNU ar uses '/' as an end of filename marker */
|
||||
if (rawHeader->ar_name[count] == '/')
|
||||
break;
|
||||
header->name[count] = rawHeader->ar_name[count];
|
||||
}
|
||||
header->name[count] = '\0';
|
||||
header->date = atoi(rawHeader->ar_date);
|
||||
header->uid = atoi(rawHeader->ar_uid);
|
||||
header->gid = atoi(rawHeader->ar_gid);
|
||||
header->mode = getOctal(rawHeader->ar_mode, sizeof(rawHeader->ar_mode));
|
||||
header->size = atoi(rawHeader->ar_size);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy size bytes from current position if srcFd to current position in dstFd
|
||||
* taken from tarExtractRegularFile in tar.c, remove later
|
||||
*/
|
||||
static int copySubFile(int srcFd, int dstFd, int copySize)
|
||||
{
|
||||
int readSize, writeSize, doneSize;
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
while (copySize > 0) {
|
||||
if (copySize > BUFSIZ)
|
||||
readSize = BUFSIZ;
|
||||
else
|
||||
readSize = copySize;
|
||||
writeSize = fullRead(srcFd, buffer, readSize);
|
||||
if (writeSize <= 0) {
|
||||
errorMsg(io_error, "copySubFile :", strerror(errno));
|
||||
return (FALSE);
|
||||
}
|
||||
doneSize = fullWrite(dstFd, buffer, writeSize);
|
||||
if (doneSize <= 0) {
|
||||
errorMsg(io_error, "copySubFile :", strerror(errno));
|
||||
return (FALSE);
|
||||
}
|
||||
copySize -= doneSize;
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Extract the file described in ArInfo to the specified path
|
||||
* set the new files uid, gid and mode
|
||||
*/
|
||||
static int extractToFile(struct ArInfo *file, int funct, int srcFd, const char *path)
|
||||
{
|
||||
int dstFd, temp;
|
||||
struct stat tmpStat;
|
||||
char *pathname = NULL;
|
||||
struct utimbuf newtime;
|
||||
|
||||
if ((temp = isDirectory(path, TRUE, &tmpStat)) != TRUE) {
|
||||
if (!createPath(path, 0777)) {
|
||||
fatalError("Cannot extract to specified path");
|
||||
return (FALSE);
|
||||
}
|
||||
}
|
||||
temp = (strlen(path) + 16);
|
||||
pathname = (char *) xmalloc(temp);
|
||||
pathname = strcpy(pathname, path);
|
||||
pathname = strcat(pathname, file->name);
|
||||
dstFd = device_open(pathname, O_WRONLY | O_CREAT);
|
||||
temp = copySubFile(srcFd, dstFd, file->size);
|
||||
fchown(dstFd, file->uid, file->gid);
|
||||
fchmod(dstFd, file->mode);
|
||||
close(dstFd);
|
||||
if ((funct&AR_PRESERVE_DATE)==AR_PRESERVE_DATE)
|
||||
newtime.modtime=file->date;
|
||||
else
|
||||
newtime.modtime=time(0);
|
||||
newtime.actime=time(0);
|
||||
temp = utime(pathname, &newtime);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a file descriptor for the specified file and do error checks
|
||||
*/
|
||||
static int getArFd(char *filename)
|
||||
{
|
||||
int arFd;
|
||||
char arVersion[8];
|
||||
|
||||
arFd = open(filename, O_RDONLY);
|
||||
if (arFd < 0) {
|
||||
errorMsg("Error opening '%s': %s\n", filename, strerror(errno));
|
||||
return (FALSE);
|
||||
}
|
||||
if (fullRead(arFd, arVersion, 8) <= 0) {
|
||||
errorMsg( "ar: Unexpected EOF in archive\n");
|
||||
return (FALSE);
|
||||
}
|
||||
if (strncmp(arVersion,"!<arch>",7) != 0) {
|
||||
errorMsg("ar header fails check ");
|
||||
return(FALSE);
|
||||
}
|
||||
return arFd;
|
||||
}
|
||||
|
||||
/*
|
||||
* Step through the ar file and process it one entry at a time
|
||||
* fileList[0] is the name of the ar archive
|
||||
* fileList[1] and up are filenames to extract from the archive
|
||||
* funct contains flags to specify the actions to be performed
|
||||
*/
|
||||
static int readArFile(char *fileList[16], int fileListSize, int funct)
|
||||
{
|
||||
int arFd, status, extFileFlag, i, lastOffset=0;
|
||||
ArHeader rawArHeader;
|
||||
ArInfo arEntry;
|
||||
|
||||
/* open the ar archive */
|
||||
arFd=getArFd(fileList[0]);
|
||||
|
||||
/* read the first header, then loop until ono more headers */
|
||||
while ((status = fullRead(arFd, (char *) &rawArHeader, AR_BLOCK_SIZE))
|
||||
== AR_BLOCK_SIZE) {
|
||||
|
||||
/* check the header is valid, if not try reading the header
|
||||
agian with an offset of 1, needed as some ar archive end
|
||||
with a '\n' which isnt counted in specified file size */
|
||||
if ((status=processArHeader(&rawArHeader, &arEntry))==FALSE ) {
|
||||
if ((i=lseek(arFd, 0, SEEK_CUR))==(lastOffset+60))
|
||||
lseek(arFd, lastOffset+1, SEEK_SET);
|
||||
else
|
||||
return(FALSE);
|
||||
}
|
||||
else {
|
||||
extFileFlag=0;
|
||||
|
||||
if (funct&AR_DISPLAY)
|
||||
displayEntry(&arEntry, funct);
|
||||
|
||||
/* check file was specified to be extracted only if
|
||||
some file were specified */
|
||||
if ((funct&AR_EXT_TO_FILE) || (funct&AR_EXT_TO_STDOUT)){
|
||||
if (fileListSize==1)
|
||||
extFileFlag=1;
|
||||
else {
|
||||
for( i=1; i<=fileListSize; i++)
|
||||
if ((status=(strcmp(fileList[i],arEntry.name)))==0)
|
||||
extFileFlag=1;
|
||||
}
|
||||
}
|
||||
if (extFileFlag==1) {
|
||||
if (funct&AR_EXT_TO_FILE)
|
||||
extractToFile(&arEntry, funct, arFd, "./");
|
||||
else
|
||||
copySubFile(arFd,fileno(stdout),arEntry.size);
|
||||
}
|
||||
else
|
||||
lseek(arFd, arEntry.size, SEEK_CUR);
|
||||
lastOffset=lseek(arFd, 0, SEEK_CUR);
|
||||
} /* if processArHeader */
|
||||
} /* while */
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
extern int ar_main(int argc, char **argv)
|
||||
{
|
||||
int funct = 0, ret=0, i=0;
|
||||
char *fileList[16], c, *opt_ptr;
|
||||
|
||||
if (argc < 2)
|
||||
usage(ar_usage);
|
||||
|
||||
opt_ptr = argv[1];
|
||||
if (*opt_ptr == '-')
|
||||
++opt_ptr;
|
||||
while ((c = *opt_ptr++) != '\0') {
|
||||
switch (c) {
|
||||
case 'o': /* preserver original dates */
|
||||
funct = funct | 1;
|
||||
break;
|
||||
case 'p': /* extract to stdout */
|
||||
funct = funct | 16;
|
||||
break;
|
||||
case 't': /* display contents */
|
||||
funct = funct | 4;
|
||||
break;
|
||||
case 'x': /* extract contents of archive */
|
||||
funct = funct | 8;
|
||||
break;
|
||||
case 'v': /* be verbose */
|
||||
funct = funct | 2;
|
||||
break;
|
||||
default:
|
||||
usage(ar_usage);
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0; i<(argc-2); i++)
|
||||
fileList[i]=argv[i+2];
|
||||
|
||||
if (funct > 3)
|
||||
ret = readArFile(fileList, (argc-2), funct);
|
||||
|
||||
return (ret);
|
||||
}
|
||||
@@ -28,13 +28,17 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
static const char gunzip_usage[] =
|
||||
"gunzip [OPTION]... FILE\n\n"
|
||||
"Uncompress FILE (or standard input if FILE is '-').\n\n"
|
||||
"gunzip [OPTION]... FILE\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nUncompress FILE (or standard input if FILE is '-').\n\n"
|
||||
"Options:\n"
|
||||
|
||||
"\t-c\tWrite output to standard output\n"
|
||||
"\t-t\tTest compressed file integrity\n";
|
||||
"\t-t\tTest compressed file integrity\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
/* These defines are very important for BusyBox. Without these,
|
||||
@@ -43,8 +47,9 @@ static const char gunzip_usage[] =
|
||||
#define SMALL_MEM
|
||||
#define DYN_ALLOC
|
||||
|
||||
#define bb_need_name_too_long
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_memory_exhausted
|
||||
#define bb_need_name_too_long
|
||||
#include "messages.c"
|
||||
|
||||
|
||||
@@ -102,7 +107,6 @@ static char *license_msg[] = {
|
||||
#include <signal.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <sys/param.h> /* for PATH_MAX */
|
||||
|
||||
/* #include "tailor.h" */
|
||||
|
||||
@@ -207,7 +211,7 @@ extern int method; /* compression method */
|
||||
# define DECLARE(type, array, size) type * array
|
||||
# define ALLOC(type, array, size) { \
|
||||
array = (type*)calloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
|
||||
if (array == NULL) errorMsg("insufficient memory"); \
|
||||
if (array == NULL) errorMsg(memory_exhausted, "gunzip"); \
|
||||
}
|
||||
# define FREE(array) {if (array != NULL) free(array), array=NULL;}
|
||||
#else
|
||||
@@ -363,25 +367,23 @@ void send_bits (int value, int length);
|
||||
unsigned bi_reverse (unsigned value, int length);
|
||||
void bi_windup (void);
|
||||
void copy_block (char *buf, unsigned len, int header);
|
||||
extern int (*read_buf) (char *buf, unsigned size);
|
||||
|
||||
/* in util.c: */
|
||||
extern int copy (int in, int out);
|
||||
extern ulg updcrc (uch * s, unsigned n);
|
||||
extern void clear_bufs (void);
|
||||
extern int fill_inbuf (int eof_ok);
|
||||
static int fill_inbuf (int eof_ok);
|
||||
extern void flush_outbuf (void);
|
||||
extern void flush_window (void);
|
||||
static void flush_window (void);
|
||||
extern void write_buf (int fd, void * buf, unsigned cnt);
|
||||
|
||||
#ifndef __linux__
|
||||
extern char *basename (char *fname);
|
||||
static char *basename (char *fname);
|
||||
#endif /* not __linux__ */
|
||||
extern void read_error (void);
|
||||
extern void write_error (void);
|
||||
void read_error_msg (void);
|
||||
void write_error_msg (void);
|
||||
|
||||
/* in inflate.c */
|
||||
extern int inflate (void);
|
||||
static int inflate (void);
|
||||
|
||||
/* #include "lzw.h" */
|
||||
|
||||
@@ -446,133 +448,6 @@ extern int unlzw (int in, int out);
|
||||
# undef LZW
|
||||
#endif
|
||||
|
||||
/* #include "getopt.h" */
|
||||
|
||||
/* Declarations for getopt.
|
||||
Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by the
|
||||
Free Software Foundation; either version 2, or (at your option) any
|
||||
later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
|
||||
#ifndef _GETOPT_H
|
||||
#define _GETOPT_H 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* For communication from `getopt' to the caller.
|
||||
When `getopt' finds an option that takes an argument,
|
||||
the argument value is returned here.
|
||||
Also, when `ordering' is RETURN_IN_ORDER,
|
||||
each non-option ARGV-element is returned here. */
|
||||
extern char *optarg;
|
||||
|
||||
/* Index in ARGV of the next element to be scanned.
|
||||
This is used for communication to and from the caller
|
||||
and for communication between successive calls to `getopt'.
|
||||
|
||||
On entry to `getopt', zero means this is the first call; initialize.
|
||||
|
||||
When `getopt' returns EOF, this is the index of the first of the
|
||||
non-option elements that the caller should itself scan.
|
||||
|
||||
Otherwise, `optind' communicates from one call to the next
|
||||
how much of ARGV has been scanned so far. */
|
||||
|
||||
extern int optind;
|
||||
|
||||
/* Callers store zero here to inhibit the error message `getopt' prints
|
||||
for unrecognized options. */
|
||||
|
||||
extern int opterr;
|
||||
|
||||
/* Set to an option character which was unrecognized. */
|
||||
|
||||
extern int optopt;
|
||||
|
||||
/* Describe the long-named options requested by the application.
|
||||
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
|
||||
of `struct option' terminated by an element containing a name which is
|
||||
zero.
|
||||
|
||||
The field `has_arg' is:
|
||||
no_argument (or 0) if the option does not take an argument,
|
||||
required_argument (or 1) if the option requires an argument,
|
||||
optional_argument (or 2) if the option takes an optional argument.
|
||||
|
||||
If the field `flag' is not NULL, it points to a variable that is set
|
||||
to the value given in the field `val' when the option is found, but
|
||||
left unchanged if the option is not found.
|
||||
|
||||
To have a long-named option do something other than set an `int' to
|
||||
a compiled-in constant, such as set a value from `optarg', set the
|
||||
option's `flag' field to zero and its `val' field to a nonzero
|
||||
value (the equivalent single-letter option character, if there is
|
||||
one). For long options that have a zero `flag' field, `getopt'
|
||||
returns the contents of the `val' field. */
|
||||
|
||||
struct option {
|
||||
#if __STDC__
|
||||
const char *name;
|
||||
#else
|
||||
char *name;
|
||||
#endif
|
||||
/* has_arg can't be an enum because some compilers complain about
|
||||
type mismatches in all the code that assumes it is an int. */
|
||||
int has_arg;
|
||||
int *flag;
|
||||
int val;
|
||||
};
|
||||
|
||||
/* Names for the values of the `has_arg' field of `struct option'. */
|
||||
|
||||
#define no_argument 0
|
||||
#define required_argument 1
|
||||
#define optional_argument 2
|
||||
|
||||
#if __STDC__ || defined(PROTO)
|
||||
#if defined(__GNU_LIBRARY__)
|
||||
/* Many other libraries have conflicting prototypes for getopt, with
|
||||
differences in the consts, in stdlib.h. To avoid compilation
|
||||
errors, only prototype getopt for the GNU C library. */
|
||||
extern int getopt(int argc, char *const *argv, const char *shortopts);
|
||||
#endif /* not __GNU_LIBRARY__ */
|
||||
extern int getopt_long(int argc, char *const *argv,
|
||||
const char *shortopts,
|
||||
const struct option *longopts, int *longind);
|
||||
extern int getopt_long_only(int argc, char *const *argv,
|
||||
const char *shortopts,
|
||||
const struct option *longopts,
|
||||
int *longind);
|
||||
|
||||
/* Internal only. Users should not call this directly. */
|
||||
extern int _getopt_internal(int argc, char *const *argv,
|
||||
const char *shortopts,
|
||||
const struct option *longopts,
|
||||
int *longind, int long_only);
|
||||
#else /* not __STDC__ */
|
||||
extern int getopt();
|
||||
extern int getopt_long();
|
||||
extern int getopt_long_only();
|
||||
|
||||
extern int _getopt_internal();
|
||||
#endif /* not __STDC__ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* _GETOPT_H */
|
||||
#include <time.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
@@ -641,8 +516,8 @@ typedef RETSIGTYPE(*sig_type) (int);
|
||||
#define RW_USER (S_IRUSR | S_IWUSR) /* creation mode for open() */
|
||||
|
||||
#ifndef MAX_PATH_LEN /* max pathname length */
|
||||
# ifdef PATH_MAX
|
||||
# define MAX_PATH_LEN PATH_MAX
|
||||
# ifdef BUFSIZ
|
||||
# define MAX_PATH_LEN BUFSIZ
|
||||
# else
|
||||
# define MAX_PATH_LEN 1024
|
||||
# endif
|
||||
@@ -716,11 +591,12 @@ int gunzip_main(int argc, char **argv)
|
||||
char ifname[MAX_PATH_LEN + 1]; /* input file name */
|
||||
char ofname[MAX_PATH_LEN + 1]; /* output file name */
|
||||
|
||||
if (argc == 1)
|
||||
usage(gunzip_usage);
|
||||
|
||||
if (strcmp(*argv, "zcat") == 0)
|
||||
if (strcmp(*argv, "zcat") == 0) {
|
||||
to_stdout = 1;
|
||||
if (argc == 1) {
|
||||
fromstdin = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Parse any options */
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
@@ -870,7 +746,7 @@ int gunzip_main(int argc, char **argv)
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
exit(exit_code);
|
||||
return(exit_code);
|
||||
}
|
||||
|
||||
|
||||
@@ -1053,7 +929,7 @@ int in, out; /* input and output file descriptors */
|
||||
int res = inflate();
|
||||
|
||||
if (res == 3) {
|
||||
errorMsg("out of memory");
|
||||
errorMsg(memory_exhausted, "gunzip");
|
||||
} else if (res != 0) {
|
||||
errorMsg("invalid compressed data--format violated");
|
||||
}
|
||||
@@ -1156,7 +1032,7 @@ unsigned n; /* number of bytes in s[] */
|
||||
/* ===========================================================================
|
||||
* Clear input and output buffers
|
||||
*/
|
||||
void clear_bufs()
|
||||
void clear_bufs(void)
|
||||
{
|
||||
outcnt = 0;
|
||||
insize = inptr = 0;
|
||||
@@ -1184,7 +1060,7 @@ int eof_ok; /* set if EOF acceptable as a result */
|
||||
if (insize == 0) {
|
||||
if (eof_ok)
|
||||
return EOF;
|
||||
read_error();
|
||||
read_error_msg();
|
||||
}
|
||||
bytes_in += (ulg) insize;
|
||||
inptr = 1;
|
||||
@@ -1235,7 +1111,7 @@ unsigned cnt;
|
||||
|
||||
while ((n = write(fd, buf, cnt)) != cnt) {
|
||||
if (n == (unsigned) (-1)) {
|
||||
write_error();
|
||||
write_error_msg();
|
||||
}
|
||||
cnt -= n;
|
||||
buf = (void *) ((char *) buf + n);
|
||||
@@ -1301,7 +1177,7 @@ const char *reject;
|
||||
/* ========================================================================
|
||||
* Error handlers.
|
||||
*/
|
||||
void read_error()
|
||||
void read_error_msg()
|
||||
{
|
||||
fprintf(stderr, "\n");
|
||||
if (errno != 0) {
|
||||
@@ -1312,7 +1188,7 @@ void read_error()
|
||||
abort_gzip();
|
||||
}
|
||||
|
||||
void write_error()
|
||||
void write_error_msg()
|
||||
{
|
||||
fprintf(stderr, "\n");
|
||||
perror("");
|
||||
|
||||
@@ -30,6 +30,9 @@
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_memory_exhausted
|
||||
#include "messages.c"
|
||||
|
||||
/* These defines are very important for BusyBox. Without these,
|
||||
* huge chunks of ram are pre-allocated making the BusyBox bss
|
||||
@@ -39,12 +42,15 @@
|
||||
|
||||
|
||||
static const char gzip_usage[] =
|
||||
"gzip [OPTION]... FILE\n\n"
|
||||
"Compress FILE with maximum compression.\n"
|
||||
"gzip [OPTION]... FILE\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCompress FILE with maximum compression.\n"
|
||||
"When FILE is '-', reads standard input. Implies -c.\n\n"
|
||||
|
||||
"Options:\n"
|
||||
"\t-c\tWrite output to standard output instead of FILE.gz\n";
|
||||
"\t-c\tWrite output to standard output instead of FILE.gz\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
/* I don't like nested includes, but the string and io functions are used
|
||||
@@ -121,7 +127,7 @@ extern int method; /* compression method */
|
||||
# define DECLARE(type, array, size) type * array
|
||||
# define ALLOC(type, array, size) { \
|
||||
array = (type*)calloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \
|
||||
if (array == NULL) errorMsg("insufficient memory"); \
|
||||
if (array == NULL) errorMsg(memory_exhausted, "gzip"); \
|
||||
}
|
||||
# define FREE(array) {if (array != NULL) free(array), array=NULL;}
|
||||
#else
|
||||
@@ -276,8 +282,6 @@ extern int save_orig_name; /* set if original name must be saved */
|
||||
#define WARN(msg) {if (!quiet) fprintf msg ; \
|
||||
if (exit_code == OK) exit_code = WARNING;}
|
||||
|
||||
#define do_exit(c) exit(c)
|
||||
|
||||
|
||||
/* in zip.c: */
|
||||
extern int zip (int in, int out);
|
||||
@@ -323,8 +327,8 @@ extern void flush_window (void);
|
||||
extern void write_buf (int fd, void * buf, unsigned cnt);
|
||||
extern char *strlwr (char *s);
|
||||
extern char *add_envopt (int *argcp, char ***argvp, char *env);
|
||||
extern void read_error (void);
|
||||
extern void write_error (void);
|
||||
extern void read_error_msg (void);
|
||||
extern void write_error_msg (void);
|
||||
extern void display_ratio (long num, long den, FILE * file);
|
||||
|
||||
/* in inflate.c */
|
||||
@@ -1778,7 +1782,6 @@ int part_nb; /* number of parts in .gz file */
|
||||
long time_stamp; /* original time stamp (modification time) */
|
||||
long ifile_size; /* input file size, -1 for devices (debug only) */
|
||||
char *env; /* contents of GZIP env variable */
|
||||
char **args = NULL; /* argv pointer if GZIP env variable defined */
|
||||
char z_suffix[MAX_SUFFIX + 1]; /* default suffix (can be set with --suffix) */
|
||||
int z_len; /* strlen(z_suffix) */
|
||||
|
||||
@@ -1878,13 +1881,13 @@ int gzip_main(int argc, char **argv)
|
||||
inFileNum = open(ifname, O_RDONLY);
|
||||
if (inFileNum < 0) {
|
||||
perror(ifname);
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
/* Get the time stamp on the input file. */
|
||||
result = stat(ifname, &statBuf);
|
||||
if (result < 0) {
|
||||
perror(ifname);
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
time_stamp = statBuf.st_ctime;
|
||||
ifile_size = statBuf.st_size;
|
||||
@@ -1918,7 +1921,7 @@ int gzip_main(int argc, char **argv)
|
||||
#endif
|
||||
if (outFileNum < 0) {
|
||||
perror(ofname);
|
||||
do_exit(WARNING);
|
||||
exit(WARNING);
|
||||
}
|
||||
SET_BINARY_MODE(outFileNum);
|
||||
/* Set permissions on the file */
|
||||
@@ -1943,7 +1946,7 @@ int gzip_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
do_exit(exit_code);
|
||||
return(exit_code);
|
||||
}
|
||||
|
||||
/* trees.c -- output deflated data using Huffman coding
|
||||
@@ -2272,7 +2275,6 @@ local void set_file_type (void);
|
||||
* used.
|
||||
*/
|
||||
|
||||
#define MAX(a,b) (a >= b ? a : b)
|
||||
/* the arguments must not have side effects */
|
||||
|
||||
/* ===========================================================================
|
||||
@@ -3134,7 +3136,7 @@ int in, out; /* input and output file descriptors */
|
||||
insize = read(in, (char *) inbuf, INBUFSIZ);
|
||||
}
|
||||
if ((int) insize == EOF && errno != 0) {
|
||||
read_error();
|
||||
read_error_msg();
|
||||
}
|
||||
bytes_in = bytes_out;
|
||||
return OK;
|
||||
@@ -3249,7 +3251,7 @@ char *env; /* name of environment variable */
|
||||
nargv = (char **) calloc(*argcp + 1, sizeof(char *));
|
||||
|
||||
if (nargv == NULL)
|
||||
errorMsg("out of memory");
|
||||
errorMsg(memory_exhausted, "gzip");
|
||||
oargv = *argvp;
|
||||
*argvp = nargv;
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
#include <utime.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysmacros.h>
|
||||
#include <sys/param.h> /* for PATH_MAX */
|
||||
|
||||
|
||||
static const char tar_usage[] =
|
||||
@@ -61,8 +60,9 @@ static const char tar_usage[] =
|
||||
#if defined BB_FEATURE_TAR_EXCLUDE
|
||||
"[--exclude File] "
|
||||
#endif
|
||||
"[-f tarFile] [FILE] ...\n\n"
|
||||
"Create, extract, or list files from a tar file. Note that\n"
|
||||
"[-f tarFile] [FILE] ...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCreate, extract, or list files from a tar file. Note that\n"
|
||||
"this version of tar treats hard links as separate files.\n\n"
|
||||
"Main operation mode:\n"
|
||||
#ifdef BB_FEATURE_TAR_CREATE
|
||||
@@ -78,6 +78,7 @@ static const char tar_usage[] =
|
||||
#endif
|
||||
"\nInformative output:\n"
|
||||
"\tv\t\tverbosely list files processed\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
/* Tar file constants */
|
||||
@@ -172,7 +173,7 @@ extern int tar_main(int argc, char **argv)
|
||||
#if defined BB_FEATURE_TAR_EXCLUDE
|
||||
int excludeListSize=0;
|
||||
#endif
|
||||
const char *tarName=NULL;
|
||||
const char *tarName="-";
|
||||
int listFlag = FALSE;
|
||||
int extractFlag = FALSE;
|
||||
int createFlag = FALSE;
|
||||
@@ -184,15 +185,15 @@ extern int tar_main(int argc, char **argv)
|
||||
usage(tar_usage);
|
||||
|
||||
/* Parse any options */
|
||||
while (--argc > 0 && (**(++argv) != '\0')) {
|
||||
while (--argc > 0 && strspn(*(++argv), "-cxt") >0 ) {
|
||||
stopIt=FALSE;
|
||||
while (stopIt==FALSE && *(++(*argv))) {
|
||||
while (stopIt==FALSE && *argv && **argv) {
|
||||
switch (**argv) {
|
||||
case 'f':
|
||||
if (--argc == 0) {
|
||||
fatalError( "Option requires an argument: No file specified\n");
|
||||
}
|
||||
if (tarName != NULL)
|
||||
if (*tarName != '-')
|
||||
fatalError( "Only one 'f' option allowed\n");
|
||||
tarName = *(++argv);
|
||||
if (tarName == NULL)
|
||||
@@ -245,12 +246,16 @@ extern int tar_main(int argc, char **argv)
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
if (strcmp(*argv, "-help")==0) {
|
||||
usage(tar_usage);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
fatalError( "Unknown tar flag '%c'\n"
|
||||
"Try `tar --help' for more information\n", **argv);
|
||||
}
|
||||
++(*argv);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,7 +269,8 @@ extern int tar_main(int argc, char **argv)
|
||||
#else
|
||||
exit(writeTarFile(tarName, tostdoutFlag, verboseFlag, argc, argv, excludeList));
|
||||
#endif
|
||||
} else {
|
||||
}
|
||||
if (listFlag == TRUE || extractFlag == TRUE) {
|
||||
exit(readTarFile(tarName, extractFlag, listFlag, tostdoutFlag, verboseFlag, excludeList));
|
||||
}
|
||||
|
||||
@@ -297,11 +303,14 @@ tarExtractRegularFile(TarInfo *header, int extractFlag, int tostdoutFlag)
|
||||
|
||||
/* Open the file to be written, if a file is supposed to be written */
|
||||
if (extractFlag==TRUE && tostdoutFlag==FALSE) {
|
||||
if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY, header->mode & ~S_IFMT)) < 0)
|
||||
errorMsg(io_error, header->name, strerror(errno));
|
||||
/* Create the path to the file, just in case it isn't there...
|
||||
* This should not screw up path permissions or anything. */
|
||||
createPath(header->name, 0777);
|
||||
if ((outFd=open(header->name, O_CREAT|O_TRUNC|O_WRONLY,
|
||||
header->mode & ~S_IFMT)) < 0) {
|
||||
errorMsg(io_error, header->name, strerror(errno));
|
||||
return( FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Write out the file, if we are supposed to be doing that */
|
||||
@@ -608,7 +617,7 @@ static int readTarFile(const char* tarName, int extractFlag, int listFlag,
|
||||
len1=snprintf(buf, sizeof(buf), "%ld,%-ld ",
|
||||
header.devmajor, header.devminor);
|
||||
} else {
|
||||
len1=snprintf(buf, sizeof(buf), "%d ", header.size);
|
||||
len1=snprintf(buf, sizeof(buf), "%lu ", (long)header.size);
|
||||
}
|
||||
/* Jump through some hoops to make the columns match up */
|
||||
for(;(len+len1)<31;len++)
|
||||
|
||||
@@ -24,22 +24,42 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
const char *basename_usage="basename FILE [SUFFIX]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nStrips directory path and suffixes from FILE.\n"
|
||||
"If specified, also removes any trailing SUFFIX.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
extern int basename_main(int argc, char **argv)
|
||||
{
|
||||
char* s, *s1;
|
||||
int m, n;
|
||||
char *s, *s1;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage("basename [file ...]\n");
|
||||
usage(basename_usage);
|
||||
}
|
||||
|
||||
argv++;
|
||||
|
||||
s1=*argv+strlen(*argv)-1;
|
||||
while (s1 && *s1 == '/') {
|
||||
*s1 = '\0';
|
||||
s1=*argv+strlen(*argv)-1;
|
||||
s1--;
|
||||
}
|
||||
s = strrchr(*argv, '/');
|
||||
printf("%s\n", (s)? s + 1 : *argv);
|
||||
exit(TRUE);
|
||||
if (s==NULL) s=*argv;
|
||||
else s++;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -30,14 +30,15 @@ int atexit(void (*__func) (void))
|
||||
void *__libc_stack_end;
|
||||
#endif
|
||||
|
||||
static const struct Applet applets[] = {
|
||||
const struct BB_applet applets[] = {
|
||||
|
||||
#ifdef BB_AR
|
||||
{"ar", ar_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_BASENAME
|
||||
{"basename", basename_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_BUSYBOX
|
||||
{"busybox", busybox_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_BLOCK_DEVICE
|
||||
{"block_device", block_device_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
@@ -65,9 +66,15 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_CP_MV
|
||||
{"cp", cp_mv_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_CUT
|
||||
{"cut", cut_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DATE
|
||||
{"date", date_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DC
|
||||
{"dc", dc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_DD
|
||||
{"dd", dd_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
@@ -134,6 +141,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_HOSTNAME
|
||||
{"hostname", hostname_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_ID
|
||||
{"id", id_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_INIT
|
||||
{"init", init_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
@@ -179,8 +189,8 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_MAKEDEVS
|
||||
{"makedevs", makedevs_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_MATH
|
||||
{"math", math_main, _BB_DIR_USR_BIN},
|
||||
#ifdef BB_MD5SUM
|
||||
{"md5sum", md5sum_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MKDIR
|
||||
{"mkdir", mkdir_main, _BB_DIR_BIN},
|
||||
@@ -197,8 +207,11 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_MKSWAP
|
||||
{"mkswap", mkswap_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_MNC
|
||||
{"mnc", mnc_main, _BB_DIR_USR_BIN},
|
||||
#ifdef BB_MKTEMP
|
||||
{"mktemp", mktemp_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_NC
|
||||
{"nc", nc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_MORE
|
||||
{"more", more_main, _BB_DIR_BIN},
|
||||
@@ -245,12 +258,15 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_SED
|
||||
{"sed", sed_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SH
|
||||
{"sh", shell_main, _BB_DIR_BIN},
|
||||
#ifdef BB_SETKEYCODES
|
||||
{"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SFDISK
|
||||
{"sfdisk", sfdisk_main, _BB_DIR_SBIN},
|
||||
#endif
|
||||
#ifdef BB_SH
|
||||
{"sh", shell_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_SLEEP
|
||||
{"sleep", sleep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
@@ -311,12 +327,21 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_UPTIME
|
||||
{"uptime", uptime_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UUENCODE
|
||||
{"uuencode", uuencode_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_UUDECODE
|
||||
{"uudecode", uudecode_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_USLEEP
|
||||
{"usleep", usleep_main, _BB_DIR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WC
|
||||
{"wc", wc_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WHICH
|
||||
{"which", which_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
#ifdef BB_WHOAMI
|
||||
{"whoami", whoami_main, _BB_DIR_USR_BIN},
|
||||
#endif
|
||||
@@ -338,7 +363,7 @@ int main(int argc, char **argv)
|
||||
{
|
||||
char *s;
|
||||
char *name;
|
||||
const struct Applet *a = applets;
|
||||
const struct BB_applet *a = applets;
|
||||
|
||||
for (s = name = argv[0]; *s != '\0';) {
|
||||
if (*s++ == '/')
|
||||
@@ -349,18 +374,11 @@ int main(int argc, char **argv)
|
||||
|
||||
while (a->name != 0) {
|
||||
if (strcmp(name, a->name) == 0) {
|
||||
int status;
|
||||
|
||||
status = ((*(a->main)) (argc, argv));
|
||||
if (status < 0) {
|
||||
fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
exit(status);
|
||||
exit(((*(a->main)) (argc, argv)));
|
||||
}
|
||||
a++;
|
||||
}
|
||||
exit(busybox_main(argc, argv));
|
||||
return(busybox_main(argc, argv));
|
||||
}
|
||||
|
||||
|
||||
@@ -372,18 +390,16 @@ int busybox_main(int argc, char **argv)
|
||||
argv++;
|
||||
|
||||
if (been_there_done_that == 1 || argc < 1) {
|
||||
const struct Applet *a = applets;
|
||||
const struct BB_applet *a = applets;
|
||||
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
|
||||
BB_VER, BB_BT);
|
||||
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
|
||||
fprintf(stderr, " or: [function] [arguments]...\n\n");
|
||||
fprintf(stderr,
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n"
|
||||
"Usage: busybox [function] [arguments]...\n"
|
||||
" or: [function] [arguments]...\n\n"
|
||||
"\tBusyBox is a multi-call binary that combines many common Unix\n"
|
||||
"\tutilities into a single executable. Most people will create a\n"
|
||||
"\tlink to busybox for each function they wish to use, and BusyBox\n"
|
||||
"\twill act like whatever it was invoked as.\n");
|
||||
fprintf(stderr, "\nCurrently defined functions:\n");
|
||||
"\twill act like whatever it was invoked as.\n"
|
||||
"\nCurrently defined functions:\n", BB_VER, BB_BT);
|
||||
|
||||
while (a->name != 0) {
|
||||
col +=
|
||||
@@ -396,11 +412,10 @@ int busybox_main(int argc, char **argv)
|
||||
}
|
||||
fprintf(stderr, "\n\n");
|
||||
exit(-1);
|
||||
} else {
|
||||
/* If we've already been here once, exit now */
|
||||
been_there_done_that = 1;
|
||||
return (main(argc, argv));
|
||||
}
|
||||
/* If we've already been here once, exit now */
|
||||
been_there_done_that = 1;
|
||||
return (main(argc, argv));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
//
|
||||
//
|
||||
// BusyBox Applications
|
||||
#define BB_AR
|
||||
#define BB_BASENAME
|
||||
#define BB_CAT
|
||||
#define BB_CHMOD_CHOWN_CHGRP
|
||||
@@ -14,7 +15,9 @@
|
||||
#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
|
||||
@@ -36,9 +39,9 @@
|
||||
#define BB_HEAD
|
||||
#define BB_HOSTID
|
||||
#define BB_HOSTNAME
|
||||
#define BB_ID
|
||||
#define BB_INIT
|
||||
// Don't bother turning BB_INSMOD on. It doesn't work yet.
|
||||
//#define BB_INSMOD
|
||||
#define BB_INSMOD
|
||||
#define BB_KILL
|
||||
#define BB_KILLALL
|
||||
#define BB_KLOGD
|
||||
@@ -52,16 +55,16 @@
|
||||
#define BB_LS
|
||||
#define BB_LSMOD
|
||||
#define BB_MAKEDEVS
|
||||
#define BB_MKFS_MINIX
|
||||
#define BB_MATH
|
||||
//#define BB_MD5SUM
|
||||
#define BB_MKDIR
|
||||
#define BB_MKFIFO
|
||||
#define BB_MKFS_MINIX
|
||||
#define BB_MKNOD
|
||||
#define BB_MKSWAP
|
||||
#define BB_MNC
|
||||
#define BB_MKTEMP
|
||||
#define BB_NC
|
||||
#define BB_MORE
|
||||
#define BB_MOUNT
|
||||
#define BB_NFSMOUNT
|
||||
#define BB_MT
|
||||
#define BB_NSLOOKUP
|
||||
#define BB_PING
|
||||
@@ -74,6 +77,7 @@
|
||||
#define BB_RMDIR
|
||||
#define BB_RMMOD
|
||||
#define BB_SED
|
||||
#define BB_SETKEYCODES
|
||||
#define BB_SFDISK
|
||||
#define BB_SH
|
||||
#define BB_SLEEP
|
||||
@@ -85,8 +89,7 @@
|
||||
#define BB_TAR
|
||||
#define BB_TEE
|
||||
#define BB_TEST
|
||||
// Don't bother turning BB_TELNET on. It doesn't work properly yet.
|
||||
//#define BB_TELNET
|
||||
#define BB_TELNET
|
||||
#define BB_TOUCH
|
||||
#define BB_TR
|
||||
#define BB_TRUE_FALSE
|
||||
@@ -94,7 +97,10 @@
|
||||
#define BB_UPTIME
|
||||
#define BB_USLEEP
|
||||
#define BB_WC
|
||||
#define BB_WHICH
|
||||
#define BB_WHOAMI
|
||||
#define BB_UUENCODE
|
||||
#define BB_UUDECODE
|
||||
#define BB_UMOUNT
|
||||
#define BB_UNIQ
|
||||
#define BB_UNAME
|
||||
@@ -130,8 +136,9 @@
|
||||
// normal strings.
|
||||
#define BB_FEATURE_FULL_REGULAR_EXPRESSIONS
|
||||
//
|
||||
// Use only simple command help
|
||||
#define BB_FEATURE_TRIVIAL_HELP
|
||||
// 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
|
||||
@@ -148,6 +155,9 @@
|
||||
// enable ls -p and -F
|
||||
#define BB_FEATURE_LS_FILETYPES
|
||||
//
|
||||
// enable ls -R
|
||||
#define BB_FEATURE_LS_RECURSIVE
|
||||
//
|
||||
// Change ping implementation -- simplified, featureless, but really small.
|
||||
//#define BB_SIMPLE_PING
|
||||
//
|
||||
@@ -178,8 +188,13 @@
|
||||
// Enable support for a real /etc/mtab file instead of /proc/mounts
|
||||
//#define BB_FEATURE_MOUNT_MTAB_SUPPORT
|
||||
//
|
||||
// Enable support for remounting filesystems
|
||||
#define BB_FEATURE_REMOUNT
|
||||
// Enable support forced filesystem unmounting
|
||||
// (i.e. in case of an unreachable NFS system).
|
||||
#define BB_FEATURE_MOUNT_FORCE
|
||||
//
|
||||
// Enable support for mounting remote NFS volumes
|
||||
// (This does not yet work with Linux 2.[34].x kernels)
|
||||
//#define BB_FEATURE_NFSMOUNT
|
||||
//
|
||||
// Enable support for creation of tar files.
|
||||
#define BB_FEATURE_TAR_CREATE
|
||||
@@ -193,6 +208,11 @@
|
||||
// Enable command line editing in the shell
|
||||
#define BB_FEATURE_SH_COMMAND_EDITING
|
||||
//
|
||||
//Allow the shell to invoke all the compiled in BusyBox commands as if they
|
||||
//were shell builtins. Nice for staticly linking an emergency rescue shell
|
||||
//amoung other thing.
|
||||
#define BB_FEATURE_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
|
||||
@@ -200,6 +220,15 @@
|
||||
//Turn on extra fbset options
|
||||
//#define BB_FEATURE_FBSET_FANCY
|
||||
//
|
||||
// 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
|
||||
//
|
||||
//
|
||||
// End of Features List
|
||||
//
|
||||
@@ -243,3 +272,24 @@
|
||||
#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,5 +1,5 @@
|
||||
Name: busybox
|
||||
Version: 0.43
|
||||
Version: 0.45
|
||||
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}
|
||||
|
||||
@@ -45,7 +45,11 @@ extern int cat_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (**(argv + 1) == '-') {
|
||||
usage("cat [file ...]\n");
|
||||
usage("cat [FILE ...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nConcatenates FILE(s) and prints them to the standard output.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
argc--;
|
||||
|
||||
@@ -57,7 +61,7 @@ extern int cat_main(int argc, char **argv)
|
||||
}
|
||||
print_file(file);
|
||||
}
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "internal.h"
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_invalid_option
|
||||
#define bb_need_too_few_args
|
||||
#include "messages.c"
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -32,8 +33,8 @@
|
||||
#include <pwd.h>
|
||||
|
||||
|
||||
static uid_t uid = -1;
|
||||
static gid_t gid = -1;
|
||||
static unsigned long uid = -1;
|
||||
static unsigned long gid = -1;
|
||||
static int whichApp;
|
||||
static char *invocationName = NULL;
|
||||
static char *theMode = NULL;
|
||||
@@ -43,21 +44,27 @@ static char *theMode = NULL;
|
||||
#define CHOWN_APP 2
|
||||
#define CHMOD_APP 3
|
||||
|
||||
static const char chgrp_usage[] = "chgrp [OPTION]... GROUP FILE...\n\n"
|
||||
"Change the group membership of each FILE to GROUP.\n"
|
||||
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively\n";
|
||||
static const char chgrp_usage[] = "chgrp [OPTION]... GROUP FILE...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nChange the group membership of each FILE to GROUP.\n"
|
||||
"\nOptions:\n\t-R\tChanges files and directories recursively.\n"
|
||||
#endif
|
||||
;
|
||||
static const char chown_usage[] =
|
||||
"chown [OPTION]... OWNER[<.|:>[GROUP] FILE...\n\n"
|
||||
"Change the owner and/or group of each FILE to OWNER and/or GROUP.\n"
|
||||
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively\n";
|
||||
"chown [OPTION]... OWNER[<.|:>[GROUP] FILE...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nChange the owner and/or group of each FILE to OWNER and/or GROUP.\n"
|
||||
"\nOptions:\n\t-R\tChanges files and directories recursively.\n"
|
||||
#endif
|
||||
;
|
||||
static const char chmod_usage[] =
|
||||
"chmod [-R] MODE[,MODE]... FILE...\n\n"
|
||||
"Each MODE is one or more of the letters ugoa, one of the symbols +-= and\n"
|
||||
|
||||
"chmod [-R] MODE[,MODE]... FILE...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nEach MODE is one or more of the letters ugoa, one of the symbols +-= and\n"
|
||||
"one or more of the letters rwxst.\n\n"
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively.\n";
|
||||
"\nOptions:\n\t-R\tChanges files and directories recursively.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
@@ -94,8 +101,8 @@ static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
int chmod_chown_chgrp_main(int argc, char **argv)
|
||||
{
|
||||
int recursiveFlag = FALSE;
|
||||
char *groupName;
|
||||
char *p;
|
||||
char *groupName=NULL;
|
||||
char *p=NULL;
|
||||
const char *appUsage;
|
||||
|
||||
whichApp = (strcmp(*argv, "chown") == 0)?
|
||||
@@ -108,24 +115,28 @@ int chmod_chown_chgrp_main(int argc, char **argv)
|
||||
if (argc < 2)
|
||||
usage(appUsage);
|
||||
invocationName = *argv;
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
while (--argc >= 0 && *argv && (**argv == '-')) {
|
||||
while (*++(*argv)) {
|
||||
switch (**argv) {
|
||||
case 'R':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, invalid_option, invocationName, **argv);
|
||||
usage(appUsage);
|
||||
case 'R':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, invalid_option, invocationName, **argv);
|
||||
usage(appUsage);
|
||||
}
|
||||
argc--;
|
||||
}
|
||||
argv++;
|
||||
}
|
||||
|
||||
if (argc == 0 || *argv == NULL) {
|
||||
fprintf(stderr, too_few_args, invocationName);
|
||||
usage(appUsage);
|
||||
}
|
||||
|
||||
if (whichApp == CHMOD_APP) {
|
||||
theMode = *argv;
|
||||
} else {
|
||||
|
||||
@@ -28,14 +28,18 @@
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n\n"
|
||||
|
||||
"Run COMMAND with root directory set to NEWROOT.\n";
|
||||
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nRun COMMAND with root directory set to NEWROOT.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
int chroot_main(int argc, char **argv)
|
||||
{
|
||||
char *prog;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage(chroot_usage);
|
||||
}
|
||||
@@ -43,27 +47,24 @@ int chroot_main(int argc, char **argv)
|
||||
argv++;
|
||||
|
||||
if (chroot(*argv) || (chdir("/"))) {
|
||||
fprintf(stderr, "chroot: cannot change root directory to %s: %s\n",
|
||||
fatalError("chroot: cannot change root directory to %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc >= 1) {
|
||||
fprintf(stderr, "command: %s\n", *argv);
|
||||
prog = *argv;
|
||||
execvp(*argv, argv);
|
||||
} else {
|
||||
char *prog;
|
||||
|
||||
prog = getenv("SHELL");
|
||||
if (!prog)
|
||||
prog = "/bin/sh";
|
||||
execlp(prog, prog, NULL);
|
||||
}
|
||||
fprintf(stderr, "chroot: cannot execute %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit(FALSE);
|
||||
fatalError("chroot: cannot execute %s: %s\n",
|
||||
prog, strerror(errno));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,15 +12,16 @@
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
extern int getfd(void);
|
||||
|
||||
int chvt_main(int argc, char **argv)
|
||||
{
|
||||
int fd, num;
|
||||
|
||||
if ((argc != 2) || (**(argv + 1) == '-')) {
|
||||
usage
|
||||
("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
|
||||
usage ("chvt N\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nChanges the foreground virtual terminal to /dev/ttyN\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
fd = get_console_fd("/dev/console");
|
||||
num = atoi(argv[1]);
|
||||
@@ -32,7 +33,7 @@ int chvt_main(int argc, char **argv)
|
||||
perror("VT_WAITACTIVE");
|
||||
exit(FALSE);
|
||||
}
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,5 +29,5 @@
|
||||
extern int clear_main(int argc, char **argv)
|
||||
{
|
||||
printf("\033[H\033[J");
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -39,7 +39,7 @@
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <termio.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <ctype.h>
|
||||
#include <signal.h>
|
||||
|
||||
@@ -53,7 +53,32 @@
|
||||
|
||||
static struct history *his_front = NULL; /* First element in command line list */
|
||||
static struct history *his_end = NULL; /* Last element in command line list */
|
||||
static struct termio old_term, new_term; /* Current termio and the previous termio before starting ash */
|
||||
|
||||
/* 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 */
|
||||
@@ -84,14 +109,15 @@ void cmdedit_reset_term(void)
|
||||
{
|
||||
if (reset_term)
|
||||
/* sparc and other have broken termios support: use old termio handling. */
|
||||
ioctl(fileno(stdin), TCSETA, (void *) &old_term);
|
||||
setTermSettings(fileno(stdin), (void*) &initial_settings);
|
||||
}
|
||||
|
||||
void clean_up_and_die(int sig)
|
||||
{
|
||||
cmdedit_reset_term();
|
||||
fprintf(stdout, "\n");
|
||||
exit(TRUE);
|
||||
if (sig!=SIGINT)
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/* Go to HOME position */
|
||||
@@ -233,7 +259,7 @@ char** exe_n_cwd_tab_completion(char* command, int *num_matches)
|
||||
return (matches);
|
||||
}
|
||||
|
||||
void input_tab(char* command, int outputFd, int *cursor, int *len)
|
||||
void input_tab(char* command, char* prompt, int outputFd, int *cursor, int *len)
|
||||
{
|
||||
/* Do TAB completion */
|
||||
static int num_matches=0;
|
||||
@@ -246,7 +272,7 @@ void input_tab(char* command, int outputFd, int *cursor, int *len)
|
||||
|
||||
/* For now, we will not bother with trying to distinguish
|
||||
* whether the cursor is in/at a command extression -- we
|
||||
* will always try all possable matches. If you don't like
|
||||
* will always try all possible matches. If you don't like
|
||||
* that then feel free to fix it.
|
||||
*/
|
||||
|
||||
@@ -379,19 +405,17 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
|
||||
|
||||
memset(command, 0, sizeof(command));
|
||||
if (!reset_term) {
|
||||
/* sparc and other have broken termios support: use old termio handling. */
|
||||
ioctl(inputFd, TCGETA, (void *) &old_term);
|
||||
memcpy(&new_term, &old_term, sizeof(struct termio));
|
||||
|
||||
new_term.c_cc[VMIN] = 1;
|
||||
new_term.c_cc[VTIME] = 0;
|
||||
new_term.c_lflag &= ~ICANON; /* unbuffered input */
|
||||
new_term.c_lflag &= ~ECHO;
|
||||
|
||||
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;
|
||||
ioctl(inputFd, TCSETA, (void *) &new_term);
|
||||
} else {
|
||||
ioctl(inputFd, TCSETA, (void *) &new_term);
|
||||
}
|
||||
setTermSettings(inputFd, (void*) &new_settings);
|
||||
|
||||
memset(command, 0, BUFSIZ);
|
||||
|
||||
@@ -399,6 +423,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
|
||||
|
||||
if ((ret = read(inputFd, &c, 1)) < 1)
|
||||
return;
|
||||
//fprintf(stderr, "got a '%c' (%d)\n", c, c);
|
||||
|
||||
switch (c) {
|
||||
case '\n':
|
||||
@@ -414,6 +439,21 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
|
||||
case 2:
|
||||
/* Control-b -- Move back one character */
|
||||
input_backward(outputFd, &cursor);
|
||||
break;
|
||||
case 3:
|
||||
/* Control-c -- leave the current line,
|
||||
* and start over on the next line */
|
||||
|
||||
/* Go to the next line */
|
||||
xwrite(outputFd, "\n", 1);
|
||||
|
||||
/* Rewrite the prompt */
|
||||
xwrite(outputFd, prompt, strlen(prompt));
|
||||
|
||||
/* Reset the command string */
|
||||
memset(command, 0, sizeof(command));
|
||||
len = cursor = 0;
|
||||
|
||||
break;
|
||||
case 4:
|
||||
/* Control-d -- Delete one character, or exit
|
||||
@@ -435,12 +475,12 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
|
||||
break;
|
||||
case '\b':
|
||||
case DEL:
|
||||
/* control-h and DEL */
|
||||
/* Control-h and DEL */
|
||||
input_backspace(command, outputFd, &cursor, &len);
|
||||
break;
|
||||
case '\t':
|
||||
#ifdef BB_FEATURE_SH_TAB_COMPLETION
|
||||
input_tab(command, outputFd, &cursor, &len);
|
||||
input_tab(command, prompt, outputFd, &cursor, &len);
|
||||
#endif
|
||||
break;
|
||||
case 14:
|
||||
@@ -591,8 +631,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
|
||||
}
|
||||
|
||||
nr = len + 1;
|
||||
/* sparc and other have broken termios support: use old termio handling. */
|
||||
ioctl(inputFd, TCSETA, (void *) &old_term);
|
||||
setTermSettings(inputFd, (void *) &initial_settings);
|
||||
reset_term = 0;
|
||||
|
||||
|
||||
@@ -644,6 +683,7 @@ extern void cmdedit_read_input(char* prompt, char command[BUFSIZ])
|
||||
extern void cmdedit_init(void)
|
||||
{
|
||||
atexit(cmdedit_reset_term);
|
||||
signal(SIGKILL, clean_up_and_die);
|
||||
signal(SIGINT, clean_up_and_die);
|
||||
signal(SIGQUIT, clean_up_and_die);
|
||||
signal(SIGTERM, clean_up_and_die);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
typedef size_t (*cmdedit_strwidth_proc)(char *);
|
||||
|
||||
void cmdedit_init(void);
|
||||
void cmdedit_read_input(char* promptStr, char* command); /* read a line of input */
|
||||
void cmdedit_setwidth(int); /* specify width of screen */
|
||||
void cmdedit_histadd(char *); /* adds entries to hist */
|
||||
@@ -21,6 +22,7 @@ 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();
|
||||
|
||||
@@ -12,15 +12,16 @@
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
extern int getfd(void);
|
||||
|
||||
int chvt_main(int argc, char **argv)
|
||||
{
|
||||
int fd, num;
|
||||
|
||||
if ((argc != 2) || (**(argv + 1) == '-')) {
|
||||
usage
|
||||
("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
|
||||
usage ("chvt N\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nChanges the foreground virtual terminal to /dev/ttyN\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
fd = get_console_fd("/dev/console");
|
||||
num = atoi(argv[1]);
|
||||
@@ -32,7 +33,7 @@ int chvt_main(int argc, char **argv)
|
||||
perror("VT_WAITACTIVE");
|
||||
exit(FALSE);
|
||||
}
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,5 +29,5 @@
|
||||
extern int clear_main(int argc, char **argv)
|
||||
{
|
||||
printf("\033[H\033[J");
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <linux/vt.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern int getfd(void);
|
||||
char *progname;
|
||||
|
||||
int deallocvt_main(int argc, char *argv[])
|
||||
@@ -20,7 +19,11 @@ int deallocvt_main(int argc, char *argv[])
|
||||
|
||||
if ((argc != 2) || (**(argv + 1) == '-')) {
|
||||
usage
|
||||
("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
|
||||
("deallocvt N\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nDeallocate unused virtual terminal /dev/ttyN\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
progname = argv[0];
|
||||
@@ -31,7 +34,7 @@ int deallocvt_main(int argc, char *argv[])
|
||||
/* deallocate all unused consoles */
|
||||
if (ioctl(fd, VT_DISALLOCATE, 0)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
exit(1);
|
||||
exit( FALSE);
|
||||
}
|
||||
} else
|
||||
for (i = 1; i < argc; i++) {
|
||||
@@ -45,8 +48,8 @@ int deallocvt_main(int argc, char *argv[])
|
||||
perror("VT_DISALLOCATE");
|
||||
fprintf(stderr, "%s: could not deallocate console %d\n",
|
||||
progname, num);
|
||||
exit(1);
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
return( TRUE);
|
||||
}
|
||||
@@ -22,8 +22,11 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/kd.h>
|
||||
|
||||
static const char loadacm_usage[] = "loadacm\n\n"
|
||||
"Loads an acm from standard input.\n";
|
||||
static const char loadacm_usage[] = "loadacm\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nLoads an acm from standard input.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
typedef unsigned short unicode;
|
||||
|
||||
@@ -137,10 +140,9 @@ int screen_map_load(int fd, FILE * fp)
|
||||
perror("PIO_SCRNMAP ioctl"), exit(1);
|
||||
else
|
||||
return 0;
|
||||
} else {
|
||||
fprintf(stderr, "Error parsing symbolic map\n");
|
||||
exit(1);
|
||||
}
|
||||
fprintf(stderr, "Error parsing symbolic map\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,8 +30,11 @@
|
||||
#define PSF_MAXMODE 0x03
|
||||
#define PSF_SEPARATOR 0xFFFF
|
||||
|
||||
static const char loadfont_usage[] = "loadfont\n\n"
|
||||
"Loads a console font from standard input.\n";
|
||||
static const char loadfont_usage[] = "loadfont\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"Loads a console font from standard input.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
struct psf_header {
|
||||
unsigned char magic1, magic2; /* Magic number */
|
||||
|
||||
@@ -29,8 +29,11 @@
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
|
||||
static const char loadkmap_usage[] = "loadkmap\n\n"
|
||||
"Loads a binary keyboard translation table from standard input.\n";
|
||||
static const char loadkmap_usage[] = "loadkmap\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"Loads a binary keyboard translation table from standard input.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
int loadkmap_main(int argc, char **argv)
|
||||
@@ -91,5 +94,5 @@ int loadkmap_main(int argc, char **argv)
|
||||
/* Don't bother to close files. Exit does that
|
||||
* automagically, so we can save a few bytes */
|
||||
/* close(fd); */
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* setkeycodes
|
||||
*
|
||||
* Copyright (C) 1994-1998 Andries E. Brouwer <aeb@cwi.nl>
|
||||
*
|
||||
* Adjusted for BusyBox by Erik Andersen <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/kd.h>
|
||||
|
||||
static const char setkeycodes_usage[] =
|
||||
"setkeycodes SCANCODE KEYCODE ...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nSet entries into the kernel's scancode-to-keycode map,\n"
|
||||
"allowing unusual keyboards to generate usable keycodes.\n\n"
|
||||
"SCANCODE may be either xx or e0xx (hexadecimal),\n"
|
||||
"and KEYCODE is given in decimal\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int
|
||||
setkeycodes_main(int argc, char** argv)
|
||||
{
|
||||
char *ep;
|
||||
int fd, sc;
|
||||
struct kbkeycode a;
|
||||
|
||||
if (argc % 2 != 1 || argc < 2) {
|
||||
usage(setkeycodes_usage);
|
||||
}
|
||||
|
||||
fd = get_console_fd("/dev/console");
|
||||
|
||||
while (argc > 2) {
|
||||
a.keycode = atoi(argv[2]);
|
||||
a.scancode = sc = strtol(argv[1], &ep, 16);
|
||||
if (*ep) {
|
||||
fatalError("error reading SCANCODE: '%s'\n", argv[1]);
|
||||
}
|
||||
if (a.scancode > 127) {
|
||||
a.scancode -= 0xe000;
|
||||
a.scancode += 128;
|
||||
}
|
||||
if (a.scancode > 255 || a.keycode > 127) {
|
||||
fatalError("SCANCODE or KEYCODE outside bounds\n");
|
||||
}
|
||||
if (ioctl(fd,KDSETKEYCODE,&a)) {
|
||||
perror("KDSETKEYCODE");
|
||||
fatalError("failed to set SCANCODE %x to KEYCODE %d\n", sc, a.keycode);
|
||||
}
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
}
|
||||
return( TRUE);
|
||||
}
|
||||
@@ -24,22 +24,42 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
const char *basename_usage="basename FILE [SUFFIX]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nStrips directory path and suffixes from FILE.\n"
|
||||
"If specified, also removes any trailing SUFFIX.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
extern int basename_main(int argc, char **argv)
|
||||
{
|
||||
char* s, *s1;
|
||||
int m, n;
|
||||
char *s, *s1;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage("basename [file ...]\n");
|
||||
usage(basename_usage);
|
||||
}
|
||||
|
||||
argv++;
|
||||
|
||||
s1=*argv+strlen(*argv)-1;
|
||||
while (s1 && *s1 == '/') {
|
||||
*s1 = '\0';
|
||||
s1=*argv+strlen(*argv)-1;
|
||||
s1--;
|
||||
}
|
||||
s = strrchr(*argv, '/');
|
||||
printf("%s\n", (s)? s + 1 : *argv);
|
||||
exit(TRUE);
|
||||
if (s==NULL) s=*argv;
|
||||
else s++;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -45,7 +45,11 @@ extern int cat_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (**(argv + 1) == '-') {
|
||||
usage("cat [file ...]\n");
|
||||
usage("cat [FILE ...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nConcatenates FILE(s) and prints them to the standard output.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
argc--;
|
||||
|
||||
@@ -57,7 +61,7 @@ extern int cat_main(int argc, char **argv)
|
||||
}
|
||||
print_file(file);
|
||||
}
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -28,14 +28,18 @@
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n\n"
|
||||
|
||||
"Run COMMAND with root directory set to NEWROOT.\n";
|
||||
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nRun COMMAND with root directory set to NEWROOT.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
int chroot_main(int argc, char **argv)
|
||||
{
|
||||
char *prog;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage(chroot_usage);
|
||||
}
|
||||
@@ -43,27 +47,24 @@ int chroot_main(int argc, char **argv)
|
||||
argv++;
|
||||
|
||||
if (chroot(*argv) || (chdir("/"))) {
|
||||
fprintf(stderr, "chroot: cannot change root directory to %s: %s\n",
|
||||
fatalError("chroot: cannot change root directory to %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc >= 1) {
|
||||
fprintf(stderr, "command: %s\n", *argv);
|
||||
prog = *argv;
|
||||
execvp(*argv, argv);
|
||||
} else {
|
||||
char *prog;
|
||||
|
||||
prog = getenv("SHELL");
|
||||
if (!prog)
|
||||
prog = "/bin/sh";
|
||||
execlp(prog, prog, NULL);
|
||||
}
|
||||
fprintf(stderr, "chroot: cannot execute %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit(FALSE);
|
||||
fatalError("chroot: cannot execute %s: %s\n",
|
||||
prog, strerror(errno));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,372 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* cut implementation for busybox
|
||||
*
|
||||
* Copyright (c) Michael J. Holme
|
||||
*
|
||||
* This version of cut is adapted from Minix cut and was modified
|
||||
* by Erik Andersen <andersee@debian.org> to be used in busybox.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Original copyright notice is retained at the end of this file.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <sys/types.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_help
|
||||
#include "messages.c"
|
||||
|
||||
#define MAX_FIELD 80 /* Pointers to the beginning of each field
|
||||
* are stored in columns[], if a line holds
|
||||
* more than MAX_FIELD columns the array
|
||||
* boundary is exceed. But unlikely at 80 */
|
||||
|
||||
#define MAX_ARGS 32 /* Maximum number of fields following -f or
|
||||
* -c switches */
|
||||
int args[MAX_ARGS * 2];
|
||||
int num_args;
|
||||
|
||||
/* Lots of new defines, should easen maintainance... */
|
||||
#define DUMP_STDIN 0 /* define for mode: no options */
|
||||
#define OPTIONF 1 /* define for mode: option -f */
|
||||
#define OPTIONC 2 /* define for mode: option -c */
|
||||
#define OPTIONB 3 /* define for mode: option -b */
|
||||
#define NOTSET 0 /* option not selected */
|
||||
#define SET 1 /* option selected */
|
||||
|
||||
/* Defines for the warnings */
|
||||
#define DELIMITER_NOT_APPLICABLE 0
|
||||
#define OVERRIDING_PREVIOUS_MODE 1
|
||||
#define OPTION_NOT_APPLICABLE 2
|
||||
#define UNKNOWN_OPTION 3
|
||||
#define FILE_NOT_READABLE 4
|
||||
|
||||
/* Defines for the fatal errors */
|
||||
#define SYNTAX_ERROR 101
|
||||
#define POSITION_ERROR 102
|
||||
#define LINE_TO_LONG_ERROR 103
|
||||
#define RANGE_ERROR 104
|
||||
#define MAX_FIELDS_EXEEDED_ERROR 105
|
||||
#define MAX_ARGS_EXEEDED_ERROR 106
|
||||
|
||||
|
||||
int mode; /* 0 = dump stdin to stdout, 1=-f, 2=-c */
|
||||
char delim = '\t'; /* default delimiting character */
|
||||
FILE *fd;
|
||||
char *name;
|
||||
char line[BUFSIZ];
|
||||
int exit_status;
|
||||
|
||||
int cut_main(int argc, char **argv);
|
||||
void warn(int warn_number, char *option);
|
||||
void cuterror(int err);
|
||||
void get_args(void);
|
||||
void cut(void);
|
||||
|
||||
void warn(int warn_number, char *option)
|
||||
{
|
||||
static char *warn_msg[] = {
|
||||
"%s: Option -d allowed only with -f\n",
|
||||
"%s: -%s overrides earlier option\n",
|
||||
"%s: -%s not allowed in current mode\n",
|
||||
"%s: Cannot open %s\n"
|
||||
};
|
||||
|
||||
fprintf(stderr, warn_msg[warn_number], name, option);
|
||||
exit_status = warn_number + 1;
|
||||
|
||||
}
|
||||
|
||||
void cuterror(int err)
|
||||
{
|
||||
static char *err_mes[] = {
|
||||
"%s: syntax error\n",
|
||||
"%s: position must be >0\n",
|
||||
"%s: line longer than BUFSIZ\n",
|
||||
"%s: range must not decrease from left to right\n",
|
||||
"%s: MAX_FIELD exceeded\n",
|
||||
"%s: MAX_ARGS exceeded\n"
|
||||
};
|
||||
|
||||
fprintf(stderr, err_mes[err - 101], name);
|
||||
exit(err);
|
||||
}
|
||||
|
||||
|
||||
void get_args()
|
||||
{
|
||||
int i = 0;
|
||||
int arg_ptr = 0;
|
||||
int flag;
|
||||
|
||||
num_args = 0;
|
||||
do {
|
||||
if (num_args == MAX_ARGS)
|
||||
cuterror(MAX_ARGS_EXEEDED_ERROR);
|
||||
if (!isdigit(line[i]) && line[i] != '-')
|
||||
cuterror(SYNTAX_ERROR);
|
||||
|
||||
args[arg_ptr] = 1;
|
||||
args[arg_ptr + 1] = BUFSIZ;
|
||||
flag = 1;
|
||||
|
||||
while (line[i] != ',' && line[i] != 0) {
|
||||
if (isdigit(line[i])) {
|
||||
args[arg_ptr] = 0;
|
||||
while (isdigit(line[i]))
|
||||
args[arg_ptr] = 10 * args[arg_ptr] + line[i++] - '0';
|
||||
if (!args[arg_ptr])
|
||||
cuterror(POSITION_ERROR);
|
||||
arg_ptr++;
|
||||
}
|
||||
if (line[i] == '-') {
|
||||
arg_ptr |= 1;
|
||||
i++;
|
||||
flag = 0;
|
||||
}
|
||||
}
|
||||
if (flag && arg_ptr & 1)
|
||||
args[arg_ptr] = args[arg_ptr - 1];
|
||||
if (args[num_args * 2] > args[num_args * 2 + 1])
|
||||
cuterror(RANGE_ERROR);
|
||||
num_args++;
|
||||
arg_ptr = num_args * 2;
|
||||
}
|
||||
while (line[i++]);
|
||||
}
|
||||
|
||||
|
||||
void cut()
|
||||
{
|
||||
int i, j, length, maxcol=0;
|
||||
char *columns[MAX_FIELD];
|
||||
|
||||
while (fgets(line, BUFSIZ, fd)) {
|
||||
length = strlen(line) - 1;
|
||||
*(line + length) = 0;
|
||||
switch (mode) {
|
||||
case DUMP_STDIN:
|
||||
printf("%s", line);
|
||||
break;
|
||||
case OPTIONF:
|
||||
columns[maxcol++] = line;
|
||||
for (i = 0; i < length; i++) {
|
||||
if (*(line + i) == delim) {
|
||||
*(line + i) = 0;
|
||||
if (maxcol == MAX_FIELD)
|
||||
cuterror(MAX_FIELDS_EXEEDED_ERROR);
|
||||
columns[maxcol] = line + i + 1;
|
||||
maxcol++;
|
||||
}
|
||||
}
|
||||
if (maxcol != 1) {
|
||||
for (i = 0; i < num_args; i++) {
|
||||
for (j = args[i * 2]; j <= args[i * 2 + 1]; j++)
|
||||
if (j <= maxcol) {
|
||||
printf("%s", columns[j - 1]);
|
||||
if (i != num_args - 1 || j != args[i * 2 + 1])
|
||||
putchar(delim);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OPTIONC:
|
||||
for (i = 0; i < num_args; i++) {
|
||||
for (j = args[i * 2];
|
||||
j <= (args[i * 2 + 1] >
|
||||
length ? length : args[i * 2 + 1]); j++)
|
||||
putchar(*(line + j - 1));
|
||||
}
|
||||
}
|
||||
if (maxcol != 1)
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int cut_main(int argc, char **argv)
|
||||
{
|
||||
int i = 1;
|
||||
int numberFilenames = 0;
|
||||
|
||||
name = argv[0];
|
||||
|
||||
if (argc == 1 || strcmp(argv[1], dash_dash_help)==0)
|
||||
usage( "cut [OPTION]... [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrints selected fields from each input FILE to standard output.\n\n"
|
||||
"Options:\n"
|
||||
"\t-b LIST\tOutput only bytes from LIST\n"
|
||||
"\t-c LIST\tOutput only characters from LIST\n"
|
||||
"\t-d DELIM\tUse DELIM instead of tab as the field delimiter\n"
|
||||
"\t-f N\tPrint only these fields\n"
|
||||
"\t-n\tIgnored\n"
|
||||
#endif
|
||||
);
|
||||
|
||||
while (i < argc) {
|
||||
if (argv[i][0] == '-') {
|
||||
switch (argv[i++][1]) {
|
||||
case 'd':
|
||||
if (mode == OPTIONC || mode == OPTIONB)
|
||||
warn(DELIMITER_NOT_APPLICABLE, "d");
|
||||
delim = argv[i++][0];
|
||||
break;
|
||||
case 'f':
|
||||
sprintf(line, "%s", argv[i++]);
|
||||
if (mode == OPTIONC || mode == OPTIONB)
|
||||
warn(OVERRIDING_PREVIOUS_MODE, "f");
|
||||
mode = OPTIONF;
|
||||
break;
|
||||
case 'b':
|
||||
sprintf(line, "%s", argv[i++]);
|
||||
if (mode == OPTIONF || mode == OPTIONC)
|
||||
warn(OVERRIDING_PREVIOUS_MODE, "b");
|
||||
mode = OPTIONB;
|
||||
break;
|
||||
case 'c':
|
||||
sprintf(line, "%s", argv[i++]);
|
||||
if (mode == OPTIONF || mode == OPTIONB)
|
||||
warn(OVERRIDING_PREVIOUS_MODE, "c");
|
||||
mode = OPTIONC;
|
||||
break;
|
||||
case '\0': /* - means: read from stdin */
|
||||
numberFilenames++;
|
||||
break;
|
||||
case 'n': /* needed for Posix, but no effect here */
|
||||
if (mode != OPTIONB)
|
||||
warn(OPTION_NOT_APPLICABLE, "n");
|
||||
break;
|
||||
default:
|
||||
warn(UNKNOWN_OPTION, &(argv[i - 1][1]));
|
||||
}
|
||||
} else {
|
||||
i++;
|
||||
numberFilenames++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Here follow the checks, if the selected options are reasonable. */
|
||||
if (mode == OPTIONB) /* since in Minix char := byte */
|
||||
mode = OPTIONC;
|
||||
get_args();
|
||||
if (numberFilenames != 0) {
|
||||
i = 1;
|
||||
while (i < argc) {
|
||||
if (argv[i][0] == '-') {
|
||||
switch (argv[i][1]) {
|
||||
case 'f':
|
||||
case 'c':
|
||||
case 'b':
|
||||
case 'd':
|
||||
i += 2;
|
||||
break;
|
||||
case 'n':
|
||||
case 'i':
|
||||
case 's':
|
||||
i++;
|
||||
break;
|
||||
case '\0':
|
||||
fd = stdin;
|
||||
i++;
|
||||
cut();
|
||||
break;
|
||||
default:
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
if ((fd = fopen(argv[i++], "r")) == NULL) {
|
||||
warn(FILE_NOT_READABLE, argv[i - 1]);
|
||||
} else {
|
||||
cut();
|
||||
fclose(fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fd = stdin;
|
||||
cut();
|
||||
}
|
||||
|
||||
return(exit_status);
|
||||
}
|
||||
|
||||
/* cut - extract columns from a file or stdin. Author: Michael J. Holme
|
||||
*
|
||||
* Copyright 1989, Michael John Holme, All rights reserved.
|
||||
* This code may be freely distributed, provided that this notice
|
||||
* remains intact.
|
||||
*
|
||||
* V1.1: 6th September 1989
|
||||
*
|
||||
* Bugs, criticisms, etc,
|
||||
* c/o Mark Powell
|
||||
* JANET sq79@uk.ac.liv
|
||||
* ARPA sq79%liv.ac.uk@nsfnet-relay.ac.uk
|
||||
* UUCP ...!mcvax!ukc!liv.ac.uk!sq79
|
||||
*-------------------------------------------------------------------------
|
||||
* Changed for POSIX1003.2/Draft10 conformance
|
||||
* Thomas Brupbacher (tobr@mw.lpc.ethz.ch), September 1990.
|
||||
* Changes:
|
||||
* - separation of error messages ( stderr) and output (stdout).
|
||||
* - support for -b and -n (no effect, -b acts as -c)
|
||||
* - support for -s
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987,1997, Prentice Hall
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use of the MINIX operating system in source and
|
||||
* binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of Prentice Hall nor the names of the software
|
||||
* authors or contributors may be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND
|
||||
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL PRENTICE HALL OR ANY AUTHORS OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
@@ -40,12 +40,14 @@
|
||||
mail commands */
|
||||
|
||||
static const char date_usage[] = "date [OPTION]... [+FORMAT]\n"
|
||||
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n\n"
|
||||
"Display the current time in the given FORMAT, or set the system date.\n"
|
||||
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
|
||||
"\t-s\t\tset time described by STRING\n"
|
||||
|
||||
"\t-u\t\tprint or set Coordinated Universal Time\n";
|
||||
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nDisplays the current time in the given FORMAT, or sets the system date.\n"
|
||||
"\nOptions:\n\t-R\tOutputs RFC-822 compliant date string\n"
|
||||
"\t-s\tSets time described by STRING\n"
|
||||
"\t-u\tPrints or sets Coordinated Universal Time\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
/* Input parsing code is always bulky - used heavy duty libc stuff as
|
||||
@@ -179,18 +181,18 @@ int date_main(int argc, char **argv)
|
||||
set_time = 1;
|
||||
if (date_str != NULL)
|
||||
usage(date_usage);
|
||||
date_str = optarg;
|
||||
date_str = *argv;
|
||||
break;
|
||||
case 'u':
|
||||
utc = 1;
|
||||
if (putenv("TZ=UTC0") != 0)
|
||||
fatalError(memory_exhausted, "date");
|
||||
/* Look ma, no break. Don't fix it either. */
|
||||
break;
|
||||
case 'd':
|
||||
use_arg = 1;
|
||||
if (date_str != NULL)
|
||||
usage(date_usage);
|
||||
date_str = optarg;
|
||||
date_str = *argv;
|
||||
break;
|
||||
case '-':
|
||||
usage(date_usage);
|
||||
@@ -271,6 +273,5 @@ int date_main(int argc, char **argv)
|
||||
strftime(t_buff, 200, date_fmt, &tm_time);
|
||||
printf("%s\n", t_buff);
|
||||
|
||||
exit(TRUE);
|
||||
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -41,17 +41,19 @@ typedef unsigned long long int uintmax_t;
|
||||
#endif
|
||||
|
||||
static const char dd_usage[] =
|
||||
"dd [if=name] [of=name] [bs=n] [count=n] [skip=n] [seek=n]\n\n"
|
||||
"Copy a file, converting and formatting according to options\n\n"
|
||||
"dd [if=FILE] [of=FILE] [bs=N] [count=N] [skip=N] [seek=N]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCopy a file, converting and formatting according to options\n\n"
|
||||
"\tif=FILE\tread from FILE instead of stdin\n"
|
||||
"\tof=FILE\twrite to FILE instead of stdout\n"
|
||||
"\tbs=n\tread and write n bytes at a time\n"
|
||||
"\tcount=n\tcopy only n input blocks\n"
|
||||
"\tskip=n\tskip n input blocks\n"
|
||||
"\tseek=n\tskip n output blocks\n"
|
||||
|
||||
"\tbs=N\tread and write N bytes at a time\n"
|
||||
"\tcount=N\tcopy only N input blocks\n"
|
||||
"\tskip=N\tskip N input blocks\n"
|
||||
"\tseek=N\tskip N output blocks\n"
|
||||
"\n"
|
||||
"Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n";
|
||||
"Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -28,8 +28,11 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/vfs.h>
|
||||
|
||||
static const char df_usage[] = "df [filesystem ...]\n\n"
|
||||
"Print the filesystem space used and space available.\n";
|
||||
static const char df_usage[] = "df [filesystem ...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint the filesystem space used and space available.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern const char mtab_file[]; /* Defined in utility.c */
|
||||
|
||||
@@ -48,7 +51,6 @@ static int df(char *device, const char *mountPoint)
|
||||
blocks_used = s.f_blocks - s.f_bfree;
|
||||
blocks_percent_used = (long)
|
||||
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
|
||||
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
|
||||
if (strcmp(device, "/dev/root") == 0) {
|
||||
/* Adjusts device to be the real root device,
|
||||
* or leaves device alone if it can't find it */
|
||||
@@ -106,7 +108,7 @@ extern int df_main(int argc, char **argv)
|
||||
endmntent(mountTable);
|
||||
}
|
||||
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -28,7 +28,11 @@ extern int dirname_main(int argc, char **argv)
|
||||
char* s;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage("dirname [file ...]\n");
|
||||
usage("dirname [FILENAME ...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nStrips non-directory suffix from FILENAME\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
argv++;
|
||||
|
||||
@@ -41,5 +45,5 @@ extern int dirname_main(int argc, char **argv)
|
||||
if (s && *s)
|
||||
*s = '\0';
|
||||
printf("%s\n", (s)? *argv : ".");
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -32,17 +32,19 @@
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/param.h> /* for PATH_MAX */
|
||||
|
||||
typedef void (Display) (long, char *);
|
||||
|
||||
static const char du_usage[] =
|
||||
"du [OPTION]... [FILE]...\n\n"
|
||||
"Summarize disk space used for each FILE and/or directory.\n"
|
||||
"du [OPTION]... [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nSummarizes disk space used for each FILE and/or directory.\n"
|
||||
"Disk space is printed in units of 1024 bytes.\n\n"
|
||||
"Options:\n"
|
||||
"\t-l\tcount sizes many times if hard linked\n"
|
||||
"\t-s\tdisplay only a total for each argument\n";
|
||||
"\t-s\tdisplay only a total for each argument\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
static int du_depth = 0;
|
||||
static int count_hardlinks = 0;
|
||||
@@ -97,7 +99,7 @@ static long du(char *filename)
|
||||
filename[--len] = '\0';
|
||||
|
||||
while ((entry = readdir(dir))) {
|
||||
char newfile[PATH_MAX + 1];
|
||||
char newfile[BUFSIZ + 1];
|
||||
char *name = entry->d_name;
|
||||
|
||||
if ((strcmp(name, "..") == 0)
|
||||
@@ -105,7 +107,7 @@ static long du(char *filename)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (len + strlen(name) + 1 > PATH_MAX) {
|
||||
if (len + strlen(name) + 1 > BUFSIZ) {
|
||||
fprintf(stderr, name_too_long, "du");
|
||||
du_depth--;
|
||||
return 0;
|
||||
@@ -179,10 +181,10 @@ int du_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* $Id: du.c,v 1.17 2000/04/13 01:18:56 erik Exp $ */
|
||||
/* $Id: du.c,v 1.20 2000/06/19 17:25:39 andersen Exp $ */
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
|
||||
@@ -26,12 +26,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
static const char uname_usage[] =
|
||||
"echo [-neE] [ARG ...]\n\n"
|
||||
"Prints the specified ARGs to stdout\n\n"
|
||||
"echo [-neE] [ARG ...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrints the specified ARGs to stdout\n\n"
|
||||
"Options:\n"
|
||||
"\t-n\tsuppress trailing newline\n"
|
||||
"\t-e\tinterpret backslash-escaped characters (i.e. \\t=tab etc)\n"
|
||||
"\t-E\tdisable interpretation of backslash-escaped characters\n";
|
||||
"\t-E\tdisable interpretation of backslash-escaped characters\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int
|
||||
echo_main(int argc, char** argv)
|
||||
@@ -93,7 +96,7 @@ echo_main(int argc, char** argv)
|
||||
if (! nflag)
|
||||
putchar('\n');
|
||||
fflush(stdout);
|
||||
exit( 0);
|
||||
return( 0);
|
||||
}
|
||||
|
||||
/*-
|
||||
|
||||
@@ -27,12 +27,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
const char head_usage[] =
|
||||
"head [OPTION] [FILE]...\n\n"
|
||||
"Print first 10 lines of each FILE to standard output.\n"
|
||||
"head [OPTION] [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint first 10 lines of each FILE to standard output.\n"
|
||||
"With more than one FILE, precede each with a header giving the\n"
|
||||
"file name. With no FILE, or when FILE is -, read standard input.\n\n"
|
||||
|
||||
"Options:\n" "\t-n NUM\t\tPrint first NUM lines instead of first 10\n";
|
||||
"Options:\n" "\t-n NUM\t\tPrint first NUM lines instead of first 10\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
int head(int len, FILE * src)
|
||||
{
|
||||
@@ -106,7 +109,7 @@ int head_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* $Id: head.c,v 1.9 2000/04/13 01:18:56 erik Exp $ */
|
||||
/* $Id: head.c,v 1.11 2000/06/19 17:25:39 andersen Exp $ */
|
||||
@@ -26,5 +26,5 @@
|
||||
extern int hostid_main(int argc, char **argv)
|
||||
{
|
||||
printf("%lx\n", gethostid());
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini id implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2000 by Randolph Chung <tausq@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
static const char id_usage[] =
|
||||
"id [OPTIONS]... [USERNAME]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint information for USERNAME or the current user\n\n"
|
||||
"Options:\n"
|
||||
"\t-g\tprints only the group ID\n"
|
||||
"\t-u\tprints only the user ID\n"
|
||||
"\t-r\tprints the real user ID instead of the effective ID (with -ug)\n\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int id_main(int argc, char **argv)
|
||||
{
|
||||
int no_user = 0, no_group = 0, print_real = 0;
|
||||
char *cp, *user, *group;
|
||||
unsigned long gid;
|
||||
|
||||
cp = user = group = NULL;
|
||||
|
||||
argc--; argv++;
|
||||
|
||||
while (argc > 0) {
|
||||
cp = *argv;
|
||||
if (*cp == '-') {
|
||||
switch (*++cp) {
|
||||
case 'u': no_group = 1; break;
|
||||
case 'g': no_user = 1; break;
|
||||
case 'r': print_real = 1; break;
|
||||
default: usage(id_usage);
|
||||
}
|
||||
} else {
|
||||
user = cp;
|
||||
}
|
||||
argc--; argv++;
|
||||
}
|
||||
|
||||
if (no_user && no_group) usage(id_usage);
|
||||
|
||||
if (user == NULL) {
|
||||
user = xmalloc(9);
|
||||
group = xmalloc(9);
|
||||
if (print_real) {
|
||||
my_getpwuid(user, getuid());
|
||||
my_getgrgid(group, getgid());
|
||||
} else {
|
||||
my_getpwuid(user, geteuid());
|
||||
my_getgrgid(group, getegid());
|
||||
}
|
||||
} else {
|
||||
group = xmalloc(9);
|
||||
gid = my_getpwnamegid(user);
|
||||
my_getgrgid(group, gid);
|
||||
}
|
||||
|
||||
if (no_group) printf("%lu\n", my_getpwnam(user));
|
||||
else if (no_user) printf("%lu\n", my_getgrnam(group));
|
||||
else
|
||||
printf("uid=%lu(%s) gid=%lu(%s)\n",
|
||||
my_getpwnam(user), user, my_getgrnam(group), group);
|
||||
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
/* END CODE */
|
||||
@@ -7,8 +7,12 @@
|
||||
extern int length_main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 2 || **(argv + 1) == '-') {
|
||||
usage("length string\n");
|
||||
usage("length STRING\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrints out the length of the specified STRING.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
printf("%d\n", strlen(argv[1]));
|
||||
printf("%lu\n", (long)strlen(argv[1]));
|
||||
return (TRUE);
|
||||
}
|
||||
@@ -30,16 +30,21 @@
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <sys/param.h> /* for PATH_MAX */
|
||||
|
||||
static const char ln_usage[] =
|
||||
"ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n"
|
||||
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n"
|
||||
"ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCreate a link named LINK_NAME or DIRECTORY to the specified TARGET\n"
|
||||
"\nYou may use '--' to indicate that all following arguments are non-options.\n\n"
|
||||
"Options:\n"
|
||||
"\t-s\tmake symbolic links instead of hard links\n"
|
||||
|
||||
"\t-f\tremove existing destination files\n"
|
||||
"\t-n\tno dereference symlinks - treat like normal file\n";
|
||||
#if 0
|
||||
"\t-n\tno dereference symlinks - treat like normal file\n"
|
||||
#endif
|
||||
#endif
|
||||
;
|
||||
|
||||
static int symlinkFlag = FALSE;
|
||||
static int removeoldFlag = FALSE;
|
||||
@@ -49,64 +54,78 @@ extern int ln_main(int argc, char **argv)
|
||||
{
|
||||
char *linkName;
|
||||
int linkIntoDirFlag;
|
||||
int stopIt = FALSE;
|
||||
|
||||
if (argc < 3) {
|
||||
usage(ln_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 's':
|
||||
symlinkFlag = TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
removeoldFlag = TRUE;
|
||||
break;
|
||||
case 'n':
|
||||
followLinks = FALSE;
|
||||
break;
|
||||
default:
|
||||
usage(ln_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
while (argc > 0 && stopIt == FALSE) {
|
||||
if (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 's':
|
||||
symlinkFlag = TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
removeoldFlag = TRUE;
|
||||
break;
|
||||
case 'n':
|
||||
followLinks = FALSE;
|
||||
break;
|
||||
case '-':
|
||||
stopIt = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage(ln_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (argc < 2) {
|
||||
usage(ln_usage);
|
||||
}
|
||||
|
||||
linkName = argv[argc - 1];
|
||||
|
||||
if (strlen(linkName) > PATH_MAX) {
|
||||
if (strlen(linkName) > BUFSIZ) {
|
||||
fprintf(stderr, name_too_long, "ln");
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
linkIntoDirFlag = isDirectory(linkName, TRUE, NULL);
|
||||
|
||||
if ((argc > 3) && !linkIntoDirFlag) {
|
||||
if ((argc >= 3) && linkIntoDirFlag == FALSE) {
|
||||
fprintf(stderr, not_a_directory, "ln", linkName);
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
while (argc-- >= 2) {
|
||||
char srcName[PATH_MAX + 1];
|
||||
int nChars, status;
|
||||
#if 0
|
||||
char srcName[BUFSIZ + 1];
|
||||
int nChars;
|
||||
#endif
|
||||
int status;
|
||||
|
||||
if (strlen(*argv) > PATH_MAX) {
|
||||
if (strlen(*argv) > BUFSIZ) {
|
||||
fprintf(stderr, name_too_long, "ln");
|
||||
exit FALSE;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (followLinks == FALSE) {
|
||||
strcpy(srcName, *argv);
|
||||
} else {
|
||||
/* Warning! This can silently truncate if > PATH_MAX, but
|
||||
I don't think that there can be one > PATH_MAX anyway. */
|
||||
nChars = readlink(*argv, srcName, PATH_MAX);
|
||||
/* Warning! This can silently truncate if > BUFSIZ, but
|
||||
I don't think that there can be one > BUFSIZ anyway. */
|
||||
nChars = readlink(*argv, srcName, BUFSIZ);
|
||||
srcName[nChars] = '\0';
|
||||
}
|
||||
#endif
|
||||
|
||||
if (removeoldFlag == TRUE) {
|
||||
status = (unlink(linkName) && errno != ENOENT);
|
||||
@@ -125,7 +144,7 @@ extern int ln_main(int argc, char **argv)
|
||||
exit FALSE;
|
||||
}
|
||||
}
|
||||
exit TRUE;
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -23,22 +23,24 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static const char logname_usage[] = "logname\n\n"
|
||||
|
||||
"Print the name of the current user.\n";
|
||||
static const char logname_usage[] = "logname\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint the name of the current user.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int logname_main(int argc, char **argv)
|
||||
{
|
||||
char *cp;
|
||||
char *user = xmalloc(9);
|
||||
|
||||
if (argc > 1)
|
||||
usage(logname_usage);
|
||||
|
||||
cp = getlogin();
|
||||
if (cp) {
|
||||
puts(cp);
|
||||
my_getpwuid(user, geteuid());
|
||||
if (user) {
|
||||
puts(user);
|
||||
exit(TRUE);
|
||||
}
|
||||
fprintf(stderr, "%s: no login name\n", argv[0]);
|
||||
exit(FALSE);
|
||||
fprintf(stderr, "no login name\n");
|
||||
return(FALSE);
|
||||
}
|
||||
@@ -86,8 +86,9 @@
|
||||
#define DISP_DOT 8 /* show . and .. */
|
||||
#define DISP_NUMERIC 16 /* numeric uid and gid */
|
||||
#define DISP_FULLTIME 32 /* show extended time display */
|
||||
#define DIR_NOLIST 64 /* show directory as itself, not contents */
|
||||
#define DIR_NOLIST 64 /* show directory as itself, not contents */
|
||||
#define DISP_DIRNAME 128 /* show directory name (for internal use) */
|
||||
#define DISP_RECURSIVE 256 /* Do a recursive listing */
|
||||
|
||||
#ifndef MAJOR
|
||||
#define MAJOR(dev) (((dev)>>8)&0xff)
|
||||
@@ -183,7 +184,7 @@ static char append_char(mode_t mode)
|
||||
static void list_single(const char *name, struct stat *info,
|
||||
const char *fullname)
|
||||
{
|
||||
char scratch[PATH_MAX + 1];
|
||||
char scratch[BUFSIZ + 1];
|
||||
short len = strlen(name);
|
||||
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
@@ -449,7 +450,12 @@ static const char ls_usage[] = "ls [-1a"
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
"F"
|
||||
#endif
|
||||
"] [filenames...]\n\n"
|
||||
#ifdef BB_FEATURE_LS_RECURSIVE
|
||||
"R"
|
||||
#endif
|
||||
"] [filenames...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nList directory contents\n\n"
|
||||
"Options:\n"
|
||||
"\t-a\tdo not hide entries starting with .\n"
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
@@ -474,9 +480,25 @@ static const char ls_usage[] = "ls [-1a"
|
||||
"\t-C\tlist entries by columns\n"
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
"\t-F\tappend indicator (one of */=@|) to entries\n"
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LS_RECURSIVE
|
||||
"\t-R\tlist subdirectories recursively\n"
|
||||
#endif
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
#ifdef BB_FEATURE_LS_RECURSIVE
|
||||
static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
int i;
|
||||
fprintf(stdout, "\n%s:\n", fileName);
|
||||
i = list_item(fileName);
|
||||
newline();
|
||||
return (i);
|
||||
}
|
||||
#endif
|
||||
|
||||
extern int ls_main(int argc, char **argv)
|
||||
{
|
||||
int argi = 1, i;
|
||||
@@ -540,6 +562,11 @@ extern int ls_main(int argc, char **argv)
|
||||
case 'e':
|
||||
opts |= DISP_FULLTIME;
|
||||
break;
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LS_RECURSIVE
|
||||
case 'R':
|
||||
opts |= DISP_RECURSIVE;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
goto print_usage_message;
|
||||
@@ -567,12 +594,25 @@ extern int ls_main(int argc, char **argv)
|
||||
#endif
|
||||
|
||||
/* process files specified, or current directory if none */
|
||||
i = 0;
|
||||
if (argi == argc)
|
||||
i = list_item(".");
|
||||
while (argi < argc)
|
||||
i |= list_item(argv[argi++]);
|
||||
newline();
|
||||
#ifdef BB_FEATURE_LS_RECURSIVE
|
||||
if (opts & DISP_RECURSIVE) {
|
||||
i = 0;
|
||||
if (argi == argc) {
|
||||
i = recursiveAction(".", TRUE, FALSE, FALSE, NULL, dirAction, NULL);
|
||||
}
|
||||
while (argi < argc) {
|
||||
i |= recursiveAction(argv[argi++], TRUE, FALSE, FALSE, NULL, dirAction, NULL);
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
i = 0;
|
||||
if (argi == argc)
|
||||
i = list_item(".");
|
||||
while (argi < argc)
|
||||
i |= list_item(argv[argi++]);
|
||||
newline();
|
||||
}
|
||||
exit(i);
|
||||
|
||||
print_usage_message:
|
||||
|
||||
@@ -28,15 +28,17 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/param.h> /* for PATH_MAX */
|
||||
|
||||
static const char mkdir_usage[] =
|
||||
"mkdir [OPTION] DIRECTORY...\n\n"
|
||||
"Create the DIRECTORY(ies), if they do not already exist\n\n"
|
||||
"mkdir [OPTION] DIRECTORY...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCreate the DIRECTORY(ies), if they do not already exist\n\n"
|
||||
"Options:\n"
|
||||
|
||||
"\t-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
|
||||
"\t-p\tno error if existing, make parent directories as needed\n";
|
||||
"\t-p\tno error if existing, make parent directories as needed\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
static int parentFlag = FALSE;
|
||||
@@ -86,9 +88,9 @@ extern int mkdir_main(int argc, char **argv)
|
||||
while (argc > 0) {
|
||||
int status;
|
||||
struct stat statBuf;
|
||||
char buf[PATH_MAX + 1];
|
||||
char buf[BUFSIZ + 1];
|
||||
|
||||
if (strlen(*argv) > PATH_MAX - 1) {
|
||||
if (strlen(*argv) > BUFSIZ - 1) {
|
||||
fprintf(stderr, name_too_long, "mkdir");
|
||||
exit FALSE;
|
||||
}
|
||||
@@ -110,5 +112,5 @@ extern int mkdir_main(int argc, char **argv)
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
exit TRUE;
|
||||
return( TRUE);
|
||||
}
|
||||
@@ -26,11 +26,13 @@
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char mkfifo_usage[] = "mkfifo [OPTIONS] name\n\n"
|
||||
"Creates a named pipe (identical to 'mknod name p')\n\n"
|
||||
|
||||
static const char mkfifo_usage[] = "mkfifo [OPTIONS] name\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCreates a named pipe (identical to 'mknod name p')\n\n"
|
||||
"Options:\n"
|
||||
"\t-m\tcreate the pipe using the specified mode (default a=rw)\n";
|
||||
"\t-m\tcreate the pipe using the specified mode (default a=rw)\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int mkfifo_main(int argc, char **argv)
|
||||
{
|
||||
@@ -58,12 +60,11 @@ extern int mkfifo_main(int argc, char **argv)
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
if (argc < 1)
|
||||
if (argc < 1 || *argv[0] == '-')
|
||||
usage(mkfifo_usage);
|
||||
if (mkfifo(*argv, mode) < 0) {
|
||||
perror("mkfifo");
|
||||
exit(255);
|
||||
} else {
|
||||
exit(TRUE);
|
||||
}
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -28,14 +28,17 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static const char mknod_usage[] = "mknod [OPTIONS] NAME TYPE MAJOR MINOR\n\n"
|
||||
"Create a special file (block, character, or pipe).\n\n"
|
||||
static const char mknod_usage[] = "mknod [OPTIONS] NAME TYPE MAJOR MINOR\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCreate a special file (block, character, or pipe).\n\n"
|
||||
"Options:\n"
|
||||
"\t-m\tcreate the special file using the specified mode (default a=rw)\n\n"
|
||||
"TYPEs include:\n"
|
||||
"\tb:\tMake a block (buffered) device.\n"
|
||||
"\tc or u:\tMake a character (un-buffered) device.\n"
|
||||
"\tp:\tMake a named pipe. MAJOR and MINOR are ignored for named pipes.\n";
|
||||
"\tp:\tMake a named pipe. MAJOR and MINOR are ignored for named pipes.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
int mknod_main(int argc, char **argv)
|
||||
{
|
||||
@@ -58,6 +61,7 @@ int mknod_main(int argc, char **argv)
|
||||
argc--;
|
||||
argv++;
|
||||
parse_mode(*argv, &perm);
|
||||
umask(0);
|
||||
break;
|
||||
default:
|
||||
usage(mknod_usage);
|
||||
@@ -87,13 +91,13 @@ int mknod_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (mode == S_IFCHR || mode == S_IFBLK) {
|
||||
dev = (atoi(argv[2]) << 8) | atoi(argv[1]);
|
||||
dev = (atoi(argv[2]) << 8) | atoi(argv[3]);
|
||||
}
|
||||
|
||||
mode |= perm;
|
||||
|
||||
if (mknod(argv[0], mode, dev) != 0)
|
||||
fatalError("%s: %s\n", argv[0], strerror(errno));
|
||||
exit (TRUE);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
@@ -51,14 +51,12 @@
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <libintl.h>
|
||||
|
||||
|
||||
#ifndef S_IFMT
|
||||
@@ -139,7 +137,12 @@ static void verify __P((char *s, char *end));
|
||||
/* The value to return to the calling program. */
|
||||
static int exit_status;
|
||||
|
||||
static const char printf_usage[] = "printf format [argument...]\n\nFormats and prints the given data.\n";
|
||||
static const char printf_usage[] = "printf FORMAT [ARGUMENT...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nFormats and prints ARGUMENT(s) according to FORMAT,\n"
|
||||
"Where FORMAT controls the output exactly as in C printf.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
int printf_main(int argc, char **argv)
|
||||
{
|
||||
@@ -167,7 +170,7 @@ int printf_main(int argc, char **argv)
|
||||
fprintf(stderr, "excess args ignored");
|
||||
*/
|
||||
|
||||
exit(exit_status);
|
||||
return(exit_status);
|
||||
}
|
||||
|
||||
/* Print the text in FORMAT, using ARGV (with ARGC elements) for
|
||||
|
||||
@@ -24,17 +24,15 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/param.h>
|
||||
#include <errno.h>
|
||||
|
||||
extern int pwd_main(int argc, char **argv)
|
||||
{
|
||||
char buf[PATH_MAX + 1];
|
||||
char buf[BUFSIZ + 1];
|
||||
|
||||
if (getcwd(buf, sizeof(buf)) == NULL) {
|
||||
perror("get working directory");
|
||||
exit(FALSE);
|
||||
}
|
||||
if (getcwd(buf, sizeof(buf)) == NULL)
|
||||
fatalError("pwd: %s\n", strerror(errno));
|
||||
|
||||
printf("%s\n", buf);
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -29,12 +29,15 @@
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char *rm_usage = "rm [OPTION]... FILE...\n\n"
|
||||
"Remove (unlink) the FILE(s).\n\n"
|
||||
static const char *rm_usage = "rm [OPTION]... FILE...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nRemove (unlink) the FILE(s). You may use '--' to\n"
|
||||
"indicate that all following arguments are non-options.\n\n"
|
||||
"Options:\n"
|
||||
|
||||
"\t-f\t\tremove existing destinations, never prompt\n"
|
||||
"\t-r or -R\tremove the contents of directories recursively\n";
|
||||
"\t-r or -R\tremove the contents of directories recursively\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
static int recursiveFlag = FALSE;
|
||||
@@ -62,30 +65,39 @@ static int dirAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
|
||||
extern int rm_main(int argc, char **argv)
|
||||
{
|
||||
int stopIt=FALSE;
|
||||
struct stat statbuf;
|
||||
|
||||
if (argc < 2) {
|
||||
usage(rm_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 'R':
|
||||
case 'r':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
forceFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage(rm_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
while (argc > 0 && stopIt == FALSE) {
|
||||
if (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 'R':
|
||||
case 'r':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
forceFlag = TRUE;
|
||||
break;
|
||||
case '-':
|
||||
stopIt = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage(rm_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (argc < 1 && forceFlag == FALSE) {
|
||||
usage(rm_usage);
|
||||
}
|
||||
|
||||
while (argc-- > 0) {
|
||||
@@ -100,5 +112,5 @@ extern int rm_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
}
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -31,7 +31,11 @@ extern int rmdir_main(int argc, char **argv)
|
||||
{
|
||||
if (argc == 1 || **(argv + 1) == '-') {
|
||||
usage
|
||||
("rmdir [OPTION]... DIRECTORY...\n\nRemove the DIRECTORY(ies), if they are empty.\n");
|
||||
("rmdir [OPTION]... DIRECTORY...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nRemove the DIRECTORY(ies), if they are empty.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
while (--argc > 0) {
|
||||
@@ -40,5 +44,5 @@ extern int rmdir_main(int argc, char **argv)
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -24,7 +24,11 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
const char sleep_usage[] = "sleep N\n\n" "Pause for N seconds.\n";
|
||||
const char sleep_usage[] = "sleep N\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPause for N seconds.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int sleep_main(int argc, char **argv)
|
||||
{
|
||||
@@ -35,6 +39,6 @@ extern int sleep_main(int argc, char **argv)
|
||||
if (sleep(atoi(*(++argv))) != 0) {
|
||||
perror("sleep");
|
||||
exit(FALSE);
|
||||
} else
|
||||
exit(TRUE);
|
||||
}
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -33,7 +33,11 @@ static const char sort_usage[] = "sort [-n]"
|
||||
#ifdef BB_FEATURE_SORT_REVERSE
|
||||
" [-r]"
|
||||
#endif
|
||||
" [FILE]...\n\nSorts lines of text in the specified files\n";
|
||||
" [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nSorts lines of text in the specified files\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
#ifdef BB_FEATURE_SORT_REVERSE
|
||||
#define APPLY_REVERSE(x) (reverse ? -(x) : (x))
|
||||
@@ -297,7 +301,7 @@ int sort_main(int argc, char **argv)
|
||||
list_release(&list);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* $Id: sort.c,v 1.15 2000/04/17 04:22:09 beppu Exp $ */
|
||||
/* $Id: sort.c,v 1.17 2000/06/19 17:25:40 andersen Exp $ */
|
||||
@@ -27,7 +27,11 @@
|
||||
extern int sync_main(int argc, char **argv)
|
||||
{
|
||||
if (argc > 1 && **(argv + 1) == '-') {
|
||||
usage("sync\n\nWrite all buffered filesystem blocks to disk.\n");
|
||||
usage("sync\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nWrite all buffered filesystem blocks to disk.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
exit(sync());
|
||||
return(sync());
|
||||
}
|
||||
@@ -47,6 +47,9 @@
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_help
|
||||
#include "messages.c"
|
||||
|
||||
|
||||
#define XWRITE(fd, buffer, n_bytes) \
|
||||
@@ -70,15 +73,18 @@ static int forever;
|
||||
static int print_headers;
|
||||
|
||||
const char tail_usage[] =
|
||||
"tail [OPTION] [FILE]...\n\n"
|
||||
"Print last 10 lines of each FILE to standard output.\n"
|
||||
"tail [OPTION] [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint last 10 lines of each FILE to standard output.\n"
|
||||
"With more than one FILE, precede each with a header giving the\n"
|
||||
"file name. With no FILE, or when FILE is -, read standard input.\n\n"
|
||||
"Options:\n"
|
||||
"\t-n NUM\t\tPrint last NUM lines instead of first 10\n"
|
||||
|
||||
"\t-f\t\tOutput data as the file grows. This version\n"
|
||||
"\t\t\tof 'tail -f' supports only one file at a time.\n";
|
||||
"\t\t\tof 'tail -f' supports only one file at a time.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
static void write_header(const char *filename)
|
||||
@@ -330,7 +336,7 @@ static int tail_file(const char *filename, off_t n_units)
|
||||
/* Not standard input. */
|
||||
fd = open(filename, O_RDONLY);
|
||||
if (fd == -1)
|
||||
fatalError("open error");
|
||||
perror(filename);
|
||||
|
||||
errors = tail_lines(filename, fd, (long) n_units);
|
||||
close(fd);
|
||||
@@ -368,8 +374,10 @@ extern int tail_main(int argc, char **argv)
|
||||
case 'h':
|
||||
usage(tail_usage);
|
||||
default:
|
||||
fprintf(stderr, "tail: invalid option -- %c\n", opt);
|
||||
usage(tail_usage);
|
||||
if ((n_units = atoi(&argv[i][1])) < 1) {
|
||||
fprintf(stderr, "tail: invalid option -- %c\n", opt);
|
||||
usage(tail_usage);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
@@ -392,7 +400,7 @@ extern int tail_main(int argc, char **argv)
|
||||
exit_status |= tail_file(argv[i], n_units);
|
||||
}
|
||||
|
||||
exit(exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
return(exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
@@ -510,9 +518,9 @@ char *program_name;
|
||||
static int have_read_stdin;
|
||||
|
||||
|
||||
static const char tail_usage[] = "tail [OPTION]... [FILE]...\n\
|
||||
\n\
|
||||
Print last 10 lines of each FILE to standard output.\n\
|
||||
static const char tail_usage[] = "tail [OPTION]... [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint last 10 lines of each FILE to standard output.\n\
|
||||
With more than one FILE, precede each with a header giving the file name.\n\
|
||||
With no FILE, or when FILE is -, read standard input.\n\
|
||||
\n\
|
||||
@@ -521,11 +529,12 @@ With no FILE, or when FILE is -, read standard input.\n\
|
||||
-n=N output the last N lines, instead of last 10\n\
|
||||
-q never output headers giving file names\n\
|
||||
-v always output headers giving file names\n\
|
||||
--help display this help and exit\n\
|
||||
\n\
|
||||
If the first character of N (bytes or lines) is a `+', output begins with \n\
|
||||
the Nth item from the start of each file, otherwise, print the last N items\n\
|
||||
in the file. N bytes may be suffixed by k (x1024), b (x512), or m (1024^2).\n\n";
|
||||
in the file. N bytes may be suffixed by k (x1024), b (x512), or m (1024^2).\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
static void write_header(const char *filename, const char *comment)
|
||||
{
|
||||
|
||||
@@ -27,12 +27,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
static const char tee_usage[] =
|
||||
"tee [OPTION]... [FILE]...\n\n"
|
||||
"Copy standard input to each FILE, and also to standard output.\n\n"
|
||||
"tee [OPTION]... [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCopy standard input to each FILE, and also to standard output.\n\n"
|
||||
"Options:\n" "\t-a\tappend to the given FILEs, do not overwrite\n"
|
||||
#if 0
|
||||
"\t-i\tignore interrupt signals\n"
|
||||
#endif
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
@@ -128,7 +130,7 @@ int tee_main(int argc, char **argv)
|
||||
/* Don't bother to close files Exit does that
|
||||
* automagically, so we can save a few bytes */
|
||||
/* free(FileList); */
|
||||
exit(0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* $Id: tee.c,v 1.9 2000/04/13 01:18:56 erik Exp $ */
|
||||
/* $Id: tee.c,v 1.11 2000/06/19 17:25:40 andersen Exp $ */
|
||||
@@ -39,6 +39,9 @@
|
||||
#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 ;
|
||||
@@ -182,14 +185,17 @@ test_main(int argc, char** argv)
|
||||
|
||||
if (strcmp(argv[0], "[") == 0) {
|
||||
if (strcmp(argv[--argc], "]"))
|
||||
fatalError("missing ]");
|
||||
fatalError("missing ]\n");
|
||||
argv[argc] = NULL;
|
||||
}
|
||||
if (strcmp(argv[1], "--help") == 0) {
|
||||
if (strcmp(argv[1], dash_dash_help) == 0) {
|
||||
usage("test EXPRESSION\n"
|
||||
"or [ EXPRESSION ]\n\n"
|
||||
"Checks file types and compares values returning an exit\n"
|
||||
"code determined by the value of EXPRESSION.\n");
|
||||
"or [ EXPRESSION ]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nChecks file types and compares values returning an exit\n"
|
||||
"code determined by the value of EXPRESSION.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
/* Implement special cases from POSIX.2, section 4.62.4 */
|
||||
@@ -229,7 +235,7 @@ test_main(int argc, char** argv)
|
||||
if (*t_wp != NULL && *++t_wp != NULL)
|
||||
syntax(*t_wp, "unknown operand");
|
||||
|
||||
exit( res);
|
||||
return( res);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -238,9 +244,9 @@ syntax(op, msg)
|
||||
char *msg;
|
||||
{
|
||||
if (op && *op)
|
||||
fatalError("%s: %s", op, msg);
|
||||
fatalError("%s: %s\n", op, msg);
|
||||
else
|
||||
fatalError("%s", msg);
|
||||
fatalError("%s\n", msg);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -475,13 +481,13 @@ getn(s)
|
||||
r = strtol(s, &p, 10);
|
||||
|
||||
if (errno != 0)
|
||||
fatalError("%s: out of range", s);
|
||||
fatalError("%s: out of range\n", s);
|
||||
|
||||
while (isspace(*p))
|
||||
p++;
|
||||
|
||||
if (*p)
|
||||
fatalError("%s: bad number", s);
|
||||
fatalError("%s: bad number\n", s);
|
||||
|
||||
return (int) r;
|
||||
}
|
||||
@@ -561,7 +567,7 @@ initialize_group_array ()
|
||||
{
|
||||
ngroups = getgroups(0, NULL);
|
||||
if ((group_array = realloc(group_array, ngroups * sizeof(gid_t))) == NULL)
|
||||
fatalError("Out of space");
|
||||
fatalError("Out of space\n");
|
||||
|
||||
getgroups(ngroups, group_array);
|
||||
}
|
||||
|
||||
@@ -31,10 +31,13 @@
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
static const char touch_usage[] = "touch [-c] file [file ...]\n\n"
|
||||
|
||||
"Update the last-modified date on the given file[s].\n";
|
||||
|
||||
static const char touch_usage[] = "touch [-c] file [file ...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nUpdate the last-modified date on the given file[s].\n\n"
|
||||
"Options:\n"
|
||||
"\t-c\tDo not create any files\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
extern int touch_main(int argc, char **argv)
|
||||
@@ -42,15 +45,9 @@ extern int touch_main(int argc, char **argv)
|
||||
int fd;
|
||||
int create = TRUE;
|
||||
|
||||
if (argc < 2) {
|
||||
usage(touch_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
while (*(++(*argv))) {
|
||||
switch (**argv) {
|
||||
case 'c':
|
||||
create = FALSE;
|
||||
@@ -59,23 +56,30 @@ extern int touch_main(int argc, char **argv)
|
||||
usage(touch_usage);
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (argc < 1) {
|
||||
usage(touch_usage);
|
||||
}
|
||||
|
||||
while (argc > 0) {
|
||||
fd = open(*argv, (create == FALSE) ? O_RDWR : O_RDWR | O_CREAT,
|
||||
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||
if (fd < 0) {
|
||||
if (create == FALSE && errno == ENOENT)
|
||||
exit(TRUE);
|
||||
else {
|
||||
fatalError("touch: %s", strerror(errno));
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
if (utime(*argv, NULL)) {
|
||||
fatalError("touch: %s", strerror(errno));
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
fd = open(*argv, (create == FALSE) ? O_RDWR : O_RDWR | O_CREAT, 0644);
|
||||
if (fd < 0) {
|
||||
if (create == FALSE && errno == ENOENT)
|
||||
exit(TRUE);
|
||||
else {
|
||||
perror("touch");
|
||||
exit(FALSE);
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
if (utime(*argv, NULL)) {
|
||||
perror("touch");
|
||||
exit(FALSE);
|
||||
} else
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -1,574 +1,246 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Copyright (c) 1988, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
* Mini tr implementation for busybox
|
||||
*
|
||||
* 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.
|
||||
* Copyright (c) Michiel Huisjes
|
||||
*
|
||||
* 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.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#ifndef lint
|
||||
static const char copyright[] = "@(#) Copyright (c) 1988, 1993\n\
|
||||
The Regents of the University of California. All rights reserved.\n";
|
||||
#endif /* not lint */
|
||||
|
||||
#ifndef lint
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)tr.c 8.2 (Berkeley) 5/4/95";
|
||||
#endif
|
||||
static const char rcsid[] =
|
||||
|
||||
"$Id: tr.c,v 1.4 2000/04/17 16:44:46 erik Exp $";
|
||||
#endif /* not lint */
|
||||
#endif /* #if 0 */
|
||||
|
||||
#include "internal.h"
|
||||
#include <locale.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.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"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <stddef.h>
|
||||
const char *tr_usage="tr [-cds] STRING1 [STRING2]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nTranslate, squeeze, and/or delete characters from\n"
|
||||
"standard input, writing to standard output.\n\n"
|
||||
"Options:\n"
|
||||
"\t-c\ttake complement of STRING1\n"
|
||||
"\t-d\tdelete input characters coded STRING1\n"
|
||||
"\t-s\tsqueeze multiple output characters of STRING2 into one character\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
typedef struct {
|
||||
enum { STRING1, STRING2 } which;
|
||||
enum { EOS, INFINITE, NORMAL, RANGE, SEQUENCE, SET } state;
|
||||
int cnt; /* character count */
|
||||
int lastch; /* last character */
|
||||
int equiv[2]; /* equivalence set */
|
||||
int *set; /* set of characters */
|
||||
char *str; /* user's string */
|
||||
} STR;
|
||||
|
||||
#include <limits.h>
|
||||
#define NCHARS (UCHAR_MAX + 1) /* Number of possible characters. */
|
||||
#define OOBCH (UCHAR_MAX + 1) /* Out of band character value. */
|
||||
|
||||
static int next __P((STR *));
|
||||
#ifdef TRUE
|
||||
#undef TRUE
|
||||
#undef FALSE
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
static int string1[NCHARS] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* ASCII */
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
|
||||
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
|
||||
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
|
||||
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
|
||||
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
|
||||
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
||||
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
|
||||
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
|
||||
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
|
||||
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
|
||||
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
|
||||
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
|
||||
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
|
||||
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
|
||||
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
|
||||
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
|
||||
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
|
||||
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
|
||||
}, string2[NCHARS];
|
||||
#define ASCII 0377
|
||||
|
||||
STR s1 = { STRING1, NORMAL, 0, OOBCH, {0, OOBCH}, NULL, NULL };
|
||||
STR s2 = { STRING2, NORMAL, 0, OOBCH, {0, OOBCH}, NULL, NULL };
|
||||
/* 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 setup(string, arg, str, cflag)
|
||||
int *string;
|
||||
char *arg;
|
||||
STR *str;
|
||||
int cflag;
|
||||
|
||||
static void convert()
|
||||
{
|
||||
register int cnt, *p;
|
||||
short read_chars = 0;
|
||||
short c, coded;
|
||||
short last = -1;
|
||||
|
||||
str->str = arg;
|
||||
bzero(string, NCHARS * sizeof(int));
|
||||
|
||||
while (next(str))
|
||||
string[str->lastch] = 1;
|
||||
if (cflag)
|
||||
for (p = string, cnt = NCHARS; cnt--; ++p)
|
||||
*p = !*p;
|
||||
}
|
||||
|
||||
static void tr_usage()
|
||||
{
|
||||
usage( "\ttr [-cdsu] string1 [string2]\n\n"
|
||||
"Translate, squeeze, and/or delete characters from standard\n"
|
||||
"input, writing to standard output.\n");
|
||||
}
|
||||
|
||||
|
||||
extern int tr_main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
register int ch, cnt, lastch, *p;
|
||||
int cflag, dflag, sflag, isstring2;
|
||||
|
||||
(void) setlocale(LC_CTYPE, "");
|
||||
|
||||
cflag = dflag = sflag = 0;
|
||||
while ((ch = getopt(argc, argv, "cdsu")) != -1)
|
||||
switch ((char) ch) {
|
||||
case 'c':
|
||||
cflag = 1;
|
||||
break;
|
||||
case 'd':
|
||||
dflag = 1;
|
||||
break;
|
||||
case 's':
|
||||
sflag = 1;
|
||||
break;
|
||||
case 'u':
|
||||
setbuf(stdout, (char *) NULL);
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
tr_usage();
|
||||
}
|
||||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
switch (argc) {
|
||||
case 0:
|
||||
default:
|
||||
tr_usage();
|
||||
/* NOTREACHED */
|
||||
case 1:
|
||||
isstring2 = 0;
|
||||
break;
|
||||
case 2:
|
||||
isstring2 = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
* tr -ds [-c] string1 string2
|
||||
* Delete all characters (or complemented characters) in string1.
|
||||
* Squeeze all characters in string2.
|
||||
*/
|
||||
if (dflag && sflag) {
|
||||
if (!isstring2)
|
||||
tr_usage();
|
||||
|
||||
setup(string1, argv[0], &s1, cflag);
|
||||
setup(string2, argv[1], &s2, 0);
|
||||
|
||||
for (lastch = OOBCH; (ch = getchar()) != EOF;)
|
||||
if (!string1[ch] && (!string2[ch] || lastch != ch)) {
|
||||
lastch = ch;
|
||||
(void) putchar(ch);
|
||||
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);
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* tr -d [-c] string1
|
||||
* Delete all characters (or complemented characters) in string1.
|
||||
*/
|
||||
if (dflag) {
|
||||
if (isstring2)
|
||||
tr_usage();
|
||||
|
||||
setup(string1, argv[0], &s1, cflag);
|
||||
|
||||
while ((ch = getchar()) != EOF)
|
||||
if (!string1[ch])
|
||||
(void) putchar(ch);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* tr -s [-c] string1
|
||||
* Squeeze all characters (or complemented characters) in string1.
|
||||
*/
|
||||
if (sflag && !isstring2) {
|
||||
setup(string1, argv[0], &s1, cflag);
|
||||
|
||||
for (lastch = OOBCH; (ch = getchar()) != EOF;)
|
||||
if (!string1[ch] || lastch != ch) {
|
||||
lastch = ch;
|
||||
(void) putchar(ch);
|
||||
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);
|
||||
}
|
||||
exit(0);
|
||||
out_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* tr [-cs] string1 string2
|
||||
* Replace all characters (or complemented characters) in string1 with
|
||||
* the character in the same position in string2. If the -s option is
|
||||
* specified, squeeze all the characters in string2.
|
||||
*/
|
||||
if (!isstring2)
|
||||
tr_usage();
|
||||
|
||||
s1.str = argv[0];
|
||||
s2.str = argv[1];
|
||||
|
||||
if (cflag)
|
||||
for (cnt = NCHARS, p = string1; cnt--;)
|
||||
*p++ = OOBCH;
|
||||
|
||||
if (!next(&s2))
|
||||
errx(1, "empty string2");
|
||||
|
||||
/* If string2 runs out of characters, use the last one specified. */
|
||||
if (sflag)
|
||||
while (next(&s1)) {
|
||||
string1[s1.lastch] = ch = s2.lastch;
|
||||
string2[ch] = 1;
|
||||
(void) next(&s2);
|
||||
} else
|
||||
while (next(&s1)) {
|
||||
string1[s1.lastch] = ch = s2.lastch;
|
||||
(void) next(&s2);
|
||||
}
|
||||
|
||||
if (cflag)
|
||||
for (cnt = 0, p = string1; cnt < NCHARS; ++p, ++cnt)
|
||||
*p = *p == OOBCH ? ch : cnt;
|
||||
|
||||
if (sflag)
|
||||
for (lastch = OOBCH; (ch = getchar()) != EOF;) {
|
||||
ch = string1[ch];
|
||||
if (!string2[ch] || lastch != ch) {
|
||||
lastch = ch;
|
||||
(void) putchar(ch);
|
||||
}
|
||||
} else
|
||||
while ((ch = getchar()) != EOF)
|
||||
(void) putchar(string1[ch]);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static int backslash __P((STR *));
|
||||
static int bracket __P((STR *));
|
||||
static int c_class __P((const void *, const void *));
|
||||
static void genclass __P((STR *));
|
||||
static void genequiv __P((STR *));
|
||||
static int genrange __P((STR *));
|
||||
static void genseq __P((STR *));
|
||||
|
||||
static int next(s)
|
||||
register STR *s;
|
||||
{
|
||||
register int ch;
|
||||
|
||||
switch (s->state) {
|
||||
case EOS:
|
||||
return (0);
|
||||
case INFINITE:
|
||||
return (1);
|
||||
case NORMAL:
|
||||
switch (ch = (u_char) * s->str) {
|
||||
case '\0':
|
||||
s->state = EOS;
|
||||
return (0);
|
||||
case '\\':
|
||||
s->lastch = backslash(s);
|
||||
break;
|
||||
case '[':
|
||||
if (bracket(s))
|
||||
return (next(s));
|
||||
/* FALLTHROUGH */
|
||||
default:
|
||||
++s->str;
|
||||
s->lastch = ch;
|
||||
break;
|
||||
}
|
||||
|
||||
/* We can start a range at any time. */
|
||||
if (s->str[0] == '-' && genrange(s))
|
||||
return (next(s));
|
||||
return (1);
|
||||
case RANGE:
|
||||
if (s->cnt-- == 0) {
|
||||
s->state = NORMAL;
|
||||
return (next(s));
|
||||
}
|
||||
++s->lastch;
|
||||
return (1);
|
||||
case SEQUENCE:
|
||||
if (s->cnt-- == 0) {
|
||||
s->state = NORMAL;
|
||||
return (next(s));
|
||||
}
|
||||
return (1);
|
||||
case SET:
|
||||
if ((s->lastch = s->set[s->cnt++]) == OOBCH) {
|
||||
s->state = NORMAL;
|
||||
return (next(s));
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
static void map(register unsigned char *string1, register unsigned char *string2)
|
||||
{
|
||||
unsigned char last = '0';
|
||||
|
||||
while (*string1) {
|
||||
if (*string2 == '\0')
|
||||
vector[*string1] = last;
|
||||
else
|
||||
vector[*string1] = last = *string2++;
|
||||
string1++;
|
||||
}
|
||||
}
|
||||
|
||||
static void expand(register char *arg, register unsigned char *buffer)
|
||||
{
|
||||
int i, ac;
|
||||
|
||||
while (*arg) {
|
||||
if (*arg == '\\') {
|
||||
arg++;
|
||||
i = ac = 0;
|
||||
if (*arg >= '0' && *arg <= '7') {
|
||||
do {
|
||||
ac = (ac << 3) + *arg++ - '0';
|
||||
i++;
|
||||
} while (i < 4 && *arg >= '0' && *arg <= '7');
|
||||
*buffer++ = ac;
|
||||
} else if (*arg != '\0')
|
||||
*buffer++ = *arg++;
|
||||
} else if (*arg == '[') {
|
||||
arg++;
|
||||
i = *arg++;
|
||||
if (*arg++ != '-') {
|
||||
*buffer++ = '[';
|
||||
arg -= 2;
|
||||
continue;
|
||||
}
|
||||
ac = *arg++;
|
||||
while (i <= ac)
|
||||
*buffer++ = i++;
|
||||
arg++; /* Skip ']' */
|
||||
} else
|
||||
*buffer++ = *arg++;
|
||||
}
|
||||
}
|
||||
|
||||
static void complement(unsigned char *buffer)
|
||||
{
|
||||
register unsigned char *ptr;
|
||||
register short i, index;
|
||||
unsigned char conv[ASCII + 2];
|
||||
|
||||
index = 0;
|
||||
for (i = 1; i <= ASCII; i++) {
|
||||
for (ptr = buffer; *ptr; ptr++)
|
||||
if (*ptr == i)
|
||||
break;
|
||||
if (*ptr == '\0')
|
||||
conv[index++] = i & ASCII;
|
||||
}
|
||||
conv[index] = '\0';
|
||||
strcpy((char *) buffer, (char *) conv);
|
||||
}
|
||||
|
||||
extern int tr_main(int argc, char **argv)
|
||||
{
|
||||
register unsigned char *ptr;
|
||||
int index = 1;
|
||||
short i;
|
||||
|
||||
if (argc > 1 && argv[index][0] == '-') {
|
||||
for (ptr = (unsigned char *) &argv[index][1]; *ptr; ptr++) {
|
||||
switch (*ptr) {
|
||||
case 'c':
|
||||
com_fl = TRUE;
|
||||
break;
|
||||
case 'd':
|
||||
del_fl = TRUE;
|
||||
break;
|
||||
case 's':
|
||||
sq_fl = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage(tr_usage);
|
||||
}
|
||||
}
|
||||
index++;
|
||||
}
|
||||
for (i = 0; i <= ASCII; i++) {
|
||||
vector[i] = i;
|
||||
invec[i] = outvec[i] = FALSE;
|
||||
}
|
||||
|
||||
if (argv[index] != NULL) {
|
||||
expand(argv[index++], input);
|
||||
if (com_fl)
|
||||
complement(input);
|
||||
if (argv[index] != NULL)
|
||||
expand(argv[index], output);
|
||||
if (argv[index] != NULL)
|
||||
map(input, output);
|
||||
for (ptr = input; *ptr; ptr++)
|
||||
invec[*ptr] = TRUE;
|
||||
for (ptr = output; *ptr; ptr++)
|
||||
outvec[*ptr] = TRUE;
|
||||
}
|
||||
convert();
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int bracket(s)
|
||||
register STR *s;
|
||||
{
|
||||
register char *p;
|
||||
|
||||
switch (s->str[1]) {
|
||||
case ':': /* "[:class:]" */
|
||||
if ((p = strstr(s->str + 2, ":]")) == NULL)
|
||||
return (0);
|
||||
*p = '\0';
|
||||
s->str += 2;
|
||||
genclass(s);
|
||||
s->str = p + 2;
|
||||
return (1);
|
||||
case '=': /* "[=equiv=]" */
|
||||
if ((p = strstr(s->str + 2, "=]")) == NULL)
|
||||
return (0);
|
||||
s->str += 2;
|
||||
genequiv(s);
|
||||
return (1);
|
||||
default: /* "[\###*n]" or "[#*n]" */
|
||||
if ((p = strpbrk(s->str + 2, "*]")) == NULL)
|
||||
return (0);
|
||||
if (p[0] != '*' || index(p, ']') == NULL)
|
||||
return (0);
|
||||
s->str += 1;
|
||||
genseq(s);
|
||||
return (1);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
int (*func) __P((int));
|
||||
int *set;
|
||||
} CLASS;
|
||||
|
||||
static CLASS classes[] = {
|
||||
#undef isalnum
|
||||
{"alnum", isalnum,},
|
||||
#undef isalpha
|
||||
{"alpha", isalpha,},
|
||||
/*#undef isblank
|
||||
{ "blank", isblank, },*/
|
||||
#undef iscntrl
|
||||
{"cntrl", iscntrl,},
|
||||
#undef isdigit
|
||||
{"digit", isdigit,},
|
||||
#undef isgraph
|
||||
{"graph", isgraph,},
|
||||
#undef islower
|
||||
{"lower", islower,},
|
||||
#undef isprint
|
||||
{"print", isprint,},
|
||||
#undef ispunct
|
||||
{"punct", ispunct,},
|
||||
#undef isspace
|
||||
{"space", isspace,},
|
||||
#undef isupper
|
||||
{"upper", isupper,},
|
||||
#undef isxdigit
|
||||
{"xdigit", isxdigit,},
|
||||
};
|
||||
|
||||
static void genclass(s)
|
||||
STR *s;
|
||||
{
|
||||
register int cnt, (*func) __P((int));
|
||||
CLASS *cp, tmp;
|
||||
int *p;
|
||||
|
||||
tmp.name = s->str;
|
||||
if ((cp = (CLASS *) bsearch(&tmp, classes, sizeof(classes) /
|
||||
sizeof(CLASS), sizeof(CLASS),
|
||||
c_class)) == NULL) errx(1,
|
||||
"unknown class %s",
|
||||
s->str);
|
||||
|
||||
cp->set = p = xmalloc((NCHARS + 1) * sizeof(int));
|
||||
bzero(p, (NCHARS + 1) * sizeof(int));
|
||||
|
||||
for (cnt = 0, func = cp->func; cnt < NCHARS; ++cnt)
|
||||
if ((func) (cnt))
|
||||
*p++ = cnt;
|
||||
*p = OOBCH;
|
||||
|
||||
s->cnt = 0;
|
||||
s->state = SET;
|
||||
s->set = cp->set;
|
||||
}
|
||||
|
||||
static int c_class(a, b)
|
||||
const void *a, *b;
|
||||
{
|
||||
return (strcmp(((CLASS *) a)->name, ((CLASS *) b)->name));
|
||||
}
|
||||
|
||||
/*
|
||||
* English doesn't have any equivalence classes, so for now
|
||||
* we just syntax check and grab the character.
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
static void genequiv(s)
|
||||
STR *s;
|
||||
{
|
||||
if (*s->str == '\\') {
|
||||
s->equiv[0] = backslash(s);
|
||||
if (*s->str != '=')
|
||||
errx(1, "misplaced equivalence equals sign");
|
||||
} else {
|
||||
s->equiv[0] = s->str[0];
|
||||
if (s->str[1] != '=')
|
||||
errx(1, "misplaced equivalence equals sign");
|
||||
}
|
||||
s->str += 2;
|
||||
s->cnt = 0;
|
||||
s->state = SET;
|
||||
s->set = s->equiv;
|
||||
}
|
||||
|
||||
static int genrange(s)
|
||||
STR *s;
|
||||
{
|
||||
int stopval;
|
||||
char *savestart;
|
||||
|
||||
savestart = s->str;
|
||||
stopval = *++s->str == '\\' ? backslash(s) : (u_char) * s->str++;
|
||||
if (stopval < (u_char) s->lastch) {
|
||||
s->str = savestart;
|
||||
return (0);
|
||||
}
|
||||
s->cnt = stopval - s->lastch + 1;
|
||||
s->state = RANGE;
|
||||
--s->lastch;
|
||||
return (1);
|
||||
}
|
||||
|
||||
static void genseq(s)
|
||||
STR *s;
|
||||
{
|
||||
char *ep;
|
||||
|
||||
if (s->which == STRING1)
|
||||
errx(1, "sequences only valid in string2");
|
||||
|
||||
if (*s->str == '\\')
|
||||
s->lastch = backslash(s);
|
||||
else
|
||||
s->lastch = *s->str++;
|
||||
if (*s->str != '*')
|
||||
errx(1, "misplaced sequence asterisk");
|
||||
|
||||
switch (*++s->str) {
|
||||
case '\\':
|
||||
s->cnt = backslash(s);
|
||||
break;
|
||||
case ']':
|
||||
s->cnt = 0;
|
||||
++s->str;
|
||||
break;
|
||||
default:
|
||||
if (isdigit((u_char) * s->str)) {
|
||||
s->cnt = strtol(s->str, &ep, 0);
|
||||
if (*ep == ']') {
|
||||
s->str = ep + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
errx(1, "illegal sequence count");
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
s->state = s->cnt ? SEQUENCE : INFINITE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Translate \??? into a character. Up to 3 octal digits, if no digits either
|
||||
* an escape code or a literal character.
|
||||
*/
|
||||
static int backslash(s)
|
||||
register STR *s;
|
||||
{
|
||||
register int ch, cnt, val;
|
||||
|
||||
for (cnt = val = 0;;) {
|
||||
ch = (u_char) * ++s->str;
|
||||
if (!isascii(ch) || !isdigit(ch))
|
||||
break;
|
||||
val = val * 8 + ch - '0';
|
||||
if (++cnt == 3) {
|
||||
++s->str;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cnt)
|
||||
return (val);
|
||||
if (ch != '\0')
|
||||
++s->str;
|
||||
switch (ch) {
|
||||
case 'a': /* escape characters */
|
||||
return ('\7');
|
||||
case 'b':
|
||||
return ('\b');
|
||||
case 'f':
|
||||
return ('\f');
|
||||
case 'n':
|
||||
return ('\n');
|
||||
case 'r':
|
||||
return ('\r');
|
||||
case 't':
|
||||
return ('\t');
|
||||
case 'v':
|
||||
return ('\13');
|
||||
case '\0': /* \" -> \ */
|
||||
s->state = EOS;
|
||||
return ('\\');
|
||||
default: /* \x" -> x */
|
||||
return (ch);
|
||||
}
|
||||
}
|
||||
@@ -24,10 +24,13 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
static const char tty_usage[] = "tty\n\n"
|
||||
"Print the file name of the terminal connected to standard input.\n\n"
|
||||
static const char tty_usage[] = "tty\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint the file name of the terminal connected to standard input.\n\n"
|
||||
"Options:\n"
|
||||
"\t-s\tprint nothing, only return an exit status\n";
|
||||
"\t-s\tprint nothing, only return an exit status\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int tty_main(int argc, char **argv)
|
||||
{
|
||||
@@ -43,5 +46,5 @@ extern int tty_main(int argc, char **argv)
|
||||
else
|
||||
puts("not a tty");
|
||||
}
|
||||
exit(isatty(0) ? TRUE : FALSE);
|
||||
return(isatty(0) ? TRUE : FALSE);
|
||||
}
|
||||
@@ -42,9 +42,9 @@
|
||||
|
||||
|
||||
static const char uname_usage[] =
|
||||
"uname [OPTION]...\n\n"
|
||||
"uname [OPTION]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"Print certain system information. With no OPTION, same as -s.\n\n"
|
||||
"\nPrint certain system information. With no OPTION, same as -s.\n\n"
|
||||
"Options:\n"
|
||||
"\t-a\tprint all information\n"
|
||||
"\t-m\tthe machine (hardware) type\n"
|
||||
@@ -156,7 +156,7 @@ int uname_main(int argc, char **argv)
|
||||
print_element(PRINT_MACHINE, name.machine);
|
||||
print_element(PRINT_PROCESSOR, processor);
|
||||
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
/* If the name element set in MASK is selected for printing in `toprint',
|
||||
|
||||
@@ -28,9 +28,12 @@
|
||||
#include <errno.h>
|
||||
|
||||
static const char uniq_usage[] =
|
||||
"uniq [OPTION]... [INPUT [OUTPUT]]\n\n"
|
||||
"Discard all but one of successive identical lines from INPUT\n"
|
||||
"(or standard input), writing to OUTPUT (or standard output).\n";
|
||||
"uniq [OPTION]... [INPUT [OUTPUT]]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nDiscard all but one of successive identical lines from INPUT\n"
|
||||
"(or standard input), writing to OUTPUT (or standard output).\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
/* max chars in line */
|
||||
#define UNIQ_MAX 4096
|
||||
@@ -181,7 +184,7 @@ int uniq_main(int argc, char **argv)
|
||||
subject_last(&s);
|
||||
subject_study(&s);
|
||||
|
||||
exit(0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* $Id: uniq.c,v 1.9 2000/04/17 16:16:10 erik Exp $ */
|
||||
/* $Id: uniq.c,v 1.11 2000/06/19 17:25:40 andersen Exp $ */
|
||||
@@ -25,7 +25,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
const char usleep_usage[] = "usleep N\n\n" "Pause for N microseconds.\n";
|
||||
const char usleep_usage[] = "usleep N\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPause for N microseconds.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int usleep_main(int argc, char **argv)
|
||||
{
|
||||
@@ -34,5 +38,5 @@ extern int usleep_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
usleep(atoi(*(++argv))); /* return void */
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -0,0 +1,350 @@
|
||||
/* uudecode.c -- uudecode utility.
|
||||
* Copyright (C) 1994, 1995 Free Software Foundation, Inc.
|
||||
*
|
||||
* This product is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This product is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this product; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* Reworked to GNU style by Ian Lance Taylor, ian@airs.com, August 93. */
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <pwd.h>
|
||||
|
||||
/*struct passwd *getpwnam();*/
|
||||
|
||||
/* Single character decode. */
|
||||
#define DEC(Char) (((Char) - ' ') & 077)
|
||||
|
||||
static int read_stduu (const char *inname)
|
||||
{
|
||||
char buf[2 * BUFSIZ];
|
||||
|
||||
while (1) {
|
||||
int n;
|
||||
char *p;
|
||||
|
||||
if (fgets (buf, sizeof(buf), stdin) == NULL) {
|
||||
errorMsg("%s: Short file\n", inname);
|
||||
return FALSE;
|
||||
}
|
||||
p = buf;
|
||||
|
||||
/* N is used to avoid writing out all the characters at the end of
|
||||
the file. */
|
||||
n = DEC (*p);
|
||||
if (n <= 0)
|
||||
break;
|
||||
for (++p; n > 0; p += 4, n -= 3) {
|
||||
char ch;
|
||||
|
||||
if (n >= 3) {
|
||||
ch = DEC (p[0]) << 2 | DEC (p[1]) >> 4;
|
||||
putchar (ch);
|
||||
ch = DEC (p[1]) << 4 | DEC (p[2]) >> 2;
|
||||
putchar (ch);
|
||||
ch = DEC (p[2]) << 6 | DEC (p[3]);
|
||||
putchar (ch);
|
||||
} else {
|
||||
if (n >= 1) {
|
||||
ch = DEC (p[0]) << 2 | DEC (p[1]) >> 4;
|
||||
putchar (ch);
|
||||
}
|
||||
if (n >= 2) {
|
||||
ch = DEC (p[1]) << 4 | DEC (p[2]) >> 2;
|
||||
putchar (ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fgets (buf, sizeof(buf), stdin) == NULL
|
||||
|| strcmp (buf, "end\n")) {
|
||||
errorMsg("%s: No `end' line\n", inname);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int read_base64 (const char *inname)
|
||||
{
|
||||
static const char b64_tab[256] = {
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*000-007*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*010-017*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*020-027*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*030-037*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*040-047*/
|
||||
'\177', '\177', '\177', '\76', '\177', '\177', '\177', '\77', /*050-057*/
|
||||
'\64', '\65', '\66', '\67', '\70', '\71', '\72', '\73', /*060-067*/
|
||||
'\74', '\75', '\177', '\177', '\177', '\100', '\177', '\177', /*070-077*/
|
||||
'\177', '\0', '\1', '\2', '\3', '\4', '\5', '\6', /*100-107*/
|
||||
'\7', '\10', '\11', '\12', '\13', '\14', '\15', '\16', /*110-117*/
|
||||
'\17', '\20', '\21', '\22', '\23', '\24', '\25', '\26', /*120-127*/
|
||||
'\27', '\30', '\31', '\177', '\177', '\177', '\177', '\177', /*130-137*/
|
||||
'\177', '\32', '\33', '\34', '\35', '\36', '\37', '\40', /*140-147*/
|
||||
'\41', '\42', '\43', '\44', '\45', '\46', '\47', '\50', /*150-157*/
|
||||
'\51', '\52', '\53', '\54', '\55', '\56', '\57', '\60', /*160-167*/
|
||||
'\61', '\62', '\63', '\177', '\177', '\177', '\177', '\177', /*170-177*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*200-207*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*210-217*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*220-227*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*230-237*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*240-247*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*250-257*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*260-267*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*270-277*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*300-307*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*310-317*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*320-327*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*330-337*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*340-347*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*350-357*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*360-367*/
|
||||
'\177', '\177', '\177', '\177', '\177', '\177', '\177', '\177', /*370-377*/
|
||||
};
|
||||
unsigned char buf[2 * BUFSIZ];
|
||||
|
||||
while (1) {
|
||||
int last_data = 0;
|
||||
unsigned char *p;
|
||||
|
||||
if (fgets (buf, sizeof(buf), stdin) == NULL) {
|
||||
errorMsg("%s: Short file\n", inname);
|
||||
return FALSE;
|
||||
}
|
||||
p = buf;
|
||||
|
||||
if (memcmp (buf, "====", 4) == 0)
|
||||
break;
|
||||
if (last_data != 0) {
|
||||
errorMsg("%s: data following `=' padding character\n", inname);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* The following implementation of the base64 decoding might look
|
||||
a bit clumsy but I only try to follow the POSIX standard:
|
||||
``All line breaks or other characters not found in the table
|
||||
[with base64 characters] shall be ignored by decoding
|
||||
software.'' */
|
||||
while (*p != '\n') {
|
||||
char c1, c2, c3;
|
||||
|
||||
while ((b64_tab[*p] & '\100') != 0)
|
||||
if (*p == '\n' || *p++ == '=')
|
||||
break;
|
||||
if (*p == '\n')
|
||||
/* This leaves the loop. */
|
||||
continue;
|
||||
c1 = b64_tab[*p++];
|
||||
|
||||
while ((b64_tab[*p] & '\100') != 0)
|
||||
if (*p == '\n' || *p++ == '=') {
|
||||
errorMsg("%s: illegal line\n", inname);
|
||||
return FALSE;
|
||||
}
|
||||
c2 = b64_tab[*p++];
|
||||
|
||||
while (b64_tab[*p] == '\177')
|
||||
if (*p++ == '\n') {
|
||||
errorMsg("%s: illegal line\n", inname);
|
||||
return FALSE;
|
||||
}
|
||||
if (*p == '=') {
|
||||
putchar (c1 << 2 | c2 >> 4);
|
||||
last_data = 1;
|
||||
break;
|
||||
}
|
||||
c3 = b64_tab[*p++];
|
||||
|
||||
while (b64_tab[*p] == '\177')
|
||||
if (*p++ == '\n') {
|
||||
errorMsg("%s: illegal line\n", inname);
|
||||
return FALSE;
|
||||
}
|
||||
putchar (c1 << 2 | c2 >> 4);
|
||||
putchar (c2 << 4 | c3 >> 2);
|
||||
if (*p == '=') {
|
||||
last_data = 1;
|
||||
break;
|
||||
}
|
||||
else
|
||||
putchar (c3 << 6 | b64_tab[*p++]);
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static int decode (const char *inname,
|
||||
const char *forced_outname)
|
||||
{
|
||||
struct passwd *pw;
|
||||
register int n;
|
||||
register char *p;
|
||||
int mode, n1;
|
||||
char buf[2 * BUFSIZ];
|
||||
char *outname;
|
||||
int do_base64 = 0;
|
||||
|
||||
/* Search for header line. */
|
||||
|
||||
while (1) {
|
||||
if (fgets (buf, sizeof (buf), stdin) == NULL) {
|
||||
errorMsg("%s: No `begin' line\n", inname);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (strncmp (buf, "begin", 5) == 0) {
|
||||
if (sscanf (buf, "begin-base64 %o %s", &mode, buf) == 2) {
|
||||
do_base64 = 1;
|
||||
break;
|
||||
} else if (sscanf (buf, "begin %o %s", &mode, buf) == 2)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* If the output file name is given on the command line this rules. */
|
||||
if (forced_outname != NULL)
|
||||
outname = (char *) forced_outname;
|
||||
else {
|
||||
/* Handle ~user/file format. */
|
||||
if (buf[0] != '~')
|
||||
outname = buf;
|
||||
else {
|
||||
p = buf + 1;
|
||||
while (*p != '/')
|
||||
++p;
|
||||
if (*p == '\0') {
|
||||
errorMsg("%s: Illegal ~user\n", inname);
|
||||
return FALSE;
|
||||
}
|
||||
*p++ = '\0';
|
||||
pw = getpwnam (buf + 1);
|
||||
if (pw == NULL) {
|
||||
errorMsg("%s: No user `%s'\n", inname, buf + 1);
|
||||
return FALSE;
|
||||
}
|
||||
n = strlen (pw->pw_dir);
|
||||
n1 = strlen (p);
|
||||
outname = (char *) alloca ((size_t) (n + n1 + 2));
|
||||
memcpy (outname + n + 1, p, (size_t) (n1 + 1));
|
||||
memcpy (outname, pw->pw_dir, (size_t) n);
|
||||
outname[n] = '/';
|
||||
}
|
||||
}
|
||||
|
||||
/* Create output file and set mode. */
|
||||
if (strcmp (outname, "/dev/stdout") != 0 && strcmp (outname, "-") != 0
|
||||
&& (freopen (outname, "w", stdout) == NULL
|
||||
|| chmod (outname, mode & (S_IRWXU | S_IRWXG | S_IRWXO))
|
||||
)) {
|
||||
errorMsg("uudeoce %s: %s %s\n", outname, inname, strerror(errno)); /* */
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* We differenciate decoding standard UU encoding and base64. A
|
||||
common function would only slow down the program. */
|
||||
|
||||
/* For each input line: */
|
||||
if (do_base64)
|
||||
return read_base64 (inname);
|
||||
else
|
||||
return read_stduu (inname);
|
||||
}
|
||||
|
||||
static const char uudecode_usage[] =
|
||||
"uudecode [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nUudecode a file that is uuencoded.\n\n"
|
||||
"Options:\n"
|
||||
"\t-o FILE\tdirect output to FILE\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
int uudecode_main (int argc,
|
||||
char **argv)
|
||||
{
|
||||
int opt;
|
||||
int exit_status;
|
||||
const char *outname;
|
||||
outname = NULL;
|
||||
|
||||
while ((opt = getopt(argc, argv, "o:")) != EOF) {
|
||||
switch (opt) {
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
outname = optarg;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(uudecode_usage);
|
||||
}
|
||||
}
|
||||
|
||||
if (optind == argc)
|
||||
exit_status = decode ("stdin", outname) == 0 ? TRUE : FALSE;
|
||||
else {
|
||||
exit_status = TRUE;
|
||||
do {
|
||||
if (freopen (argv[optind], "r", stdin) != NULL) {
|
||||
if (decode (argv[optind], outname) != 0)
|
||||
exit_status = FALSE;
|
||||
} else {
|
||||
errorMsg("uudecode: %s: %s\n", argv[optind], strerror(errno));
|
||||
exit_status = FALSE;
|
||||
}
|
||||
optind++;
|
||||
}
|
||||
while (optind < argc);
|
||||
}
|
||||
return(exit_status);
|
||||
}
|
||||
@@ -0,0 +1,244 @@
|
||||
/* uuencode.c -- uuencode utility.
|
||||
* Copyright (C) 1994, 1995 Free Software Foundation, Inc.
|
||||
*
|
||||
* This product is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This product is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this product; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*/
|
||||
|
||||
/* Copyright (c) 1983 Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* Reworked to GNU style by Ian Lance Taylor, ian@airs.com, August 93. */
|
||||
/* Hacked to work with BusyBox by Alfred M. Szmidt */
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <pwd.h>
|
||||
|
||||
#define RW (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
|
||||
|
||||
static void encode __P ((void));
|
||||
|
||||
/* Pointer to the translation table we currently use. */
|
||||
const char *trans_ptr;
|
||||
|
||||
/* The two currently defined translation tables. The first is the
|
||||
standard uuencoding, the second is base64 encoding. */
|
||||
const char uu_std[64] = {
|
||||
'`', '!', '"', '#', '$', '%', '&', '\'',
|
||||
'(', ')', '*', '+', ',', '-', '.', '/',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', ':', ';', '<', '=', '>', '?',
|
||||
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
|
||||
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
||||
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
||||
'X', 'Y', 'Z', '[', '\\', ']', '^', '_'
|
||||
};
|
||||
|
||||
const char uu_base64[64] = {
|
||||
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
|
||||
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
|
||||
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
|
||||
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
|
||||
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
||||
'w', 'x', 'y', 'z', '0', '1', '2', '3',
|
||||
'4', '5', '6', '7', '8', '9', '+', '/'
|
||||
};
|
||||
|
||||
/* ENC is the basic 1 character encoding function to make a char printing. */
|
||||
#define ENC(Char) (trans_ptr[(Char) & 077])
|
||||
|
||||
/* Copy from IN to OUT, encoding as you go along. */
|
||||
static void encode()
|
||||
{
|
||||
register int ch, n;
|
||||
char *p = NULL;
|
||||
char buf[80];
|
||||
|
||||
while (1) {
|
||||
n = 0;
|
||||
do {
|
||||
register int m = fread (buf, 1, 45 - n, stdin);
|
||||
if (m == 0)
|
||||
break;
|
||||
n += m;
|
||||
}
|
||||
while (n < 45);
|
||||
|
||||
if (n == 0)
|
||||
break;
|
||||
|
||||
if (trans_ptr == uu_std)
|
||||
if (putchar (ENC (n)) == EOF)
|
||||
break;
|
||||
for (p = buf; n > 2; n -= 3, p += 3) {
|
||||
ch = *p >> 2;
|
||||
ch = ENC (ch);
|
||||
if (putchar (ch) == EOF)
|
||||
break;
|
||||
ch = ((*p << 4) & 060) | ((p[1] >> 4) & 017);
|
||||
ch = ENC (ch);
|
||||
if (putchar (ch) == EOF)
|
||||
break;
|
||||
ch = ((p[1] << 2) & 074) | ((p[2] >> 6) & 03);
|
||||
ch = ENC (ch);
|
||||
if (putchar (ch) == EOF)
|
||||
break;
|
||||
ch = p[2] & 077;
|
||||
ch = ENC (ch);
|
||||
if (putchar (ch) == EOF)
|
||||
break;
|
||||
}
|
||||
|
||||
if (n != 0)
|
||||
break;
|
||||
|
||||
if (putchar ('\n') == EOF)
|
||||
break;
|
||||
}
|
||||
|
||||
while (n != 0) {
|
||||
char c1 = *p;
|
||||
char c2 = n == 1 ? 0 : p[1];
|
||||
|
||||
ch = c1 >> 2;
|
||||
ch = ENC (ch);
|
||||
if (putchar (ch) == EOF)
|
||||
break;
|
||||
|
||||
ch = ((c1 << 4) & 060) | ((c2 >> 4) & 017);
|
||||
ch = ENC (ch);
|
||||
if (putchar (ch) == EOF)
|
||||
break;
|
||||
|
||||
if (n == 1)
|
||||
ch = trans_ptr == uu_std ? ENC ('\0') : '=';
|
||||
else {
|
||||
ch = (c2 << 2) & 074;
|
||||
ch = ENC (ch);
|
||||
}
|
||||
if (putchar (ch) == EOF)
|
||||
break;
|
||||
ch = trans_ptr == uu_std ? ENC ('\0') : '=';
|
||||
if (putchar (ch) == EOF)
|
||||
break;
|
||||
putchar ('\n');
|
||||
break;
|
||||
}
|
||||
|
||||
if (ferror (stdin))
|
||||
errorMsg("Read error\n");
|
||||
|
||||
if (trans_ptr == uu_std) {
|
||||
putchar (ENC ('\0'));
|
||||
putchar ('\n');
|
||||
}
|
||||
}
|
||||
|
||||
static const char uuencode_usage[] =
|
||||
"uuencode [OPTION] [INFILE] REMOTEFILE\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nUuencode a file.\n\n"
|
||||
"Options:\n"
|
||||
"\t-m\tuse base64 encoding as of RFC1521\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
int uuencode_main (int argc,
|
||||
char **argv)
|
||||
{
|
||||
int opt;
|
||||
struct stat sb;
|
||||
int mode;
|
||||
|
||||
trans_ptr = uu_std; /* Standard encoding is old uu format */
|
||||
|
||||
/* Parse any options */
|
||||
while ((opt = getopt (argc, argv, "m")) != EOF) {
|
||||
switch (opt) {
|
||||
case 'm':
|
||||
trans_ptr = uu_base64;
|
||||
break;
|
||||
|
||||
case 0:
|
||||
break;
|
||||
|
||||
default:
|
||||
usage(uuencode_usage);
|
||||
}
|
||||
}
|
||||
|
||||
switch (argc - optind) {
|
||||
case 2:
|
||||
/* Optional first argument is input file. */
|
||||
if (!freopen (argv[optind], "r", stdin) || fstat (fileno (stdin), &sb)) {
|
||||
errorMsg("uuencode: %s: %s\n", argv[optind], strerror(errno));
|
||||
exit FALSE;
|
||||
}
|
||||
mode = sb.st_mode & (S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
optind++;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
mode = RW & ~umask (RW);
|
||||
break;
|
||||
|
||||
case 0:
|
||||
default:
|
||||
usage(uuencode_usage);
|
||||
}
|
||||
|
||||
printf("begin%s %o %s\n", trans_ptr == uu_std ? "" : "-base64",
|
||||
mode, argv[optind]);
|
||||
encode();
|
||||
printf(trans_ptr == uu_std ? "end\n" : "====\n");
|
||||
if (ferror (stdout)) {
|
||||
errorMsg("Write error\n");
|
||||
exit FALSE;
|
||||
}
|
||||
return( TRUE);
|
||||
}
|
||||
@@ -23,15 +23,18 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static const char wc_usage[] = "wc [OPTION]... [FILE]...\n\n"
|
||||
"Print line, word, and byte counts for each FILE, and a total line if\n"
|
||||
static const char wc_usage[] = "wc [OPTION]... [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint line, word, and byte counts for each FILE, and a total line if\n"
|
||||
"more than one FILE is specified. With no FILE, read standard input.\n\n"
|
||||
"Options:\n"
|
||||
"\t-c\tprint the byte counts\n"
|
||||
"\t-l\tprint the newline counts\n"
|
||||
|
||||
"\t-L\tprint the length of the longest line\n"
|
||||
"\t-w\tprint the word counts\n";
|
||||
"\t-w\tprint the word counts\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
static int total_lines, total_words, total_chars, max_length;
|
||||
static int print_lines, print_words, print_chars, print_length;
|
||||
@@ -163,5 +166,5 @@ int wc_main(int argc, char **argv)
|
||||
print_counts(total_lines, total_words, total_chars,
|
||||
max_length, "total");
|
||||
}
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -24,24 +24,26 @@
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
|
||||
static const char whoami_usage[] = "whoami\n\n"
|
||||
"Prints the user name associated with the current effective user id.\n";
|
||||
static const char whoami_usage[] = "whoami\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrints the user name associated with the current effective user id.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int whoami_main(int argc, char **argv)
|
||||
{
|
||||
struct passwd *pw;
|
||||
uid_t uid;
|
||||
char *user = xmalloc(9);
|
||||
uid_t uid = geteuid();
|
||||
|
||||
if (argc > 1)
|
||||
usage(whoami_usage);
|
||||
|
||||
uid = geteuid();
|
||||
pw = getpwuid(uid);
|
||||
if (pw) {
|
||||
puts(pw->pw_name);
|
||||
my_getpwuid(user, uid);
|
||||
if (user) {
|
||||
puts(user);
|
||||
exit(TRUE);
|
||||
}
|
||||
fprintf(stderr, "%s: cannot find username for UID %u\n", argv[0],
|
||||
(unsigned) uid);
|
||||
exit(FALSE);
|
||||
return(FALSE);
|
||||
}
|
||||
@@ -27,9 +27,12 @@ extern int yes_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (argc >=1 && *argv[1]=='-') {
|
||||
usage("yes [OPTION]... [STRING]...\n\n"
|
||||
"Repeatedly outputs a line with all specified STRING(s), or `y'.\n");
|
||||
if (argc >= 2 && *argv[1] == '-') {
|
||||
usage("yes [OPTION]... [STRING]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nRepeatedly outputs a line with all specified STRING(s), or `y'.\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
if (argc == 1) {
|
||||
|
||||
@@ -49,27 +49,34 @@ static const char *dz; /* dollar zero, .bss */
|
||||
static const char *cp_mv_usage[] = /* .rodata */
|
||||
{
|
||||
"cp [OPTION]... SOURCE DEST\n"
|
||||
" or: cp [OPTION]... SOURCE... DIRECTORY\n\n"
|
||||
"Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n"
|
||||
" or: cp [OPTION]... SOURCE... DIRECTORY\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCopies SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n"
|
||||
"\n"
|
||||
"\t-a\tsame as -dpR\n"
|
||||
"\t-d\tpreserve links\n"
|
||||
"\t-p\tpreserve file attributes if possible\n"
|
||||
"\t-R\tcopy directories recursively\n",
|
||||
"\t-a\tSame as -dpR\n"
|
||||
"\t-d\tPreserves links\n"
|
||||
"\t-p\tPreserves file attributes if possible\n"
|
||||
"\t-f\tforce (implied; ignored) - always set\n"
|
||||
"\t-R\tCopies directories recursively\n"
|
||||
#endif
|
||||
,
|
||||
"mv SOURCE DEST\n"
|
||||
" or: mv SOURCE... DIRECTORY\n\n"
|
||||
"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n"
|
||||
" or: mv SOURCE... DIRECTORY\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nRename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n"
|
||||
#endif
|
||||
};
|
||||
|
||||
static int recursiveFlag;
|
||||
static int followLinks;
|
||||
static int preserveFlag;
|
||||
static int forceFlag;
|
||||
|
||||
static const char *baseSrcName;
|
||||
static int srcDirFlag;
|
||||
static struct stat srcStatBuf;
|
||||
|
||||
static char baseDestName[PATH_MAX + 1];
|
||||
static char baseDestName[BUFSIZ + 1];
|
||||
static size_t baseDestLen;
|
||||
static int destDirFlag;
|
||||
static struct stat destStatBuf;
|
||||
@@ -83,7 +90,7 @@ static
|
||||
void name_too_long__exit (void)
|
||||
{
|
||||
fprintf(stderr, name_too_long, dz);
|
||||
exit FALSE;
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -92,12 +99,12 @@ fill_baseDest_buf(char *_buf, size_t * _buflen) {
|
||||
if ((srcBasename = strrchr(baseSrcName, '/')) == NULL) {
|
||||
srcBasename = baseSrcName;
|
||||
if (_buf[*_buflen - 1] != '/') {
|
||||
if (++(*_buflen) > PATH_MAX)
|
||||
if (++(*_buflen) > BUFSIZ)
|
||||
name_too_long__exit();
|
||||
strcat(_buf, "/");
|
||||
}
|
||||
}
|
||||
if (*_buflen + strlen(srcBasename) > PATH_MAX)
|
||||
if (*_buflen + strlen(srcBasename) > BUFSIZ)
|
||||
name_too_long__exit();
|
||||
strcat(_buf, srcBasename);
|
||||
return;
|
||||
@@ -107,7 +114,7 @@ fill_baseDest_buf(char *_buf, size_t * _buflen) {
|
||||
static int
|
||||
cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
char destName[PATH_MAX + 1];
|
||||
char destName[BUFSIZ + 1];
|
||||
size_t destLen;
|
||||
const char *srcBasename;
|
||||
char *name;
|
||||
@@ -123,7 +130,7 @@ cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
|
||||
srcBasename = (strstr(fileName, baseSrcName)
|
||||
+ strlen(baseSrcName));
|
||||
|
||||
if (destLen + strlen(srcBasename) > PATH_MAX) {
|
||||
if (destLen + strlen(srcBasename) > BUFSIZ) {
|
||||
fprintf(stderr, name_too_long, dz);
|
||||
return FALSE;
|
||||
}
|
||||
@@ -161,7 +168,7 @@ cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
|
||||
add_to_ino_dev_hashtable(statbuf, destName);
|
||||
}
|
||||
}
|
||||
return copyFile(fileName, destName, preserveFlag, followLinks);
|
||||
return copyFile(fileName, destName, preserveFlag, followLinks, forceFlag);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -194,9 +201,9 @@ extern int cp_mv_main(int argc, char **argv)
|
||||
argv++;
|
||||
|
||||
if (dz_i == is_cp) {
|
||||
recursiveFlag = preserveFlag = FALSE;
|
||||
recursiveFlag = preserveFlag = forceFlag = FALSE;
|
||||
followLinks = TRUE;
|
||||
while (**argv == '-') {
|
||||
while (*argv && **argv == '-') {
|
||||
while (*++(*argv)) {
|
||||
switch (**argv) {
|
||||
case 'a':
|
||||
@@ -213,6 +220,9 @@ extern int cp_mv_main(int argc, char **argv)
|
||||
case 'R':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
forceFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage(cp_mv_usage[is_cp]);
|
||||
}
|
||||
@@ -220,12 +230,16 @@ extern int cp_mv_main(int argc, char **argv)
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
if (argc < 2) {
|
||||
usage(cp_mv_usage[dz_i]);
|
||||
}
|
||||
} else { /* (dz_i == is_mv) */
|
||||
recursiveFlag = preserveFlag = TRUE;
|
||||
followLinks = FALSE;
|
||||
}
|
||||
|
||||
|
||||
if (strlen(argv[argc - 1]) > PATH_MAX) {
|
||||
if (strlen(argv[argc - 1]) > BUFSIZ) {
|
||||
fprintf(stderr, name_too_long, "cp");
|
||||
goto exit_false;
|
||||
}
|
||||
@@ -247,7 +261,7 @@ extern int cp_mv_main(int argc, char **argv)
|
||||
|
||||
baseSrcName = *(argv++);
|
||||
|
||||
if ((srcLen = strlen(baseSrcName)) > PATH_MAX)
|
||||
if ((srcLen = strlen(baseSrcName)) > BUFSIZ)
|
||||
name_too_long__exit();
|
||||
|
||||
if (srcLen == 0) continue; /* "" */
|
||||
@@ -261,7 +275,7 @@ extern int cp_mv_main(int argc, char **argv)
|
||||
int state = 0;
|
||||
char *pushd, *d, *p;
|
||||
|
||||
if ((pushd = getcwd(NULL, PATH_MAX + 1)) == NULL) {
|
||||
if ((pushd = getcwd(NULL, BUFSIZ + 1)) == NULL) {
|
||||
fprintf(stderr, "%s: getcwd(): %s\n", dz, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
@@ -269,7 +283,7 @@ extern int cp_mv_main(int argc, char **argv)
|
||||
fprintf(stderr, "%s: chdir(%s): %s\n", dz, baseSrcName, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
if ((d = getcwd(NULL, PATH_MAX + 1)) == NULL) {
|
||||
if ((d = getcwd(NULL, BUFSIZ + 1)) == NULL) {
|
||||
fprintf(stderr, "%s: getcwd(): %s\n", dz, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
@@ -319,10 +333,9 @@ extern int cp_mv_main(int argc, char **argv)
|
||||
if (flags_memo)
|
||||
*(baseDestName + baseDestLen) = '\0';
|
||||
}
|
||||
// exit_true:
|
||||
exit TRUE;
|
||||
return( TRUE);
|
||||
exit_false:
|
||||
exit FALSE;
|
||||
return( FALSE);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -0,0 +1,372 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* cut implementation for busybox
|
||||
*
|
||||
* Copyright (c) Michael J. Holme
|
||||
*
|
||||
* This version of cut is adapted from Minix cut and was modified
|
||||
* by Erik Andersen <andersee@debian.org> to be used in busybox.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Original copyright notice is retained at the end of this file.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <sys/types.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_help
|
||||
#include "messages.c"
|
||||
|
||||
#define MAX_FIELD 80 /* Pointers to the beginning of each field
|
||||
* are stored in columns[], if a line holds
|
||||
* more than MAX_FIELD columns the array
|
||||
* boundary is exceed. But unlikely at 80 */
|
||||
|
||||
#define MAX_ARGS 32 /* Maximum number of fields following -f or
|
||||
* -c switches */
|
||||
int args[MAX_ARGS * 2];
|
||||
int num_args;
|
||||
|
||||
/* Lots of new defines, should easen maintainance... */
|
||||
#define DUMP_STDIN 0 /* define for mode: no options */
|
||||
#define OPTIONF 1 /* define for mode: option -f */
|
||||
#define OPTIONC 2 /* define for mode: option -c */
|
||||
#define OPTIONB 3 /* define for mode: option -b */
|
||||
#define NOTSET 0 /* option not selected */
|
||||
#define SET 1 /* option selected */
|
||||
|
||||
/* Defines for the warnings */
|
||||
#define DELIMITER_NOT_APPLICABLE 0
|
||||
#define OVERRIDING_PREVIOUS_MODE 1
|
||||
#define OPTION_NOT_APPLICABLE 2
|
||||
#define UNKNOWN_OPTION 3
|
||||
#define FILE_NOT_READABLE 4
|
||||
|
||||
/* Defines for the fatal errors */
|
||||
#define SYNTAX_ERROR 101
|
||||
#define POSITION_ERROR 102
|
||||
#define LINE_TO_LONG_ERROR 103
|
||||
#define RANGE_ERROR 104
|
||||
#define MAX_FIELDS_EXEEDED_ERROR 105
|
||||
#define MAX_ARGS_EXEEDED_ERROR 106
|
||||
|
||||
|
||||
int mode; /* 0 = dump stdin to stdout, 1=-f, 2=-c */
|
||||
char delim = '\t'; /* default delimiting character */
|
||||
FILE *fd;
|
||||
char *name;
|
||||
char line[BUFSIZ];
|
||||
int exit_status;
|
||||
|
||||
int cut_main(int argc, char **argv);
|
||||
void warn(int warn_number, char *option);
|
||||
void cuterror(int err);
|
||||
void get_args(void);
|
||||
void cut(void);
|
||||
|
||||
void warn(int warn_number, char *option)
|
||||
{
|
||||
static char *warn_msg[] = {
|
||||
"%s: Option -d allowed only with -f\n",
|
||||
"%s: -%s overrides earlier option\n",
|
||||
"%s: -%s not allowed in current mode\n",
|
||||
"%s: Cannot open %s\n"
|
||||
};
|
||||
|
||||
fprintf(stderr, warn_msg[warn_number], name, option);
|
||||
exit_status = warn_number + 1;
|
||||
|
||||
}
|
||||
|
||||
void cuterror(int err)
|
||||
{
|
||||
static char *err_mes[] = {
|
||||
"%s: syntax error\n",
|
||||
"%s: position must be >0\n",
|
||||
"%s: line longer than BUFSIZ\n",
|
||||
"%s: range must not decrease from left to right\n",
|
||||
"%s: MAX_FIELD exceeded\n",
|
||||
"%s: MAX_ARGS exceeded\n"
|
||||
};
|
||||
|
||||
fprintf(stderr, err_mes[err - 101], name);
|
||||
exit(err);
|
||||
}
|
||||
|
||||
|
||||
void get_args()
|
||||
{
|
||||
int i = 0;
|
||||
int arg_ptr = 0;
|
||||
int flag;
|
||||
|
||||
num_args = 0;
|
||||
do {
|
||||
if (num_args == MAX_ARGS)
|
||||
cuterror(MAX_ARGS_EXEEDED_ERROR);
|
||||
if (!isdigit(line[i]) && line[i] != '-')
|
||||
cuterror(SYNTAX_ERROR);
|
||||
|
||||
args[arg_ptr] = 1;
|
||||
args[arg_ptr + 1] = BUFSIZ;
|
||||
flag = 1;
|
||||
|
||||
while (line[i] != ',' && line[i] != 0) {
|
||||
if (isdigit(line[i])) {
|
||||
args[arg_ptr] = 0;
|
||||
while (isdigit(line[i]))
|
||||
args[arg_ptr] = 10 * args[arg_ptr] + line[i++] - '0';
|
||||
if (!args[arg_ptr])
|
||||
cuterror(POSITION_ERROR);
|
||||
arg_ptr++;
|
||||
}
|
||||
if (line[i] == '-') {
|
||||
arg_ptr |= 1;
|
||||
i++;
|
||||
flag = 0;
|
||||
}
|
||||
}
|
||||
if (flag && arg_ptr & 1)
|
||||
args[arg_ptr] = args[arg_ptr - 1];
|
||||
if (args[num_args * 2] > args[num_args * 2 + 1])
|
||||
cuterror(RANGE_ERROR);
|
||||
num_args++;
|
||||
arg_ptr = num_args * 2;
|
||||
}
|
||||
while (line[i++]);
|
||||
}
|
||||
|
||||
|
||||
void cut()
|
||||
{
|
||||
int i, j, length, maxcol=0;
|
||||
char *columns[MAX_FIELD];
|
||||
|
||||
while (fgets(line, BUFSIZ, fd)) {
|
||||
length = strlen(line) - 1;
|
||||
*(line + length) = 0;
|
||||
switch (mode) {
|
||||
case DUMP_STDIN:
|
||||
printf("%s", line);
|
||||
break;
|
||||
case OPTIONF:
|
||||
columns[maxcol++] = line;
|
||||
for (i = 0; i < length; i++) {
|
||||
if (*(line + i) == delim) {
|
||||
*(line + i) = 0;
|
||||
if (maxcol == MAX_FIELD)
|
||||
cuterror(MAX_FIELDS_EXEEDED_ERROR);
|
||||
columns[maxcol] = line + i + 1;
|
||||
maxcol++;
|
||||
}
|
||||
}
|
||||
if (maxcol != 1) {
|
||||
for (i = 0; i < num_args; i++) {
|
||||
for (j = args[i * 2]; j <= args[i * 2 + 1]; j++)
|
||||
if (j <= maxcol) {
|
||||
printf("%s", columns[j - 1]);
|
||||
if (i != num_args - 1 || j != args[i * 2 + 1])
|
||||
putchar(delim);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OPTIONC:
|
||||
for (i = 0; i < num_args; i++) {
|
||||
for (j = args[i * 2];
|
||||
j <= (args[i * 2 + 1] >
|
||||
length ? length : args[i * 2 + 1]); j++)
|
||||
putchar(*(line + j - 1));
|
||||
}
|
||||
}
|
||||
if (maxcol != 1)
|
||||
putchar('\n');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int cut_main(int argc, char **argv)
|
||||
{
|
||||
int i = 1;
|
||||
int numberFilenames = 0;
|
||||
|
||||
name = argv[0];
|
||||
|
||||
if (argc == 1 || strcmp(argv[1], dash_dash_help)==0)
|
||||
usage( "cut [OPTION]... [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrints selected fields from each input FILE to standard output.\n\n"
|
||||
"Options:\n"
|
||||
"\t-b LIST\tOutput only bytes from LIST\n"
|
||||
"\t-c LIST\tOutput only characters from LIST\n"
|
||||
"\t-d DELIM\tUse DELIM instead of tab as the field delimiter\n"
|
||||
"\t-f N\tPrint only these fields\n"
|
||||
"\t-n\tIgnored\n"
|
||||
#endif
|
||||
);
|
||||
|
||||
while (i < argc) {
|
||||
if (argv[i][0] == '-') {
|
||||
switch (argv[i++][1]) {
|
||||
case 'd':
|
||||
if (mode == OPTIONC || mode == OPTIONB)
|
||||
warn(DELIMITER_NOT_APPLICABLE, "d");
|
||||
delim = argv[i++][0];
|
||||
break;
|
||||
case 'f':
|
||||
sprintf(line, "%s", argv[i++]);
|
||||
if (mode == OPTIONC || mode == OPTIONB)
|
||||
warn(OVERRIDING_PREVIOUS_MODE, "f");
|
||||
mode = OPTIONF;
|
||||
break;
|
||||
case 'b':
|
||||
sprintf(line, "%s", argv[i++]);
|
||||
if (mode == OPTIONF || mode == OPTIONC)
|
||||
warn(OVERRIDING_PREVIOUS_MODE, "b");
|
||||
mode = OPTIONB;
|
||||
break;
|
||||
case 'c':
|
||||
sprintf(line, "%s", argv[i++]);
|
||||
if (mode == OPTIONF || mode == OPTIONB)
|
||||
warn(OVERRIDING_PREVIOUS_MODE, "c");
|
||||
mode = OPTIONC;
|
||||
break;
|
||||
case '\0': /* - means: read from stdin */
|
||||
numberFilenames++;
|
||||
break;
|
||||
case 'n': /* needed for Posix, but no effect here */
|
||||
if (mode != OPTIONB)
|
||||
warn(OPTION_NOT_APPLICABLE, "n");
|
||||
break;
|
||||
default:
|
||||
warn(UNKNOWN_OPTION, &(argv[i - 1][1]));
|
||||
}
|
||||
} else {
|
||||
i++;
|
||||
numberFilenames++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Here follow the checks, if the selected options are reasonable. */
|
||||
if (mode == OPTIONB) /* since in Minix char := byte */
|
||||
mode = OPTIONC;
|
||||
get_args();
|
||||
if (numberFilenames != 0) {
|
||||
i = 1;
|
||||
while (i < argc) {
|
||||
if (argv[i][0] == '-') {
|
||||
switch (argv[i][1]) {
|
||||
case 'f':
|
||||
case 'c':
|
||||
case 'b':
|
||||
case 'd':
|
||||
i += 2;
|
||||
break;
|
||||
case 'n':
|
||||
case 'i':
|
||||
case 's':
|
||||
i++;
|
||||
break;
|
||||
case '\0':
|
||||
fd = stdin;
|
||||
i++;
|
||||
cut();
|
||||
break;
|
||||
default:
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
if ((fd = fopen(argv[i++], "r")) == NULL) {
|
||||
warn(FILE_NOT_READABLE, argv[i - 1]);
|
||||
} else {
|
||||
cut();
|
||||
fclose(fd);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fd = stdin;
|
||||
cut();
|
||||
}
|
||||
|
||||
return(exit_status);
|
||||
}
|
||||
|
||||
/* cut - extract columns from a file or stdin. Author: Michael J. Holme
|
||||
*
|
||||
* Copyright 1989, Michael John Holme, All rights reserved.
|
||||
* This code may be freely distributed, provided that this notice
|
||||
* remains intact.
|
||||
*
|
||||
* V1.1: 6th September 1989
|
||||
*
|
||||
* Bugs, criticisms, etc,
|
||||
* c/o Mark Powell
|
||||
* JANET sq79@uk.ac.liv
|
||||
* ARPA sq79%liv.ac.uk@nsfnet-relay.ac.uk
|
||||
* UUCP ...!mcvax!ukc!liv.ac.uk!sq79
|
||||
*-------------------------------------------------------------------------
|
||||
* Changed for POSIX1003.2/Draft10 conformance
|
||||
* Thomas Brupbacher (tobr@mw.lpc.ethz.ch), September 1990.
|
||||
* Changes:
|
||||
* - separation of error messages ( stderr) and output (stdout).
|
||||
* - support for -b and -n (no effect, -b acts as -c)
|
||||
* - support for -s
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987,1997, Prentice Hall
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use of the MINIX operating system in source and
|
||||
* binary forms, with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the following
|
||||
* disclaimer in the documentation and/or other materials provided
|
||||
* with the distribution.
|
||||
*
|
||||
* Neither the name of Prentice Hall nor the names of the software
|
||||
* authors or contributors may be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS, AUTHORS, AND
|
||||
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL PRENTICE HALL OR ANY AUTHORS OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
||||
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
||||
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
@@ -40,12 +40,14 @@
|
||||
mail commands */
|
||||
|
||||
static const char date_usage[] = "date [OPTION]... [+FORMAT]\n"
|
||||
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n\n"
|
||||
"Display the current time in the given FORMAT, or set the system date.\n"
|
||||
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
|
||||
"\t-s\t\tset time described by STRING\n"
|
||||
|
||||
"\t-u\t\tprint or set Coordinated Universal Time\n";
|
||||
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nDisplays the current time in the given FORMAT, or sets the system date.\n"
|
||||
"\nOptions:\n\t-R\tOutputs RFC-822 compliant date string\n"
|
||||
"\t-s\tSets time described by STRING\n"
|
||||
"\t-u\tPrints or sets Coordinated Universal Time\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
/* Input parsing code is always bulky - used heavy duty libc stuff as
|
||||
@@ -179,18 +181,18 @@ int date_main(int argc, char **argv)
|
||||
set_time = 1;
|
||||
if (date_str != NULL)
|
||||
usage(date_usage);
|
||||
date_str = optarg;
|
||||
date_str = *argv;
|
||||
break;
|
||||
case 'u':
|
||||
utc = 1;
|
||||
if (putenv("TZ=UTC0") != 0)
|
||||
fatalError(memory_exhausted, "date");
|
||||
/* Look ma, no break. Don't fix it either. */
|
||||
break;
|
||||
case 'd':
|
||||
use_arg = 1;
|
||||
if (date_str != NULL)
|
||||
usage(date_usage);
|
||||
date_str = optarg;
|
||||
date_str = *argv;
|
||||
break;
|
||||
case '-':
|
||||
usage(date_usage);
|
||||
@@ -271,6 +273,5 @@ int date_main(int argc, char **argv)
|
||||
strftime(t_buff, 200, date_fmt, &tm_time);
|
||||
printf("%s\n", t_buff);
|
||||
|
||||
exit(TRUE);
|
||||
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include "internal.h"
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@@ -7,10 +8,13 @@
|
||||
|
||||
/* Tiny RPN calculator, because "expr" didn't give me bitwise operations. */
|
||||
|
||||
static const char math_usage[] = "math expression ...\n\n"
|
||||
"This is a Tiny RPN calculator that understands the\n"
|
||||
static const char dc_usage[] = "dc expression ...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nThis is a Tiny RPN calculator that understands the\n"
|
||||
"following operations: +, -, /, *, and, or, not, eor.\n"
|
||||
"i.e. 'math 2 2 add' -> 4, and 'math 8 8 \\* 2 2 + /' -> 16\n";
|
||||
"i.e. 'dc 2 2 add' -> 4, and 'dc 8 8 \\* 2 2 + /' -> 16\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
static double stack[100];
|
||||
static unsigned int pointer;
|
||||
@@ -18,7 +22,7 @@ static unsigned int pointer;
|
||||
static void push(double a)
|
||||
{
|
||||
if (pointer >= (sizeof(stack) / sizeof(*stack))) {
|
||||
fprintf(stderr, "math: stack overflow\n");
|
||||
fprintf(stderr, "dc: stack overflow\n");
|
||||
exit(-1);
|
||||
} else
|
||||
stack[pointer++] = a;
|
||||
@@ -27,7 +31,7 @@ static void push(double a)
|
||||
static double pop()
|
||||
{
|
||||
if (pointer == 0) {
|
||||
fprintf(stderr, "math: stack underflow\n");
|
||||
fprintf(stderr, "dc: stack underflow\n");
|
||||
exit(-1);
|
||||
}
|
||||
return stack[--pointer];
|
||||
@@ -88,15 +92,19 @@ struct op {
|
||||
};
|
||||
|
||||
static const struct op operators[] = {
|
||||
{"+", add},
|
||||
{"-", sub},
|
||||
{"*", mul},
|
||||
{"/", divide},
|
||||
{"+", add},
|
||||
{"add", add},
|
||||
{"-", sub},
|
||||
{"sub", sub},
|
||||
{"*", mul},
|
||||
{"mul", mul},
|
||||
{"/", divide},
|
||||
{"div", divide},
|
||||
{"and", and},
|
||||
{"or", or},
|
||||
{"or", or},
|
||||
{"not", not},
|
||||
{"eor", eor},
|
||||
{0, 0}
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
static void stack_machine(const char *argument)
|
||||
@@ -124,19 +132,63 @@ static void stack_machine(const char *argument)
|
||||
}
|
||||
o++;
|
||||
}
|
||||
fprintf(stderr, "math: %s: syntax error.\n", argument);
|
||||
fprintf(stderr, "dc: %s: syntax error.\n", argument);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
int math_main(int argc, char **argv)
|
||||
/* return pointer to next token in buffer and set *buffer to one char
|
||||
* past the end of the above mentioned token
|
||||
*/
|
||||
static char *get_token(char **buffer)
|
||||
{
|
||||
if (argc <= 1 || *argv[1]=='-')
|
||||
usage(math_usage);
|
||||
while (argc >= 2) {
|
||||
stack_machine(argv[1]);
|
||||
argv++;
|
||||
argc--;
|
||||
char *start = NULL;
|
||||
char *current = *buffer;
|
||||
|
||||
while (isspace(*current)) { current++; }
|
||||
if (*current != 0) {
|
||||
start = current;
|
||||
while (!isspace(*current) && current != 0) { current++; }
|
||||
*buffer = current;
|
||||
}
|
||||
return start;
|
||||
}
|
||||
|
||||
/* In Perl one might say, scalar m|\s*(\S+)\s*|g */
|
||||
static int number_of_tokens(char *buffer)
|
||||
{
|
||||
int i = 0;
|
||||
char *b = buffer;
|
||||
while (get_token(&b)) { i++; }
|
||||
return i;
|
||||
}
|
||||
|
||||
int dc_main(int argc, char **argv)
|
||||
{
|
||||
/* take stuff from stdin if no args are given */
|
||||
if (argc <= 1) {
|
||||
int i, len;
|
||||
char *line = NULL;
|
||||
char *cursor = NULL;
|
||||
char *token = NULL;
|
||||
while ((line = cstring_lineFromFile(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);
|
||||
exit( TRUE);
|
||||
return( TRUE);
|
||||
}
|
||||
@@ -41,17 +41,19 @@ typedef unsigned long long int uintmax_t;
|
||||
#endif
|
||||
|
||||
static const char dd_usage[] =
|
||||
"dd [if=name] [of=name] [bs=n] [count=n] [skip=n] [seek=n]\n\n"
|
||||
"Copy a file, converting and formatting according to options\n\n"
|
||||
"dd [if=FILE] [of=FILE] [bs=N] [count=N] [skip=N] [seek=N]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nCopy a file, converting and formatting according to options\n\n"
|
||||
"\tif=FILE\tread from FILE instead of stdin\n"
|
||||
"\tof=FILE\twrite to FILE instead of stdout\n"
|
||||
"\tbs=n\tread and write n bytes at a time\n"
|
||||
"\tcount=n\tcopy only n input blocks\n"
|
||||
"\tskip=n\tskip n input blocks\n"
|
||||
"\tseek=n\tskip n output blocks\n"
|
||||
|
||||
"\tbs=N\tread and write N bytes at a time\n"
|
||||
"\tcount=N\tcopy only N input blocks\n"
|
||||
"\tskip=N\tskip N input blocks\n"
|
||||
"\tseek=N\tskip N output blocks\n"
|
||||
"\n"
|
||||
"Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n";
|
||||
"Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <linux/vt.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern int getfd(void);
|
||||
char *progname;
|
||||
|
||||
int deallocvt_main(int argc, char *argv[])
|
||||
@@ -20,7 +19,11 @@ int deallocvt_main(int argc, char *argv[])
|
||||
|
||||
if ((argc != 2) || (**(argv + 1) == '-')) {
|
||||
usage
|
||||
("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
|
||||
("deallocvt N\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nDeallocate unused virtual terminal /dev/ttyN\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
progname = argv[0];
|
||||
@@ -31,7 +34,7 @@ int deallocvt_main(int argc, char *argv[])
|
||||
/* deallocate all unused consoles */
|
||||
if (ioctl(fd, VT_DISALLOCATE, 0)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
exit(1);
|
||||
exit( FALSE);
|
||||
}
|
||||
} else
|
||||
for (i = 1; i < argc; i++) {
|
||||
@@ -45,8 +48,8 @@ int deallocvt_main(int argc, char *argv[])
|
||||
perror("VT_DISALLOCATE");
|
||||
fprintf(stderr, "%s: could not deallocate console %d\n",
|
||||
progname, num);
|
||||
exit(1);
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
return( TRUE);
|
||||
}
|
||||
@@ -0,0 +1,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
|
||||
@@ -0,0 +1,18 @@
|
||||
busybox (0.45-1) frozen; 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> Sun, 18 Jun 2000 21:45:47 -0600
|
||||
|
||||
Local variables:
|
||||
mode: debian-changelog
|
||||
add-log-mailing-address: "andersee@debian.org"
|
||||
End:
|
||||
@@ -0,0 +1,46 @@
|
||||
Source: busybox
|
||||
Priority: optional
|
||||
Maintainer: Erik Andersen <andersee@debian.org>
|
||||
Build-Depends: debhelper (>= 2.0.80)
|
||||
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: dpkg, 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.
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
This package was debianized by Erik Andersen <andersee@debian.org> on
|
||||
Sun, 18 Jun 2000 23:31:02 -0600
|
||||
|
||||
It was downloaded from ftp://ftp.lineo.com/pub/busybox
|
||||
HomePage is at: http://busybox.lineo.com/
|
||||
|
||||
Copyright: GPL
|
||||
@@ -0,0 +1,119 @@
|
||||
#!/usr/bin/make -f
|
||||
|
||||
# This is a bit unusual, in that I have to completely recompile everything
|
||||
# twice. The first is the normal, dynamically linked package. The second is
|
||||
# for the statically linked package. This file has been adjusted accordingly.
|
||||
|
||||
# This is the debhelper compatability version to use.
|
||||
export DH_COMPAT=1
|
||||
|
||||
bb=debian/tmp
|
||||
bbs=debian/busybox-static
|
||||
|
||||
clean:
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
rm -f build-stamp-busybox build-stamp-busybox-static
|
||||
-$(MAKE) clean
|
||||
-rm -rf $(bb) $(bbs)
|
||||
dh_clean
|
||||
|
||||
half_clean:
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
rm -rf $(bbs) build-stamp-busybox-static
|
||||
-$(MAKE) clean
|
||||
|
||||
build: build-stamp-busybox
|
||||
build-stamp-busybox:
|
||||
dh_testdir
|
||||
$(MAKE)
|
||||
touch build-stamp-busybox
|
||||
|
||||
install: build
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_clean -k
|
||||
dh_installdirs
|
||||
$(MAKE) "PREFIX=$(bb)" install
|
||||
mkdir -p $(bb)/usr/share/man/man1
|
||||
cp docs/BusyBox.1 $(bb)/usr/share/man/man1/busybox.1
|
||||
|
||||
# Now for the statically linked stuff
|
||||
build-static: build-stamp-busybox-static
|
||||
build-stamp-busybox-static:
|
||||
dh_testdir
|
||||
$(MAKE) DOSTATIC=true
|
||||
touch build-stamp-busybox-static
|
||||
|
||||
install-static: build
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_clean -k
|
||||
dh_installdirs
|
||||
# Do not run 'make install', since we do not want all the symlinks.
|
||||
# This just installes the busybox binary...
|
||||
#$(MAKE) "PREFIX=$(bbs)" install
|
||||
mkdir -p $(bbs)/bin/
|
||||
cp busybox $(bbs)/bin/busybox
|
||||
mkdir -p $(bbs)/usr/share/man/man1/
|
||||
cp docs/BusyBox.1 $(bbs)/usr/share/man/man1/busybox.1
|
||||
|
||||
do_static: half_clean build-static install-static
|
||||
|
||||
|
||||
# Build architecture-independent files here.
|
||||
binary-indep:
|
||||
# We have nothing to do by default.
|
||||
|
||||
# Build architecture-dependent files here.
|
||||
binary-arch: busybox busybox-static
|
||||
|
||||
busybox: install
|
||||
@echo "--- Building: $@"
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_installdirs
|
||||
dh_installdocs -p$@ docs/BusyBox.txt \
|
||||
docs/BusyBox.html docs/busybox.lineo.com AUTHORS README TODO
|
||||
rm -rf $(bb)/usr/share/doc/busybox/busybox.lineo.com/CVS \
|
||||
$(bb)/usr/share/doc/busybox/busybox.lineo.com/.cvsignore \
|
||||
$(bb)/usr/share/doc/busybox/busybox.lineo.com/images/CVS \
|
||||
$(bb)/usr/share/doc/busybox/busybox.lineo.com/images/.cvsignore
|
||||
#dh_undocumented -p$@
|
||||
dh_installchangelogs -p$@ Changelog
|
||||
dh_strip -p$@
|
||||
dh_compress -p$@
|
||||
dh_fixperms -p$@
|
||||
dh_installdeb -p$@
|
||||
dh_shlibdeps -p$@
|
||||
dh_gencontrol -p$@
|
||||
dh_md5sums -p$@
|
||||
dh_builddeb -p$@
|
||||
|
||||
|
||||
busybox-static: do_static
|
||||
@echo "--- Building: $@"
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_installdirs
|
||||
dh_installdocs -p$@ docs/BusyBox.txt \
|
||||
docs/BusyBox.html docs/busybox.lineo.com AUTHORS README TODO
|
||||
rm -rf $(bbs)/usr/share/doc/busybox-static/busybox.lineo.com/CVS \
|
||||
$(bbs)/usr/share/doc/busybox-static/busybox.lineo.com/.cvsignore \
|
||||
$(bbs)/usr/share/doc/busybox-static/busybox.lineo.com/images/CVS \
|
||||
$(bbs)/usr/share/doc/busybox-static/busybox.lineo.com/images/.cvsignore
|
||||
dh_undocumented -p$@
|
||||
dh_installchangelogs -p$@ Changelog
|
||||
dh_strip -p$@
|
||||
dh_compress -p$@
|
||||
dh_fixperms -p$@
|
||||
dh_installdeb -p$@
|
||||
dh_shlibdeps -p$@
|
||||
dh_gencontrol -p$@
|
||||
dh_md5sums -p$@
|
||||
dh_builddeb -p$@
|
||||
|
||||
|
||||
binary: binary-indep binary-arch
|
||||
.PHONY: build clean binary-indep binary-arch binary install
|
||||
@@ -28,8 +28,11 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/vfs.h>
|
||||
|
||||
static const char df_usage[] = "df [filesystem ...]\n\n"
|
||||
"Print the filesystem space used and space available.\n";
|
||||
static const char df_usage[] = "df [filesystem ...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrint the filesystem space used and space available.\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern const char mtab_file[]; /* Defined in utility.c */
|
||||
|
||||
@@ -48,7 +51,6 @@ static int df(char *device, const char *mountPoint)
|
||||
blocks_used = s.f_blocks - s.f_bfree;
|
||||
blocks_percent_used = (long)
|
||||
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
|
||||
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
|
||||
if (strcmp(device, "/dev/root") == 0) {
|
||||
/* Adjusts device to be the real root device,
|
||||
* or leaves device alone if it can't find it */
|
||||
@@ -106,7 +108,7 @@ extern int df_main(int argc, char **argv)
|
||||
endmntent(mountTable);
|
||||
}
|
||||
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -28,7 +28,11 @@ extern int dirname_main(int argc, char **argv)
|
||||
char* s;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
usage("dirname [file ...]\n");
|
||||
usage("dirname [FILENAME ...]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nStrips non-directory suffix from FILENAME\n"
|
||||
#endif
|
||||
);
|
||||
}
|
||||
argv++;
|
||||
|
||||
@@ -41,5 +45,5 @@ extern int dirname_main(int argc, char **argv)
|
||||
if (s && *s)
|
||||
*s = '\0';
|
||||
printf("%s\n", (s)? *argv : ".");
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||
@@ -18,7 +18,6 @@
|
||||
#include "internal.h"
|
||||
#include <linux/unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#if __GNU_LIBRARY__ < 5
|
||||
@@ -34,7 +33,15 @@ static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
|
||||
# include <sys/klog.h>
|
||||
#endif
|
||||
|
||||
static const char dmesg_usage[] = "dmesg [-c] [-n level] [-s bufsize]\n";
|
||||
static const char dmesg_usage[] = "dmesg [-c] [-n LEVEL] [-s SIZE]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nPrints or controls the kernel ring buffer\n\n"
|
||||
"Options:\n"
|
||||
"\t-c\t\tClears the ring buffer's contents after printing\n"
|
||||
"\t-n LEVEL\tSets console logging level\n"
|
||||
"\t-s SIZE\t\tUse a buffer of size SIZE\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
int dmesg_main(int argc, char **argv)
|
||||
{
|
||||
@@ -121,6 +128,5 @@ int dmesg_main(int argc, char **argv)
|
||||
exit(FALSE);
|
||||
klogctl_error:
|
||||
perror("klogctl");
|
||||
exit(FALSE);
|
||||
|
||||
return(FALSE);
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
BusyBox.txt
|
||||
BusyBox.1
|
||||
BusyBox.html
|
||||
@@ -1,21 +0,0 @@
|
||||
# busybox/docs/Makefile - Create the documentation
|
||||
# ------------------------
|
||||
# Copyright (C) 2000 Erik Andersen <andersee@debian.org> GPL
|
||||
|
||||
all: clean doc
|
||||
|
||||
doc:
|
||||
@echo
|
||||
@echo BusyBox Documentation
|
||||
@echo
|
||||
pod2html busybox.pod > ../BusyBox.html
|
||||
@rm pod2html-*
|
||||
pod2man --center=BusyBox --release="version $(VERSION)" busybox.pod > ../BusyBox.1
|
||||
pod2text busybox.pod > ../BusyBox.txt
|
||||
@rm -f pod2html*
|
||||
|
||||
clean:
|
||||
@rm -f ../BusyBox.html ../BusyBox.1 ../BusyBox.txt pod2html*
|
||||
|
||||
distclean: clean
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
BusyBox.html
|
||||
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 8.8 KiB |
|
After Width: | Height: | Size: 8.0 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 620 B |
|
After Width: | Height: | Size: 1.8 KiB |
@@ -0,0 +1,268 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
|
||||
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>BusyBox</TITLE>
|
||||
</HEAD>
|
||||
|
||||
<body text="#000000" alink="#660000" link="#660000" bgcolor="#dee2de" vlink="#660000">
|
||||
|
||||
<basefont face="lucida, helvetica, arial" size="3">
|
||||
|
||||
|
||||
<CENTER>
|
||||
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=2>
|
||||
<TR>
|
||||
<td bgcolor="#000000">
|
||||
<FONT FACE="lucida, helvetica" COLOR="#ccccc0">
|
||||
<B>B u s y B o x</B>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
<a href="/"><IMG SRC="images/busybox2.jpg" alt="BusyBox" border="0" width="360" height="230"</a><BR>
|
||||
|
||||
|
||||
<!-- Begin Introduction section -->
|
||||
|
||||
|
||||
<TABLE WIDTH=95% CELLSPACING=1 CELLPADDING=4 BORDER=1>
|
||||
<TR><TD BGCOLOR="#ccccc0" ALIGN=center>
|
||||
<A NAME="intro"> <BIG><B>
|
||||
The Swiss Army Knife of Embedded Linux
|
||||
</font>
|
||||
</A></B></BIG>
|
||||
</TD></TR>
|
||||
<TR><TD BGCOLOR="#eeeee0">
|
||||
|
||||
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 embedded system. 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.
|
||||
<p>
|
||||
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).
|
||||
<p>
|
||||
|
||||
BusyBox is now maintained by
|
||||
<a href="http://www.xmission.com/~andersen/erik/erik.html">
|
||||
Erik Andersen</a>, and its ongoing development is being sponsored by
|
||||
<a href="http://www.lineo.com/">Lineo</a>.
|
||||
<p>
|
||||
BusyBox is licensed under the
|
||||
<a href="http://www.gnu.org/copyleft/gpl.html">GNU GENERAL PUBLIC LICENSE</a>
|
||||
<p>
|
||||
|
||||
<H3>NEW!</h3>
|
||||
BusyBox now has a mailing list <a href="http://opensource.lineo.com/lists/busybox/">mailing list</a>!
|
||||
To subscribe, go and visit <a href="http://opensource.lineo.com/mailman/listinfo/busybox">this page</a>.
|
||||
|
||||
<!-- Begin Latest News section -->
|
||||
|
||||
<TR><TD BGCOLOR="#ccccc0" ALIGN=center>
|
||||
<A NAME="news">
|
||||
<BIG><B>
|
||||
Latest News</A>
|
||||
</B></BIG>
|
||||
</A>
|
||||
</TD></TR>
|
||||
<TR><TD BGCOLOR="#eeeee0">
|
||||
|
||||
<ul>
|
||||
|
||||
<p> <li> <b>21 June 2000 -- BusyBox 0.45 released</b>
|
||||
<br>
|
||||
|
||||
This release has been slow in coming, but is very solid at this
|
||||
point. BusyBox now supports libc5 as well as GNU libc. This
|
||||
release provides the following new apps: cut, tr, insmod, ar,
|
||||
mktemp, ,setkeycodes md5sum, uuencode, uudecode, which , and
|
||||
telnet. There are bug fixes for just about every app as well (see
|
||||
the <a href="ftp://ftp.lineo.com/pub/busybox/Changelog">changelog</a> for
|
||||
details).
|
||||
<p>
|
||||
Also, some exciting infrastructure news! Busybox now has its own
|
||||
<a href="http://opensource.lineo.com/lists/busybox/">mailing list</a>,
|
||||
publically browsable
|
||||
<a href="http://opensource.lineo.com/cgi-bin/cvsweb/busybox/">CVS tree</a>,
|
||||
anonymous
|
||||
<a href="http://opensource.lineo.com/cvs_anon.html">CVS access</a>, and
|
||||
for those that are actively contributing there is even
|
||||
<a href="http://opensource.lineo.com/cvs_write.html">CVS write access</a>.
|
||||
I think this will be a huge help to the ongoing development of BusyBox.
|
||||
<p>
|
||||
Also, for the curious, there is no 0.44 release. Somehow 0.44 got announced
|
||||
a few weeks ago prior to its actually being released. To avoid any confusion
|
||||
we are just skipping 0.44.
|
||||
<p>
|
||||
Many thanks go out to the many people that have contributed to this release
|
||||
of BusyBox (esp. Pavel Roskin)!
|
||||
|
||||
|
||||
|
||||
<p> <li> <b>Old News</b>
|
||||
<br>
|
||||
For the old news, visit <a href="http://busybox.lineo.com/oldnews.html">the old news page</a>.
|
||||
</ul>
|
||||
|
||||
|
||||
<!-- Begin Download section -->
|
||||
|
||||
<TR><TD BGCOLOR="#ccccc0" ALIGN=center>
|
||||
<A NAME="download"><BIG><B>
|
||||
Download
|
||||
</A></B></BIG>
|
||||
</TD></TR>
|
||||
<TR><TD BGCOLOR="#eeeee0">
|
||||
<ul>
|
||||
<li> Source for the latest release can always be downloaded from
|
||||
<a href="ftp://ftp.lineo.com/pub/busybox">ftp://ftp.lineo.com/pub/busybox</a>.
|
||||
<li> BusyBox now has its own publically browsable
|
||||
<a href="http://opensource.lineo.com/cgi-bin/cvsweb/busybox/">CVS tree</a>,
|
||||
anonymous
|
||||
<a href="http://opensource.lineo.com/cvs_anon.html">CVS access</a>, and
|
||||
for those that are actively contributing there is even
|
||||
<a href="http://opensource.lineo.com/cvs_write.html">CVS write access</a>.
|
||||
</ul>
|
||||
|
||||
|
||||
<!-- Begin Docs section -->
|
||||
|
||||
<TR><TD BGCOLOR="#ccccc0" ALIGN=center>
|
||||
<A NAME="docs"><BIG><B>
|
||||
Documentation
|
||||
</A></B></BIG>
|
||||
</TD></TR>
|
||||
<TR><TD BGCOLOR="#eeeee0">
|
||||
Current documentation for BusyBox includes:
|
||||
<ul>
|
||||
<li> <a href="BusyBox.html">BusyBox.html</a>
|
||||
This is a list of the all the available commands in BusyBox with complete
|
||||
usage information and examples of how to use each app. I spent
|
||||
a <em>lot</em> of time updating these docs and trying to make them
|
||||
fairly comprehensive for the BusyBox 0.43 release. If you find any
|
||||
errors (factual, grammatical, whatever) please let me know.
|
||||
|
||||
<li> More documentation will follow.
|
||||
</ul>
|
||||
|
||||
|
||||
<!-- Begin Projects section -->
|
||||
|
||||
<TR><TD BGCOLOR="#ccccc0" ALIGN=center>
|
||||
<A NAME="docs"><BIG><B>
|
||||
Projects using BusyBox
|
||||
</A></B></BIG>
|
||||
</TD></TR>
|
||||
<TR><TD BGCOLOR="#eeeee0">
|
||||
I know of the following projects that use BusyBox
|
||||
<ul>
|
||||
<li> <a href="http://www.lineo.com/products/embedix.html">Lineo Embedix Linux</a>
|
||||
<li> <a href="http://cvs.debian.org/boot-floppies/">Debian boot floppies project</a>
|
||||
<li> <a href="http://www.linuxrouter.org/">Linux Router Project </a>
|
||||
<li> <a href="http://linux-embedded.org/">LEM</a>
|
||||
<li> <a href="http://www.toms.net/rb/">tomsrtbt</a>
|
||||
<li> <a href="http://www.stormix.com/">Stormix Installer</a>
|
||||
<li> <a href="http://www.emacinc.com/linux2_sbc.htm">EMAC Linux 2.0 SBC</a>
|
||||
|
||||
</ul>
|
||||
Do you use BusyBox? I'd love to know about it and I'd be happy to link to you.
|
||||
|
||||
|
||||
|
||||
<!-- Begin Links section -->
|
||||
|
||||
<TR><TD BGCOLOR="#ccccc0" ALIGN=center>
|
||||
<A NAME="links">
|
||||
<BIG><B>
|
||||
Important Links</A>
|
||||
</B></BIG>
|
||||
</A>
|
||||
</TD></TR>
|
||||
<TR><TD BGCOLOR="#eeeee0">
|
||||
|
||||
<ul>
|
||||
|
||||
<li> <A HREF="http://perens.com/FreeSoftware/">
|
||||
Free Software from Bruce Perens</A><br>
|
||||
The original idea for BusyBox, and all versions up to 0.26 were written
|
||||
by <A HREF="mailto:bruce@perens.com">Bruce Perens</a>. This is his BusyBox website.
|
||||
<p>
|
||||
|
||||
<li> <A HREF="http://freshmeat.net/appindex/1999/04/11/923859921.html">
|
||||
Freshmeat AppIndex record for BusyBox</A>
|
||||
<p>
|
||||
|
||||
<li> <a href="http://opensource.lineo.com/software.html">Other cool embedded software</a>.
|
||||
<p>
|
||||
|
||||
<li> <a href="http://opensource.lineo.com/">opensource.lineo.com</a>.
|
||||
<p>
|
||||
|
||||
<li> <A HREF="http://www.lineo.com/">Lineo</A> is sponsoring BusyBox development.
|
||||
<p>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- End of Table -->
|
||||
|
||||
</TD></TR>
|
||||
</TABLE>
|
||||
</P>
|
||||
|
||||
|
||||
|
||||
<!-- Footer -->
|
||||
<HR>
|
||||
<TABLE WIDTH="100%">
|
||||
<TR>
|
||||
<TD>
|
||||
<font size="-1" face="arial, helvetica, sans-serif">
|
||||
Mail all comments, insults, suggestions and bribes to
|
||||
<a href="mailto:andersen@lineo.com">Erik Andersen</a><BR>
|
||||
The Busybox logo is copyright 1999,2000, Erik Andersen.
|
||||
</font>
|
||||
</TD>
|
||||
|
||||
<TD>
|
||||
<a href="http://www.vim.org"><img border=0 width=88 height=32
|
||||
src="images/anim.written.in.vi.gif"
|
||||
alt="This site created with the vi editor"></a>
|
||||
</TD>
|
||||
|
||||
<TD>
|
||||
<a href="http://www.gimp.org/"><img border=0 width=88 height=38
|
||||
src="images/gfx_by_gimp.gif" alt="Graphics by GIMP"></a>
|
||||
</TD>
|
||||
|
||||
<TD>
|
||||
<a href="http://www.linuxtoday.com"><img width=90 height=36
|
||||
src="images/ltbutton2.jpg" alt="Linux Today"></a>
|
||||
</TD>
|
||||
|
||||
<TD>
|
||||
<p><a href="http://slashdot.org"><img width=90 height=36
|
||||
src="images/sdsmall.gif" alt="Slashdot"></a>
|
||||
</TD>
|
||||
|
||||
<TD>
|
||||
<a href="http://freshmeat.net"><img width=90 height=36
|
||||
src="images/fm.mini.jpg" alt="Freshmeat"></a>
|
||||
</TD>
|
||||
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
|
||||
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<TITLE>BusyBox</TITLE>
|
||||
</HEAD>
|
||||
|
||||
<body text="#000000" alink="#660000" link="#660000" bgcolor="#dee2de" vlink="#660000">
|
||||
|
||||
<basefont face="lucida, helvetica, arial" size="3">
|
||||
|
||||
|
||||
<CENTER>
|
||||
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=2>
|
||||
<TR>
|
||||
<td bgcolor="#000000">
|
||||
<FONT FACE="lucida, helvetica" COLOR="#ccccc0">
|
||||
<B>B u s y B o x</B>
|
||||
</FONT>
|
||||
</TD>
|
||||
</TR>
|
||||
</TABLE>
|
||||
<a href="/"><IMG SRC="images/busybox2.jpg" alt="BusyBox" border="0" width="360" height="230"</a><BR>
|
||||
|
||||
|
||||
<TABLE WIDTH=95% CELLSPACING=1 CELLPADDING=4 BORDER=1>
|
||||
|
||||
<!-- Begin Older News section -->
|
||||
|
||||
<TR><TD BGCOLOR="#ccccc0" ALIGN=center>
|
||||
<A NAME="news">
|
||||
<BIG><B>
|
||||
Older BusyBox News</A>
|
||||
</B></BIG>
|
||||
</A>
|
||||
</TD></TR>
|
||||
<TR><TD BGCOLOR="#eeeee0">
|
||||
|
||||
<ul>
|
||||
|
||||
<p> <li> <b>Take me back to the <a href="http://busybox.lineo.com/">BusyBox</a> web site.</b>
|
||||
<hr>
|
||||
|
||||
<p> <li> <b>19 April 2000 -- syslogd bugfix</b>
|
||||
<br>
|
||||
Turns out that there was still a bug in busybox syslogd.
|
||||
For example, with the following test app:
|
||||
<pre>
|
||||
#include <syslog.h>
|
||||
|
||||
int do_log(char* msg, int delay)
|
||||
{
|
||||
openlog("testlog", LOG_PID, LOG_DAEMON);
|
||||
while(1) {
|
||||
syslog(LOG_ERR, "%s: testing one, two, three\n", msg);
|
||||
sleep(delay);
|
||||
}
|
||||
closelog();
|
||||
return(0);
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
if (fork()==0)
|
||||
do_log("A", 2);
|
||||
do_log("B", 3);
|
||||
}
|
||||
</pre>
|
||||
it should be logging stuff from both "A" and "B". As released in 0.43 only stuff
|
||||
from "A" would have been logged. This means that if init tries to log something
|
||||
while say ppp has the syslog open, init would block (which is bad, bad, bad).
|
||||
<p>
|
||||
Karl M. Hegbloom has created a
|
||||
<a href="ftp://ftp.lineo.com/pub/busybox/busybox-0.43-syslog_patch">fix for the problem</a>.
|
||||
Thanks Karl!
|
||||
|
||||
|
||||
<p> <li> <b>18 April 2000 -- BusyBox 0.43 released (finally!)</b>
|
||||
<br>
|
||||
I have finally gotten everything into a state where I feel pretty
|
||||
good about things. This is definitely the most stable, solid release
|
||||
so far. A lot of bugs have been fixed, and the following new apps
|
||||
have been added: sh, basename, dirname, killall, uptime,
|
||||
freeramdisk, tr, echo, test, and usleep. Tar has been completely
|
||||
rewritten from scratch. Bss size has also been greatly reduced.
|
||||
More details are available in the
|
||||
<a href="ftp://ftp.lineo.com/pub/busybox/Changelog">changelog</a>.
|
||||
Oh, and as a special bonus, I wrote some fairly comprehensive
|
||||
<em>documentation</em>, complete with examples and full usage information.
|
||||
|
||||
<p>
|
||||
Many thanks go out to the fine people that have helped by submitting patches
|
||||
and bug reports; particularly instrumental in helping for this release were
|
||||
Karl Hegbloom, Pavel Roskin, Friedrich Vedder, Emanuele Caratti,
|
||||
Bob Tinsley, Nicolas Pitre, Avery Pennarun, Arne Bernin, John Beppu, and Jim Gleason.
|
||||
There were others so if I somehow forgot to mention you, I'm very sorry.
|
||||
<p>
|
||||
|
||||
You can grab BusyBox 0.43 tarballs <a href="ftp://ftp.lineo.com/pub/busybox/">here</a>.
|
||||
|
||||
<p> <li> <b>9 April 2000 -- BusyBox 0.43 pre release</b>
|
||||
<br>
|
||||
Unfortunately, I have not yet finished all the things I want to
|
||||
do for BusyBox 0.43, so I am posting this pre-release for people
|
||||
to poke at. This contains my complete rewrite of tar, which now weighs in at
|
||||
5k (7k with all options turned on) and works for reading and writing
|
||||
tarballs (which it does correctly for everything I have been able to throw
|
||||
at it). Tar also (optionally) supports the "--exclude" option (mainly because
|
||||
the Linux Router Project folks asked for it). This also has a pre-release
|
||||
of the micro shell I have been writing. This pre-release should be stable
|
||||
enough for production use -- it just isn't a release since I have some structural
|
||||
changes I still want to make.
|
||||
<p>
|
||||
The pre-release can be found <a href="ftp://ftp.lineo.com/pub/busybox/">here</a>.
|
||||
Please let me know ASAP if you find <em>any</em> bugs.
|
||||
|
||||
<p> <li> <b>28 March 2000 -- Andersen Baby Boy release</b>
|
||||
<br>
|
||||
I am pleased to announce that on Tuesday March 28th at 5:48pm, weighing in at 7
|
||||
lbs. 12 oz, Micah Erik Andersen was born at LDS Hospital here in Salt Lake City.
|
||||
He was born in the emergency room less then 5 minutes after we arrived -- and
|
||||
it was such a relief that we even made it to the hospital at all. Despite the
|
||||
fact that I was driving at an amazingly unlawful speed and honking at everybody
|
||||
and thinking decidedly unkind thoughts about the people in our way, my wife
|
||||
(inconsiderate of my feelings and complete lack of medical training) was lying
|
||||
down in the back seat saying things like "I think I need to start pushing now"
|
||||
(which she then proceeded to do despite my best encouraging statements to the
|
||||
contrary).
|
||||
<p>
|
||||
Anyway, I'm glad to note that despite the much-faster-than-we-were-expecting
|
||||
labor, both Shaunalei and our new baby boy are doing wonderfully.
|
||||
<p>
|
||||
So now that I am done with my excuse for the slow release cycle...
|
||||
Progress on the next release of BusyBox has been slow but steady. I expect
|
||||
to have a release sometime during the first week of April. This release will
|
||||
include a number of important changes, including the addition of a shell, a
|
||||
re-write of tar (to accommodate the Linux Router Project), and syslogd can now
|
||||
accept multiple concurrent connections, fixing lots of unexpected blocking
|
||||
problems.
|
||||
|
||||
|
||||
<p> <li> <b>11 February 2000 -- BusyBox 0.42 released</b>
|
||||
<br>
|
||||
|
||||
This is the most solid BusyBox release so far. Many, many
|
||||
bugs have been fixed. See the
|
||||
<a href="ftp://ftp.lineo.com/pub/busybox/Changelog">changelog</a> for details.
|
||||
|
||||
Of particular interest, init will now cleanly unmount
|
||||
filesystems on reboot, cp and mv have been rewritten and
|
||||
behave much better, and mount and umount no longer leak
|
||||
loop devices. Many thanks go out to Randolph Chung,
|
||||
Karl M. Hegbloom, Taketoshi Sano, and Pavel Roskin for
|
||||
their hard work on this release of BusyBox. Please pound
|
||||
on it and let me know if you find any bugs.
|
||||
|
||||
<p> <li> <b>19 January 2000 -- BusyBox 0.41 released</b>
|
||||
<br>
|
||||
|
||||
This release includes bugfixes to cp, mv, logger, true, false,
|
||||
mkdir, syslogd, and init. New apps include wc, hostid,
|
||||
logname, tty, whoami, and yes. New features include loop device
|
||||
support in mount and umount, and better TERM handling by init.
|
||||
The changelog can be found <a href="ftp://ftp.lineo.com/pub/busybox/Changelog">here</a>.
|
||||
|
||||
<p> <li> <b>7 January 2000 -- BusyBox 0.40 released</b>
|
||||
<br>
|
||||
|
||||
This release includes bugfixes to init (now includes inittab support),
|
||||
syslogd, head, logger, du, grep, cp, mv, sed, dmesg, ls, kill, gunzip, and mknod.
|
||||
New apps include sort, uniq, lsmod, rmmod, fbset, and loadacm.
|
||||
In particular, this release fixes an important bug in tar which
|
||||
in some cases produced serious security problems.
|
||||
As always, the changelog can be found <a href="ftp://ftp.lineo.com/pub/busybox/Changelog">here</a>.
|
||||
|
||||
<p> <li> <b>11 December 1999 -- BusyBox Website</b>
|
||||
<br>
|
||||
I have received permission from Bruce Perens (the original author of BusyBox)
|
||||
to set up this site as the new primary website for BusyBox. This website
|
||||
will always contain pointers to the latest and greatest, and will also
|
||||
contain the latest documentation on how to use BusyBox, what it can do,
|
||||
what arguments its apps support, etc.
|
||||
|
||||
<p> <li> <b>10 December 1999 -- BusyBox 0.39 released</b>
|
||||
<br>
|
||||
This release includes fixes to init, reboot, halt, kill, and ls, and contains
|
||||
the new apps ping, hostname, mkfifo, free, tail, du, tee, and head. A full
|
||||
changelog can be found <a href="ftp://ftp.lineo.com/pub/busybox/Changelog">here</a>.
|
||||
<p> <li> <b>5 December 1999 -- BusyBox 0.38 released</b>
|
||||
<br>
|
||||
This release includes fixes to tar, cat, ls, dd, rm, umount, find, df,
|
||||
and make install, and includes new apps syslogd/klogd and logger.
|
||||
</ul>
|
||||
|
||||
|
||||
<!-- Begin Links section -->
|
||||
|
||||
<TR><TD BGCOLOR="#ccccc0" ALIGN=center>
|
||||
<A NAME="links">
|
||||
<BIG><B>
|
||||
Important Links</A>
|
||||
</B></BIG>
|
||||
</A>
|
||||
</TD></TR>
|
||||
<TR><TD BGCOLOR="#eeeee0">
|
||||
|
||||
<ul>
|
||||
|
||||
<li> <a href="http://busybox.lineo.com/">Take me back to http://busybox.lineo.com/</a>.
|
||||
<p>
|
||||
|
||||
<li> <A HREF="http://perens.com/FreeSoftware/">
|
||||
Free Software from Bruce Perens</A><br>
|
||||
The original idea for BusyBox, and all versions up to 0.26 were written
|
||||
by <A HREF="mailto:bruce@perens.com">Bruce Perens</a>. This is his BusyBox website.
|
||||
<p>
|
||||
|
||||
<li> <A HREF="http://freshmeat.net/appindex/1999/04/11/923859921.html">
|
||||
Freshmeat AppIndex record for BusyBox</A>
|
||||
<p>
|
||||
|
||||
<li> <a href="http://opensource.lineo.com/software.html">Other cool embedded software</a>.
|
||||
<p>
|
||||
|
||||
<li> <a href="http://opensource.lineo.com/">opensource.lineo.com</a>.
|
||||
<p>
|
||||
|
||||
<li> <A HREF="http://www.lineo.com/">Lineo</A> is sponsoring BusyBox development.
|
||||
<p>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
<!-- End of Table -->
|
||||
|
||||
</TD></TR>
|
||||
</TABLE>
|
||||
</P>
|
||||
|
||||
|
||||
|
||||
<!-- Footer -->
|
||||
<HR>
|
||||
<TABLE WIDTH="100%">
|
||||
<TR>
|
||||
<TD>
|
||||
<font size="-1" face="arial, helvetica, sans-serif">
|
||||
Mail all comments, insults, suggestions and bribes to
|
||||
<a href="mailto:andersen@lineo.com">Erik Andersen</a><BR>
|
||||
The Busybox logo is copyright 1999,2000, Erik Andersen.
|
||||
</font>
|
||||
</TD>
|
||||
|
||||
<TD>
|
||||
<a href="http://www.vim.org"><img border=0 width=88 height=32
|
||||
src="images/anim.written.in.vi.gif"
|
||||
alt="This site created with the vi editor"></a>
|
||||
</TD>
|
||||
|
||||
<TD>
|
||||
<a href="http://www.gimp.org/"><img border=0 width=88 height=38
|
||||
src="images/gfx_by_gimp.gif" alt="Graphics by GIMP"></a>
|
||||
</TD>
|
||||
|
||||
<TD>
|
||||
<a href="http://www.linuxtoday.com"><img width=90 height=36
|
||||
src="images/ltbutton2.jpg" alt="Linux Today"></a>
|
||||
</TD>
|
||||
|
||||
<TD>
|
||||
<p><a href="http://slashdot.org"><img width=90 height=36
|
||||
src="images/sdsmall.gif" alt="Slashdot"></a>
|
||||
</TD>
|
||||
|
||||
<TD>
|
||||
<a href="http://freshmeat.net"><img width=90 height=36
|
||||
src="images/fm.mini.jpg" alt="Freshmeat"></a>
|
||||
</TD>
|
||||
|
||||
</TR>
|
||||
</TABLE>
|
||||
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
||||
|
||||
@@ -2,36 +2,50 @@
|
||||
|
||||
=head1 NAME
|
||||
|
||||
busybox - I am BusyBox of Borg. Unix will be assimilated.
|
||||
BusyBox - The Swiss Army Knife of Embedded Linux
|
||||
|
||||
=head1 SYNOPSIS
|
||||
=head1 SYNTAX
|
||||
|
||||
busybox <function> [arguments...] # or
|
||||
BusyBox <function> [arguments...] # or
|
||||
|
||||
<function> [arguments...] # if symlinked
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
BusyBox is a multi-call binary that combines many common Unix utilities into a
|
||||
single executable. Most people will create a link to busybox for each function
|
||||
they wish to use, and BusyBox will act like whatever it was invoked as. For
|
||||
example,
|
||||
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 embedded system. 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.
|
||||
|
||||
ln -s ./busybox ls
|
||||
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).
|
||||
|
||||
=head1 USAGE
|
||||
|
||||
When you create a link to BusyBox for the function you wish to use, when BusyBox
|
||||
is called using that link it will behave as if the command itself has been invoked.
|
||||
|
||||
For example, entering
|
||||
|
||||
ln -s ./BusyBox ls
|
||||
./ls
|
||||
|
||||
will cause BusyBox to behave as 'ls' (if the 'ls' command has been compiled
|
||||
into busybox). You can also invoke BusyBox by providing it the command to run
|
||||
on the command line. For example,
|
||||
into BusyBox).
|
||||
|
||||
./busybox ls
|
||||
You can also invoke BusyBox by issuing the command as an argument on the
|
||||
command line. For example, entering
|
||||
|
||||
./BusyBox ls
|
||||
|
||||
will also cause BusyBox to behave as 'ls'.
|
||||
|
||||
BusyBox has been written with size-optimization in mind. It is very easy to
|
||||
include or exclude the commands (or features) you want installed. BusyBox
|
||||
tries to make itself useful to small systems with limited resources.
|
||||
|
||||
=head1 COMMON OPTIONS
|
||||
|
||||
Most BusyBox commands support the B<--help> option to provide a
|
||||
@@ -41,38 +55,60 @@ terse runtime description of their behavior.
|
||||
|
||||
Currently defined functions include:
|
||||
|
||||
basename, cat, chgrp, chmod, chown, chroot, clear, chvt, cp, date, dd, df,
|
||||
dirname, dmesg, du, dutmp, echo, false, fbset, fdflush, find, free,
|
||||
freeramdisk, deallocvt, fsck.minix, grep, gunzip, gzip, halt, head, hostid,
|
||||
hostname, init, kill, killall, length, ln, loadacm, loadfont, loadkmap, logger,
|
||||
logname, ls, lsmod, makedevs, math, mkdir, mkfifo, mkfs.minix, mknod, mkswap,
|
||||
mnc, more, mount, mt, mv, nslookup, ping, poweroff, printf, ps, pwd, reboot,
|
||||
rm, rmdir, rmmod, sed, sh, sfdisk, sleep, sort, sync, syslogd, swapon, swapoff,
|
||||
tail, tar, test, tee, touch, tr, true, tty, umount, uname, uniq, update,
|
||||
uptime, usleep, wc, whoami, yes, zcat, [
|
||||
ar, basename, cat, chgrp, chmod, chown, chroot, chvt, clear, cp, cut, date,
|
||||
dc, dd, deallocvt, df, dirname, dmesg, du, dutmp, echo, false, fbset,
|
||||
fdflush, find, free, freeramdisk, fsck.minix, grep, gunzip, gzip, halt,
|
||||
head, hostid, hostname, id, init, insmod, kill, killall, length, ln,
|
||||
loadacm, loadfont, loadkmap, logger, logname, ls, lsmod, makedevs, mkdir,
|
||||
mkfifo, mkfs.minix, mknod, mkswap, mktemp, more, mount, mt, mv, nc,
|
||||
nslookup, ping, poweroff, printf, ps, pwd, reboot, rm, rmdir, rmmod, sed,
|
||||
setkeycodes, sfdisk, sh, sleep, sort, swapoff, swapon, sync, syslogd, tail,
|
||||
tar, tee, telnet, test, touch, tr, true, tty, umount, uname, uniq, update,
|
||||
uptime, usleep, uudecode, uuencode, wc, which, whoami, yes, zcat, [
|
||||
|
||||
-------------------------------
|
||||
|
||||
=over 4
|
||||
|
||||
=item ar
|
||||
|
||||
Usage: ar [optxvV] archive [filenames]
|
||||
|
||||
Extract or list files from an ar archive.
|
||||
|
||||
Options:
|
||||
|
||||
o preserve original dates
|
||||
p extract to stdout
|
||||
t list
|
||||
x extract
|
||||
v verbosely list files processed
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item basename
|
||||
|
||||
Usage: basename [file ...]
|
||||
Usage: basename FILE [SUFFIX]
|
||||
|
||||
Strips directory and suffix from filenames.
|
||||
Strips directory path and suffixes from FILE.
|
||||
If specified, also removes any trailing SUFFIX.
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
$ basename /usr/local/bin/foo
|
||||
foo
|
||||
$ basename /usr/local/bin/
|
||||
bin
|
||||
$ basename /foo/bar.txt .txt
|
||||
bar
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item cat
|
||||
|
||||
Usage: cat [file ...]
|
||||
Usage: cat [FILE ...]
|
||||
|
||||
Concatenates files and prints them to the standard output.
|
||||
Concatenates FILE(s) and prints them to the standard output.
|
||||
|
||||
Example:
|
||||
|
||||
@@ -105,49 +141,49 @@ Example:
|
||||
|
||||
Usage: chmod [B<-R>] MODE[,MODE]... FILE...
|
||||
|
||||
Changes file access permissions for the specified file(s) or directory(s).
|
||||
Changes file access permissions for the specified FILE(s) (or directories).
|
||||
Each MODE is defined by combining the letters for WHO has access to the file,
|
||||
an OPERATOR for selecting how the permissions should be changed, and a
|
||||
PERISSION for the file(s) or directory(s).
|
||||
PERMISSION for FILE(s) (or directories).
|
||||
|
||||
WHO may be chosen from:
|
||||
WHO may be chosen from
|
||||
|
||||
u the User who owns the file
|
||||
g users in the file's Group
|
||||
u User who owns the file
|
||||
g Users in the file's Group
|
||||
o Other users not in the file's group
|
||||
a All users
|
||||
|
||||
OPERATOR may be chosen from:
|
||||
OPERATOR may be chosen from
|
||||
|
||||
+ add a permission
|
||||
- remove a permission
|
||||
= assign a permission
|
||||
|
||||
PERMISSION may be chosen from:
|
||||
+ Add a permission
|
||||
- Remove a permission
|
||||
= Assign a permission
|
||||
|
||||
r Read
|
||||
PERMISSION may be chosen from
|
||||
|
||||
r Read
|
||||
w Write
|
||||
x eXecute (or access for directories)
|
||||
x Execute (or access for directories)
|
||||
s Set user (or group) ID bit
|
||||
t sTickey bit (for directories prevents removing files by non-owners)
|
||||
t Sticky bit (for directories prevents removing files by non-owners)
|
||||
|
||||
Alternately, permissions may be set numerically where the first three
|
||||
numbers are calculated by adding the octal values:
|
||||
Alternately, permissions can be set numerically where the first three
|
||||
numbers are calculated by adding the octal values, such as
|
||||
|
||||
4 Read
|
||||
2 Write
|
||||
1 eXecute
|
||||
1 Execute
|
||||
|
||||
An optional fourth digit may also be used to specify
|
||||
An optional fourth digit can also be used to specify
|
||||
|
||||
4 Set user ID
|
||||
2 Set group ID
|
||||
1 sTickey bit
|
||||
1 Sticky bit
|
||||
|
||||
Options:
|
||||
|
||||
-R change files and directories recursively.
|
||||
|
||||
-R Change files and directories recursively.
|
||||
|
||||
Example:
|
||||
|
||||
$ ls -l /tmp/foo
|
||||
@@ -163,13 +199,13 @@ Example:
|
||||
|
||||
=item chown
|
||||
|
||||
Usage: chown [OPTION]... OWNER[.[GROUP] FILE...
|
||||
Usage: chown [OPTION]... OWNER[<.|:>[GROUP] FILE...
|
||||
|
||||
Changes the owner and/or group of each FILE to OWNER and/or GROUP.
|
||||
|
||||
Options:
|
||||
|
||||
-R change files and directories recursively
|
||||
-R Changes files and directories recursively
|
||||
|
||||
Example:
|
||||
|
||||
@@ -189,11 +225,11 @@ Example:
|
||||
Usage: chroot NEWROOT [COMMAND...]
|
||||
|
||||
Run COMMAND with root directory set to NEWROOT.
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
$ ls -l /bin/ls
|
||||
lrwxrwxrwx 1 root root 12 Apr 13 00:46 /bin/ls -> /busybox
|
||||
lrwxrwxrwx 1 root root 12 Apr 13 00:46 /bin/ls -> /BusyBox
|
||||
$ mount /dev/hdc1 /mnt -t minix
|
||||
$ chroot /mnt
|
||||
$ ls -l /bin/ls
|
||||
@@ -211,7 +247,7 @@ Clears the screen.
|
||||
|
||||
Usage: chvt N
|
||||
|
||||
Change foreground virtual terminal to /dev/ttyN
|
||||
Changes the foreground virtual terminal to /dev/ttyN
|
||||
|
||||
-------------------------------
|
||||
|
||||
@@ -221,12 +257,38 @@ Usage: cp [OPTION]... SOURCE DEST
|
||||
|
||||
or: cp [OPTION]... SOURCE... DIRECTORY
|
||||
|
||||
Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
|
||||
Copies SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.
|
||||
|
||||
Options:
|
||||
|
||||
-a Same as -dpR
|
||||
-d Preserves links
|
||||
-p Preserves file attributes if possible
|
||||
-R Copies directories recursively
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item cut
|
||||
|
||||
Usage: cut [OPTION]... [FILE]...
|
||||
|
||||
Prints selected fields from each input FILE to standard output.
|
||||
|
||||
Options:
|
||||
|
||||
-b LIST Output only bytes from LIST
|
||||
-c LIST Output only characters from LIST
|
||||
-d DELIM Use DELIM instead of tab as the field delimiter
|
||||
-f N Print only these fields
|
||||
-n Ignored
|
||||
|
||||
Example:
|
||||
|
||||
$ echo "Hello world" | cut -f 1 -d ' '
|
||||
Hello
|
||||
$ echo "Hello world" | cut -f 2 -d ' '
|
||||
world
|
||||
|
||||
-a same as -dpR
|
||||
-d preserve links
|
||||
-p preserve file attributes if possable
|
||||
-R copy directories recursively
|
||||
|
||||
-------------------------------
|
||||
|
||||
@@ -236,13 +298,13 @@ Usage: date [OPTION]... [+FORMAT]
|
||||
|
||||
or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]
|
||||
|
||||
Display the current time in the given FORMAT, or set the system date.
|
||||
Displays the current time in the given FORMAT, or sets the system date.
|
||||
|
||||
Options:
|
||||
|
||||
-R output RFC-822 compliant date string
|
||||
-s set time described by STRING
|
||||
-u print or set Coordinated Universal Time
|
||||
-R Outputs RFC-822 compliant date string
|
||||
-s Sets time described by STRING
|
||||
-u Prints or sets Coordinated Universal Time
|
||||
|
||||
Example:
|
||||
|
||||
@@ -251,6 +313,32 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item dc
|
||||
|
||||
Usage: dc expression ...
|
||||
|
||||
This is a Tiny RPN calculator that understands the
|
||||
following operations: +, -, /, *, and, or, not, eor.
|
||||
If no arguments are given, dc will process input from STDIN.
|
||||
|
||||
The behaviour of BusyBox/dc deviates (just a little ;-) from
|
||||
GNU/dc, but this will be remedied in the future.
|
||||
|
||||
Example:
|
||||
|
||||
$ dc 2 2 +
|
||||
4
|
||||
$ dc 8 8 \* 2 2 + /
|
||||
16
|
||||
$ dc 0 1 and
|
||||
0
|
||||
$ dc 0 1 or
|
||||
1
|
||||
$ echo 72 9 div 8 mul | dc
|
||||
64
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item dd
|
||||
|
||||
Usage: dd [if=name] [of=name] [bs=n] [count=n] [skip=n] [seek=n]
|
||||
@@ -265,7 +353,7 @@ Copy a file, converting and formatting according to options
|
||||
seek=n skip n output blocks
|
||||
|
||||
Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
$ dd if=/dev/zero of=/dev/ram1 bs=1M count=4
|
||||
@@ -310,7 +398,7 @@ Example:
|
||||
=item dmesg
|
||||
|
||||
Usage: dmesg [B<-c>] [B<-n> level] [B<-s> bufsize]
|
||||
|
||||
|
||||
Print or controls the kernel ring buffer.
|
||||
|
||||
-------------------------------
|
||||
@@ -329,7 +417,7 @@ Options:
|
||||
|
||||
Example:
|
||||
|
||||
$ ./busybox du
|
||||
$ ./BusyBox du
|
||||
16 ./CVS
|
||||
12 ./kernel-patches/CVS
|
||||
80 ./kernel-patches
|
||||
@@ -340,7 +428,7 @@ Example:
|
||||
12 ./docs/CVS
|
||||
104 ./docs
|
||||
2417 .
|
||||
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item dutmp
|
||||
@@ -360,7 +448,7 @@ Example:
|
||||
6|245|tty1|1|LOGIN||0|0|0|955637630|998974|0
|
||||
6|246|tty2|2|LOGIN||0|0|0|955637630|999498|0
|
||||
7|336|pts/0|vt00andersen|andersen|:0.0|0|0|0|955637763|0|0
|
||||
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item echo
|
||||
@@ -385,7 +473,7 @@ Example:
|
||||
cool
|
||||
$ echo "Erik\nis\ncool"
|
||||
Erik\nis\ncool
|
||||
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item false
|
||||
@@ -467,7 +555,7 @@ Example:
|
||||
|
||||
Usage: free
|
||||
|
||||
Displays the amount of free and used memory in the system.
|
||||
Displays the amount of free and used system memory.
|
||||
|
||||
Example:
|
||||
|
||||
@@ -483,7 +571,7 @@ Example:
|
||||
|
||||
Usage: freeramdisk DEVICE
|
||||
|
||||
Free all memory used by the specified ramdisk.
|
||||
Frees all memory used by the specified ramdisk.
|
||||
|
||||
Example:
|
||||
|
||||
@@ -529,8 +617,9 @@ OPTIONS:
|
||||
-i ignore case distinctions
|
||||
-n print line number with output lines
|
||||
-q be quiet. Returns 0 if result was found, 1 otherwise
|
||||
-v select non-matching lines
|
||||
|
||||
This version of grep matches full regular expresions.
|
||||
This version of grep matches full regular expressions.
|
||||
|
||||
Example:
|
||||
|
||||
@@ -554,11 +643,11 @@ Options:
|
||||
|
||||
Example:
|
||||
|
||||
$ ls -la /tmp/busybox*
|
||||
-rw-rw-r-- 1 andersen andersen 557009 Apr 11 10:55 /tmp/busybox-0.43.tar.gz
|
||||
$ gunzip /tmp/busybox-0.43.tar.gz
|
||||
$ ls -la /tmp/busybox*
|
||||
-rw-rw-r-- 1 andersen andersen 1761280 Apr 14 17:47 /tmp/busybox-0.43.tar
|
||||
$ ls -la /tmp/BusyBox*
|
||||
-rw-rw-r-- 1 andersen andersen 557009 Apr 11 10:55 /tmp/BusyBox-0.43.tar.gz
|
||||
$ gunzip /tmp/BusyBox-0.43.tar.gz
|
||||
$ ls -la /tmp/BusyBox*
|
||||
-rw-rw-r-- 1 andersen andersen 1761280 Apr 14 17:47 /tmp/BusyBox-0.43.tar
|
||||
|
||||
-------------------------------
|
||||
|
||||
@@ -575,11 +664,11 @@ Options:
|
||||
|
||||
Example:
|
||||
|
||||
$ ls -la /tmp/busybox*
|
||||
-rw-rw-r-- 1 andersen andersen 1761280 Apr 14 17:47 /tmp/busybox-0.43.tar
|
||||
$ gzip /tmp/busybox-0.43.tar
|
||||
$ ls -la /tmp/busybox*
|
||||
-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox-0.43.tar.gz
|
||||
$ ls -la /tmp/BusyBox*
|
||||
-rw-rw-r-- 1 andersen andersen 1761280 Apr 14 17:47 /tmp/BusyBox-0.43.tar
|
||||
$ gzip /tmp/BusyBox-0.43.tar
|
||||
$ ls -la /tmp/BusyBox*
|
||||
-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/BusyBox-0.43.tar.gz
|
||||
|
||||
|
||||
-------------------------------
|
||||
@@ -588,7 +677,7 @@ Example:
|
||||
|
||||
Usage: halt
|
||||
|
||||
This comand halts the system.
|
||||
This command halts the system.
|
||||
|
||||
-------------------------------
|
||||
|
||||
@@ -643,6 +732,23 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item id
|
||||
|
||||
Print information for USERNAME or the current user
|
||||
|
||||
Options:
|
||||
|
||||
-g prints only the group ID
|
||||
-u prints only the user ID
|
||||
-r prints the real user ID instead of the effective ID (with -ug)
|
||||
|
||||
Example:
|
||||
|
||||
$ id
|
||||
uid=1000(andersen) gid=1000(andersen)
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item init
|
||||
|
||||
Usage: init
|
||||
@@ -695,7 +801,7 @@ If you choose to use an /etc/inittab file, the inittab entry format is as follow
|
||||
console." and then waits for the user to press enter before starting
|
||||
the specified process.
|
||||
|
||||
Unrecognised actions (like initdefault) will cause init to emit
|
||||
Unrecognized actions (like initdefault) will cause init to emit
|
||||
an error message, and then go along with its business.
|
||||
|
||||
<process>:
|
||||
@@ -736,6 +842,21 @@ Example /etc/inittab file:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item insmod
|
||||
|
||||
Usage: insmod [OPTION]... MODULE [symbol=value]...
|
||||
|
||||
Loads the specified kernel modules into the kernel.
|
||||
|
||||
Options:
|
||||
|
||||
-f Force module to load into the wrong kernel version.
|
||||
-k Make module autoclean-able.
|
||||
-v verbose output
|
||||
-x do not export externs
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item kill
|
||||
|
||||
Usage: kill [B<-signal>] process-id [process-id ...]
|
||||
@@ -777,11 +898,12 @@ Example:
|
||||
|
||||
=item length
|
||||
|
||||
Usage: length string
|
||||
Usage: length STRING
|
||||
|
||||
Prints out the length of the specified string.
|
||||
Prints out the length of the specified STRING.
|
||||
|
||||
Example:
|
||||
|
||||
$ length "Hello"
|
||||
5
|
||||
|
||||
@@ -790,18 +912,20 @@ Example:
|
||||
=item ln
|
||||
|
||||
Usage: ln [OPTION] TARGET... LINK_NAME|DIRECTORY
|
||||
|
||||
Create a link named LINK_NAME or DIRECTORY to the specified TARGET
|
||||
|
||||
You may use '--' to indicate that all following arguments are non-options.
|
||||
|
||||
Options:
|
||||
|
||||
-s make symbolic links instead of hard links
|
||||
-f remove existing destination files
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
$ ln -s busybox /tmp/ls
|
||||
[andersen@debian busybox]$ ls -l /tmp/ls
|
||||
lrwxrwxrwx 1 root root 7 Apr 12 18:39 ls -> busybox*
|
||||
$ ln -s BusyBox /tmp/ls
|
||||
$ ls -l /tmp/ls
|
||||
lrwxrwxrwx 1 root root 7 Apr 12 18:39 ls -> BusyBox*
|
||||
|
||||
-------------------------------
|
||||
|
||||
@@ -875,7 +999,7 @@ Example:
|
||||
|
||||
=item ls
|
||||
|
||||
Usage: ls [B<-1acdelnpuxACF>] [filenames...]
|
||||
Usage: ls [B<-1acdelnpuxACFR>] [filenames...]
|
||||
|
||||
Options:
|
||||
|
||||
@@ -893,6 +1017,7 @@ Options:
|
||||
-A do not list implied . and ..
|
||||
-C list entries by columns
|
||||
-F append indicator (one of */=@|) to entries
|
||||
-R list subdirectories recursively
|
||||
|
||||
-------------------------------
|
||||
|
||||
@@ -929,23 +1054,32 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item math
|
||||
=item md5sum
|
||||
|
||||
Usage: math expression ...
|
||||
Usage: md5sum [OPTION] [file ...]
|
||||
|
||||
This is a Tiny RPN calculator that understands the
|
||||
following operations: +, -, /, *, and, or, not, eor.
|
||||
Print or check MD5 checksums.
|
||||
|
||||
Options:
|
||||
|
||||
-b read files in binary mode
|
||||
-c check MD5 sums against given list
|
||||
-t read files in text mode (default)
|
||||
-g read a string
|
||||
|
||||
The following two options are useful only when verifying checksums:
|
||||
|
||||
-s don't output anything, status code shows success
|
||||
-w warn about improperly formated MD5 checksum lines
|
||||
|
||||
Example:
|
||||
|
||||
$ math 2 2 add
|
||||
4
|
||||
$ math 8 8 \* 2 2 + /
|
||||
16
|
||||
$ math 0 1 and
|
||||
0
|
||||
$ math 0 1 or
|
||||
1
|
||||
$ md5sum busybox
|
||||
6fd11e98b98a58f64ff3398d7b324003 busybox
|
||||
$ md5sum -c -
|
||||
6fd11e98b98a58f64ff3398d7b324003 busybox
|
||||
busybox: OK
|
||||
^D
|
||||
|
||||
-------------------------------
|
||||
|
||||
@@ -958,7 +1092,7 @@ Create the DIRECTORY(ies), if they do not already exist
|
||||
Options:
|
||||
|
||||
-m set permission mode (as in chmod), not rwxrwxrwx - umask
|
||||
-p no error if dir exists, make parent directories as needed
|
||||
-p no error if directory exists, make parent directories as needed
|
||||
|
||||
Example:
|
||||
|
||||
@@ -1036,15 +1170,31 @@ Options:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item mnc
|
||||
=item mktemp
|
||||
|
||||
Usage: mnc [IP] [port]
|
||||
Usage: mktemp [B<-q>] TEMPLATE
|
||||
|
||||
mini-netcat opens a pipe to IP:port
|
||||
Creates a temporary file with its name based on TEMPLATE.
|
||||
TEMPLATE is any name with six `Xs' (i.e. /tmp/temp.XXXXXX).
|
||||
|
||||
Example:
|
||||
|
||||
$ mnc foobar.somedomain.com 25
|
||||
$ mktemp /tmp/temp.XXXXXX
|
||||
/tmp/temp.mWiLjM
|
||||
$ ls -la /tmp/temp.mWiLjM
|
||||
-rw------- 1 andersen andersen 0 Apr 25 17:10 /tmp/temp.mWiLjM
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item nc
|
||||
|
||||
Usage: nc [IP] [port]
|
||||
|
||||
Netcat opens a pipe to IP:port
|
||||
|
||||
Example:
|
||||
|
||||
$ nc foobar.somedomain.com 25
|
||||
220 foobar ESMTP Exim 3.12 #1 Sat, 15 Apr 2000 00:03:02 -0600
|
||||
help
|
||||
214-Commands supported:
|
||||
@@ -1052,7 +1202,7 @@ Example:
|
||||
214 NOOP QUIT RSET HELP
|
||||
quit
|
||||
221 foobar closing connection
|
||||
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item more
|
||||
@@ -1074,21 +1224,22 @@ Usage: mount [flags]
|
||||
|
||||
Flags:
|
||||
|
||||
-a: Mount all file systems in fstab.
|
||||
-a: Mount all file systems in fstab.
|
||||
-o option: One of many filesystem options, listed below.
|
||||
-r: Mount the filesystem read-only.
|
||||
-t filesystem-type: Specify the filesystem type.
|
||||
-w: Mount for reading and writing (default).
|
||||
-r: Mount the filesystem read-only.
|
||||
-t fs-type: Specify the filesystem type.
|
||||
-w: Mount for reading and writing (default).
|
||||
|
||||
Options for use with the "B<-o>" flag:
|
||||
|
||||
async / sync: Writes are asynchronous / synchronous.
|
||||
dev / nodev: Allow use of special device files / disallow them.
|
||||
exec / noexec: Allow use of executable files / disallow them.
|
||||
loop: Mounts a file via loop device.
|
||||
suid / nosuid: Allow set-user-id-root programs / disallow them.
|
||||
remount: Re-mount a currently-mounted filesystem, changing its flags.
|
||||
ro / rw: Mount for read-only / read-write.
|
||||
async/sync: Writes are asynchronous / synchronous.
|
||||
atime/noatime: Enable / disable updates to inode access times.
|
||||
dev/nodev: Allow use of special device files / disallow them.
|
||||
exec/noexec: Allow use of executable files / disallow them.
|
||||
loop: Mounts a file via loop device.
|
||||
suid/nosuid: Allow set-user-id-root programs / disallow them.
|
||||
remount: Re-mount a currently-mounted filesystem, changing its flags.
|
||||
ro/rw: Mount for read-only / read-write.
|
||||
There are EVEN MORE flags that are specific to each filesystem.
|
||||
You'll have to see the written documentation for those.
|
||||
|
||||
@@ -1151,6 +1302,7 @@ Send ICMP ECHO_REQUEST packets to network hosts.
|
||||
Options:
|
||||
|
||||
-c COUNT Send only COUNT pings.
|
||||
-s SIZE Send SIZE data bytes in packets (default=56).
|
||||
-q Quiet mode, only displays output at start
|
||||
and when finished.
|
||||
Example:
|
||||
@@ -1229,7 +1381,8 @@ Instructs the kernel to reboot the system.
|
||||
|
||||
Usage: rm [OPTION]... FILE...
|
||||
|
||||
Remove (unlink) the FILE(s).
|
||||
Remove (unlink) the FILE(s). You may use '--' to
|
||||
indicate that all following arguments are non-options.
|
||||
|
||||
Options:
|
||||
|
||||
@@ -1297,7 +1450,7 @@ Options:
|
||||
-e add the script to the commands to be executed
|
||||
-n suppress automatic printing of pattern space
|
||||
|
||||
This version of sed matches full regular expresions.
|
||||
This version of sed matches full regular expressions.
|
||||
|
||||
Example:
|
||||
|
||||
@@ -1306,6 +1459,22 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item setkeycodes
|
||||
|
||||
Usage: setkeycodes SCANCODE KEYCODE ...
|
||||
|
||||
Set entries into the kernel's scancode-to-keycode map,
|
||||
allowing unusual keyboards to generate usable keycodes.
|
||||
|
||||
SCANCODE may be either xx or e0xx (hexadecimal),
|
||||
and KEYCODE is given in decimal
|
||||
|
||||
Example:
|
||||
|
||||
# setkeycodes e030 127
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item sh
|
||||
|
||||
Usage: sh
|
||||
@@ -1414,10 +1583,10 @@ Note that this version of syslogd/klogd ignores /etc/syslog.conf.
|
||||
|
||||
Options:
|
||||
|
||||
-m Change the mark timestamp interval. default=20min. 0=off
|
||||
-n Do not fork into the background (for when run by init)
|
||||
-K Do not start up the klogd process (by default syslogd spawns klogd).
|
||||
-O Specify an alternate log file. default=/var/log/messages
|
||||
-m NUM Interval between MARK lines (default=20min, 0=off)
|
||||
-n Run as a foreground process
|
||||
-K Do not start up the klogd process
|
||||
-O FILE Use an alternate log file (default=/var/log/messages)
|
||||
|
||||
-------------------------------
|
||||
|
||||
@@ -1521,6 +1690,15 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item telnet
|
||||
|
||||
Usage: telnet host [port]
|
||||
|
||||
Telnet is used to establish interactive communication with another
|
||||
computer over a network using the TELNET protocol.
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item tee
|
||||
|
||||
Usage: tee [OPTION]... [FILE]...
|
||||
@@ -1557,10 +1735,16 @@ Example:
|
||||
|
||||
=item tr
|
||||
|
||||
Usage: tr [B<-cdsu>] string1 [string2]
|
||||
Usage: tr [-cds] STRING1 [STRING2]
|
||||
|
||||
Translate, squeeze, and/or delete characters from standard
|
||||
input, writing to standard output.
|
||||
Translate, squeeze, and/or delete characters from
|
||||
standard input, writing to standard output.
|
||||
|
||||
Options:
|
||||
|
||||
-c take complement of STRING1
|
||||
-d delete input characters coded STRING1
|
||||
-s squeeze multiple output characters of STRING2 into one character
|
||||
|
||||
Example:
|
||||
|
||||
@@ -1598,15 +1782,55 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item uuencode
|
||||
|
||||
Usage: uuencode [OPTION] [INFILE] REMOTEFILE
|
||||
|
||||
Uuencode a file.
|
||||
|
||||
Options:
|
||||
|
||||
-m use base64 encoding as of RFC1521
|
||||
|
||||
Example:
|
||||
|
||||
$ uuencode busybox busybox
|
||||
begin 755 busybox
|
||||
M?T5,1@$!`0````````````(``P`!````L+@$"#0```!0N@,``````#0`(``&
|
||||
.....
|
||||
$ uudecode busybox busybox > busybox.uu
|
||||
$
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item uudecode
|
||||
|
||||
Usage: uudecode [OPTION] [FILE]
|
||||
|
||||
Uudecode a uuencoded file
|
||||
|
||||
Options:
|
||||
|
||||
-o FILE direct output to FILE
|
||||
|
||||
Example:
|
||||
|
||||
$ uudecode -o busybox busybox.uu
|
||||
$ ls -l busybox
|
||||
-rwxr-xr-x 1 ams ams 245264 Jun 7 21:35 busybox
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item umount
|
||||
|
||||
Usage: umount [flags] filesystem|directory
|
||||
|
||||
Flags:
|
||||
|
||||
-a: Unmount all file systems
|
||||
-r: Try to remount devices as read-only if mount is busy
|
||||
-f: Do not free loop device (if a loop device has been used)
|
||||
-a: Unmount all file systems
|
||||
-r: Try to remount devices as read-only if mount is busy
|
||||
-f: Force filesystem umount (i.e. unreachable NFS server)
|
||||
-l: Do not free loop device (if a loop device has been used)
|
||||
|
||||
Example:
|
||||
|
||||
@@ -1714,6 +1938,19 @@ Example:
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item which
|
||||
|
||||
Usage: which [COMMAND ...]
|
||||
|
||||
Locates a COMMAND.
|
||||
|
||||
Example:
|
||||
|
||||
$ which login
|
||||
/bin/login
|
||||
|
||||
-------------------------------
|
||||
|
||||
=item whoami
|
||||
|
||||
Usage: whoami
|
||||
@@ -1738,12 +1975,26 @@ Repeatedly outputs a line with all specified STRING(s), or `y'.
|
||||
=item zcat
|
||||
|
||||
This is essentially an alias for invoking "gunzip B<-c>", where
|
||||
it decompresses the file inquestion and send the output to stdout.
|
||||
it decompresses the file in question and send the output to stdout.
|
||||
|
||||
-------------------------------
|
||||
|
||||
=back
|
||||
|
||||
=head1 LIBC NSS
|
||||
|
||||
GNU Libc uses the Name Service Switch (NSS) to configure the behavior of the C
|
||||
library for the local environment, and to configure how it reads system data,
|
||||
such as passwords and group information. BusyBox has made it Policy that it
|
||||
will never use NSS, and will never use and libc calls that make use of NSS.
|
||||
This allows you to run an embedded system without the need for installing an
|
||||
/etc/nsswitch.conf file and without and /lib/libnss_* libraries installed.
|
||||
|
||||
If you are using a system that is using a remote LDAP server for authentication
|
||||
via GNU libc NSS, and you want to use BusyBox, then you will need to adjust the
|
||||
BusyBox source. Chances are though, that if you have enough space to install
|
||||
of that stuff on your system, then you probably want the full GNU utilities.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
textutils(1), shellutils(1), etc...
|
||||
@@ -1785,10 +2036,18 @@ John Lombardo <john@deltanet.com>
|
||||
|
||||
=for html <br>
|
||||
|
||||
Glenn McGrath <bug1@netconnect.com.au>
|
||||
|
||||
=for html <br>
|
||||
|
||||
Bruce Perens <bruce@perens.com>
|
||||
|
||||
=for html <br>
|
||||
|
||||
Pavel Roskin <proski@gnu.org>
|
||||
|
||||
=for html <br>
|
||||
|
||||
Linus Torvalds <torvalds@transmeta.com>
|
||||
|
||||
=for html <br>
|
||||
@@ -1803,4 +2062,4 @@ Enrique Zanardi <ezanardi@ull.es>
|
||||
|
||||
=cut
|
||||
|
||||
# $Id: busybox.pod,v 1.19 2000/04/19 05:15:12 erik Exp $
|
||||
# $Id: busybox.pod,v 1.51 2000/06/21 22:53:24 andersen Exp $
|
||||
@@ -32,17 +32,19 @@
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/param.h> /* for PATH_MAX */
|
||||
|
||||
typedef void (Display) (long, char *);
|
||||
|
||||
static const char du_usage[] =
|
||||
"du [OPTION]... [FILE]...\n\n"
|
||||
"Summarize disk space used for each FILE and/or directory.\n"
|
||||
"du [OPTION]... [FILE]...\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nSummarizes disk space used for each FILE and/or directory.\n"
|
||||
"Disk space is printed in units of 1024 bytes.\n\n"
|
||||
"Options:\n"
|
||||
"\t-l\tcount sizes many times if hard linked\n"
|
||||
"\t-s\tdisplay only a total for each argument\n";
|
||||
"\t-s\tdisplay only a total for each argument\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
static int du_depth = 0;
|
||||
static int count_hardlinks = 0;
|
||||
@@ -97,7 +99,7 @@ static long du(char *filename)
|
||||
filename[--len] = '\0';
|
||||
|
||||
while ((entry = readdir(dir))) {
|
||||
char newfile[PATH_MAX + 1];
|
||||
char newfile[BUFSIZ + 1];
|
||||
char *name = entry->d_name;
|
||||
|
||||
if ((strcmp(name, "..") == 0)
|
||||
@@ -105,7 +107,7 @@ static long du(char *filename)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (len + strlen(name) + 1 > PATH_MAX) {
|
||||
if (len + strlen(name) + 1 > BUFSIZ) {
|
||||
fprintf(stderr, name_too_long, "du");
|
||||
du_depth--;
|
||||
return 0;
|
||||
@@ -179,10 +181,10 @@ int du_main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* $Id: du.c,v 1.17 2000/04/13 01:18:56 erik Exp $ */
|
||||
/* $Id: du.c,v 1.20 2000/06/19 17:25:39 andersen Exp $ */
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
|
||||
@@ -8,46 +8,53 @@
|
||||
* versions of 'who', 'last', etc. IP Addr is output in hex,
|
||||
* little endian on x86.
|
||||
*
|
||||
* made against libc6
|
||||
* Modified to support all sort of libcs by
|
||||
* Erik Andersen <andersen@lineo.com>
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <utmp.h>
|
||||
#define BB_DECLARE_EXTERN
|
||||
#define bb_need_io_error
|
||||
#include "messages.c"
|
||||
#include <utmp.h>
|
||||
|
||||
static const char dutmp_usage[] = "dutmp [FILE]\n\n"
|
||||
"Dump utmp file format (pipe delimited) from FILE\n"
|
||||
"or stdin to stdout. (i.e. 'dutmp /var/run/utmp')\n";
|
||||
|
||||
static const char dutmp_usage[] = "dutmp [FILE]\n"
|
||||
#ifndef BB_FEATURE_TRIVIAL_HELP
|
||||
"\nDump utmp file format (pipe delimited) from FILE\n"
|
||||
"or stdin to stdout. (i.e. 'dutmp /var/run/utmp')\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
extern int dutmp_main(int argc, char **argv)
|
||||
{
|
||||
|
||||
FILE *f;
|
||||
int file;
|
||||
struct utmp ut;
|
||||
|
||||
if (argc<2) {
|
||||
f = stdin;
|
||||
file = fileno(stdin);
|
||||
} else if (*argv[1] == '-' ) {
|
||||
usage(dutmp_usage);
|
||||
} else {
|
||||
f = fopen(argv[1], "r");
|
||||
if (f == NULL) {
|
||||
file = open(argv[1], O_RDONLY);
|
||||
if (file < 0) {
|
||||
fatalError(io_error, argv[1], strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
while (fread(&ut, sizeof(struct utmp), 1, f)) {
|
||||
printf("%d|%d|%s|%s|%s|%s|%d|%d|%ld|%ld|%ld|%x\n",
|
||||
ut.ut_type, ut.ut_pid, ut.ut_line,
|
||||
ut.ut_id, ut.ut_user, ut.ut_host,
|
||||
ut.ut_exit.e_termination, ut.ut_exit.e_exit,
|
||||
ut.ut_session,
|
||||
ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, ut.ut_addr);
|
||||
while (read(file, (void*)&ut, sizeof(struct utmp))) {
|
||||
printf("%d|%d|%s|%s|%s|%s|%s|%lx\n",
|
||||
ut.ut_type, ut.ut_pid, ut.ut_line,
|
||||
ut.ut_id, ut.ut_user, ut.ut_host,
|
||||
ctime(&(ut.ut_time)),
|
||||
(long)ut.ut_addr);
|
||||
}
|
||||
|
||||
exit(TRUE);
|
||||
return(TRUE);
|
||||
}
|
||||