Compare commits
51
Commits
0_41
..
0_60_stable
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
267b925bb4 | ||
|
|
aad0c53aa2 | ||
|
|
eb2a21f68d | ||
|
|
ce998051b4 | ||
|
|
2ecdbd9eb8 | ||
|
|
fe5bc552e6 | ||
|
|
d9ffc9caa6 | ||
|
|
62fda96120 | ||
|
|
75851b363b | ||
|
|
a97ef8eed4 | ||
|
|
41a82698c3 | ||
|
|
9019ed994f | ||
|
|
0eaef54878 | ||
|
|
f8d5b031c2 | ||
|
|
e5a1a23577 | ||
|
|
37ded2819b | ||
|
|
7f65e78f5c | ||
|
|
f295db8fbd | ||
|
|
9959ef4e2c | ||
|
|
cf969517dc | ||
|
|
64ef2d4cfa | ||
|
|
6a18de72c4 | ||
|
|
bf31a8c450 | ||
|
|
3f6bb561db | ||
|
|
2fd475509a | ||
|
|
93fc393486 | ||
|
|
6b4d645722 | ||
|
|
8ccef78172 | ||
|
|
018e9e8c0f | ||
|
|
9b2afe6dd6 | ||
|
|
3cba82678b | ||
|
|
b7090fda30 | ||
|
|
61a37e248d | ||
|
|
c960eda2eb | ||
|
|
c83f8e765d | ||
|
|
8fdaace1d9 | ||
|
|
43a6ed1171 | ||
|
|
170e4a7395 | ||
|
|
c4174b1b30 | ||
|
|
3b8b434e53 | ||
|
|
27656e1868 | ||
|
|
df73587122 | ||
|
|
59feb4b9bb | ||
|
|
b3d5dd7220 | ||
|
|
82c22aa311 | ||
|
|
afe07daf34 | ||
|
|
435680426e | ||
|
|
686a24b2f5 | ||
|
|
d85117bb85 | ||
|
|
6c8c51a470 | ||
|
|
4a5360b97e |
No files matched your search
@@ -1,2 +1,4 @@
|
||||
busybox
|
||||
busybox.links
|
||||
_install
|
||||
applet_source_list
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
--blank-lines-after-declarations
|
||||
--blank-lines-after-procedures
|
||||
--break-before-boolean-operator
|
||||
--no-blank-lines-after-commas
|
||||
--braces-on-if-line
|
||||
--braces-on-struct-decl-line
|
||||
--comment-indentation25
|
||||
--declaration-comment-column25
|
||||
--no-comment-delimiters-on-blank-lines
|
||||
--cuddle-else
|
||||
--continuation-indentation4
|
||||
--case-indentation0
|
||||
--else-endif-column33
|
||||
--space-after-cast
|
||||
--line-comments-indentation0
|
||||
--declaration-indentation1
|
||||
--dont-format-first-column-comments
|
||||
--dont-format-comments
|
||||
--honour-newlines
|
||||
--indent-level4
|
||||
/* changed from 0 to 4 */
|
||||
--parameter-indentation4
|
||||
--line-length78 /* changed from 75 */
|
||||
--continue-at-parentheses
|
||||
--no-space-after-function-call-names
|
||||
--dont-break-procedure-type
|
||||
--dont-star-comments
|
||||
--leave-optional-blank-lines
|
||||
--dont-space-special-semicolon
|
||||
--tab-size4
|
||||
/* additions by Mark */
|
||||
--case-brace-indentation0
|
||||
--leave-preprocessor-space
|
||||
@@ -1,22 +1,22 @@
|
||||
List of the authors of code contained in busybox.
|
||||
List of the authors of code contained in BusyBox.
|
||||
|
||||
If you should be listed here, or the description of
|
||||
what you have done needs more detail, or is incorect,
|
||||
_please_ let me know.
|
||||
If you have code in BusyBox, you should be listed here. If you should be
|
||||
listed, or the description of what you have done needs more detail, or is
|
||||
incorect, _please_ let me know.
|
||||
|
||||
-Erik
|
||||
|
||||
-----------
|
||||
|
||||
Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
Erik Andersen <andersen@codepoet.org>, <andersee@debian.org>
|
||||
Tons of new stuff, major rewrite of most of the
|
||||
core apps, tons of new apps as noted in header files.
|
||||
|
||||
Bruce Perens <bruce@pixar.com>
|
||||
Original author of BusyBox. His code is still in many apps.
|
||||
|
||||
John Beppu <beppu@lineo.com>
|
||||
du, head, tee
|
||||
Edward Betts <edward@debian.org>
|
||||
expr, hostid, logname, tty, wc, whoami, yes
|
||||
|
||||
John Beppu <beppu@codepoet.org>
|
||||
du, head, nslookup, sort, tee, uniq
|
||||
|
||||
Brian Candler <B.Candler@pobox.com>
|
||||
tiny-ls(ls)
|
||||
@@ -28,13 +28,66 @@ Dave Cinege <dcinege@psychosis.com>
|
||||
more(v2), makedevs, dutmp, modularization, auto links file,
|
||||
various fixes, Linux Router Project maintenance
|
||||
|
||||
Magnus Damm <damm@opensource.se>
|
||||
tftp client
|
||||
insmod powerpc support
|
||||
|
||||
Larry Doolittle <ldoolitt@recycle.lbl.gov>
|
||||
pristine source directory compilation, lots of patches and fixes.
|
||||
|
||||
Gennady Feldman <gfeldman@cachier.com>
|
||||
Sysklogd (single threaded syslogd, IPC Circular buffer support,
|
||||
logread), various fixes.
|
||||
|
||||
Karl M. Hegbloom <karlheg@debian.org>
|
||||
cp_mv.c, the test suite, various fixes to utility.c, &c.
|
||||
|
||||
Daniel Jacobowitz <dan@debian.org>
|
||||
mktemp.c
|
||||
|
||||
Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
||||
documentation, bugfixes, test suite
|
||||
|
||||
John Lombardo <john@deltanet.com>
|
||||
dirname, tr
|
||||
|
||||
Glenn McGrath <bug1@optushome.com.au>
|
||||
ar, dpkg, dpkg-deb
|
||||
|
||||
Vladimir Oleynik <dzo@simtreas.ru>
|
||||
cmdedit; ports: ash, stty, traceroute; locale, various fixes
|
||||
and irreconcilable critic of everything not perfect.
|
||||
|
||||
Bruce Perens <bruce@pixar.com>
|
||||
Original author of BusyBox. His code is still in many apps.
|
||||
|
||||
Tim Riker <Tim@Rikers.org>
|
||||
bug fixes, member of fan club
|
||||
|
||||
Kent Robotti <robotti@metconnect.com>
|
||||
reset, tons and tons of bug reports and patchs.
|
||||
|
||||
Chip Rosenthal <chip@unicom.com>, <crosenth@covad.com>
|
||||
wget - Contributed by permission of Covad Communications
|
||||
|
||||
Pavel Roskin <proski@gnu.org>
|
||||
Lots of bugs fixes and patches.
|
||||
|
||||
Gyepi Sam <gyepi@praxis-sw.com>
|
||||
Remote logging feature for syslogd
|
||||
|
||||
Linus Torvalds <torvalds@transmeta.com>
|
||||
mkswap, fsck.minix, mkfs.minix
|
||||
|
||||
Mark Whitley <markw@codepoet.org>
|
||||
grep, sed, cut, xargs, style-guide, new-applet-HOWTO, bug fixes, etc.
|
||||
|
||||
Charles P. Wright <cpwright@villagenet.com>
|
||||
gzip, mini-netcat(nc)
|
||||
|
||||
Enrique Zanardi <ezanardi@ull.es>
|
||||
tarcat (since removed), loadkmap, various fixes, Debian maintenance
|
||||
|
||||
Emanuele Aina <emanuele.aina@tiscali.it>
|
||||
run-parts
|
||||
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
2002-10-27 Erik Andersen <andersen@dillweed>
|
||||
|
||||
* Makefile: Increment version number
|
||||
|
||||
* debian/control, debian/changelog: Update packaging info
|
||||
|
||||
2002-10-26 Erik Andersen <andersen@dillweed>
|
||||
|
||||
* debian/Config.h-udeb:
|
||||
Don't support init being run as /linux in the debian installer
|
||||
-Erik
|
||||
|
||||
* swaponoff.c: last_patch64 from vodz:
|
||||
|
||||
The following usage from original user:
|
||||
$ ./busybox swapon -a
|
||||
Have typo problem:
|
||||
swapon: swapon: Operation not permitted
|
||||
|
||||
But regular version:
|
||||
swapon: /dev/hda5: Operation not permitted
|
||||
|
||||
Patch attached, reduced 9 bytes and advanced
|
||||
exit code also.
|
||||
|
||||
* vi.c:
|
||||
A patch from Jouni Malinen to avoid some buffer overflows in vi,
|
||||
closing bug #1270
|
||||
|
||||
* Makefile: Ivan Popov noticed that handling of PREFIX was bad.
|
||||
-Erik
|
||||
|
||||
2002-10-25 Erik Andersen <andersen@dillweed>
|
||||
|
||||
* tftp.c: This patch from Magnus Damm fixed a long standing problem
|
||||
with freeing memory.
|
||||
|
||||
2002-10-23 Erik Andersen <andersen@dillweed>
|
||||
|
||||
* top.c: Backport vodz' reworked top applet from unstable
|
||||
|
||||
2002-10-22 Erik Andersen <andersen@dillweed>
|
||||
|
||||
* ash.c, ifconfig.c: Fix warnings
|
||||
|
||||
* md5sum.c: Fix undefined operation (temp = temp = <stuff>) and remove
|
||||
double definition.
|
||||
-Erik
|
||||
|
||||
* init.c: I committed the fflush in the wrong spot. I should go to bed
|
||||
earlier so I don't screw up such easy stuff.
|
||||
-Erik
|
||||
|
||||
* ash.c: Apply last_patch51_3 from vodz
|
||||
|
||||
* init.c: Be absurdly careful about flushing stdout.
|
||||
|
||||
2002-10-18 Erik Andersen <andersen@dillweed>
|
||||
|
||||
* tests/sh.testcases: Missed a spot
|
||||
|
||||
* tests/sh.testcases: disambiguate a test
|
||||
|
||||
* lsmod.c: Fixup some needless formatting differences vs modutils
|
||||
|
||||
* hostname.c:
|
||||
Fixup slight difference in 'hostname -d' behavior vs GNU hostname
|
||||
|
||||
2002-10-12 Erik Andersen <andersen@dillweed>
|
||||
|
||||
* init.c:
|
||||
After thinking about it, I think this patch from Matt Kraai is probably the
|
||||
best way to go. Sysvinit does not provide a controlling tty since it doesn't
|
||||
even try to open ttys for apps. We do. We we should _try_ to provide a
|
||||
controlling tty if possible, but we needn't freak out if it doesn't work. So
|
||||
we won't need to use openvt or similar, we'll just have init do the Right
|
||||
Thing(tm).
|
||||
|
||||
2002-10-08 Erik Andersen <andersen@dillweed>
|
||||
|
||||
* docs/.cvsignore: oops
|
||||
|
||||
* docs/.cvsignore, Makefile: Remove docs/busybox.pod on 'make clean'
|
||||
|
||||
* init.c:
|
||||
Patch from Ben Gamsa <ben@somanetworks.com> to handle it when orphaned
|
||||
processes are created faster than busybox init reaps them.
|
||||
|
||||
* lsmod.c: Fix missing \n noticed by Robert Schwebel
|
||||
|
||||
* debian/Config.h-udeb: Enable pidof
|
||||
|
||||
* libbb/copy_file.c:
|
||||
Doh! It turns out I broke 'cp -a' symlink handling. Oops. This fix, from
|
||||
Tollef Fog Heen <tollef@add.no> fixes my stupid thinko so that 'cp -a' once
|
||||
again copies symlinks properly.
|
||||
|
||||
2002-09-30 Erik Andersen <andersen@dillweed>
|
||||
|
||||
* usage.h: Fix docs
|
||||
|
||||
* lash.c:
|
||||
Use %m, not strerror (changing since strerror(err) was broken anyways)
|
||||
|
||||
* init.c: Set the close-on-exec flag, just to be safe
|
||||
|
||||
* time.c: Doh. We divide microseconds by 60?
|
||||
|
||||
2002-09-27 Erik Andersen <andersen@dillweed>
|
||||
|
||||
* time.c: Bug fix from Nitin Gupta <gupta@equator.com>
|
||||
|
||||
2002-09-26 Erik Andersen <andersen@dillweed>
|
||||
|
||||
* lash.c: Avoid calling exit() from within fork/vfork'ed processes.
|
||||
-Erik
|
||||
|
||||
2002-09-25 Erik Andersen <andersen@dillweed>
|
||||
|
||||
* init.c:
|
||||
Ignoring SIGCHLD causes a race leading to the occasional hang of init
|
||||
when init will wait() on itself in waitfor() when the child exits before
|
||||
init is scheduled to run. Letting init hang is very seriously bad.
|
||||
-Erik
|
||||
|
||||
2002-09-22 Erik Andersen <andersen@dillweed>
|
||||
|
||||
* Makefile: Fixup largefile settings.
|
||||
-Erik
|
||||
|
||||
2002-09-20 Erik Andersen <andersen@dillweed>
|
||||
|
||||
* gunzip.c: Doh! As noted by K.-P. Kirchdörfer" <kapeka@epost.de>,
|
||||
gunzip -c deletes the source source file! This fixes it.
|
||||
-Erik
|
||||
|
||||
* top.c: Don't leak FILEs
|
||||
|
||||
@@ -0,0 +1,494 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
// This file defines the feature set to be compiled into busybox.
|
||||
// When you turn things off here, they won't be compiled in at all.
|
||||
//
|
||||
//// This file is parsed by sed. You MUST use single line comments.
|
||||
// i.e., //#define BB_BLAH
|
||||
//
|
||||
//
|
||||
// BusyBox Applications
|
||||
//#define BB_ADJTIMEX
|
||||
//#define BB_AR
|
||||
#define BB_ASH
|
||||
#define BB_BASENAME
|
||||
#define BB_CAT
|
||||
#define BB_CHGRP
|
||||
#define BB_CHMOD
|
||||
#define BB_CHOWN
|
||||
#define BB_CHROOT
|
||||
#define BB_CHVT
|
||||
#define BB_CLEAR
|
||||
//#define BB_CMP
|
||||
#define BB_CP
|
||||
//#define BB_CPIO
|
||||
#define BB_CUT
|
||||
#define BB_DATE
|
||||
//#define BB_DC
|
||||
#define BB_DD
|
||||
//#define BB_DEALLOCVT
|
||||
#define BB_DF
|
||||
#define BB_DIRNAME
|
||||
#define BB_DMESG
|
||||
//#define BB_DOS2UNIX
|
||||
//#define BB_DPKG
|
||||
//#define BB_DPKG_DEB
|
||||
//#define BB_DUTMP
|
||||
#define BB_DU
|
||||
//#define BB_DUMPKMAP
|
||||
#define BB_ECHO
|
||||
#define BB_ENV
|
||||
//#define BB_EXPR
|
||||
//#define BB_FBSET
|
||||
//#define BB_FDFLUSH
|
||||
#define BB_FIND
|
||||
#define BB_FREE
|
||||
//#define BB_FREERAMDISK
|
||||
//#define BB_FSCK_MINIX
|
||||
//#define BB_GETOPT
|
||||
#define BB_GREP
|
||||
#define BB_GUNZIP
|
||||
#define BB_GZIP
|
||||
#define BB_HALT
|
||||
#define BB_HEAD
|
||||
//#define BB_HOSTID
|
||||
//#define BB_HOSTNAME
|
||||
//#define BB_HUSH
|
||||
#define BB_ID
|
||||
//#define BB_IFCONFIG
|
||||
#define BB_INIT
|
||||
//#define BB_INSMOD
|
||||
#define BB_KILL
|
||||
#define BB_KILLALL
|
||||
#define BB_KLOGD
|
||||
//#define BB_LASH
|
||||
//#define BB_LENGTH
|
||||
#define BB_LN
|
||||
//#define BB_LOADACM
|
||||
//#define BB_LOADFONT
|
||||
//#define BB_LOADKMAP
|
||||
#define BB_LOGGER
|
||||
//#define BB_LOGNAME
|
||||
//#define BB_LOSETUP
|
||||
#define BB_LS
|
||||
#define BB_LSMOD
|
||||
//#define BB_MAKEDEVS
|
||||
//#define BB_MD5SUM
|
||||
#define BB_MKDIR
|
||||
//#define BB_MKFIFO
|
||||
//#define BB_MKFS_MINIX
|
||||
#define BB_MKNOD
|
||||
#define BB_MKSWAP
|
||||
//#define BB_MKTEMP
|
||||
#define BB_MODPROBE
|
||||
#define BB_MORE
|
||||
#define BB_MOUNT
|
||||
//#define BB_MSH
|
||||
//#define BB_MT
|
||||
#define BB_MV
|
||||
//#define BB_NC
|
||||
//#define BB_NSLOOKUP
|
||||
#define BB_PIDOF
|
||||
//#define BB_PING
|
||||
//#define BB_PIVOT_ROOT
|
||||
#define BB_POWEROFF
|
||||
//#define BB_PRINTF
|
||||
#define BB_PS
|
||||
#define BB_PWD
|
||||
//#define BB_RDATE
|
||||
//#define BB_READLINK
|
||||
#define BB_REBOOT
|
||||
//#define BB_RENICE
|
||||
#define BB_RESET
|
||||
#define BB_RM
|
||||
#define BB_RMDIR
|
||||
//#define BB_RMMOD
|
||||
//#define BB_ROUTE
|
||||
//#define BB_RPM2CPIO
|
||||
#define BB_SED
|
||||
//#define BB_SETKEYCODES
|
||||
#define BB_SLEEP
|
||||
#define BB_SORT
|
||||
//#define BB_STTY
|
||||
#define BB_SWAPONOFF
|
||||
#define BB_SYNC
|
||||
#define BB_SYSLOGD
|
||||
#define BB_TAIL
|
||||
#define BB_TAR
|
||||
//#define BB_TEE
|
||||
//#define BB_TEST
|
||||
//#define BB_TELNET
|
||||
//#define BB_TFTP
|
||||
//#define BB_TIME
|
||||
//#define BB_TOP
|
||||
#define BB_TOUCH
|
||||
//#define BB_TR
|
||||
//#define BB_TRACEROUTE
|
||||
#define BB_TRUE_FALSE
|
||||
#define BB_TTY
|
||||
//#define BB_UNIX2DOS
|
||||
//#define BB_UUENCODE
|
||||
//#define BB_UUDECODE
|
||||
#define BB_UMOUNT
|
||||
#define BB_UNIQ
|
||||
#define BB_UNAME
|
||||
//#define BB_UPDATE
|
||||
#define BB_UPTIME
|
||||
//#define BB_USLEEP
|
||||
//#define BB_VI
|
||||
//#define BB_WATCHDOG
|
||||
#define BB_WC
|
||||
//#define BB_WGET
|
||||
#define BB_WHICH
|
||||
#define BB_WHOAMI
|
||||
#define BB_XARGS
|
||||
#define BB_YES
|
||||
// End of Applications List
|
||||
//
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------
|
||||
// This is where feature definitions go. Generally speaking,
|
||||
// turning this stuff off makes things a bit smaller (and less
|
||||
// pretty/useful).
|
||||
//
|
||||
//
|
||||
// If you enabled one or more of the shells, you may select which one
|
||||
// should be run when sh is invoked:
|
||||
#define BB_FEATURE_SH_IS_ASH
|
||||
//#define BB_FEATURE_SH_IS_HUSH
|
||||
//#define BB_FEATURE_SH_IS_LASH
|
||||
//#define BB_FEATURE_SH_IS_MSH
|
||||
//
|
||||
// BusyBox will, by default, malloc space for its buffers. This costs code
|
||||
// size for the call to xmalloc. You can use the following feature to have
|
||||
// them put on the stack. For some very small machines with limited stack
|
||||
// space, this can be deadly. For most folks, this works just fine...
|
||||
//#define BB_FEATURE_BUFFERS_GO_ON_STACK
|
||||
// The third alternative for buffer allocation is to use BSS. This works
|
||||
// beautifully for computers with a real MMU (and OS support), but wastes
|
||||
// runtime RAM for uCLinux. This behavior was the only one available for
|
||||
// BusyBox versions 0.48 and earlier.
|
||||
//#define BB_FEATURE_BUFFERS_GO_IN_BSS
|
||||
//
|
||||
// Turn this on to use Erik's very cool devps, and devmtab kernel drivers,
|
||||
// thereby eliminating the need for the /proc filesystem and thereby saving
|
||||
// lots and lots memory for more important things. NOTE: If you enable this
|
||||
// feature, you _must_ have patched the kernel to include the devps patch that
|
||||
// is included in the busybox/kernel-patches directory. You will also need to
|
||||
// create some device special files in /dev on your embedded system:
|
||||
// mknod /dev/mtab c 10 22
|
||||
// mknod /dev/ps c 10 21
|
||||
// I emailed Linus and this patch will not be going into the stock kernel.
|
||||
//#define BB_FEATURE_USE_DEVPS_PATCH
|
||||
//
|
||||
// show verbose usage messages
|
||||
#define BB_FEATURE_VERBOSE_USAGE
|
||||
//
|
||||
// Use termios to manipulate the screen ('more' is prettier with this on)
|
||||
//#define BB_FEATURE_USE_TERMIOS
|
||||
//
|
||||
// calculate terminal & column widths (for more, ls, and telnet)
|
||||
#define BB_FEATURE_AUTOWIDTH
|
||||
//
|
||||
// show username/groupnames for ls
|
||||
#define BB_FEATURE_LS_USERNAME
|
||||
//
|
||||
// show file timestamps in ls
|
||||
#define BB_FEATURE_LS_TIMESTAMPS
|
||||
//
|
||||
// enable ls -p and -F
|
||||
#define BB_FEATURE_LS_FILETYPES
|
||||
//
|
||||
// sort the file names
|
||||
#define BB_FEATURE_LS_SORTFILES
|
||||
//
|
||||
// enable ls -R
|
||||
#define BB_FEATURE_LS_RECURSIVE
|
||||
//
|
||||
// enable ls -L
|
||||
#define BB_FEATURE_LS_FOLLOWLINKS
|
||||
//
|
||||
// Use color to identify different file types
|
||||
#define BB_FEATURE_LS_COLOR
|
||||
//
|
||||
// Disable for a smaller (but less functional) ping
|
||||
#define BB_FEATURE_FANCY_PING
|
||||
//
|
||||
// Make init use a simplified /etc/inittab file (recommended).
|
||||
#define BB_FEATURE_USE_INITTAB
|
||||
//
|
||||
//Enable init being called as /linuxrc
|
||||
#define BB_FEATURE_LINUXRC
|
||||
//
|
||||
//Have init enable core dumping for child processes (for debugging only)
|
||||
//#define BB_FEATURE_INIT_COREDUMPS
|
||||
//
|
||||
//Make sure nothing is printed to the console on boot
|
||||
//#define BB_FEATURE_EXTRA_QUIET
|
||||
//
|
||||
// enable syslogd -R remotehost
|
||||
#define BB_FEATURE_REMOTE_LOG
|
||||
//
|
||||
// enable syslogd -C
|
||||
//#define BB_FEATURE_IPC_SYSLOG
|
||||
//
|
||||
//Disable for a simple tail implementation (2.34k vs 3k for the full one).
|
||||
//Both provide 'tail -f', but this cuts out -c, -q, -s, and -v.
|
||||
#define BB_FEATURE_FANCY_TAIL
|
||||
//
|
||||
// Enable support for loop devices in mount
|
||||
#define BB_FEATURE_MOUNT_LOOP
|
||||
//
|
||||
// Enable support for a real /etc/mtab file instead of /proc/mounts
|
||||
//#define BB_FEATURE_MTAB_SUPPORT
|
||||
//
|
||||
// Enable support for mounting remote NFS volumes.
|
||||
// You may need to mount with "-o nolock" if you are
|
||||
// not running a local portmapper daemon...
|
||||
//
|
||||
// If you are using uClibc, be sure that you've already compiled
|
||||
// uClibc with INCLUDE_RPC=true (contained in the Config file)
|
||||
//#define BB_FEATURE_NFSMOUNT
|
||||
//
|
||||
// Enable support forced filesystem unmounting
|
||||
// (i.e., in case of an unreachable NFS system).
|
||||
#define BB_FEATURE_MOUNT_FORCE
|
||||
//
|
||||
// Enable support for creation of tar files.
|
||||
#define BB_FEATURE_TAR_CREATE
|
||||
//
|
||||
// Enable support for "--exclude" and "-X" for excluding files
|
||||
#define BB_FEATURE_TAR_EXCLUDE
|
||||
//
|
||||
// Enable support for tar -z option (currently only works for inflating)
|
||||
#define BB_FEATURE_TAR_GZIP
|
||||
//
|
||||
// Enable reverse sort
|
||||
#define BB_FEATURE_SORT_REVERSE
|
||||
//
|
||||
// Enable uniqe sort
|
||||
#define BB_FEATURE_SORT_UNIQUE
|
||||
//
|
||||
// Enable command line editing in the shell.
|
||||
// Only relevant if a shell is enabled. On by default.
|
||||
#define BB_FEATURE_COMMAND_EDITING
|
||||
//
|
||||
// Enable tab completion in the shell. This is now working quite nicely.
|
||||
// This feature adds a bit over 4k. Only relevant if a shell is enabled.
|
||||
#define BB_FEATURE_COMMAND_TAB_COMPLETION
|
||||
//
|
||||
// Attempts to match usernames in a ~-prefixed path
|
||||
//#define BB_FEATURE_COMMAND_USERNAME_COMPLETION
|
||||
//
|
||||
//Allow the shell to invoke all the compiled in BusyBox applets as if they
|
||||
//were shell builtins. Nice for staticly linking an emergency rescue shell,
|
||||
//among other things. Off by default.
|
||||
// Only relevant if a shell is enabled.
|
||||
//#define BB_FEATURE_SH_STANDALONE_SHELL
|
||||
//
|
||||
//When this is enabled, busybox shell applets can be called using full path
|
||||
//names. This causes applets (i.e., most busybox commands) to override
|
||||
//real commands on the filesystem. For example, if you run run /bin/cat, it
|
||||
//will use BusyBox cat even if /bin/cat exists on the filesystem and is _not_
|
||||
//busybox. Some systems want this, others do not. Choose wisely. :-) This
|
||||
//only has meaning when BB_FEATURE_SH_STANDALONE_SHELL is enabled.
|
||||
// Only relevant if a shell is enabled. Off by default.
|
||||
//#define BB_FEATURE_SH_APPLETS_ALWAYS_WIN
|
||||
//
|
||||
// Uncomment this option for a fancy shell prompt that includes the
|
||||
// current username and hostname. On systems that don't have usernames
|
||||
// or hostnames, this can look hideous.
|
||||
// Only relevant if a shell is enabled.
|
||||
//#define BB_FEATURE_SH_FANCY_PROMPT
|
||||
//
|
||||
// Uncomment this option to disable job control. Job control lets you
|
||||
// run jobs in the background (which completely useless for is all you
|
||||
// are doing is running scripts). Disabing this is bad for interactive
|
||||
// use, since when you hit ^C in an application, it will also kill the
|
||||
// shell. This adds about 2.5k on an x86 system.
|
||||
#define BB_FEATURE_ASH_JOB_CONTROL
|
||||
//
|
||||
//Turn on extra fbset options
|
||||
//#define BB_FEATURE_FBSET_FANCY
|
||||
//
|
||||
//Turn on fbset readmode support
|
||||
//#define BB_FEATURE_FBSET_READMODE
|
||||
//
|
||||
// Support insmod/lsmod/rmmod for post 2.1 kernels
|
||||
#define BB_FEATURE_NEW_MODULE_INTERFACE
|
||||
//
|
||||
// Support insmod/lsmod/rmmod for pre 2.1 kernels
|
||||
//#define BB_FEATURE_OLD_MODULE_INTERFACE
|
||||
//
|
||||
// Support module version checking
|
||||
//#define BB_FEATURE_INSMOD_VERSION_CHECKING
|
||||
//
|
||||
// Support for uClinux memory usage optimization, which will load the image
|
||||
// directly into the kernel memory. This divides memory requrements by three.
|
||||
// If you are not running uClinux (i.e., your CPU has an MMU) leave this
|
||||
// disabled...
|
||||
//#define BB_FEATURE_INSMOD_LOADINKMEM
|
||||
//
|
||||
// Support for Minix filesystem, version 2
|
||||
//#define BB_FEATURE_MINIX2
|
||||
//
|
||||
// Enable ifconfig status reporting output -- this feature adds 7k.
|
||||
//#define BB_FEATURE_IFCONFIG_STATUS
|
||||
//
|
||||
// Enable ifconfig slip-specific options "keepalive" and "outfill"
|
||||
//#define BB_FEATURE_IFCONFIG_SLIP
|
||||
//
|
||||
// Enable ifconfig options "mem_start", "io_addr", and "irq".
|
||||
//#define BB_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ
|
||||
//
|
||||
// Enable ifconfig option "hw". Currently works for only with "ether".
|
||||
//#define BB_FEATURE_IFCONFIG_HW
|
||||
//
|
||||
// Allows "broadcast +" to set broadcast automatically based on hostaddr
|
||||
// and netmask, at a cost of about 100 bytes of code (i386).
|
||||
//#define BB_FEATURE_IFCONFIG_BROADCAST_PLUS
|
||||
//
|
||||
// Enable busybox --install [-s]
|
||||
// to create links (or symlinks) for all the commands that are
|
||||
// compiled into the binary. (needs /proc filesystem)
|
||||
//#define BB_FEATURE_INSTALLER
|
||||
//
|
||||
// Enable a nifty progress meter in wget (adds just under 2k)
|
||||
#define BB_FEATURE_WGET_STATUSBAR
|
||||
//
|
||||
// Enable HTTP authentication in wget
|
||||
#define BB_FEATURE_WGET_AUTHENTICATION
|
||||
//
|
||||
// Clean up all memory before exiting -- usually not needed
|
||||
// as the OS can clean up... Don't enable this unless you
|
||||
// have a really good reason for cleaning things up manually.
|
||||
//#define BB_FEATURE_CLEAN_UP
|
||||
//
|
||||
// Support for human readable output by ls, du, etc.(example 13k, 23M, 235G)
|
||||
#define BB_FEATURE_HUMAN_READABLE
|
||||
//
|
||||
// Support for the find -type option.
|
||||
#define BB_FEATURE_FIND_TYPE
|
||||
//
|
||||
// Support for the find -perm option.
|
||||
#define BB_FEATURE_FIND_PERM
|
||||
//
|
||||
// Support for the find -mtime option.
|
||||
#define BB_FEATURE_FIND_MTIME
|
||||
//
|
||||
//// Support for the find -newer option.
|
||||
#define BB_FEATURE_FIND_NEWER
|
||||
//
|
||||
// Support for the -A -B and -C context flags in grep
|
||||
//#define BB_FEATURE_GREP_CONTEXT
|
||||
//
|
||||
// Support for the EGREP applet (alias to the grep applet)
|
||||
//#define BB_FEATURE_GREP_EGREP_ALIAS
|
||||
//
|
||||
// Tell tftp what commands that should be supported.
|
||||
#define BB_FEATURE_TFTP_PUT
|
||||
#define BB_FEATURE_TFTP_GET
|
||||
//
|
||||
// features for vi
|
||||
#define BB_FEATURE_VI_COLON // ":" colon commands, no "ex" mode
|
||||
#define BB_FEATURE_VI_YANKMARK // Yank/Put commands and Mark cmds
|
||||
#define BB_FEATURE_VI_SEARCH // search and replace cmds
|
||||
#define BB_FEATURE_VI_USE_SIGNALS // catch signals
|
||||
#define BB_FEATURE_VI_DOT_CMD // remember previous cmd and "." cmd
|
||||
#define BB_FEATURE_VI_READONLY // vi -R and "view" mode
|
||||
#define BB_FEATURE_VI_SETOPTS // set-able options, ai ic showmatch
|
||||
#define BB_FEATURE_VI_SET // :set
|
||||
#define BB_FEATURE_VI_WIN_RESIZE // handle window resize
|
||||
//
|
||||
// Enable a if you system have setuped locale
|
||||
//#define BB_LOCALE_SUPPORT
|
||||
//
|
||||
// Support for TELNET to pass TERM type to remote host. Adds 384 bytes.
|
||||
#define BB_FEATURE_TELNET_TTYPE
|
||||
//
|
||||
// Support for devfs.
|
||||
//#define BB_FEATURE_DEVFS
|
||||
//
|
||||
// End of Features List
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------
|
||||
// Nothing beyond this point should ever be touched by
|
||||
// mere mortals so leave this stuff alone.
|
||||
//
|
||||
#include <features.h>
|
||||
#if defined(__uClinux__)
|
||||
#undef BB_ASH /* Not even a chance it will work */
|
||||
#undef BB_RPM2CPIO /* Uses gz_open(), which uses fork() */
|
||||
#undef BB_DPKG_DEB /* Uses gz_open(), which uses fork() */
|
||||
#undef BB_FEATURE_TAR_GZIP /* Uses fork() */
|
||||
#undef BB_UPDATE /* Uses daemon() */
|
||||
#endif
|
||||
#if defined BB_ASH || defined BB_HUSH || defined BB_LASH || defined BB_MSH
|
||||
#if defined BB_FEATURE_COMMAND_EDITING
|
||||
#define BB_CMDEDIT
|
||||
#else
|
||||
#undef BB_FEATURE_COMMAND_EDITING
|
||||
#undef BB_FEATURE_COMMAND_TAB_COMPLETION
|
||||
#undef BB_FEATURE_COMMAND_USERNAME_COMPLETION
|
||||
#undef BB_FEATURE_SH_FANCY_PROMPT
|
||||
#endif
|
||||
#else
|
||||
#undef BB_FEATURE_SH_APPLETS_ALWAYS_WIN
|
||||
#undef BB_FEATURE_SH_STANDALONE_SHELL
|
||||
#undef BB_FEATURE_SH_FANCY_PROMPT
|
||||
#endif
|
||||
//
|
||||
#if (defined BB_ASH || defined BB_HUSH || defined BB_MSH) && ! defined BB_TEST
|
||||
#define BB_TEST
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_KILLALL
|
||||
#ifndef BB_KILL
|
||||
#define BB_KILL
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#ifndef BB_INIT
|
||||
#undef BB_FEATURE_LINUXRC
|
||||
#endif
|
||||
//
|
||||
#if defined BB_MOUNT && defined BB_FEATURE_NFSMOUNT
|
||||
#define BB_NFSMOUNT
|
||||
#endif
|
||||
//
|
||||
#if defined BB_FEATURE_AUTOWIDTH
|
||||
#ifndef BB_FEATURE_USE_TERMIOS
|
||||
#define BB_FEATURE_USE_TERMIOS
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#if defined BB_INSMOD || defined BB_LSMOD
|
||||
#if ! defined BB_FEATURE_NEW_MODULE_INTERFACE && ! defined BB_FEATURE_OLD_MODULE_INTERFACE
|
||||
#define BB_FEATURE_NEW_MODULE_INTERFACE
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_UNIX2DOS
|
||||
#define BB_DOS2UNIX
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_SYSLOGD
|
||||
#if defined BB_FEATURE_IPC_SYSLOG
|
||||
#define BB_LOGREAD
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#if defined BB_ASH && defined BB_FEATURE_SH_IS_ASH
|
||||
# define shell_main ash_main
|
||||
#elif defined BB_HUSH && defined BB_FEATURE_SH_IS_HUSH
|
||||
# define shell_main hush_main
|
||||
#elif defined BB_LASH && defined BB_FEATURE_SH_IS_LASH
|
||||
# define shell_main lash_main
|
||||
#elif defined BB_MSH && defined BB_FEATURE_SH_IS_MSH
|
||||
# define shell_main msh_main
|
||||
#endif
|
||||
@@ -0,0 +1,8 @@
|
||||
1) Check Config.h and adjust if you need a different functionality than
|
||||
defined by default.
|
||||
|
||||
2) Check the Makefile
|
||||
|
||||
3) make
|
||||
|
||||
4) make install
|
||||
@@ -17,15 +17,14 @@ Copyright 1998 Dave Cinege <dcinege@psychosis.com>
|
||||
mini-gzip(gzip), mini-netcat(mnc)
|
||||
Copyright 1998 Charles P. Wright <cpwright@villagenet.com>
|
||||
|
||||
Tons of new stuff as noted in header files
|
||||
Copyright (C) 1999 by Lineo, inc. and written by
|
||||
Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
|
||||
Tons of new stuff as noted in header files
|
||||
Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
|
||||
Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
|
||||
|
||||
|
||||
Please feed suggestions, bug reports, insults, and bribes back to:
|
||||
Erik Andersen
|
||||
<andersen@lineo.com>
|
||||
<andersen@codepoet.org>
|
||||
<andersee@debian.org>
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2002 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
|
||||
@@ -15,115 +17,471 @@
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
PROG := busybox
|
||||
VERSION := 0.60.5
|
||||
BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z")
|
||||
export VERSION
|
||||
|
||||
PROG=busybox
|
||||
VERSION=0.41
|
||||
BUILDTIME=$(shell date "+%Y%m%d-%H%M")
|
||||
# With a modern GNU make(1) (highly recommended, that's what all the
|
||||
# developers use), all of the following configuration values can be
|
||||
# overridden at the command line. For example:
|
||||
# make CROSS=powerpc-linux- BB_SRC_DIR=$HOME/busybox PREFIX=/mnt/app
|
||||
|
||||
# Comment out the following to make a debuggable build
|
||||
# Leave this off for production use.
|
||||
DODEBUG=false
|
||||
# If you want a static binary, turn this on. I can't think
|
||||
# of many situations where anybody would ever want it static,
|
||||
# but...
|
||||
DOSTATIC=false
|
||||
# If you want to add some simple compiler switches (like -march=i686),
|
||||
# especially from the command line, use this instead of CFLAGS directly.
|
||||
# For optimization overrides, it's better still to set OPTIMIZATION.
|
||||
CFLAGS_EXTRA =
|
||||
|
||||
# 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/'`
|
||||
# Set the following to `true' to make a debuggable build.
|
||||
# Leave this set to `false' for production use.
|
||||
DODEBUG = false
|
||||
|
||||
GCCMAJVERSION=$(shell $(CC) --version | sed -n "s/^\([^\.]*\).*/\1/p" )
|
||||
GCCMINVERSION=$(shell $(CC) --version | sed -n "s/^[^\.]*\.\([^\.]*\)[\.].*/\1/p" )
|
||||
GCCEGCS=$(shell $(CC) --version | sed -n "s/.*\(egcs\).*/\1/p" )
|
||||
# If you enable this option, busybox will use the system's password
|
||||
# and group functions. And if you are using the GNU C library
|
||||
# (glibc), you will then need to install the /etc/nsswitch.conf
|
||||
# configuration file and the required /lib/libnss_* libraries in
|
||||
# order for the password and group functions to work. This generally
|
||||
# makes your embedded system quite a bit larger.
|
||||
# Disabling this option will cause busybox to directly access the
|
||||
# system's /etc/password, /etc/group files (and your system will be
|
||||
# smaller, and I will get fewer emails asking about how glibc NSS
|
||||
# works). When this option is disabled, you will not be able to use
|
||||
# PAM to access remote LDAP password servers and whatnot. And if you
|
||||
# want hostname resolution to work with glibc, you still need the
|
||||
# /lib/libnss_* libraries.
|
||||
# If you disable this option, it will add about 1.5k to busybox.
|
||||
USE_SYSTEM_PWD_GRP = true
|
||||
|
||||
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; )
|
||||
# This enables compiling with dmalloc ( http://dmalloc.com/ )
|
||||
# which is an excellent public domain mem leak and malloc problem
|
||||
# detector. To enable dmalloc, before running busybox you will
|
||||
# want to first set up your environment.
|
||||
# eg: `export DMALLOC_OPTIONS=debug=0x34f47d83,inter=100,log=logfile`
|
||||
# The debug= value is generated using the following command
|
||||
# dmalloc -p log-stats -p log-non-free -p log-bad-space -p log-elapsed-time \
|
||||
# -p check-fence -p check-heap -p check-lists -p check-blank \
|
||||
# -p check-funcs -p realloc-copy -p allow-free-null
|
||||
# Do not enable this for production builds...
|
||||
DODMALLOC = false
|
||||
|
||||
GCCISEGCS=$(shell \
|
||||
if ( test "x$(GCCEGCS)" == "xegcs" ) ; then \
|
||||
echo "true"; \
|
||||
else \
|
||||
echo "false"; \
|
||||
fi; )
|
||||
# Electric-fence is another very useful malloc debugging library.
|
||||
# Do not enable this for production builds...
|
||||
DOEFENCE = false
|
||||
|
||||
EGCSEXTREMEFLAGS = -m386 -mcpu=i386 -march=i386 -malign-jumps=1 -malign-loops=1 -malign-functions=1
|
||||
GCCEXTREMEFLAGS = -m386 -malign-jumps=1 -malign-loops=1 -malign-functions=1
|
||||
# If you want large file summit support, turn this on.
|
||||
# This has no effect if you don't have a kernel with lfs
|
||||
# support, and a system with libc-2.1.3 or later.
|
||||
# Some of the programs that can benefit from lfs support
|
||||
# are dd, gzip, mount, tar, and mkfs_minix.
|
||||
# LFS allows you to use the above programs for files
|
||||
# larger than 2GB!
|
||||
DOLFS = false
|
||||
|
||||
ifeq ($(GCCISEGCS), true)
|
||||
EXTREMEFLAGS = $(EGCSEXTREMEFLAGS)
|
||||
else
|
||||
EXTREMEFLAGS = $(GCCEXTREMEFLAGS)
|
||||
# If you have a "pristine" source directory, point BB_SRC_DIR to it.
|
||||
# Experimental and incomplete; tell the mailing list
|
||||
# <busybox@busybox.net> if you do or don't like it so far.
|
||||
BB_SRC_DIR =
|
||||
|
||||
# If you are running a cross compiler, you may want to set this
|
||||
# to something more interesting, like "powerpc-linux-".
|
||||
CROSS =
|
||||
CC = $(CROSS)gcc
|
||||
AR = $(CROSS)ar
|
||||
STRIP = $(CROSS)strip
|
||||
|
||||
# To compile vs uClibc, just use the compiler wrapper built by uClibc...
|
||||
# Everything should compile and work as expected these days...
|
||||
#CC=/usr/i386-linux-uclibc/bin/i386-uclibc-gcc
|
||||
|
||||
# To compile vs some other alternative libc, you may need to use/adjust
|
||||
# the following lines to meet your needs...
|
||||
#
|
||||
# If you are using Red Hat 6.x with the compatible RPMs (for developing under
|
||||
# Red Hat 5.x and glibc 2.0) uncomment the following. Be sure to read about
|
||||
# using the compatible RPMs (compat-*) at http://www.redhat.com !
|
||||
#LIBCDIR=/usr/i386-glibc20-linux
|
||||
#
|
||||
# The following is used for libc5 (if you install altgcc and libc5-altdev
|
||||
# on a Debian system).
|
||||
#LIBCDIR=/usr/i486-linuxlibc1
|
||||
#
|
||||
# For other libraries, you are on your own...
|
||||
#LDFLAGS+=-nostdlib
|
||||
#LIBRARIES = $(LIBCDIR)/lib/libc.a -lgcc
|
||||
#CROSS_CFLAGS+=-nostdinc -I$(LIBCDIR)/include -I$(GCCINCDIR)
|
||||
#GCCINCDIR = $(shell gcc -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp")
|
||||
|
||||
WARNINGS = -Wall -Wshadow
|
||||
|
||||
ARFLAGS = -r
|
||||
|
||||
|
||||
TARGET_ARCH:=${shell $(CC) -dumpmachine | sed -e s'/-.*//' \
|
||||
-e 's/i.86/i386/' \
|
||||
-e 's/sparc.*/sparc/' \
|
||||
-e 's/arm.*/arm/g' \
|
||||
-e 's/m68k.*/m68k/' \
|
||||
-e 's/ppc/powerpc/g' \
|
||||
-e 's/v850.*/v850/g' \
|
||||
-e 's/sh[234]/sh/' \
|
||||
-e 's/mips.*/mips/' \
|
||||
}
|
||||
|
||||
#--------------------------------------------------------
|
||||
# Arch specific compiler optimization stuff should go here.
|
||||
# Unless you want to override the defaults, do not set anything
|
||||
# for OPTIMIZATION...
|
||||
|
||||
# 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}
|
||||
|
||||
# Some nice architecture specific optimizations
|
||||
ifeq ($(strip $(TARGET_ARCH)),arm)
|
||||
OPTIMIZATION+=-fstrict-aliasing
|
||||
endif
|
||||
|
||||
ifeq ($(GCCSUPPORTSOPTSIZE), true)
|
||||
OPTIMIZATION=-Os $(EXTREMEFLAGS)
|
||||
else
|
||||
OPTIMIZATION=-O2 $(EXTREMEFLAGS)
|
||||
ifeq ($(strip $(TARGET_ARCH)),i386)
|
||||
OPTIMIZATION+=-march=i386
|
||||
OPTIMIZATION+=${shell if $(CC) -mpreferred-stack-boundary=2 -S -o /dev/null -xc \
|
||||
/dev/null >/dev/null 2>&1; then echo "-mpreferred-stack-boundary=2"; fi}
|
||||
OPTIMIZATION+=${shell if $(CC) -falign-functions=1 -falign-jumps=0 -falign-loops=0 \
|
||||
-S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo \
|
||||
"-falign-functions=1 -falign-jumps=0 -falign-loops=0"; else \
|
||||
if $(CC) -malign-functions=0 -malign-jumps=0 -S -o /dev/null -xc \
|
||||
/dev/null >/dev/null 2>&1; then echo "-malign-functions=0 -malign-jumps=0"; fi; fi}
|
||||
endif
|
||||
OPTIMIZATIONS:=$(OPTIMIZATION) -fomit-frame-pointer
|
||||
|
||||
# -D_GNU_SOURCE is needed because environ is used in init.c
|
||||
ifeq ($(DODEBUG),true)
|
||||
CFLAGS+=-Wall -g -D_GNU_SOURCE -DDEBUG_INIT
|
||||
STRIP=
|
||||
LDFLAGS=
|
||||
|
||||
#--------------------------------------------------------
|
||||
# If you're going to do a lot of builds with a non-vanilla configuration,
|
||||
# it makes sense to adjust parameters above, so you can type "make"
|
||||
# by itself, instead of following it by the same half-dozen overrides
|
||||
# every time. The stuff below, on the other hand, is probably less
|
||||
# prone to casual user adjustment.
|
||||
#
|
||||
ifeq ($(strip $(DOLFS)),true)
|
||||
# For large file support
|
||||
CFLAGS+=-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
|
||||
endif
|
||||
ifeq ($(strip $(DODMALLOC)),true)
|
||||
# For testing mem leaks with dmalloc
|
||||
CFLAGS+=-DDMALLOC
|
||||
LIBRARIES = -ldmalloc
|
||||
# Force debug=true, since this is useless when not debugging...
|
||||
DODEBUG = true
|
||||
else
|
||||
CFLAGS+=-Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
|
||||
LDFLAGS= -s
|
||||
STRIP= strip --remove-section=.note --remove-section=.comment $(PROG)
|
||||
#Only staticly link when _not_ debugging
|
||||
ifeq ($(DOSTATIC),true)
|
||||
LDFLAGS+= --static
|
||||
ifeq ($(strip $(DOEFENCE)),true)
|
||||
LIBRARIES = -lefence
|
||||
# Force debug=true, since this is useless when not debugging...
|
||||
DODEBUG = true
|
||||
endif
|
||||
|
||||
endif
|
||||
ifeq ($(strip $(DODEBUG)),true)
|
||||
CFLAGS += $(WARNINGS) -g -D_GNU_SOURCE
|
||||
LDFLAGS += -Wl,-warn-common
|
||||
STRIPCMD = /bin/true -Since_we_are_debugging
|
||||
else
|
||||
CFLAGS += $(WARNINGS) $(OPTIMIZATIONS) -D_GNU_SOURCE
|
||||
LDFLAGS += -s -Wl,-warn-common
|
||||
STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
|
||||
endif
|
||||
ifeq ($(strip $(DOSTATIC)),true)
|
||||
LDFLAGS += --static
|
||||
#
|
||||
#use '-ffunction-sections -fdata-sections' and '--gc-sections' (if they
|
||||
# work) to try and strip out any unused junk. Doesn't do much for me,
|
||||
# but you may want to give it a shot...
|
||||
#
|
||||
#ifeq ($(shell $(CC) -ffunction-sections -fdata-sections -S \
|
||||
# -o /dev/null -xc /dev/null 2>/dev/null && $(LD) \
|
||||
# --gc-sections -v >/dev/null && echo 1),1)
|
||||
# CFLAGS += -ffunction-sections -fdata-sections
|
||||
# LDFLAGS += --gc-sections
|
||||
#endif
|
||||
endif
|
||||
|
||||
ifndef $(PREFIX)
|
||||
PREFIX=`pwd`/_install
|
||||
ifeq ($(strip $(PREFIX)),)
|
||||
PREFIX = `pwd`/_install
|
||||
endif
|
||||
|
||||
LIBRARIES=
|
||||
OBJECTS=$(shell ./busybox.sh)
|
||||
CFLAGS+= -DBB_VER='"$(VERSION)"'
|
||||
CFLAGS+= -DBB_BT='"$(BUILDTIME)"'
|
||||
# Additional complications due to support for pristine source dir.
|
||||
# Include files in the build directory should take precedence over
|
||||
# the copy in BB_SRC_DIR, both during the compilation phase and the
|
||||
# shell script that finds the list of object files.
|
||||
# Work in progress by <ldoolitt@recycle.lbl.gov>.
|
||||
#
|
||||
ifneq ($(strip $(BB_SRC_DIR)),)
|
||||
VPATH = $(BB_SRC_DIR)
|
||||
endif
|
||||
#ifneq ($(strip $(VPATH)),)
|
||||
# CFLAGS += -I- -I. $(patsubst %,-I%,$(subst :, ,$(VPATH)))
|
||||
#endif
|
||||
|
||||
# We need to set APPLET_SOURCES to something like
|
||||
# $(shell busybox.sh Config.h)
|
||||
# but in a manner that works with VPATH and BB_SRC_DIR.
|
||||
# Possible ways to approach this:
|
||||
#
|
||||
# 1. Explicitly search through .:$(VPATH) for busybox.sh and config.h,
|
||||
# then $(shell $(BUSYBOX_SH) $(CONFIG_H) $(BB_SRC_DIR))
|
||||
#
|
||||
# 2. Explicity search through .:$(VPATH) for slist.mk,
|
||||
# then $(shell $(MAKE) -f $(SLIST_MK) VPATH=$(VPATH) BB_SRC_DIR=$(BB_SRC_DIR))
|
||||
#
|
||||
# 3. Create slist.mk in this directory, with commands embedded in
|
||||
# a $(shell ...) command, and $(MAKE) it immediately.
|
||||
#
|
||||
# 4. Use a real rule within this makefile to create a file that sets
|
||||
# APPLET_SOURCE_LIST, then include that file. Has complications
|
||||
# with the first trip through the makefile (before processing the
|
||||
# include) trying to do too much, and a spurious warning the first
|
||||
# time make is run.
|
||||
#
|
||||
# This is option 3:
|
||||
#
|
||||
#APPLET_SOURCES = $(shell \
|
||||
# echo -e 'all: busybox.sh Config.h\n\t@ $$(SHELL) $$^ $$(BB_SRC_DIR)' >slist.mk; \
|
||||
# make -f slist.mk VPATH=$(VPATH) BB_SRC_DIR=$(BB_SRC_DIR) \
|
||||
#)
|
||||
# And option 4:
|
||||
-include applet_source_list
|
||||
|
||||
OBJECTS = $(APPLET_SOURCES:.c=.o) busybox.o usage.o applets.o
|
||||
CFLAGS += $(CROSS_CFLAGS)
|
||||
CFLAGS += -DBB_VER='"$(VERSION)"'
|
||||
CFLAGS += -DBB_BT='"$(BUILDTIME)"'
|
||||
ifdef BB_INIT_SCRIPT
|
||||
CFLAGS += -DINIT_SCRIPT=${BB_INIT_SCRIPT}
|
||||
CFLAGS += -DINIT_SCRIPT='"$(BB_INIT_SCRIPT)"'
|
||||
endif
|
||||
|
||||
all: busybox busybox.links
|
||||
ifneq ($(strip $(USE_SYSTEM_PWD_GRP)),true)
|
||||
PWD_GRP = pwd_grp
|
||||
PWD_GRP_DIR = $(BB_SRC_DIR:=/)$(PWD_GRP)
|
||||
PWD_LIB = libpwd.a
|
||||
PWD_CSRC=__getpwent.c pwent.c getpwnam.c getpwuid.c putpwent.c getpw.c \
|
||||
fgetpwent.c __getgrent.c grent.c getgrnam.c getgrgid.c fgetgrent.c \
|
||||
initgroups.c setgroups.c
|
||||
PWD_OBJS=$(patsubst %.c,$(PWD_GRP)/%.o, $(PWD_CSRC))
|
||||
ifneq ($(strip $(BB_SRC_DIR)),)
|
||||
PWD_CFLAGS = -I- -I.
|
||||
endif
|
||||
PWD_CFLAGS += -I$(PWD_GRP_DIR)
|
||||
else
|
||||
CFLAGS += -DUSE_SYSTEM_PWD_GRP
|
||||
endif
|
||||
|
||||
LIBBB = libbb
|
||||
LIBBB_LIB = libbb.a
|
||||
LIBBB_CSRC= ask_confirmation.c chomp.c concat_path_file.c copy_file.c \
|
||||
copy_file_chunk.c libc5.c device_open.c error_msg.c inode_hash.c \
|
||||
error_msg_and_die.c fgets_str.c find_mount_point.c find_pid_by_name.c \
|
||||
find_root_device.c full_read.c full_write.c get_console.c \
|
||||
get_last_path_component.c get_line_from_file.c gz_open.c human_readable.c \
|
||||
isdirectory.c kernel_version.c loop.c mode_string.c module_syscalls.c mtab.c \
|
||||
mtab_file.c my_getgrnam.c my_getgrgid.c my_getpwnam.c my_getpwnamegid.c \
|
||||
my_getpwuid.c parse_mode.c parse_number.c perror_msg.c perror_msg_and_die.c \
|
||||
print_file.c process_escape_sequence.c read_package_field.c recursive_action.c \
|
||||
safe_read.c safe_write.c safe_strncpy.c syscalls.c syslog_msg_with_name.c time_string.c \
|
||||
trim.c unzip.c vdprintf.c verror_msg.c vperror_msg.c wfopen.c xfuncs.c \
|
||||
xgetcwd.c xreadlink.c xregcomp.c interface.c remove_file.c last_char_is.c \
|
||||
copyfd.c vherror_msg.c herror_msg.c herror_msg_and_die.c xgethostbyname.c \
|
||||
dirname.c make_directory.c create_icmp_socket.c u_signal_names.c arith.c \
|
||||
simplify_path.c
|
||||
LIBBB_OBJS=$(patsubst %.c,$(LIBBB)/%.o, $(LIBBB_CSRC))
|
||||
ifeq ($(strip $(BB_SRC_DIR)),)
|
||||
LIBBB_CFLAGS += -I$(LIBBB)
|
||||
else
|
||||
LIBBB_CFLAGS = -I- -I. -I./$(LIBBB) -I$(BB_SRC_DIR)/$(LIBBB) -I$(BB_SRC_DIR)
|
||||
endif
|
||||
|
||||
busybox: $(OBJECTS)
|
||||
$(CC) $(LDFLAGS) -o $(PROG) $(OBJECTS) $(LIBRARIES)
|
||||
$(STRIP)
|
||||
LIBBB_MSRC=libbb/messages.c
|
||||
LIBBB_MESSAGES= full_version name_too_long omitting_directory not_a_directory \
|
||||
memory_exhausted invalid_date invalid_option io_error dash_dash_help \
|
||||
write_error too_few_args name_longer_than_foo unknown can_not_create_raw_socket
|
||||
LIBBB_MOBJ=$(patsubst %,$(LIBBB)/%.o, $(LIBBB_MESSAGES))
|
||||
|
||||
busybox.links:
|
||||
- ./busybox.mkll | sort >$@
|
||||
LIBBB_ARCSRC=libbb/unarchive.c
|
||||
LIBBB_ARCOBJ= archive_offset seek_sub_file extract_archive unarchive \
|
||||
get_header_ar get_header_cpio get_header_tar deb_extract
|
||||
LIBBB_AROBJS=$(patsubst %,$(LIBBB)/%.o, $(LIBBB_ARCOBJ))
|
||||
|
||||
|
||||
# Put user-supplied flags at the end, where they
|
||||
# have a chance of winning.
|
||||
CFLAGS += $(CFLAGS_EXTRA)
|
||||
|
||||
.EXPORT_ALL_VARIABLES:
|
||||
|
||||
all: applet_source_list busybox busybox.links doc
|
||||
|
||||
applet_source_list: busybox.sh Config.h
|
||||
(echo -n "APPLET_SOURCES := "; CC="$(CC)" BB_SRC_DIR="$(BB_SRC_DIR)" $(SHELL) $^) > $@
|
||||
|
||||
doc: olddoc
|
||||
|
||||
# Old Docs...
|
||||
olddoc: docs/busybox.pod docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html
|
||||
|
||||
docs/busybox.pod : docs/busybox_header.pod usage.h docs/busybox_footer.pod
|
||||
- ( cat docs/busybox_header.pod; \
|
||||
docs/autodocifier.pl usage.h; \
|
||||
cat docs/busybox_footer.pod ) > docs/busybox.pod
|
||||
|
||||
docs/BusyBox.txt: docs/busybox.pod
|
||||
@echo
|
||||
@echo BusyBox Documentation
|
||||
@echo
|
||||
-mkdir -p docs
|
||||
-pod2text $< > $@
|
||||
|
||||
docs/BusyBox.1: docs/busybox.pod
|
||||
- mkdir -p docs
|
||||
- pod2man --center=BusyBox --release="version $(VERSION)" \
|
||||
$< > $@
|
||||
|
||||
docs/BusyBox.html: docs/busybox.pod
|
||||
-@ mkdir -p docs
|
||||
- pod2html --noindex $< > docs/BusyBox.html
|
||||
-@ rm -f pod2htm*
|
||||
|
||||
|
||||
# New docs based on DOCBOOK SGML
|
||||
newdoc: docs/busybox.txt docs/busybox.pdf docs/busybox/busyboxdocumentation.html
|
||||
|
||||
docs/busybox.txt: docs/busybox.sgml
|
||||
@echo
|
||||
@echo BusyBox Documentation
|
||||
@echo
|
||||
- mkdir -p docs
|
||||
(cd docs; sgmltools -b txt busybox.sgml)
|
||||
|
||||
docs/busybox.dvi: docs/busybox.sgml
|
||||
- mkdir -p docs
|
||||
(cd docs; sgmltools -b dvi busybox.sgml)
|
||||
|
||||
docs/busybox.ps: docs/busybox.sgml
|
||||
- mkdir -p docs
|
||||
(cd docs; sgmltools -b ps busybox.sgml)
|
||||
|
||||
docs/busybox.pdf: docs/busybox.ps
|
||||
- mkdir -p docs
|
||||
(cd docs; ps2pdf busybox.ps)
|
||||
|
||||
docs/busybox/busyboxdocumentation.html: docs/busybox.sgml
|
||||
- mkdir -p docs
|
||||
(cd docs; sgmltools -b html ../busybox.sgml)
|
||||
|
||||
|
||||
busybox: $(PWD_LIB) $(LIBBB_LIB) $(OBJECTS)
|
||||
$(CC) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBBB_LIB) $(PWD_LIB) $(LIBRARIES)
|
||||
$(STRIPCMD) $(PROG)
|
||||
|
||||
# Without VPATH, rule expands to "/bin/sh busybox.mkll Config.h applets.h"
|
||||
# but with VPATH, some or all of those file names are resolved to the
|
||||
# directories in which they live.
|
||||
busybox.links: busybox.mkll Config.h applets.h
|
||||
- $(SHELL) $^ >$@
|
||||
|
||||
nfsmount.o cmdedit.o: %.o: %.h
|
||||
ash.o hush.o lash.o msh.o: cmdedit.h
|
||||
$(OBJECTS): %.o: %.c Config.h busybox.h applets.h Makefile
|
||||
ifeq ($(strip $(BB_SRC_DIR)),)
|
||||
$(CC) $(CFLAGS) -I. $(patsubst %,-I%,$(subst :, ,$(BB_SRC_DIR))) -c $< -o $*.o
|
||||
else
|
||||
$(CC) $(CFLAGS) -I- -I. $(patsubst %,-I%,$(subst :, ,$(BB_SRC_DIR))) -c $< -o $*.o
|
||||
endif
|
||||
|
||||
$(PWD_OBJS): %.o: %.c Config.h busybox.h applets.h Makefile
|
||||
ifneq ($(strip $(BB_SRC_DIR)),)
|
||||
-mkdir -p $(PWD_GRP)
|
||||
endif
|
||||
$(CC) $(CFLAGS) $(PWD_CFLAGS) -c $< -o $*.o
|
||||
|
||||
$(LIBBB_OBJS): %.o: %.c Config.h busybox.h applets.h Makefile libbb/libbb.h
|
||||
ifneq ($(strip $(BB_SRC_DIR)),)
|
||||
-mkdir -p $(LIBBB)
|
||||
endif
|
||||
$(CC) $(CFLAGS) $(LIBBB_CFLAGS) -c $< -o $*.o
|
||||
|
||||
$(LIBBB_MOBJ): $(LIBBB_MSRC)
|
||||
ifneq ($(strip $(BB_SRC_DIR)),)
|
||||
-mkdir -p $(LIBBB)
|
||||
endif
|
||||
$(CC) $(CFLAGS) $(LIBBB_CFLAGS) -DL_$(patsubst libbb/%,%,$*) -c $< -o $*.o
|
||||
|
||||
$(LIBBB_AROBJS): $(LIBBB_ARCSRC)
|
||||
ifneq ($(strip $(BB_SRC_DIR)),)
|
||||
-mkdir -p $(LIBBB)
|
||||
endif
|
||||
$(CC) $(CFLAGS) $(LIBBB_CFLAGS) -DL_$(patsubst libbb/%,%,$*) -c $< -o $*.o
|
||||
|
||||
libpwd.a: $(PWD_OBJS)
|
||||
$(AR) $(ARFLAGS) $@ $^
|
||||
|
||||
libbb.a: $(LIBBB_MOBJ) $(LIBBB_AROBJS) $(LIBBB_OBJS)
|
||||
$(AR) $(ARFLAGS) $@ $^
|
||||
|
||||
usage.o: usage.h
|
||||
|
||||
libbb/loop.o: libbb/loop.h
|
||||
|
||||
libbb/loop.h: mk_loop_h.sh
|
||||
@ $(SHELL) $< > $@
|
||||
|
||||
test tests:
|
||||
# old way of doing it
|
||||
#cd tests && $(MAKE) all
|
||||
# new way of doing it
|
||||
cd tests && ./tester.sh
|
||||
|
||||
clean:
|
||||
- rm -f $(PROG) busybox.links *~ *.o core
|
||||
- rm -rf _install
|
||||
- cd tests && $(MAKE) clean
|
||||
- rm -f docs/BusyBox.txt docs/BusyBox.1 docs/BusyBox.html docs/BusyBox.html
|
||||
- rm -f docs/busybox.txt docs/busybox.dvi docs/busybox.ps \
|
||||
docs/busybox.pdf docs/busybox.html docs/busybox.pod
|
||||
- rm -f multibuild.log Config.h.orig *.gdb *.elf
|
||||
- rm -rf docs/busybox _install libpwd.a libbb.a pod2htm*
|
||||
- rm -f busybox busybox.links libbb/loop.h *~ slist.mk core applet_source_list
|
||||
- find . -name \*.o -exec rm -f {} \;
|
||||
|
||||
distclean: clean
|
||||
- rm -f $(PROG)
|
||||
- cd tests && $(MAKE) distclean
|
||||
- rm -f busybox applet_source_list
|
||||
|
||||
$(OBJECTS): busybox.def.h internal.h Makefile
|
||||
install: install.sh busybox busybox.links
|
||||
$(SHELL) $< $(PREFIX)
|
||||
|
||||
install: busybox busybox.links
|
||||
./install.sh $(PREFIX)
|
||||
uninstall: busybox busybox.links
|
||||
for i in `cat busybox.links` ; do rm -f $$PREFIX$$i; done
|
||||
|
||||
dist: release
|
||||
install-hardlinks: install.sh busybox busybox.links
|
||||
$(SHELL) $< $(PREFIX) --hardlinks
|
||||
|
||||
release: distclean
|
||||
(cd .. ; rm -rf busybox-$(VERSION) ; cp -a busybox busybox-$(VERSION); rm -rf busybox-$(VERSION)/CVS busybox-$(VERSION)/scripts/CVS busybox-$(VERSION)/docs/CVS busybox-$(VERSION)/.cvsignore ; tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION))
|
||||
debug_pristine:
|
||||
@ echo VPATH=\"$(VPATH)\"
|
||||
@ echo OBJECTS=\"$(OBJECTS)\"
|
||||
|
||||
dist release: distclean doc
|
||||
cd ..; \
|
||||
rm -rf busybox-$(VERSION); \
|
||||
cp -a busybox busybox-$(VERSION); \
|
||||
\
|
||||
find busybox-$(VERSION)/ -type d \
|
||||
-name CVS \
|
||||
-print \
|
||||
-exec rm -rf {} \; ; \
|
||||
\
|
||||
find busybox-$(VERSION)/ -type f \
|
||||
-name .\#* \
|
||||
-print \
|
||||
-exec rm -f {} \; ; \
|
||||
\
|
||||
tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION)/;
|
||||
|
||||
.PHONY: tags
|
||||
tags:
|
||||
ctags -R .
|
||||
@@ -1,30 +1,148 @@
|
||||
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
|
||||
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.
|
||||
|
||||
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 /dev, /etc, and a kernel.
|
||||
|
||||
As of version 0.20 there is a version number. : ) Also as of version
|
||||
0.20, BB is now modularized to easily allow you to build of only the
|
||||
BB parts you need, thereby reducing binary size. To turn off unwanted
|
||||
Busybox components, simply edit the file busybox.def.h and comment out
|
||||
the parts you do not need using C++ style (//) comments.
|
||||
BusyBox was originally written to support the Debian Rescue/Install disks, but
|
||||
it also makes an excellent environment for any small or embedded system.
|
||||
|
||||
After the build is complete a busybox.links file is generated which is
|
||||
then used by 'make install' to create symlinks to the busybox binary
|
||||
for all compiled in functions. By default, 'make install' will place
|
||||
the symlink forest into `pwd`/_install unless you have defined the
|
||||
PREFIX environment variable.
|
||||
As of version 0.20 there is now a version number. : ) Also as of version 0.20,
|
||||
BusyBox is now modularized to easily allow you to build only the components you
|
||||
need, thereby reducing binary size. To turn off unwanted BusyBox components,
|
||||
simply edit the file "Config.h" and comment out the components you do not need
|
||||
using C++ style (//) comments.
|
||||
|
||||
After the build is complete, a busybox.links file is generated. This is
|
||||
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')
|
||||
|
||||
----------------
|
||||
|
||||
Supported architectures:
|
||||
|
||||
Busybox in general will build on any architecture supported by gcc. It has
|
||||
a few specialized features added for __sparc__ and __alpha__. insmod
|
||||
functionality is currently limited to x86, ARM, SH3/4, powerpc, m68k,
|
||||
and MIPS.
|
||||
|
||||
Supported libcs:
|
||||
|
||||
glibc-2.0.x, glibc-2.1.x, glibc-2.2.x, Linux-libc5, uClibc. People
|
||||
are looking at newlib and diet-libc, but consider them unsupported,
|
||||
untested, or worse.
|
||||
|
||||
Supported kernels:
|
||||
|
||||
Full functionality requires Linux 2.0.x, 2.2.x, or 2.4.x. A large fraction
|
||||
of the code should run on just about anything.
|
||||
|
||||
----------------
|
||||
|
||||
Shells:
|
||||
|
||||
lash is the very smallest shell (adds just 10k) and it is quite usable as
|
||||
a command prompt, but it is not suitable for any but the most trivial
|
||||
scripting (such as an initrd that calls insmod a few times) since it does
|
||||
not understand Bourne shell grammer. It does handle pipes, redirects, and
|
||||
job control though. Adding in command editing makes it a very nice
|
||||
lightweight command prompt.
|
||||
|
||||
hush is also quite small (just 18k) and it has very complete Bourne shell
|
||||
grammer. It handles if/then/else/fi just fine, but doesn't handle loops
|
||||
like for/do/done or case/esac and such. It also currently has a problem
|
||||
with job control. Using hush is not yet recommended.
|
||||
|
||||
msh: The minix shell (adds just 30k) is quite complete and handles things
|
||||
like for/do/done, case/esac and all the things you expect a Bourne shell to
|
||||
do. It is not always pedantically correct about Bourne shell grammer (try
|
||||
running the shell testscript "tests/sh.testcases" on it and compare vs bash)
|
||||
but for most things it works quite well. It also uses only vfork, so it can
|
||||
be used on uClinux systems. This was only recently added, so there is still
|
||||
room to shrink it further...
|
||||
|
||||
ash: This adds about 60k in the default configuration and is the most
|
||||
complete and most pedantically correct shell included with busybox. This
|
||||
shell was also recently added, and several people (mainly Vladimir and Erik)
|
||||
have been working on it. There are a number of configurable things at the
|
||||
top of ash.c as well, so check those out if you want to tweak things.
|
||||
|
||||
----------------
|
||||
|
||||
Getting help:
|
||||
|
||||
When you find you need help, you can check out the BusyBox mailing list
|
||||
archives at http://busybox.net/lists/busybox/ or even join
|
||||
the mailing list if you are interested.
|
||||
|
||||
----------------
|
||||
|
||||
Bugs:
|
||||
|
||||
If you find bugs, please submit a bug report. Full instructions on how to
|
||||
report a bug are found at http://bugs.busybox.net/Reporting.html.
|
||||
|
||||
For the impatient: To submit a bug, simply send an email describing the problem
|
||||
to submit@bugs.busybox.net. Bug reports should look something like this:
|
||||
|
||||
To: submit@bugs.busybox.net
|
||||
From: diligent@testing.linux.org
|
||||
Subject: /bin/true doesn't work
|
||||
|
||||
Package: busybox
|
||||
Version: 0.51
|
||||
|
||||
When I invoke '/bin/true' it doesn't work. I expected it to return
|
||||
a "0" but it returned a "1" instead. Here is the transcript:
|
||||
$ /bin/true ; echo $?
|
||||
1
|
||||
With GNU /bin/true, I get the following output:
|
||||
$ /bin/true ; echo $?
|
||||
0
|
||||
I am using Debian 2.2r2, kernel version 2.2.18, and the latest
|
||||
uClibc from CVS. Thanks for the wonderful program!
|
||||
-Diligent
|
||||
|
||||
Note the careful description and use of examples showing not only what BusyBox
|
||||
does, but also a counter example showing what an equivalent GNU app does. Bug
|
||||
reports lacking such detail may take a _long_ time to be fixed... Thanks for
|
||||
understanding.
|
||||
|
||||
----------------
|
||||
|
||||
FTP:
|
||||
|
||||
Source for the latest released version can always be downloaded from
|
||||
http://busybox.net/downloads/
|
||||
|
||||
----------------
|
||||
|
||||
CVS:
|
||||
|
||||
BusyBox now has its own publicly browsable CVS tree at:
|
||||
http://busybox.net/cgi-bin/cvsweb/busybox/
|
||||
|
||||
Anonymous CVS access is available. For instructions, check out:
|
||||
http://busybox.net/cvs_anon.html
|
||||
|
||||
For those that are actively contributing there is even CVS write access:
|
||||
http://busybox.net/cvs_write.html
|
||||
|
||||
----------------
|
||||
|
||||
Please feed suggestions, bug reports, insults, and bribes back to:
|
||||
Erik Andersen
|
||||
<andersen@lineo.com>
|
||||
<andersen@codepoet.org>
|
||||
<andersee@debian.org>
|
||||
|
||||
<blatent plug>
|
||||
Many thanks to go to Lineo for paying me to work on busybox.
|
||||
</blatent plug>
|
||||
|
||||
@@ -4,25 +4,49 @@ 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.
|
||||
* We _were_ going to split networking apps into a new package called
|
||||
netkit-tiny. Per discussions on the mailing list, this isn't going
|
||||
to happen. False alarm. Sorry about the confusion.
|
||||
|
||||
|
||||
-Erik
|
||||
|
||||
-----------
|
||||
|
||||
* Allow tar to create archives with sockets, devices, and other special files
|
||||
* Make insmod actually work
|
||||
* dnsdomainname
|
||||
* traceroute/nslookup/netstat
|
||||
* rdate
|
||||
* hwclock
|
||||
* killall
|
||||
* stty
|
||||
* tr
|
||||
* expr (maybe?) (ash builtin?)
|
||||
Possible apps to include some time:
|
||||
|
||||
* hwclock
|
||||
* group/commonize strings, remove dups (for i18n, l10n)
|
||||
|
||||
-----------
|
||||
|
||||
With sysvinit, reboot, poweroff and halt all used a named pipe,
|
||||
/dev/initctl, to communicate with the init process. Busybox
|
||||
currently uses signals to communicate with init. This makes
|
||||
busybox incompatible with sysvinit. We should probably use
|
||||
a named pipe as well so we can be compatible.
|
||||
|
||||
-----------------------
|
||||
|
||||
Run 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, to
|
||||
reduce the footprint of busybox, especially when staticly linking with
|
||||
libraries such as uClibc.
|
||||
|
||||
-----------------------
|
||||
|
||||
Compile with debugging on, run 'nm --size-sort ./busybox'
|
||||
and then start with the biggest things and make them smaller...
|
||||
|
||||
-----------------------
|
||||
|
||||
xargs could use a -l option
|
||||
|
||||
------------------------------------------------------------------
|
||||
+176
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* adjtimex.c - read, and possibly modify, the Linux kernel `timex' variables.
|
||||
*
|
||||
* Originally written: October 1997
|
||||
* Last hack: March 2001
|
||||
* Copyright 1997, 2000, 2001 Larry Doolittle <LRDoolittle@lbl.gov>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License (Version 2,
|
||||
* June 1991) as published by the Free Software Foundation. At the
|
||||
* time of writing, that license was published by the FSF with the URL
|
||||
* http://www.gnu.org/copyleft/gpl.html, and is incorporated herein by
|
||||
* reference.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* This adjtimex(1) is very similar in intent to adjtimex(8) by Steven
|
||||
* Dick <ssd@nevets.oau.org> and Jim Van Zandt <jrv@vanzandt.mv.com>
|
||||
* (see http://metalab.unc.edu/pub/Linux/system/admin/time/adjtimex*).
|
||||
* That version predates this one, and is _much_ bigger and more
|
||||
* featureful. My independently written version was very similar to
|
||||
* Steven's from the start, because they both follow the kernel timex
|
||||
* structure. I further tweaked this version to be equivalent to Steven's
|
||||
* where possible, but I don't like getopt_long, so the actual usage
|
||||
* syntax is incompatible.
|
||||
*
|
||||
* Amazingly enough, my Red Hat 5.2 sys/timex (and sub-includes)
|
||||
* don't actually give a prototype for adjtimex(2), so building
|
||||
* this code (with -Wall) gives a warning. Later versions of
|
||||
* glibc fix this issue.
|
||||
*
|
||||
* This program is too simple for a Makefile, just build with:
|
||||
* gcc -Wall -O adjtimex.c -o adjtimex
|
||||
*
|
||||
* busyboxed 20 March 2001, Larry Doolittle <ldoolitt@recycle.lbl.gov>
|
||||
* It will autosense if it is built in a busybox environment, based
|
||||
* on the BB_VER preprocessor macro.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if __GNU_LIBRARY__ < 5
|
||||
#include <sys/timex.h>
|
||||
extern int adjtimex(struct timex *buf);
|
||||
#else
|
||||
#include <sys/timex.h>
|
||||
#endif
|
||||
|
||||
#ifdef BB_VER
|
||||
#include "busybox.h"
|
||||
#endif
|
||||
|
||||
static struct {int bit; char *name;} statlist[] = {
|
||||
{ STA_PLL, "PLL" },
|
||||
{ STA_PPSFREQ, "PPSFREQ" },
|
||||
{ STA_PPSTIME, "PPSTIME" },
|
||||
{ STA_FLL, "FFL" },
|
||||
{ STA_INS, "INS" },
|
||||
{ STA_DEL, "DEL" },
|
||||
{ STA_UNSYNC, "UNSYNC" },
|
||||
{ STA_FREQHOLD, "FREQHOLD" },
|
||||
{ STA_PPSSIGNAL, "PPSSIGNAL" },
|
||||
{ STA_PPSJITTER, "PPSJITTER" },
|
||||
{ STA_PPSWANDER, "PPSWANDER" },
|
||||
{ STA_PPSERROR, "PPSERROR" },
|
||||
{ STA_CLOCKERR, "CLOCKERR" },
|
||||
{ 0, NULL } };
|
||||
|
||||
static char *ret_code_descript[] = {
|
||||
"clock synchronized",
|
||||
"insert leap second",
|
||||
"delete leap second",
|
||||
"leap second in progress",
|
||||
"leap second has occurred",
|
||||
"clock not synchronized" };
|
||||
|
||||
#ifdef BB_VER
|
||||
#define main adjtimex_main
|
||||
#else
|
||||
void usage(char *prog)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Usage: %s [ -q ] [ -o offset ] [ -f frequency ] [ -p timeconstant ] [ -t tick ]\n",
|
||||
prog);
|
||||
}
|
||||
#define show_usage() usage(argv[0])
|
||||
#endif
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
struct timex txc;
|
||||
int quiet=0;
|
||||
int c, i, ret, sep;
|
||||
char *descript;
|
||||
txc.modes=0;
|
||||
for (;;) {
|
||||
c = getopt( argc, argv, "qo:f:p:t:");
|
||||
if (c == EOF) break;
|
||||
switch (c) {
|
||||
case 'q':
|
||||
quiet=1;
|
||||
break;
|
||||
case 'o':
|
||||
txc.offset = atoi(optarg);
|
||||
txc.modes |= ADJ_OFFSET_SINGLESHOT;
|
||||
break;
|
||||
case 'f':
|
||||
txc.freq = atoi(optarg);
|
||||
txc.modes |= ADJ_FREQUENCY;
|
||||
break;
|
||||
case 'p':
|
||||
txc.constant = atoi(optarg);
|
||||
txc.modes |= ADJ_TIMECONST;
|
||||
break;
|
||||
case 't':
|
||||
txc.tick = atoi(optarg);
|
||||
txc.modes |= ADJ_TICK;
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
if (argc != optind) { /* no valid non-option parameters */
|
||||
show_usage();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
ret = adjtimex(&txc);
|
||||
|
||||
if (ret < 0) perror("adjtimex");
|
||||
|
||||
if (!quiet && ret>=0) {
|
||||
printf(
|
||||
" mode: %d\n"
|
||||
"-o offset: %ld\n"
|
||||
"-f frequency: %ld\n"
|
||||
" maxerror: %ld\n"
|
||||
" esterror: %ld\n"
|
||||
" status: %d ( ",
|
||||
txc.modes, txc.offset, txc.freq, txc.maxerror,
|
||||
txc.esterror, txc.status);
|
||||
|
||||
/* representative output of next code fragment:
|
||||
"PLL | PPSTIME" */
|
||||
sep=0;
|
||||
for (i=0; statlist[i].name; i++) {
|
||||
if (txc.status & statlist[i].bit) {
|
||||
if (sep) fputs(" | ",stdout);
|
||||
fputs(statlist[i].name,stdout);
|
||||
sep=1;
|
||||
}
|
||||
}
|
||||
|
||||
descript = "error";
|
||||
if (ret >= 0 && ret <= 5) descript = ret_code_descript[ret];
|
||||
printf(" )\n"
|
||||
"-p timeconstant: %ld\n"
|
||||
" precision: %ld\n"
|
||||
" tolerance: %ld\n"
|
||||
"-t tick: %ld\n"
|
||||
" time.tv_sec: %ld\n"
|
||||
" time.tv_usec: %ld\n"
|
||||
" return value: %d (%s)\n",
|
||||
txc.constant,
|
||||
txc.precision, txc.tolerance, txc.tick,
|
||||
(long)txc.time.tv_sec, (long)txc.time.tv_usec, ret, descript);
|
||||
}
|
||||
return (ret<0);
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Utility routines.
|
||||
*
|
||||
* Copyright (C) tons of folks. Tracking down who wrote what
|
||||
* isn't something I'm going to worry about... If you wrote something
|
||||
* here, please feel free to acknowledge your work.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
|
||||
* Permission has been granted to redistribute this code under the GPL.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "busybox.h"
|
||||
|
||||
#undef APPLET
|
||||
#undef APPLET_NOUSAGE
|
||||
#undef PROTOTYPES
|
||||
#include "applets.h"
|
||||
|
||||
struct BB_applet *applet_using;
|
||||
|
||||
/* The -1 arises because of the {0,NULL,0,-1} entry above. */
|
||||
const size_t NUM_APPLETS = (sizeof (applets) / sizeof (struct BB_applet) - 1);
|
||||
|
||||
extern void show_usage(void)
|
||||
{
|
||||
const char *format_string;
|
||||
const char *usage_string = usage_messages;
|
||||
int i;
|
||||
|
||||
for (i = applet_using - applets; i > 0; ) {
|
||||
if (!*usage_string++) {
|
||||
--i;
|
||||
}
|
||||
}
|
||||
format_string = "%s\n\nUsage: %s %s\n\n";
|
||||
if(*usage_string == 0)
|
||||
format_string = "%s\n\nNo help available.\n\n";
|
||||
fprintf(stderr, format_string,
|
||||
full_version, applet_using->name, usage_string);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static int applet_name_compare(const void *x, const void *y)
|
||||
{
|
||||
const char *name = x;
|
||||
const struct BB_applet *applet = y;
|
||||
|
||||
return strcmp(name, applet->name);
|
||||
}
|
||||
|
||||
extern const size_t NUM_APPLETS;
|
||||
|
||||
struct BB_applet *find_applet_by_name(const char *name)
|
||||
{
|
||||
return bsearch(name, applets, NUM_APPLETS, sizeof(struct BB_applet),
|
||||
applet_name_compare);
|
||||
}
|
||||
|
||||
void run_applet_by_name(const char *name, int argc, char **argv)
|
||||
{
|
||||
static int recurse_level = 0;
|
||||
extern int been_there_done_that; /* From busybox.c */
|
||||
|
||||
recurse_level++;
|
||||
/* Do a binary search to find the applet entry given the name. */
|
||||
if ((applet_using = find_applet_by_name(name)) != NULL) {
|
||||
applet_name = applet_using->name;
|
||||
if (argv[1] && strcmp(argv[1], "--help") == 0) {
|
||||
if (strcmp(applet_using->name, "busybox")==0) {
|
||||
if(argv[2])
|
||||
applet_using = find_applet_by_name(argv[2]);
|
||||
else
|
||||
applet_using = NULL;
|
||||
}
|
||||
if(applet_using)
|
||||
show_usage();
|
||||
been_there_done_that=1;
|
||||
busybox_main(0, NULL);
|
||||
}
|
||||
exit((*(applet_using->main)) (argc, argv));
|
||||
}
|
||||
/* Just in case they have renamed busybox - Check argv[1] */
|
||||
if (recurse_level == 1) {
|
||||
run_applet_by_name("busybox", argc, argv);
|
||||
}
|
||||
recurse_level--;
|
||||
}
|
||||
|
||||
|
||||
/* END CODE */
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -0,0 +1,487 @@
|
||||
/*
|
||||
* applets.h - a listing of all busybox applets.
|
||||
*
|
||||
* If you write a new applet, you need to add an entry to this list to make
|
||||
* busybox aware of it.
|
||||
*
|
||||
* It is CRUCIAL that this listing be kept in ascii order, otherwise the binary
|
||||
* search lookup contributed by Gaute B Strokkenes stops working. If you value
|
||||
* your kneecaps, you'll be sure to *make sure* that any changes made to this
|
||||
* file result in the listing remaining in ascii order. You have been warned.
|
||||
*/
|
||||
|
||||
#undef APPLET
|
||||
#undef APPLET_ODDNAME
|
||||
#undef APPLET_NOUSAGE
|
||||
|
||||
|
||||
#if defined(PROTOTYPES)
|
||||
#define APPLET(a,b,c) extern int b(int argc, char **argv);
|
||||
#define APPLET_NOUSAGE(a,b,c) extern int b(int argc, char **argv);
|
||||
#define APPLET_ODDNAME(a,b,c,d) extern int b(int argc, char **argv);
|
||||
extern const char usage_messages[];
|
||||
#elif defined(MAKE_USAGE)
|
||||
#ifdef BB_FEATURE_VERBOSE_USAGE
|
||||
#define APPLET(a,b,c) a##_trivial_usage "\n\n" a##_full_usage "\0"
|
||||
#define APPLET_NOUSAGE(a,b,c) "\0"
|
||||
#define APPLET_ODDNAME(a,b,c,d) d##_trivial_usage "\n\n" d##_full_usage "\0"
|
||||
#else
|
||||
#define APPLET(a,b,c) a##_trivial_usage "\0"
|
||||
#define APPLET_NOUSAGE(a,b,c) "\0"
|
||||
#define APPLET_ODDNAME(a,b,c,d) d##_trivial_usage "\0"
|
||||
#endif
|
||||
#elif defined(MAKE_LINKS)
|
||||
# define APPLET(a,b,c) LINK c a
|
||||
# define APPLET_NOUSAGE(a,b,c) LINK c a
|
||||
# define APPLET_ODDNAME(a,b,c,d) LINK c a
|
||||
#else
|
||||
const struct BB_applet applets[] = {
|
||||
#define APPLET(a,b,c) {#a,b,c},
|
||||
#define APPLET_NOUSAGE(a,b,c) {a,b,c},
|
||||
#define APPLET_ODDNAME(a,b,c,d) {a,b,c},
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef BB_TEST
|
||||
APPLET_NOUSAGE("[", test_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_ADJTIMEX
|
||||
APPLET(adjtimex, adjtimex_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_AR
|
||||
APPLET(ar, ar_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_ASH
|
||||
APPLET_NOUSAGE("ash", ash_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_BASENAME
|
||||
APPLET(basename, basename_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
APPLET_NOUSAGE("busybox", busybox_main, _BB_DIR_BIN)
|
||||
#ifdef BB_CAT
|
||||
APPLET(cat, cat_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_CHGRP
|
||||
APPLET(chgrp, chgrp_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_CHMOD
|
||||
APPLET(chmod, chmod_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_CHOWN
|
||||
APPLET(chown, chown_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_CHROOT
|
||||
APPLET(chroot, chroot_main, _BB_DIR_USR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_CHVT
|
||||
APPLET(chvt, chvt_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_CLEAR
|
||||
APPLET(clear, clear_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_CMP
|
||||
APPLET(cmp, cmp_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_CP
|
||||
APPLET(cp, cp_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_CPIO
|
||||
APPLET(cpio, cpio_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_CUT
|
||||
APPLET(cut, cut_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_DATE
|
||||
APPLET(date, date_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_DC
|
||||
APPLET(dc, dc_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_DD
|
||||
APPLET(dd, dd_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_DEALLOCVT
|
||||
APPLET(deallocvt, deallocvt_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_DF
|
||||
APPLET(df, df_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_DIRNAME
|
||||
APPLET(dirname, dirname_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_DMESG
|
||||
APPLET(dmesg, dmesg_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_DOS2UNIX
|
||||
APPLET(dos2unix, dos2unix_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_DPKG
|
||||
APPLET(dpkg, dpkg_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_DPKG_DEB
|
||||
APPLET_ODDNAME("dpkg-deb", dpkg_deb_main, _BB_DIR_USR_BIN, dpkg_deb)
|
||||
#endif
|
||||
#ifdef BB_DU
|
||||
APPLET(du, du_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_DUMPKMAP
|
||||
APPLET(dumpkmap, dumpkmap_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_DUTMP
|
||||
APPLET(dutmp, dutmp_main, _BB_DIR_USR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_ECHO
|
||||
APPLET(echo, echo_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#if defined(BB_FEATURE_GREP_EGREP_ALIAS) && defined(BB_GREP)
|
||||
APPLET_NOUSAGE("egrep", grep_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_ENV
|
||||
APPLET(env, env_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_EXPR
|
||||
APPLET(expr, expr_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE
|
||||
APPLET(false, false_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_FBSET
|
||||
APPLET(fbset, fbset_main, _BB_DIR_USR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_FDFLUSH
|
||||
APPLET(fdflush, fdflush_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_FIND
|
||||
APPLET(find, find_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_FREE
|
||||
APPLET(free, free_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_FREERAMDISK
|
||||
APPLET(freeramdisk, freeramdisk_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_FSCK_MINIX
|
||||
APPLET_ODDNAME("fsck.minix", fsck_minix_main, _BB_DIR_SBIN, fsck_minix)
|
||||
#endif
|
||||
#ifdef BB_GETOPT
|
||||
APPLET(getopt, getopt_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_GREP
|
||||
APPLET(grep, grep_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_GUNZIP
|
||||
APPLET(gunzip, gunzip_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_GZIP
|
||||
APPLET(gzip, gzip_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_HALT
|
||||
APPLET(halt, halt_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_HEAD
|
||||
APPLET(head, head_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_HOSTID
|
||||
APPLET(hostid, hostid_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_HOSTNAME
|
||||
APPLET(hostname, hostname_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_HUSH
|
||||
APPLET_NOUSAGE("hush", hush_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_ID
|
||||
APPLET(id, id_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_IFCONFIG
|
||||
APPLET(ifconfig, ifconfig_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_INIT
|
||||
APPLET(init, init_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_INSMOD
|
||||
APPLET(insmod, insmod_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_KILL
|
||||
APPLET(kill, kill_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_KILLALL
|
||||
APPLET(killall, kill_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_KLOGD
|
||||
APPLET(klogd, klogd_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_LASH
|
||||
APPLET(lash, lash_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_LENGTH
|
||||
APPLET(length, length_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LINUXRC
|
||||
APPLET_NOUSAGE("linuxrc", init_main, _BB_DIR_ROOT)
|
||||
#endif
|
||||
#ifdef BB_LN
|
||||
APPLET(ln, ln_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_LOADACM
|
||||
APPLET(loadacm, loadacm_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_LOADFONT
|
||||
APPLET(loadfont, loadfont_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_LOADKMAP
|
||||
APPLET(loadkmap, loadkmap_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_LOGGER
|
||||
APPLET(logger, logger_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_LOGNAME
|
||||
APPLET(logname, logname_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_LOGREAD
|
||||
APPLET(logread, logread_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_LOSETUP
|
||||
APPLET(losetup, losetup_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_LS
|
||||
APPLET(ls, ls_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_LSMOD
|
||||
APPLET(lsmod, lsmod_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_MAKEDEVS
|
||||
APPLET(makedevs, makedevs_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_MD5SUM
|
||||
APPLET(md5sum, md5sum_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_MKDIR
|
||||
APPLET(mkdir, mkdir_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_MKFIFO
|
||||
APPLET(mkfifo, mkfifo_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_MKFS_MINIX
|
||||
APPLET_ODDNAME("mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN, mkfs_minix)
|
||||
#endif
|
||||
#ifdef BB_MKNOD
|
||||
APPLET(mknod, mknod_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_MKSWAP
|
||||
APPLET(mkswap, mkswap_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_MKTEMP
|
||||
APPLET(mktemp, mktemp_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_MODPROBE
|
||||
APPLET(modprobe, modprobe_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_MORE
|
||||
APPLET(more, more_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_MOUNT
|
||||
APPLET(mount, mount_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_MSH
|
||||
APPLET_NOUSAGE("msh", msh_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_MT
|
||||
APPLET(mt, mt_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_MV
|
||||
APPLET(mv, mv_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_NC
|
||||
APPLET(nc, nc_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_NSLOOKUP
|
||||
APPLET(nslookup, nslookup_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_PIDOF
|
||||
APPLET(pidof, pidof_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_PING
|
||||
APPLET(ping, ping_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_PIVOT_ROOT
|
||||
APPLET(pivot_root, pivot_root_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_POWEROFF
|
||||
APPLET(poweroff, poweroff_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_PRINTF
|
||||
APPLET(printf, printf_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_PS
|
||||
APPLET(ps, ps_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_PWD
|
||||
APPLET(pwd, pwd_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_RDATE
|
||||
APPLET(rdate, rdate_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_READLINK
|
||||
APPLET(readlink, readlink_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_REBOOT
|
||||
APPLET(reboot, reboot_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_RENICE
|
||||
APPLET(renice, renice_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_RESET
|
||||
APPLET(reset, reset_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_RM
|
||||
APPLET(rm, rm_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_RMDIR
|
||||
APPLET(rmdir, rmdir_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_RMMOD
|
||||
APPLET(rmmod, rmmod_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_ROUTE
|
||||
APPLET(route, route_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_RPM2CPIO
|
||||
APPLET(rpm2cpio, rpm2cpio_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_SED
|
||||
APPLET(sed, sed_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_SETKEYCODES
|
||||
APPLET(setkeycodes, setkeycodes_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#if defined(BB_FEATURE_SH_IS_ASH) && defined(BB_ASH)
|
||||
APPLET_NOUSAGE("sh", ash_main, _BB_DIR_BIN)
|
||||
#elif defined(BB_FEATURE_SH_IS_HUSH) && defined(BB_HUSH)
|
||||
APPLET_NOUSAGE("sh", hush_main, _BB_DIR_BIN)
|
||||
#elif defined(BB_FEATURE_SH_IS_LASH) && defined(BB_LASH)
|
||||
APPLET_NOUSAGE("sh", lash_main, _BB_DIR_BIN)
|
||||
#elif defined(BB_FEATURE_SH_IS_MSH) && defined(BB_MSH)
|
||||
APPLET_NOUSAGE("sh", msh_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_SLEEP
|
||||
APPLET(sleep, sleep_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_SORT
|
||||
APPLET(sort, sort_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_STTY
|
||||
APPLET(stty, stty_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF
|
||||
APPLET(swapoff, swap_on_off_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF
|
||||
APPLET(swapon, swap_on_off_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_SYNC
|
||||
APPLET(sync, sync_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_SYSLOGD
|
||||
APPLET(syslogd, syslogd_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_TAIL
|
||||
APPLET(tail, tail_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_TAR
|
||||
APPLET(tar, tar_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_TEE
|
||||
APPLET(tee, tee_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_TELNET
|
||||
APPLET(telnet, telnet_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_TEST
|
||||
APPLET(test, test_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_TFTP
|
||||
APPLET(tftp, tftp_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_TIME
|
||||
APPLET(time, time_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_TOP
|
||||
APPLET(top, top_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_TOUCH
|
||||
APPLET(touch, touch_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_TR
|
||||
APPLET(tr, tr_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_TRACEROUTE
|
||||
APPLET(traceroute, traceroute_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE
|
||||
APPLET(true, true_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_TTY
|
||||
APPLET(tty, tty_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_UMOUNT
|
||||
APPLET(umount, umount_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_UNAME
|
||||
APPLET(uname, uname_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_UNIQ
|
||||
APPLET(uniq, uniq_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_UNIX2DOS
|
||||
APPLET(unix2dos, dos2unix_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_UPDATE
|
||||
APPLET(update, update_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_UPTIME
|
||||
APPLET(uptime, uptime_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_USLEEP
|
||||
APPLET(usleep, usleep_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_UUDECODE
|
||||
APPLET(uudecode, uudecode_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_UUENCODE
|
||||
APPLET(uuencode, uuencode_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_VI
|
||||
APPLET(vi, vi_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
#ifdef BB_WATCHDOG
|
||||
APPLET(watchdog, watchdog_main, _BB_DIR_SBIN)
|
||||
#endif
|
||||
#ifdef BB_WC
|
||||
APPLET(wc, wc_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_WGET
|
||||
APPLET(wget, wget_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_WHICH
|
||||
APPLET(which, which_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_WHOAMI
|
||||
APPLET(whoami, whoami_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_XARGS
|
||||
APPLET(xargs, xargs_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_YES
|
||||
APPLET(yes, yes_main, _BB_DIR_USR_BIN)
|
||||
#endif
|
||||
#ifdef BB_GUNZIP
|
||||
APPLET(zcat, gunzip_main, _BB_DIR_BIN)
|
||||
#endif
|
||||
|
||||
#if !defined(PROTOTYPES) && !defined(MAKE_USAGE)
|
||||
{ 0,NULL,0 }
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,343 +0,0 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef BB_INIT
|
||||
#undef BB_FEATURE_LINUXRC
|
||||
#endif
|
||||
|
||||
static int been_there_done_that = 0;
|
||||
|
||||
/* It has been alledged that doing such things can
|
||||
* help reduce binary size when staticly linking,
|
||||
* of course with glibc, this is unlikely as long
|
||||
* as we use things like printf -- perhaps a printf
|
||||
* replacement may be in order
|
||||
*/
|
||||
#if 0
|
||||
void exit (int status) __attribute__ ((noreturn));
|
||||
void exit (int status) { _exit(status); };
|
||||
void abort (void) __attribute__ ((__noreturn__));
|
||||
void abort (void) { _exit(0); };
|
||||
int atexit (void (*__func) (void)) { _exit(0); };
|
||||
void *__libc_stack_end;
|
||||
#endif
|
||||
|
||||
|
||||
static const struct Applet applets[] = {
|
||||
|
||||
#ifdef BB_BUSYBOX //bin
|
||||
{"busybox", busybox_main},
|
||||
#endif
|
||||
#ifdef BB_BLOCK_DEVICE //sbin
|
||||
{"block_device", block_device_main},
|
||||
#endif
|
||||
#ifdef BB_CAT //bin
|
||||
{"cat", cat_main},
|
||||
#endif
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP //bin
|
||||
{"chmod", chmod_chown_chgrp_main},
|
||||
{"chown", chmod_chown_chgrp_main},
|
||||
{"chgrp", chmod_chown_chgrp_main},
|
||||
#endif
|
||||
#ifdef BB_CHROOT //sbin
|
||||
{"chroot", chroot_main},
|
||||
#endif
|
||||
#ifdef BB_CLEAR //usr/bin
|
||||
{"clear", clear_main},
|
||||
#endif
|
||||
#ifdef BB_CHVT //usr/bin
|
||||
{"chvt", chvt_main},
|
||||
#endif
|
||||
#ifdef BB_CP //bin
|
||||
{"cp", cp_main},
|
||||
#endif
|
||||
#ifdef BB_DATE //bin
|
||||
{"date", date_main},
|
||||
#endif
|
||||
#ifdef BB_DD //bin
|
||||
{"dd", dd_main},
|
||||
#endif
|
||||
#ifdef BB_DF //bin
|
||||
{"df", df_main},
|
||||
#endif
|
||||
#ifdef BB_DMESG //bin
|
||||
{"dmesg", dmesg_main},
|
||||
#endif
|
||||
#ifdef BB_DU //bin
|
||||
{"du", du_main},
|
||||
#endif
|
||||
#ifdef BB_DUTMP //usr/sbin
|
||||
{"dutmp", dutmp_main},
|
||||
#endif
|
||||
#ifdef BB_FBSET //usr/sbin
|
||||
{"fbset", fbset_main},
|
||||
#endif
|
||||
#ifdef BB_FDFLUSH //bin
|
||||
{"fdflush", fdflush_main},
|
||||
#endif
|
||||
#ifdef BB_FIND //usr/bin
|
||||
{"find", find_main},
|
||||
#endif
|
||||
#ifdef BB_FREE //usr/bin
|
||||
{"free", free_main},
|
||||
#endif
|
||||
#ifdef BB_DEALLOCVT //usr/bin
|
||||
{"deallocvt", deallocvt_main},
|
||||
#endif
|
||||
#ifdef BB_FSCK_MINIX //sbin
|
||||
{"fsck.minix", fsck_minix_main},
|
||||
#endif
|
||||
#ifdef BB_MKFS_MINIX //sbin
|
||||
{"mkfs.minix", mkfs_minix_main},
|
||||
#endif
|
||||
#ifdef BB_GREP //bin
|
||||
{"grep", grep_main},
|
||||
#endif
|
||||
#ifdef BB_HALT //sbin
|
||||
{"halt", halt_main},
|
||||
#endif
|
||||
#ifdef BB_HEAD //bin
|
||||
{"head", head_main},
|
||||
#endif
|
||||
#ifdef BB_HOSTID //usr/bin
|
||||
{"hostid", hostid_main},
|
||||
#endif
|
||||
#ifdef BB_HOSTNAME //bin
|
||||
{"hostname", hostname_main},
|
||||
#endif
|
||||
#ifdef BB_INIT //sbin
|
||||
{"init", init_main},
|
||||
#endif
|
||||
#ifdef BB_INSMOD //sbin
|
||||
{"insmod", insmod_main},
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LINUXRC //
|
||||
{"linuxrc", init_main},
|
||||
#endif
|
||||
#ifdef BB_KILL //bin
|
||||
{"kill", kill_main},
|
||||
#endif
|
||||
#ifdef BB_LENGTH //usr/bin
|
||||
{"length", length_main},
|
||||
#endif
|
||||
#ifdef BB_LN //bin
|
||||
{"ln", ln_main},
|
||||
#endif
|
||||
#ifdef BB_LOADACM //usr/bin
|
||||
{"loadacm", loadacm_main},
|
||||
#endif
|
||||
#ifdef BB_LOADFONT //usr/bin
|
||||
{"loadfont", loadfont_main},
|
||||
#endif
|
||||
#ifdef BB_LOADKMAP //sbin
|
||||
{"loadkmap", loadkmap_main},
|
||||
#endif
|
||||
#ifdef BB_LS //bin
|
||||
{"ls", ls_main},
|
||||
#endif
|
||||
#ifdef BB_LSMOD //sbin
|
||||
{"lsmod", lsmod_main},
|
||||
#endif
|
||||
#ifdef BB_MAKEDEVS //sbin
|
||||
{"makedevs", makedevs_main},
|
||||
#endif
|
||||
#ifdef BB_MATH //usr/bin
|
||||
{"math", math_main},
|
||||
#endif
|
||||
#ifdef BB_MKDIR //bin
|
||||
{"mkdir", mkdir_main},
|
||||
#endif
|
||||
#ifdef BB_MKFIFO //usr/bin
|
||||
{"mkfifo", mkfifo_main},
|
||||
#endif
|
||||
#ifdef BB_MKNOD //bin
|
||||
{"mknod", mknod_main},
|
||||
#endif
|
||||
#ifdef BB_MKSWAP //sbin
|
||||
{"mkswap", mkswap_main},
|
||||
#endif
|
||||
#ifdef BB_MNC //usr/bin
|
||||
{"mnc", mnc_main},
|
||||
#endif
|
||||
#ifdef BB_MORE //bin
|
||||
{"more", more_main},
|
||||
#endif
|
||||
#ifdef BB_MOUNT //bin
|
||||
{"mount", mount_main},
|
||||
#endif
|
||||
#ifdef BB_MT //bin
|
||||
{"mt", mt_main},
|
||||
#endif
|
||||
#ifdef BB_MV //bin
|
||||
{"mv", mv_main},
|
||||
#endif
|
||||
#ifdef BB_PING //bin
|
||||
{"ping", ping_main},
|
||||
#endif
|
||||
#ifdef BB_POWEROFF //sbin
|
||||
{"poweroff", poweroff_main},
|
||||
#endif
|
||||
#ifdef BB_PRINTF //usr/bin
|
||||
{"printf", printf_main},
|
||||
#endif
|
||||
#ifdef BB_PS //bin
|
||||
{"ps", ps_main},
|
||||
#endif
|
||||
#ifdef BB_PWD //bin
|
||||
{"pwd", pwd_main},
|
||||
#endif
|
||||
#ifdef BB_REBOOT //sbin
|
||||
{"reboot", reboot_main},
|
||||
#endif
|
||||
#ifdef BB_RM //bin
|
||||
{"rm", rm_main},
|
||||
#endif
|
||||
#ifdef BB_RMDIR //bin
|
||||
{"rmdir", rmdir_main},
|
||||
#endif
|
||||
#ifdef BB_RMMOD //sbin
|
||||
{"rmmod", rmmod_main},
|
||||
#endif
|
||||
#ifdef BB_SFDISK //sbin
|
||||
{"fdisk", sfdisk_main},
|
||||
{"sfdisk", sfdisk_main},
|
||||
#endif
|
||||
#ifdef BB_SED //bin
|
||||
{"sed", sed_main},
|
||||
#endif
|
||||
#ifdef BB_SLEEP //bin
|
||||
{"sleep", sleep_main},
|
||||
#endif
|
||||
#ifdef BB_SORT //bin
|
||||
{"sort", sort_main},
|
||||
#endif
|
||||
#ifdef BB_SYNC //bin
|
||||
{"sync", sync_main},
|
||||
#endif
|
||||
#ifdef BB_SYSLOGD //sbin
|
||||
{"syslogd", syslogd_main},
|
||||
#endif
|
||||
#ifdef BB_LOGGER //usr/bin
|
||||
{"logger", logger_main},
|
||||
#endif
|
||||
#ifdef BB_LOGNAME //usr/bin
|
||||
{"logname", logname_main},
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF //sbin
|
||||
{"swapon", swap_on_off_main},
|
||||
{"swapoff", swap_on_off_main},
|
||||
#endif
|
||||
#ifdef BB_TAIL //usr/bin
|
||||
{"tail", tail_main},
|
||||
#endif
|
||||
#ifdef BB_TAR //bin
|
||||
{"tar", tar_main},
|
||||
#endif
|
||||
#ifdef BB_TEE //bin
|
||||
{"tee", tee_main},
|
||||
#endif
|
||||
#ifdef BB_TOUCH //usr/bin
|
||||
{"touch", touch_main},
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE //bin
|
||||
{"true", true_main},
|
||||
{"false", false_main},
|
||||
#endif
|
||||
#ifdef BB_TTY //usr/bin
|
||||
{"tty", tty_main},
|
||||
#endif
|
||||
#ifdef BB_UNAME //bin
|
||||
{"uname", uname_main},
|
||||
#endif
|
||||
#ifdef BB_UMOUNT //bin
|
||||
{"umount", umount_main},
|
||||
#endif
|
||||
#ifdef BB_UNIQ //bin
|
||||
{"uniq", uniq_main},
|
||||
#endif
|
||||
#ifdef BB_UPDATE //sbin
|
||||
{"update", update_main},
|
||||
#endif
|
||||
#ifdef BB_WC //usr/bin
|
||||
{"wc", wc_main},
|
||||
#endif
|
||||
#ifdef BB_WHOAMI //usr/bin
|
||||
{"whoami", whoami_main},
|
||||
#endif
|
||||
#ifdef BB_YES //usr/bin
|
||||
{"yes", yes_main},
|
||||
#endif
|
||||
#ifdef BB_GUNZIP //bin
|
||||
{"zcat", gunzip_main},
|
||||
{"gunzip", gunzip_main},
|
||||
#endif
|
||||
#ifdef BB_GZIP //bin
|
||||
{"gzip", gzip_main},
|
||||
#endif
|
||||
{0}
|
||||
};
|
||||
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *s = argv[0];
|
||||
char *name = argv[0];
|
||||
const struct Applet *a = applets;
|
||||
|
||||
while (*s != '\0') {
|
||||
if (*s++ == '/')
|
||||
name = s;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
a++;
|
||||
}
|
||||
exit (busybox_main(argc, argv));
|
||||
}
|
||||
|
||||
|
||||
int busybox_main(int argc, char **argv)
|
||||
{
|
||||
int col=0;
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
if (been_there_done_that == 1 || argc < 1) {
|
||||
const struct Applet *a = applets;
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
|
||||
BB_VER, BB_BT);
|
||||
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
|
||||
fprintf(stderr, " or: [function] [arguments]...\n\n");
|
||||
fprintf(stderr,
|
||||
"\tMost people will create a symlink to busybox for each\n"
|
||||
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
|
||||
fprintf(stderr, "\nCurrently defined functions:\n");
|
||||
|
||||
while (a->name != 0) {
|
||||
col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), (a++)->name);
|
||||
if (col>60) {
|
||||
fprintf(stderr, ",\n");
|
||||
col=0;
|
||||
}
|
||||
}
|
||||
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));
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
#!/bin/sh
|
||||
#Make busybox links list file
|
||||
|
||||
DF="busybox.def.h"
|
||||
MF="busybox.c"
|
||||
|
||||
LIST="$(sed -n '/^#define/{s/^#define //p;}' $DF)"
|
||||
|
||||
for def in ${LIST}; do
|
||||
i=`sed -n 's/^#ifdef \<'$def'\>.*\/\/\(.*$\)/\/\1\//gp' $MF`
|
||||
j=`sed -n '/^#ifdef '$def'.*/,/^#endif/{ s/.*\"\(.*\)\".*/\1/gp; }' $MF`
|
||||
for k in $j; do
|
||||
echo $i$k
|
||||
done
|
||||
done
|
||||
@@ -1,4 +0,0 @@
|
||||
#!/bin/sh
|
||||
ls -1 `sed -n '/^#define/{s/.*BB_// ; s/$/.c/p; }' busybox.def.h | \
|
||||
tr [:upper:] [:lower:]` 2> /dev/null | sed -e 's/\.c$/\.o/g'
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
if [ "$1" == "" ]; then
|
||||
echo "No installation directory, aborting."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
h=`sort busybox.links | uniq`
|
||||
|
||||
for i in $h ; do
|
||||
echo " $1$i -> /bin/busybox"
|
||||
mkdir -p $1/`echo $i | sed -e 's/\/[^\/]*$//' `
|
||||
ln -fs /bin/busybox $1$i
|
||||
done
|
||||
rm -f $1/bin/busybox
|
||||
install -m 755 busybox $1/bin/busybox
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,89 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini ar implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 by Glenn McGrath
|
||||
* Written by Glenn McGrath <bug1@optushome.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
|
||||
*
|
||||
*/
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
#include "busybox.h"
|
||||
|
||||
extern int ar_main(int argc, char **argv)
|
||||
{
|
||||
FILE *src_stream = NULL;
|
||||
char **extract_names = NULL;
|
||||
char ar_magic[8];
|
||||
int extract_function = extract_unconditional;
|
||||
int opt;
|
||||
int num_of_entries = 0;
|
||||
extern off_t archive_offset;
|
||||
|
||||
while ((opt = getopt(argc, argv, "ovtpx")) != -1) {
|
||||
switch (opt) {
|
||||
case 'o':
|
||||
extract_function |= extract_preserve_date;
|
||||
break;
|
||||
case 'v':
|
||||
extract_function |= extract_verbose_list;
|
||||
break;
|
||||
case 't':
|
||||
extract_function |= extract_list;
|
||||
break;
|
||||
case 'p':
|
||||
extract_function |= extract_to_stdout;
|
||||
break;
|
||||
case 'x':
|
||||
extract_function |= extract_all_to_fs;
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
/* check the src filename was specified */
|
||||
if (optind == argc) {
|
||||
show_usage();
|
||||
}
|
||||
|
||||
src_stream = xfopen(argv[optind++], "r");
|
||||
|
||||
/* check ar magic */
|
||||
fread(ar_magic, 1, 8, src_stream);
|
||||
archive_offset = 8;
|
||||
if (strncmp(ar_magic,"!<arch>",7) != 0) {
|
||||
error_msg_and_die("invalid magic");
|
||||
}
|
||||
|
||||
/* Create a list of files to extract */
|
||||
while (optind < argc) {
|
||||
extract_names = xrealloc(extract_names, sizeof(char *) * (num_of_entries + 2));
|
||||
extract_names[num_of_entries] = xstrdup(argv[optind]);
|
||||
num_of_entries++;
|
||||
extract_names[num_of_entries] = NULL;
|
||||
optind++;
|
||||
}
|
||||
|
||||
unarchive(src_stream, stdout, &get_header_ar, extract_function, "./", extract_names);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
-2334
File diff suppressed because it is too large.
Load diff
-3286
File diff suppressed because it is too large.
Load diff
-1239
File diff suppressed because it is too large.
Load diff
+52
@@ -0,0 +1,52 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini basename implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
|
||||
* Copyright (C) 1999,2000,2001 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
|
||||
*
|
||||
*/
|
||||
|
||||
/* getopt not needed */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "busybox.h"
|
||||
#include <string.h>
|
||||
|
||||
extern int basename_main(int argc, char **argv)
|
||||
{
|
||||
int m, n;
|
||||
char *s;
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
show_usage();
|
||||
}
|
||||
|
||||
argv++;
|
||||
|
||||
s = get_last_path_component(*argv);
|
||||
|
||||
if (argc>2) {
|
||||
argv++;
|
||||
n = strlen(*argv);
|
||||
m = strlen(s);
|
||||
if (m>n && strncmp(s+m-n, *argv, n)==0)
|
||||
s[m-n] = '\0';
|
||||
}
|
||||
puts(s);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,343 +1,172 @@
|
||||
#include "internal.h"
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifndef BB_INIT
|
||||
#undef BB_FEATURE_LINUXRC
|
||||
#include <stdlib.h>
|
||||
#include "busybox.h"
|
||||
#ifdef BB_LOCALE_SUPPORT
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
static int been_there_done_that = 0;
|
||||
int been_there_done_that = 0; /* Also used in applets.c */
|
||||
const char *applet_name;
|
||||
|
||||
/* It has been alledged that doing such things can
|
||||
* help reduce binary size when staticly linking,
|
||||
* of course with glibc, this is unlikely as long
|
||||
* as we use things like printf -- perhaps a printf
|
||||
* replacement may be in order
|
||||
#ifdef BB_FEATURE_INSTALLER
|
||||
/*
|
||||
* directory table
|
||||
* this should be consistent w/ the enum, busybox.h::Location,
|
||||
* or else...
|
||||
*/
|
||||
#if 0
|
||||
void exit (int status) __attribute__ ((noreturn));
|
||||
void exit (int status) { _exit(status); };
|
||||
void abort (void) __attribute__ ((__noreturn__));
|
||||
void abort (void) { _exit(0); };
|
||||
int atexit (void (*__func) (void)) { _exit(0); };
|
||||
void *__libc_stack_end;
|
||||
#endif
|
||||
static const char usr_bin [] ="/usr/bin";
|
||||
static const char usr_sbin[] ="/usr/sbin";
|
||||
static const char* const install_dir[] = {
|
||||
&usr_bin [8], /* "", equivalent to "/" for concat_path_file() */
|
||||
&usr_bin [4], /* "/bin" */
|
||||
&usr_sbin[4], /* "/sbin" */
|
||||
usr_bin,
|
||||
usr_sbin
|
||||
};
|
||||
|
||||
/* abstract link() */
|
||||
typedef int (*__link_f)(const char *, const char *);
|
||||
|
||||
static const struct Applet applets[] = {
|
||||
/* create (sym)links for each applet */
|
||||
static void install_links(const char *busybox, int use_symbolic_links)
|
||||
{
|
||||
__link_f Link = link;
|
||||
|
||||
#ifdef BB_BUSYBOX //bin
|
||||
{"busybox", busybox_main},
|
||||
#endif
|
||||
#ifdef BB_BLOCK_DEVICE //sbin
|
||||
{"block_device", block_device_main},
|
||||
#endif
|
||||
#ifdef BB_CAT //bin
|
||||
{"cat", cat_main},
|
||||
#endif
|
||||
#ifdef BB_CHMOD_CHOWN_CHGRP //bin
|
||||
{"chmod", chmod_chown_chgrp_main},
|
||||
{"chown", chmod_chown_chgrp_main},
|
||||
{"chgrp", chmod_chown_chgrp_main},
|
||||
#endif
|
||||
#ifdef BB_CHROOT //sbin
|
||||
{"chroot", chroot_main},
|
||||
#endif
|
||||
#ifdef BB_CLEAR //usr/bin
|
||||
{"clear", clear_main},
|
||||
#endif
|
||||
#ifdef BB_CHVT //usr/bin
|
||||
{"chvt", chvt_main},
|
||||
#endif
|
||||
#ifdef BB_CP //bin
|
||||
{"cp", cp_main},
|
||||
#endif
|
||||
#ifdef BB_DATE //bin
|
||||
{"date", date_main},
|
||||
#endif
|
||||
#ifdef BB_DD //bin
|
||||
{"dd", dd_main},
|
||||
#endif
|
||||
#ifdef BB_DF //bin
|
||||
{"df", df_main},
|
||||
#endif
|
||||
#ifdef BB_DMESG //bin
|
||||
{"dmesg", dmesg_main},
|
||||
#endif
|
||||
#ifdef BB_DU //bin
|
||||
{"du", du_main},
|
||||
#endif
|
||||
#ifdef BB_DUTMP //usr/sbin
|
||||
{"dutmp", dutmp_main},
|
||||
#endif
|
||||
#ifdef BB_FBSET //usr/sbin
|
||||
{"fbset", fbset_main},
|
||||
#endif
|
||||
#ifdef BB_FDFLUSH //bin
|
||||
{"fdflush", fdflush_main},
|
||||
#endif
|
||||
#ifdef BB_FIND //usr/bin
|
||||
{"find", find_main},
|
||||
#endif
|
||||
#ifdef BB_FREE //usr/bin
|
||||
{"free", free_main},
|
||||
#endif
|
||||
#ifdef BB_DEALLOCVT //usr/bin
|
||||
{"deallocvt", deallocvt_main},
|
||||
#endif
|
||||
#ifdef BB_FSCK_MINIX //sbin
|
||||
{"fsck.minix", fsck_minix_main},
|
||||
#endif
|
||||
#ifdef BB_MKFS_MINIX //sbin
|
||||
{"mkfs.minix", mkfs_minix_main},
|
||||
#endif
|
||||
#ifdef BB_GREP //bin
|
||||
{"grep", grep_main},
|
||||
#endif
|
||||
#ifdef BB_HALT //sbin
|
||||
{"halt", halt_main},
|
||||
#endif
|
||||
#ifdef BB_HEAD //bin
|
||||
{"head", head_main},
|
||||
#endif
|
||||
#ifdef BB_HOSTID //usr/bin
|
||||
{"hostid", hostid_main},
|
||||
#endif
|
||||
#ifdef BB_HOSTNAME //bin
|
||||
{"hostname", hostname_main},
|
||||
#endif
|
||||
#ifdef BB_INIT //sbin
|
||||
{"init", init_main},
|
||||
#endif
|
||||
#ifdef BB_INSMOD //sbin
|
||||
{"insmod", insmod_main},
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LINUXRC //
|
||||
{"linuxrc", init_main},
|
||||
#endif
|
||||
#ifdef BB_KILL //bin
|
||||
{"kill", kill_main},
|
||||
#endif
|
||||
#ifdef BB_LENGTH //usr/bin
|
||||
{"length", length_main},
|
||||
#endif
|
||||
#ifdef BB_LN //bin
|
||||
{"ln", ln_main},
|
||||
#endif
|
||||
#ifdef BB_LOADACM //usr/bin
|
||||
{"loadacm", loadacm_main},
|
||||
#endif
|
||||
#ifdef BB_LOADFONT //usr/bin
|
||||
{"loadfont", loadfont_main},
|
||||
#endif
|
||||
#ifdef BB_LOADKMAP //sbin
|
||||
{"loadkmap", loadkmap_main},
|
||||
#endif
|
||||
#ifdef BB_LS //bin
|
||||
{"ls", ls_main},
|
||||
#endif
|
||||
#ifdef BB_LSMOD //sbin
|
||||
{"lsmod", lsmod_main},
|
||||
#endif
|
||||
#ifdef BB_MAKEDEVS //sbin
|
||||
{"makedevs", makedevs_main},
|
||||
#endif
|
||||
#ifdef BB_MATH //usr/bin
|
||||
{"math", math_main},
|
||||
#endif
|
||||
#ifdef BB_MKDIR //bin
|
||||
{"mkdir", mkdir_main},
|
||||
#endif
|
||||
#ifdef BB_MKFIFO //usr/bin
|
||||
{"mkfifo", mkfifo_main},
|
||||
#endif
|
||||
#ifdef BB_MKNOD //bin
|
||||
{"mknod", mknod_main},
|
||||
#endif
|
||||
#ifdef BB_MKSWAP //sbin
|
||||
{"mkswap", mkswap_main},
|
||||
#endif
|
||||
#ifdef BB_MNC //usr/bin
|
||||
{"mnc", mnc_main},
|
||||
#endif
|
||||
#ifdef BB_MORE //bin
|
||||
{"more", more_main},
|
||||
#endif
|
||||
#ifdef BB_MOUNT //bin
|
||||
{"mount", mount_main},
|
||||
#endif
|
||||
#ifdef BB_MT //bin
|
||||
{"mt", mt_main},
|
||||
#endif
|
||||
#ifdef BB_MV //bin
|
||||
{"mv", mv_main},
|
||||
#endif
|
||||
#ifdef BB_PING //bin
|
||||
{"ping", ping_main},
|
||||
#endif
|
||||
#ifdef BB_POWEROFF //sbin
|
||||
{"poweroff", poweroff_main},
|
||||
#endif
|
||||
#ifdef BB_PRINTF //usr/bin
|
||||
{"printf", printf_main},
|
||||
#endif
|
||||
#ifdef BB_PS //bin
|
||||
{"ps", ps_main},
|
||||
#endif
|
||||
#ifdef BB_PWD //bin
|
||||
{"pwd", pwd_main},
|
||||
#endif
|
||||
#ifdef BB_REBOOT //sbin
|
||||
{"reboot", reboot_main},
|
||||
#endif
|
||||
#ifdef BB_RM //bin
|
||||
{"rm", rm_main},
|
||||
#endif
|
||||
#ifdef BB_RMDIR //bin
|
||||
{"rmdir", rmdir_main},
|
||||
#endif
|
||||
#ifdef BB_RMMOD //sbin
|
||||
{"rmmod", rmmod_main},
|
||||
#endif
|
||||
#ifdef BB_SFDISK //sbin
|
||||
{"fdisk", sfdisk_main},
|
||||
{"sfdisk", sfdisk_main},
|
||||
#endif
|
||||
#ifdef BB_SED //bin
|
||||
{"sed", sed_main},
|
||||
#endif
|
||||
#ifdef BB_SLEEP //bin
|
||||
{"sleep", sleep_main},
|
||||
#endif
|
||||
#ifdef BB_SORT //bin
|
||||
{"sort", sort_main},
|
||||
#endif
|
||||
#ifdef BB_SYNC //bin
|
||||
{"sync", sync_main},
|
||||
#endif
|
||||
#ifdef BB_SYSLOGD //sbin
|
||||
{"syslogd", syslogd_main},
|
||||
#endif
|
||||
#ifdef BB_LOGGER //usr/bin
|
||||
{"logger", logger_main},
|
||||
#endif
|
||||
#ifdef BB_LOGNAME //usr/bin
|
||||
{"logname", logname_main},
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF //sbin
|
||||
{"swapon", swap_on_off_main},
|
||||
{"swapoff", swap_on_off_main},
|
||||
#endif
|
||||
#ifdef BB_TAIL //usr/bin
|
||||
{"tail", tail_main},
|
||||
#endif
|
||||
#ifdef BB_TAR //bin
|
||||
{"tar", tar_main},
|
||||
#endif
|
||||
#ifdef BB_TEE //bin
|
||||
{"tee", tee_main},
|
||||
#endif
|
||||
#ifdef BB_TOUCH //usr/bin
|
||||
{"touch", touch_main},
|
||||
#endif
|
||||
#ifdef BB_TRUE_FALSE //bin
|
||||
{"true", true_main},
|
||||
{"false", false_main},
|
||||
#endif
|
||||
#ifdef BB_TTY //usr/bin
|
||||
{"tty", tty_main},
|
||||
#endif
|
||||
#ifdef BB_UNAME //bin
|
||||
{"uname", uname_main},
|
||||
#endif
|
||||
#ifdef BB_UMOUNT //bin
|
||||
{"umount", umount_main},
|
||||
#endif
|
||||
#ifdef BB_UNIQ //bin
|
||||
{"uniq", uniq_main},
|
||||
#endif
|
||||
#ifdef BB_UPDATE //sbin
|
||||
{"update", update_main},
|
||||
#endif
|
||||
#ifdef BB_WC //usr/bin
|
||||
{"wc", wc_main},
|
||||
#endif
|
||||
#ifdef BB_WHOAMI //usr/bin
|
||||
{"whoami", whoami_main},
|
||||
#endif
|
||||
#ifdef BB_YES //usr/bin
|
||||
{"yes", yes_main},
|
||||
#endif
|
||||
#ifdef BB_GUNZIP //bin
|
||||
{"zcat", gunzip_main},
|
||||
{"gunzip", gunzip_main},
|
||||
#endif
|
||||
#ifdef BB_GZIP //bin
|
||||
{"gzip", gzip_main},
|
||||
#endif
|
||||
{0}
|
||||
};
|
||||
char *fpc;
|
||||
int i;
|
||||
int rc;
|
||||
|
||||
if (use_symbolic_links)
|
||||
Link = symlink;
|
||||
|
||||
for (i = 0; applets[i].name != NULL; i++) {
|
||||
fpc = concat_path_file(
|
||||
install_dir[applets[i].location], applets[i].name);
|
||||
rc = Link(busybox, fpc);
|
||||
if (rc!=0 && errno!=EEXIST) {
|
||||
perror_msg("%s", fpc);
|
||||
}
|
||||
free(fpc);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* BB_FEATURE_INSTALLER */
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *s = argv[0];
|
||||
char *name = argv[0];
|
||||
const struct Applet *a = applets;
|
||||
const char *s;
|
||||
|
||||
while (*s != '\0') {
|
||||
if (*s++ == '/')
|
||||
name = s;
|
||||
}
|
||||
applet_name = argv[0];
|
||||
|
||||
while (a->name != 0) {
|
||||
if (strcmp(name, a->name) == 0) {
|
||||
int status;
|
||||
if (applet_name[0] == '-')
|
||||
applet_name++;
|
||||
|
||||
status = ((*(a->main)) (argc, argv));
|
||||
if (status < 0) {
|
||||
fprintf(stderr, "%s: %s\n", a->name, strerror(errno));
|
||||
}
|
||||
fprintf(stderr, "\n");
|
||||
exit(status);
|
||||
for (s = applet_name; *s != '\0';) {
|
||||
if (*s++ == '/')
|
||||
applet_name = s;
|
||||
}
|
||||
a++;
|
||||
}
|
||||
exit (busybox_main(argc, argv));
|
||||
|
||||
#ifdef BB_LOCALE_SUPPORT
|
||||
#ifdef BB_INIT
|
||||
if(getpid()!=1) /* Do not set locale for `init' */
|
||||
#endif
|
||||
{
|
||||
setlocale(LC_ALL, "");
|
||||
}
|
||||
#endif
|
||||
|
||||
run_applet_by_name(applet_name, argc, argv);
|
||||
error_msg_and_die("applet not found");
|
||||
}
|
||||
|
||||
|
||||
int busybox_main(int argc, char **argv)
|
||||
{
|
||||
int col=0;
|
||||
argc--;
|
||||
argv++;
|
||||
int col = 0, len, i;
|
||||
|
||||
if (been_there_done_that == 1 || argc < 1) {
|
||||
const struct Applet *a = applets;
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
|
||||
BB_VER, BB_BT);
|
||||
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
|
||||
fprintf(stderr, " or: [function] [arguments]...\n\n");
|
||||
fprintf(stderr,
|
||||
"\tMost people will create a symlink to busybox for each\n"
|
||||
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
|
||||
fprintf(stderr, "\nCurrently defined functions:\n");
|
||||
#ifdef BB_FEATURE_INSTALLER
|
||||
/*
|
||||
* This style of argument parsing doesn't scale well
|
||||
* in the event that busybox starts wanting more --options.
|
||||
* If someone has a cleaner approach, by all means implement it.
|
||||
*/
|
||||
if (argc > 1 && (strcmp(argv[1], "--install") == 0)) {
|
||||
int use_symbolic_links = 0;
|
||||
int rc = 0;
|
||||
char *busybox;
|
||||
|
||||
while (a->name != 0) {
|
||||
col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), (a++)->name);
|
||||
if (col>60) {
|
||||
fprintf(stderr, ",\n");
|
||||
col=0;
|
||||
}
|
||||
/* to use symlinks, or not to use symlinks... */
|
||||
if (argc > 2) {
|
||||
if ((strcmp(argv[2], "-s") == 0)) {
|
||||
use_symbolic_links = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* link */
|
||||
busybox = xreadlink("/proc/self/exe");
|
||||
if (busybox) {
|
||||
install_links(busybox, use_symbolic_links);
|
||||
free(busybox);
|
||||
} else {
|
||||
rc = 1;
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
fprintf(stderr, "\n\n");
|
||||
exit(-1);
|
||||
} else {
|
||||
#endif /* BB_FEATURE_INSTALLER */
|
||||
|
||||
argc--;
|
||||
|
||||
/* If we've already been here once, exit now */
|
||||
if (been_there_done_that == 1 || argc < 1) {
|
||||
const struct BB_applet *a = applets;
|
||||
|
||||
fprintf(stderr, "%s\n\n"
|
||||
"Usage: busybox [function] [arguments]...\n"
|
||||
" or: [function] [arguments]...\n\n"
|
||||
"\tBusyBox is a multi-call binary that combines many common Unix\n"
|
||||
"\tutilities into a single executable. Most people will create a\n"
|
||||
"\tlink to busybox for each function they wish to use, and BusyBox\n"
|
||||
"\twill act like whatever it was invoked as.\n"
|
||||
"\nCurrently defined functions:\n", full_version);
|
||||
|
||||
while (a->name != 0) {
|
||||
col +=
|
||||
fprintf(stderr, "%s%s", ((col == 0) ? "\t" : ", "),
|
||||
(a++)->name);
|
||||
if (col > 60 && a->name != 0) {
|
||||
fprintf(stderr, ",\n");
|
||||
col = 0;
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "\n\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* Flag that we've been here already */
|
||||
been_there_done_that = 1;
|
||||
|
||||
/* Move the command line down a notch */
|
||||
len = argv[argc] + strlen(argv[argc]) - argv[1];
|
||||
memmove(argv[0], argv[1], len);
|
||||
memset(argv[0] + len, 0, argv[1] - argv[0]);
|
||||
|
||||
/* Fix up the argv pointers */
|
||||
len = argv[1] - argv[0];
|
||||
memmove(argv, argv + 1, sizeof(char *) * (argc + 1));
|
||||
for (i = 0; i < argc; i++)
|
||||
argv[i] -= len;
|
||||
|
||||
return (main(argc, argv));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
-138
@@ -1,138 +0,0 @@
|
||||
// This file defines the feature set to be compiled into busybox.
|
||||
// When you turn things off here, they won't be compiled in at all.
|
||||
//
|
||||
//// This file is parsed by sed. You MUST use single line comments.
|
||||
// i.e. //#define BB_BLAH
|
||||
//
|
||||
//
|
||||
// BusyBox Applications
|
||||
#define BB_BUSYBOX
|
||||
#define BB_CAT
|
||||
#define BB_CHMOD_CHOWN_CHGRP
|
||||
#define BB_CHROOT
|
||||
#define BB_CHVT
|
||||
#define BB_CLEAR
|
||||
#define BB_CP
|
||||
#define BB_DATE
|
||||
#define BB_DD
|
||||
#define BB_DEALLOCVT
|
||||
#define BB_DF
|
||||
#define BB_DMESG
|
||||
//#define BB_DUTMP
|
||||
#define BB_DU
|
||||
#define BB_FBSET
|
||||
//#define BB_FDFLUSH
|
||||
#define BB_FIND
|
||||
#define BB_FREE
|
||||
#define BB_FSCK_MINIX
|
||||
#define BB_GREP
|
||||
#define BB_GUNZIP
|
||||
#define BB_GZIP
|
||||
//#define BB_HALT
|
||||
#define BB_HEAD
|
||||
//#define BB_HOSTID
|
||||
#define BB_HOSTNAME
|
||||
#define BB_INIT
|
||||
// Don't turn BB_INSMOD on. It doesn't work.
|
||||
//#define BB_INSMOD
|
||||
#define BB_KILL
|
||||
#define BB_KLOGD
|
||||
//#define BB_LENGTH
|
||||
#define BB_LN
|
||||
//#define BB_LOADACM
|
||||
//#define BB_LOADFONT
|
||||
//#define BB_LOADKMAP
|
||||
//#define BB_LOGGER
|
||||
#define BB_LOGNAME
|
||||
#define BB_LS
|
||||
#define BB_LSMOD
|
||||
//#define BB_MAKEDEVS
|
||||
#define BB_MKFS_MINIX
|
||||
//#define BB_MATH
|
||||
#define BB_MKDIR
|
||||
//#define BB_MKFIFO
|
||||
#define BB_MKNOD
|
||||
#define BB_MKSWAP
|
||||
//#define BB_MNC
|
||||
#define BB_MORE
|
||||
#define BB_MOUNT
|
||||
#define BB_NFSMOUNT
|
||||
//#define BB_MT
|
||||
//#define BB_MTAB
|
||||
#define BB_MV
|
||||
#define BB_PING
|
||||
#define BB_POWEROFF
|
||||
//#define BB_PRINTF
|
||||
#define BB_PS
|
||||
#define BB_PWD
|
||||
#define BB_REBOOT
|
||||
#define BB_REGEXP
|
||||
#define BB_RM
|
||||
#define BB_RMDIR
|
||||
//#define BB_RMMOD
|
||||
#define BB_SED
|
||||
//#define BB_SFDISK
|
||||
#define BB_SLEEP
|
||||
#define BB_SORT
|
||||
#define BB_SWAPONOFF
|
||||
#define BB_SYNC
|
||||
#define BB_SYSLOGD
|
||||
#define BB_TAIL
|
||||
#define BB_TAR
|
||||
#define BB_TEE
|
||||
#define BB_TOUCH
|
||||
#define BB_TRUE_FALSE
|
||||
#define BB_TTY
|
||||
#define BB_WC
|
||||
#define BB_WHOAMI
|
||||
#define BB_UMOUNT
|
||||
#define BB_UNIQ
|
||||
#define BB_UNAME
|
||||
#define BB_UPDATE
|
||||
#define BB_YES
|
||||
// End of Applications List
|
||||
//
|
||||
//
|
||||
//
|
||||
// Don't turn BB_UTILITY off. It contains support code
|
||||
// that compiles to 0 if everything else if turned off.
|
||||
#define BB_UTILITY
|
||||
//
|
||||
//
|
||||
//
|
||||
// This is where feature definitions go. Generally speaking,
|
||||
// turning this stuff off makes things a bit smaller (and less
|
||||
// pretty/useful).
|
||||
//
|
||||
//
|
||||
// enable features that use the /proc filesystem (apps that
|
||||
// break without this will tell you on compile)...
|
||||
#define BB_FEATURE_USE_PROCFS
|
||||
//
|
||||
// Use termios to manipulate the screen ('more' is prettier with this on)
|
||||
#define BB_FEATURE_USE_TERMIOS
|
||||
//
|
||||
// calculate terminal & column widths (for more and ls)
|
||||
#define BB_FEATURE_AUTOWIDTH
|
||||
//
|
||||
// show username/groupnames (bypasses libc6 NSS) for ls
|
||||
#define BB_FEATURE_LS_USERNAME
|
||||
//
|
||||
// show file timestamps in ls
|
||||
#define BB_FEATURE_LS_TIMESTAMPS
|
||||
//
|
||||
// enable ls -p and -F
|
||||
#define BB_FEATURE_LS_FILETYPES
|
||||
//
|
||||
// Change ping implementation -- simplified, featureless, but really small.
|
||||
//#define BB_SIMPLE_PING
|
||||
////
|
||||
// Make init use a simplified /etc/inittab file (recommended).
|
||||
#define BB_FEATURE_USE_INITTAB
|
||||
//
|
||||
//Enable init being called as /linuxrc
|
||||
#define BB_FEATURE_LINUXRC
|
||||
//
|
||||
// Enable support for loop devices in mount
|
||||
#define BB_FEATURE_MOUNT_LOOP
|
||||
//
|
||||
@@ -0,0 +1,112 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Busybox main internal header file
|
||||
*
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Based in part on code from sash, Copyright (c) 1999 by David I. Bell
|
||||
* Permission has been granted to redistribute this code under the GPL.
|
||||
*
|
||||
*/
|
||||
#ifndef _BB_INTERNAL_H_
|
||||
#define _BB_INTERNAL_H_ 1
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define BB_BANNER "BusyBox v" BB_VER " (" BB_BT ")"
|
||||
|
||||
#ifdef DMALLOC
|
||||
#include "dmalloc.h"
|
||||
#endif
|
||||
|
||||
#include <features.h>
|
||||
|
||||
|
||||
enum Location {
|
||||
_BB_DIR_ROOT = 0,
|
||||
_BB_DIR_BIN,
|
||||
_BB_DIR_SBIN,
|
||||
_BB_DIR_USR_BIN,
|
||||
_BB_DIR_USR_SBIN
|
||||
};
|
||||
|
||||
struct BB_applet {
|
||||
const char* name;
|
||||
int (*main)(int argc, char** argv);
|
||||
enum Location location;
|
||||
};
|
||||
/* From busybox.c */
|
||||
extern const struct BB_applet applets[];
|
||||
|
||||
/* Automagically pull in all the applet function prototypes and
|
||||
* applet usage strings. These are all of the form:
|
||||
* extern int foo_main(int argc, char **argv);
|
||||
* extern const char foo_usage[];
|
||||
* These are all autogenerated from the set of currently defined applets.
|
||||
*/
|
||||
#define PROTOTYPES
|
||||
#include "applets.h"
|
||||
#undef PROTOTYPES
|
||||
|
||||
#ifdef BB_FEATURE_BUFFERS_GO_ON_STACK
|
||||
#define RESERVE_BB_BUFFER(buffer,len) char buffer[len]
|
||||
#define RESERVE_BB_UBUFFER(buffer,len) unsigned char buffer[len]
|
||||
#define RELEASE_BB_BUFFER(buffer) ((void)0)
|
||||
#else
|
||||
#ifdef BB_FEATURE_BUFFERS_GO_IN_BSS
|
||||
#define RESERVE_BB_BUFFER(buffer,len) static char buffer[len]
|
||||
#define RESERVE_BB_UBUFFER(buffer,len) static unsigned char buffer[len]
|
||||
#define RELEASE_BB_BUFFER(buffer) ((void)0)
|
||||
#else
|
||||
#define RESERVE_BB_BUFFER(buffer,len) char *buffer=xmalloc(len)
|
||||
#define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
|
||||
#define RELEASE_BB_BUFFER(buffer) free (buffer)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* Bit map related macros -- libc5 doens't provide these... sigh. */
|
||||
#ifndef setbit
|
||||
#define NBBY CHAR_BIT
|
||||
#define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
|
||||
#define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
|
||||
#define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
|
||||
#define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
|
||||
#endif
|
||||
|
||||
#ifndef RB_POWER_OFF
|
||||
/* Stop system and switch power off if possible. */
|
||||
#define RB_POWER_OFF 0x4321fedc
|
||||
#endif
|
||||
|
||||
|
||||
/* Pull in the utility routines from libbb */
|
||||
#include "libbb/libbb.h"
|
||||
|
||||
/* Try to pull in PATH_MAX */
|
||||
#include <limits.h>
|
||||
/* for PATH_MAX on systems that don't have it in limits.h */
|
||||
#include <sys/param.h>
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 256
|
||||
#endif
|
||||
|
||||
#endif /* _BB_INTERNAL_H_ */
|
||||
+20
-11
@@ -1,15 +1,24 @@
|
||||
#!/bin/sh
|
||||
#Make busybox links list file
|
||||
# Make busybox links list file.
|
||||
|
||||
DF="busybox.def.h"
|
||||
MF="busybox.c"
|
||||
# input $1: full path to Config.h
|
||||
# input $2: full path to applets.h
|
||||
# output (stdout): list of pathnames that should be linked to busybox
|
||||
|
||||
LIST="$(sed -n '/^#define/{s/^#define //p;}' $DF)"
|
||||
# Maintainer: Larry Doolittle <ldoolitt@recycle.lbl.gov>
|
||||
|
||||
for def in ${LIST}; do
|
||||
i=`sed -n 's/^#ifdef \<'$def'\>.*\/\/\(.*$\)/\/\1\//gp' $MF`
|
||||
j=`sed -n '/^#ifdef '$def'.*/,/^#endif/{ s/.*\"\(.*\)\".*/\1/gp; }' $MF`
|
||||
for k in $j; do
|
||||
echo $i$k
|
||||
done
|
||||
done
|
||||
export LC_ALL=POSIX
|
||||
export LC_CTYPE=POSIX
|
||||
|
||||
CONFIG_H=${1:-Config.h}
|
||||
APPLETS_H=${2:-applets.h}
|
||||
gcc -E -DMAKE_LINKS -include $CONFIG_H $APPLETS_H |
|
||||
awk '/^[ \t]*LINK/{
|
||||
dir=substr($2,8)
|
||||
gsub("_","/",dir)
|
||||
if(dir=="/ROOT") dir=""
|
||||
file=$3
|
||||
gsub("\"","",file)
|
||||
if (file=="busybox") next
|
||||
print tolower(dir) "/" file
|
||||
}'
|
||||
+14
-2
@@ -1,4 +1,16 @@
|
||||
#!/bin/sh
|
||||
ls -1 `sed -n '/^#define/{s/.*BB_// ; s/$/.c/p; }' busybox.def.h | \
|
||||
tr [:upper:] [:lower:]` 2> /dev/null | sed -e 's/\.c$/\.o/g'
|
||||
|
||||
export LC_ALL=POSIX
|
||||
export LC_CTYPE=POSIX
|
||||
|
||||
RAW=` \
|
||||
$CC -E -dM ${1:-Config.h} | \
|
||||
sed -n -e '/^.*BB_FEATURE.*$/d;s/^#define.*\<BB_\(.*\)\>/\1.c/gp;' \
|
||||
| tr A-Z a-z | sort
|
||||
`
|
||||
test "${RAW}" != "" || exit
|
||||
if [ -d "$BB_SRC_DIR" ]; then cd $BB_SRC_DIR; fi
|
||||
# By running $RAW through "ls", we avoid listing
|
||||
# source files that don't exist.
|
||||
ls $RAW 2>/dev/null | tr '\n' ' '
|
||||
|
||||
+24
-15
@@ -1,24 +1,33 @@
|
||||
Name: busybox
|
||||
Version: 0.41
|
||||
Release: 1
|
||||
%define name busybox
|
||||
%define epoch 0
|
||||
%define version 0.60.3
|
||||
%define release %(date -I | sed -e 's/-/_/g')
|
||||
%define serial 1
|
||||
|
||||
Name: %{name}
|
||||
#Epoch: %{epoch}
|
||||
Version: %{version}
|
||||
Release: %{release}
|
||||
Serial: %{serial}
|
||||
Copyright: GPL
|
||||
Group: System/Utilities
|
||||
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
||||
Copyright: GPL
|
||||
Packager : Erik Andersen <andersen@lineo.com>
|
||||
Conflicts: fileutils grep shellutils
|
||||
Buildroot: /tmp/%{Name}-%{Version}
|
||||
Source: %{Name}-%{Version}.tar.gz
|
||||
URL: http://busybox.net/
|
||||
Source: ftp://busybox.net/busybox/%{name}-%{version}.tar.gz
|
||||
Buildroot: /var/tmp/%{name}-%{version}
|
||||
Packager : Erik Andersen <andersen@codepoet.org>
|
||||
|
||||
%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}
|
||||
%setup -q -n %{name}-%{version}
|
||||
|
||||
%Build
|
||||
make
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini Cat implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
|
||||
* Copyright (C) 1999,2000,2001 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
|
||||
@@ -20,40 +21,33 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
static void print_file( FILE *file)
|
||||
{
|
||||
int c;
|
||||
while ((c = getc(file)) != EOF)
|
||||
putc(c, stdout);
|
||||
fclose(file);
|
||||
fflush(stdout);
|
||||
}
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "busybox.h"
|
||||
|
||||
extern int cat_main(int argc, char **argv)
|
||||
{
|
||||
FILE *file;
|
||||
int status = EXIT_SUCCESS;
|
||||
|
||||
if (argc==1) {
|
||||
print_file( stdin);
|
||||
exit( TRUE);
|
||||
}
|
||||
|
||||
if ( **(argv+1) == '-' ) {
|
||||
usage ("cat [file ...]\n");
|
||||
}
|
||||
argc--;
|
||||
|
||||
while (argc-- > 0 && *(argv++) != '\0' && strlen(*argv) ) {
|
||||
file = fopen(*argv, "r");
|
||||
if (file == NULL) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
if (argc == 1) {
|
||||
print_file(stdin);
|
||||
return status;
|
||||
}
|
||||
print_file( file);
|
||||
}
|
||||
exit(TRUE);
|
||||
|
||||
while (--argc > 0) {
|
||||
if(!(strcmp(*++argv, "-"))) {
|
||||
print_file(stdin);
|
||||
} else if (print_file_by_name(*argv) == FALSE) {
|
||||
status = EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -0,0 +1,91 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini chown/chmod/chgrp implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
|
||||
* Copyright (C) 1999,2000,2001 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "busybox.h"
|
||||
|
||||
/* Don't use lchown for libc5 or glibc older then 2.1.x */
|
||||
#if (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 1)
|
||||
#define lchown chown
|
||||
#endif
|
||||
|
||||
|
||||
static long gid;
|
||||
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
if (lchown(fileName, statbuf->st_uid, (gid == -1) ? statbuf->st_gid : gid) == 0) {
|
||||
return (TRUE);
|
||||
}
|
||||
perror(fileName);
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
int chgrp_main(int argc, char **argv)
|
||||
{
|
||||
int opt;
|
||||
int recursiveFlag = FALSE;
|
||||
char *p=NULL;
|
||||
|
||||
/* do normal option parsing */
|
||||
while ((opt = getopt(argc, argv, "R")) > 0) {
|
||||
switch (opt) {
|
||||
case 'R':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (argc > optind && argc > 2 && argv[optind]) {
|
||||
/* Find the selected group */
|
||||
gid = strtoul(argv[optind], &p, 10); /* maybe it's already numeric */
|
||||
if (argv[optind] == p)
|
||||
gid = my_getgrnam(argv[optind]);
|
||||
} else {
|
||||
error_msg_and_die(too_few_args);
|
||||
}
|
||||
|
||||
/* Ok, ready to do the deed now */
|
||||
while (++optind < argc) {
|
||||
if (recursive_action (argv[optind], recursiveFlag, FALSE, FALSE,
|
||||
fileAction, fileAction, NULL) == FALSE) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -0,0 +1,97 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini chown/chmod/chgrp implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
|
||||
* Copyright (C) 1999,2000,2001 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include "busybox.h"
|
||||
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
if (!parse_mode((char *)junk, &(statbuf->st_mode)))
|
||||
error_msg_and_die("internal error");
|
||||
if (chmod(fileName, statbuf->st_mode) == 0)
|
||||
return (TRUE);
|
||||
perror(fileName);
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
int chmod_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int opt;
|
||||
int recursiveFlag = FALSE;
|
||||
int opt_eq_modeFlag = FALSE;
|
||||
|
||||
/* do normal option parsing */
|
||||
while ((opt = getopt(argc, argv, "Rrwxst")) > 0) {
|
||||
switch (opt) {
|
||||
case 'R':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
case 'r':
|
||||
case 'w':
|
||||
case 'x':
|
||||
case 's':
|
||||
case 't':
|
||||
opt_eq_modeFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (opt_eq_modeFlag == TRUE) {
|
||||
optind--;
|
||||
}
|
||||
|
||||
if (argc > optind && argc > 2 && argv[optind]) {
|
||||
/* Parse the specified mode */
|
||||
mode_t mode;
|
||||
if (parse_mode(argv[optind], &mode) == FALSE) {
|
||||
error_msg_and_die( "unknown mode: %s", argv[optind]);
|
||||
}
|
||||
} else {
|
||||
error_msg_and_die(too_few_args);
|
||||
}
|
||||
|
||||
/* Ok, ready to do the deed now */
|
||||
for (i = optind + 1; i < argc; i++) {
|
||||
if (recursive_action (argv[i], recursiveFlag, FALSE, FALSE, fileAction,
|
||||
fileAction, argv[optind]) == FALSE) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -1,155 +0,0 @@
|
||||
/*
|
||||
* Mini chown/chmod/chgrp implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <grp.h>
|
||||
#include <pwd.h>
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
static uid_t uid=-1;
|
||||
static gid_t gid=-1;
|
||||
static int whichApp;
|
||||
static char* invocationName=NULL;
|
||||
static char* theMode=NULL;
|
||||
|
||||
|
||||
#define CHGRP_APP 1
|
||||
#define CHOWN_APP 2
|
||||
#define CHMOD_APP 3
|
||||
|
||||
static const char chgrp_usage[] = "chgrp [OPTION]... GROUP FILE...\n\n"
|
||||
"Change the group membership of each FILE to GROUP.\n"
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively\n";
|
||||
static const char chown_usage[] = "chown [OPTION]... OWNER[.[GROUP] FILE...\n\n"
|
||||
"Change the owner and/or group of each FILE to OWNER and/or GROUP.\n"
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively\n";
|
||||
static const char chmod_usage[] = "chmod [-R] MODE[,MODE]... FILE...\n\n"
|
||||
"Each MODE is one or more of the letters ugoa, one of the symbols +-= and\n"
|
||||
"one or more of the letters rwxst.\n\n"
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively.\n";
|
||||
|
||||
|
||||
static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
switch (whichApp) {
|
||||
case CHGRP_APP:
|
||||
case CHOWN_APP:
|
||||
if (chown(fileName, (whichApp==CHOWN_APP)? uid : statbuf->st_uid,
|
||||
(gid==-1)? statbuf->st_gid : gid) == 0) {
|
||||
return( TRUE);
|
||||
}
|
||||
break;
|
||||
case CHMOD_APP:
|
||||
/* Parse the specified modes */
|
||||
if ( parse_mode(theMode, &(statbuf->st_mode)) == FALSE ) {
|
||||
fprintf(stderr, "%s: Unknown mode: %s\n", invocationName, theMode);
|
||||
exit( FALSE);
|
||||
}
|
||||
if (chmod(fileName, statbuf->st_mode) == 0)
|
||||
return( TRUE);
|
||||
break;
|
||||
}
|
||||
perror(fileName);
|
||||
return( FALSE);
|
||||
}
|
||||
|
||||
int chmod_chown_chgrp_main(int argc, char **argv)
|
||||
{
|
||||
int recursiveFlag=FALSE;
|
||||
char *groupName;
|
||||
const char *appUsage;
|
||||
|
||||
whichApp = (strcmp(*argv, "chown")==0)? CHOWN_APP : (strcmp(*argv, "chmod")==0)? CHMOD_APP : CHGRP_APP;
|
||||
|
||||
appUsage = (whichApp==CHOWN_APP)? chown_usage : (whichApp==CHMOD_APP)? chmod_usage : chgrp_usage;
|
||||
|
||||
if (argc < 2)
|
||||
usage( appUsage);
|
||||
invocationName=*argv;
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv)) switch (**argv) {
|
||||
case 'R':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unknown option: %c\n", **argv);
|
||||
usage( appUsage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
if ( whichApp == CHMOD_APP ) {
|
||||
theMode=*argv;
|
||||
} else {
|
||||
|
||||
/* Find the selected group */
|
||||
if ( whichApp==CHGRP_APP ) {
|
||||
groupName = *argv;
|
||||
gid = my_getgrnam(groupName);
|
||||
if (gid == -1)
|
||||
goto bad_group;
|
||||
} else {
|
||||
groupName = strchr(*argv, '.');
|
||||
if (groupName) {
|
||||
*groupName++ = '\0';
|
||||
gid = my_getgrnam(groupName);
|
||||
if (gid == -1)
|
||||
goto bad_group;
|
||||
} else
|
||||
gid = -1;
|
||||
}
|
||||
|
||||
|
||||
/* Find the selected user (if appropriate) */
|
||||
if (whichApp==CHOWN_APP) {
|
||||
uid = my_getpwnam(*argv);
|
||||
if (uid == -1) {
|
||||
fprintf(stderr, "%s: Unknown user name: %s\n", invocationName, *argv);
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Ok, ready to do the deed now */
|
||||
if (argc <= 1) {
|
||||
fprintf(stderr, "%s: too few arguments", invocationName);
|
||||
exit( FALSE);
|
||||
}
|
||||
while (argc-- > 1) {
|
||||
if (recursiveAction( *(++argv), recursiveFlag, TRUE, FALSE, fileAction, fileAction)==FALSE)
|
||||
exit( FALSE);
|
||||
}
|
||||
exit(TRUE);
|
||||
|
||||
bad_group:
|
||||
fprintf(stderr, "%s: Unknown group name: %s\n", invocationName, groupName);
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini chown/chmod/chgrp implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
|
||||
* Copyright (C) 1999,2000,2001 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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "busybox.h"
|
||||
|
||||
/* Don't use lchown for libc5 or glibc older then 2.1.x */
|
||||
#if (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 1)
|
||||
#define lchown chown
|
||||
#endif
|
||||
|
||||
static long uid;
|
||||
static long gid;
|
||||
|
||||
static int (*chown_func)(const char *, __uid_t, __gid_t) = chown;
|
||||
|
||||
static int fileAction(const char *fileName, struct stat *statbuf, void* junk)
|
||||
{
|
||||
if (chown_func(fileName, uid, (gid == -1) ? statbuf->st_gid : gid) == 0) {
|
||||
return (TRUE);
|
||||
}
|
||||
perror(fileName);
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
int chown_main(int argc, char **argv)
|
||||
{
|
||||
int opt;
|
||||
int recursiveFlag = FALSE,
|
||||
noderefFlag = FALSE;
|
||||
char *groupName=NULL;
|
||||
char *p=NULL;
|
||||
|
||||
/* do normal option parsing */
|
||||
while ((opt = getopt(argc, argv, "Rh")) > 0) {
|
||||
switch (opt) {
|
||||
case 'R':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
case 'h':
|
||||
noderefFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (noderefFlag) chown_func = lchown;
|
||||
|
||||
if (argc > optind && argc > 2 && argv[optind]) {
|
||||
/* First, check if there is a group name here */
|
||||
groupName = strchr(argv[optind], '.');
|
||||
if (groupName == NULL)
|
||||
groupName = strchr(argv[optind], ':');
|
||||
if (groupName) {
|
||||
*groupName++ = '\0';
|
||||
gid = strtoul(groupName, &p, 10);
|
||||
if (groupName == p)
|
||||
gid = my_getgrnam(groupName);
|
||||
} else {
|
||||
gid = -1;
|
||||
}
|
||||
/* Now check for the username */
|
||||
uid = strtoul(argv[optind], &p, 10); /* Is is numeric? */
|
||||
if (argv[optind] == p) {
|
||||
uid = my_getpwnam(argv[optind]);
|
||||
}
|
||||
} else {
|
||||
error_msg_and_die(too_few_args);
|
||||
}
|
||||
|
||||
/* Ok, ready to do the deed now */
|
||||
while (++optind < argc) {
|
||||
if (recursive_action (argv[optind], recursiveFlag, FALSE, FALSE,
|
||||
fileAction, fileAction, NULL) == FALSE) {
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -1,9 +1,10 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini chroot implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
|
||||
* Copyright (C) 1999,2000,2001 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
|
||||
@@ -21,46 +22,54 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n\n"
|
||||
"Run COMMAND with root directory set to NEWROOT.\n";
|
||||
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
int chroot_main(int argc, char **argv)
|
||||
{
|
||||
if ( (argc < 2) || (**(argv+1) == '-') ) {
|
||||
usage( chroot_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
if (chroot (*argv) || (chdir ("/"))) {
|
||||
fprintf(stderr, "chroot: cannot change root directory to %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc >= 1) {
|
||||
fprintf(stderr, "command: %s\n", *argv);
|
||||
execvp (*argv, argv);
|
||||
}
|
||||
else {
|
||||
char *prog;
|
||||
prog = getenv ("SHELL");
|
||||
if (!prog)
|
||||
prog = "/bin/sh";
|
||||
execlp (prog, prog, NULL);
|
||||
}
|
||||
fprintf(stderr, "chroot: cannot execute %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit( FALSE);
|
||||
|
||||
if ((argc < 2) || (**(argv + 1) == '-')) {
|
||||
show_usage();
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
if (chroot(*argv) || (chdir("/"))) {
|
||||
perror_msg_and_die("cannot change root directory to %s", *argv);
|
||||
}
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc >= 1) {
|
||||
prog = *argv;
|
||||
execvp(*argv, argv);
|
||||
} else {
|
||||
#if defined shell_main && defined BB_FEATURE_SH_STANDALONE_SHELL
|
||||
char shell[] = "/bin/sh";
|
||||
char *shell_argv[2] = { shell, NULL };
|
||||
applet_name = shell;
|
||||
shell_main(1, shell_argv);
|
||||
return EXIT_SUCCESS;
|
||||
#else
|
||||
prog = getenv("SHELL");
|
||||
if (!prog)
|
||||
prog = "/bin/sh";
|
||||
execlp(prog, prog, NULL);
|
||||
#endif
|
||||
}
|
||||
perror_msg_and_die("cannot execute %s", prog);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -1,36 +1,43 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* chvt.c - aeb - 940227 - Change virtual terminal
|
||||
*
|
||||
* busyboxed by Erik Andersen
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/vt.h>
|
||||
|
||||
/* getopt not needed */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include "busybox.h"
|
||||
|
||||
extern int getfd(void);
|
||||
/* From <linux/vt.h> */
|
||||
static const int VT_ACTIVATE = 0x5606; /* make vt active */
|
||||
static const int VT_WAITACTIVE = 0x5607; /* wait for vt active */
|
||||
|
||||
int
|
||||
chvt_main(int argc, char** argv)
|
||||
int chvt_main(int argc, char **argv)
|
||||
{
|
||||
int fd, num;
|
||||
int fd, num;
|
||||
|
||||
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
|
||||
usage ("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
|
||||
}
|
||||
fd = get_console_fd("/dev/console");
|
||||
num = atoi(argv[1]);
|
||||
if (ioctl(fd,VT_ACTIVATE,num)) {
|
||||
perror("VT_ACTIVATE");
|
||||
exit(FALSE);
|
||||
}
|
||||
if (ioctl(fd,VT_WAITACTIVE,num)) {
|
||||
perror("VT_WAITACTIVE");
|
||||
exit(FALSE);
|
||||
}
|
||||
exit( TRUE);
|
||||
if ((argc != 2) || (**(argv + 1) == '-'))
|
||||
show_usage();
|
||||
fd = get_console_fd();
|
||||
num = atoi(argv[1]);
|
||||
if (ioctl(fd, VT_ACTIVATE, num))
|
||||
perror_msg_and_die("VT_ACTIVATE");
|
||||
if (ioctl(fd, VT_WAITACTIVE, num))
|
||||
perror_msg_and_die("VT_WAITACTIVE");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -1,9 +1,10 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini clear implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
|
||||
* Copyright (C) 1999,2000,2001 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
|
||||
@@ -21,13 +22,13 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "busybox.h"
|
||||
|
||||
|
||||
extern int
|
||||
clear_main(int argc, char** argv)
|
||||
extern int clear_main(int argc, char **argv)
|
||||
{
|
||||
printf("\033[H\033[J");
|
||||
exit( TRUE);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
#ifndef CMDEDIT_H
|
||||
#define CMDEDIT_H
|
||||
|
||||
int cmdedit_read_input(char* promptStr, char* command);
|
||||
|
||||
#ifdef CONFIG_FEATURE_COMMAND_SAVEHISTORY
|
||||
void load_history ( const char *fromfile );
|
||||
void save_history ( const char *tofile );
|
||||
#endif
|
||||
|
||||
#endif /* CMDEDIT_H */
|
||||
@@ -0,0 +1,78 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini cmp implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999,2000,2001 by Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
#include "busybox.h"
|
||||
|
||||
int cmp_main(int argc, char **argv)
|
||||
{
|
||||
FILE *fp1 = NULL, *fp2 = stdin;
|
||||
char *filename1, *filename2 = "-";
|
||||
int c, c1, c2, char_pos = 1, line_pos = 1, silent = FALSE;
|
||||
|
||||
while ((c = getopt(argc, argv, "s")) != EOF) {
|
||||
switch (c) {
|
||||
case 's':
|
||||
silent = TRUE;
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
filename1 = argv[optind];
|
||||
switch (argc - optind) {
|
||||
case 2:
|
||||
fp2 = xfopen(filename2 = argv[optind + 1], "r");
|
||||
case 1:
|
||||
fp1 = xfopen(filename1, "r");
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
|
||||
do {
|
||||
c1 = fgetc(fp1);
|
||||
c2 = fgetc(fp2);
|
||||
if (c1 != c2) {
|
||||
if (silent)
|
||||
return EXIT_FAILURE;
|
||||
if (c1 == EOF)
|
||||
printf("EOF on %s\n", filename1);
|
||||
else if (c2 == EOF)
|
||||
printf("EOF on %s\n", filename2);
|
||||
else
|
||||
printf("%s %s differ: char %d, line %d\n", filename1, filename2,
|
||||
char_pos, line_pos);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
char_pos++;
|
||||
if (c1 == '\n')
|
||||
line_pos++;
|
||||
} while (c1 != EOF);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* chvt.c - aeb - 940227 - Change virtual terminal
|
||||
*
|
||||
* busyboxed by Erik Andersen
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/vt.h>
|
||||
#include <stdio.h>
|
||||
#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");
|
||||
}
|
||||
fd = get_console_fd("/dev/console");
|
||||
num = atoi(argv[1]);
|
||||
if (ioctl(fd,VT_ACTIVATE,num)) {
|
||||
perror("VT_ACTIVATE");
|
||||
exit(FALSE);
|
||||
}
|
||||
if (ioctl(fd,VT_WAITACTIVE,num)) {
|
||||
perror("VT_WAITACTIVE");
|
||||
exit(FALSE);
|
||||
}
|
||||
exit( TRUE);
|
||||
}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
|
||||
* Renamed deallocvt.
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/vt.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern int getfd(void);
|
||||
char *progname;
|
||||
|
||||
int
|
||||
deallocvt_main(int argc, char *argv[]) {
|
||||
int fd, num, i;
|
||||
|
||||
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
|
||||
usage ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
|
||||
}
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
fd = get_console_fd("/dev/console");
|
||||
|
||||
if (argc == 1) {
|
||||
/* deallocate all unused consoles */
|
||||
if (ioctl(fd,VT_DISALLOCATE,0)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
exit(1);
|
||||
}
|
||||
} else
|
||||
for (i = 1; i < argc; i++) {
|
||||
num = atoi(argv[i]);
|
||||
if (num == 0)
|
||||
fprintf(stderr, "%s: 0: illegal VT number\n", progname);
|
||||
else if (num == 1)
|
||||
fprintf(stderr, "%s: VT 1 cannot be deallocated\n", progname);
|
||||
else
|
||||
if (ioctl(fd,VT_DISALLOCATE,num)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
fprintf(stderr, "%s: could not deallocate console %d\n",
|
||||
progname, num);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
@@ -1,441 +0,0 @@
|
||||
/*
|
||||
* Derived from
|
||||
* mapscrn.c - version 0.92
|
||||
*
|
||||
* Was taken from console-tools and adapted by
|
||||
* Peter Novodvorsky <petya@logic.ru>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/kd.h>
|
||||
|
||||
typedef unsigned short unicode;
|
||||
|
||||
static long int ctoi(unsigned char *s, int *is_unicode);
|
||||
int old_screen_map_read_ascii(FILE *fp, unsigned char buf[]);
|
||||
int uni_screen_map_read_ascii(FILE *fp, unicode buf[], int* is_unicode);
|
||||
unicode utf8_to_ucs2 (char* buf);
|
||||
int screen_map_load(int fd, FILE *fp);
|
||||
|
||||
int loadacm_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open("/dev/tty", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty1: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (screen_map_load(fd, stdin))
|
||||
{
|
||||
fprintf(stderr, "Error loading acm: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
write(fd, "\033(K", 3);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int screen_map_load(int fd, FILE *fp)
|
||||
{
|
||||
struct stat stbuf;
|
||||
unicode wbuf[E_TABSZ];
|
||||
unsigned char buf[E_TABSZ];
|
||||
int parse_failed = 0;
|
||||
int is_unicode;
|
||||
|
||||
if (fstat(fp->_fileno, &stbuf))
|
||||
perror("Cannot stat map file"), exit(1);
|
||||
|
||||
/* first try a UTF screen-map: either ASCII (no restriction) or binary (regular file) */
|
||||
if (!(parse_failed = (-1 == uni_screen_map_read_ascii(fp,wbuf,&is_unicode))) ||
|
||||
(S_ISREG(stbuf.st_mode) &&
|
||||
(stbuf.st_size == (sizeof(unicode) * E_TABSZ)))) /* test for binary UTF map by size */
|
||||
{
|
||||
if (parse_failed)
|
||||
{
|
||||
if (-1 == fseek (fp, 0, SEEK_SET))
|
||||
{
|
||||
if (errno == ESPIPE)
|
||||
fprintf (stderr, "16bit screen-map MUST be a regular file.\n"), exit (1);
|
||||
else
|
||||
perror ("fseek failed reading binary 16bit screen-map"), exit (1);
|
||||
}
|
||||
|
||||
if (fread(wbuf, sizeof(unicode) * E_TABSZ, 1, fp) != 1)
|
||||
perror("Cannot read [new] map from file"), exit(1);
|
||||
#if 0
|
||||
else
|
||||
fprintf(stderr, "Input screen-map is binary.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
/* if it was effectively a 16-bit ASCII, OK, else try to read as 8-bit map */
|
||||
/* same if it was binary, ie. if parse_failed */
|
||||
if (parse_failed || is_unicode)
|
||||
{
|
||||
if (ioctl(fd,PIO_UNISCRNMAP,wbuf))
|
||||
perror("PIO_UNISCRNMAP ioctl"), exit(1);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* rewind... */
|
||||
if (-1 == fseek (fp, 0, SEEK_SET))
|
||||
{
|
||||
if (errno == ESPIPE)
|
||||
fprintf (stderr, "Assuming 8bit screen-map - MUST be a regular file.\n"), exit (1);
|
||||
else
|
||||
perror ("fseek failed assuming 8bit screen-map"), exit (1);
|
||||
}
|
||||
|
||||
/* ... and try an old 8-bit screen-map */
|
||||
if (!(parse_failed = (-1 == old_screen_map_read_ascii(fp,buf))) ||
|
||||
(S_ISREG(stbuf.st_mode) &&
|
||||
(stbuf.st_size == E_TABSZ))) /* test for binary old 8-bit map by size */
|
||||
{
|
||||
if (parse_failed)
|
||||
{
|
||||
if (-1 == fseek (fp, 0, SEEK_SET))
|
||||
{
|
||||
if (errno == ESPIPE)
|
||||
/* should not - it succedeed above */
|
||||
fprintf (stderr, "fseek() returned ESPIPE !\n"), exit (1);
|
||||
else
|
||||
perror ("fseek for binary 8bit screen-map"), exit (1);
|
||||
}
|
||||
|
||||
if (fread(buf,E_TABSZ,1,fp) != 1)
|
||||
perror("Cannot read [old] map from file"), exit(1);
|
||||
#if 0
|
||||
else
|
||||
fprintf(stderr, "Input screen-map is binary.\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
if (ioctl(fd,PIO_SCRNMAP,buf))
|
||||
perror("PIO_SCRNMAP ioctl"), exit(1);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Error parsing symbolic map\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* - reads `fp' as a 16-bit ASCII SFM file.
|
||||
* - returns -1 on error.
|
||||
* - returns it in `unicode' in an E_TABSZ-elements array.
|
||||
* - sets `*is_unicode' flagiff there were any non-8-bit
|
||||
* (ie. real 16-bit) mapping.
|
||||
*
|
||||
* FIXME: ignores everything after second word
|
||||
*/
|
||||
int uni_screen_map_read_ascii(FILE *fp, unicode buf[], int *is_unicode)
|
||||
{
|
||||
char buffer[256]; /* line buffer reading file */
|
||||
char *p, *q; /* 1st + 2nd words in line */
|
||||
int in, on; /* the same, as numbers */
|
||||
int tmp_is_unicode; /* tmp for is_unicode calculation */
|
||||
int i; /* loop index - result holder */
|
||||
int ret_code = 0; /* return code */
|
||||
sigset_t sigset, old_sigset;
|
||||
|
||||
assert (is_unicode);
|
||||
|
||||
*is_unicode = 0;
|
||||
|
||||
/* first 128 codes defaults to ASCII */
|
||||
for (i=0; i<128; i++) buf[i] = i;
|
||||
/* remaining defaults to replacement char (usually E_TABSZ = 256) */
|
||||
for ( ; i<E_TABSZ; i++) buf[i] = 0xfffd;
|
||||
|
||||
/* block SIGCHLD */
|
||||
sigemptyset (&sigset);
|
||||
sigaddset (&sigset, SIGCHLD);
|
||||
sigprocmask (SIG_BLOCK, &sigset, &old_sigset);
|
||||
|
||||
do
|
||||
{
|
||||
if (NULL == fgets(buffer, sizeof(buffer),fp))
|
||||
{
|
||||
if (feof (fp))
|
||||
break;
|
||||
else
|
||||
{
|
||||
perror ("uni_screen_map_read_ascii() can't read line");
|
||||
exit (2);
|
||||
}
|
||||
}
|
||||
|
||||
/* get "charset-relative charcode", stripping leading spaces */
|
||||
p = strtok(buffer," \t\n");
|
||||
|
||||
/* skip empty lines and comments */
|
||||
if (!p || *p == '#')
|
||||
continue;
|
||||
|
||||
/* get unicode mapping */
|
||||
q = strtok(NULL," \t\n");
|
||||
if (q)
|
||||
{
|
||||
in = ctoi(p, NULL);
|
||||
if (in < 0 || in > 255)
|
||||
{
|
||||
ret_code = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
on = ctoi(q, &tmp_is_unicode);
|
||||
if (in < 0 && on > 65535)
|
||||
{
|
||||
ret_code = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
*is_unicode |= tmp_is_unicode;
|
||||
buf[in] = on;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret_code = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (1); /* terminated by break on feof() */
|
||||
|
||||
/* restore sig mask */
|
||||
sigprocmask (SIG_SETMASK, &old_sigset, NULL);
|
||||
|
||||
return ret_code;
|
||||
}
|
||||
|
||||
|
||||
int old_screen_map_read_ascii(FILE *fp, unsigned char buf[])
|
||||
{
|
||||
char buffer[256];
|
||||
int in, on;
|
||||
char *p, *q;
|
||||
|
||||
for (in=0; in<256; in++) buf[in]=in;
|
||||
|
||||
while (fgets(buffer,sizeof(buffer)-1,fp))
|
||||
{
|
||||
p = strtok(buffer," \t\n");
|
||||
|
||||
if (!p || *p == '#')
|
||||
continue;
|
||||
|
||||
q = strtok(NULL," \t\n#");
|
||||
if (q)
|
||||
{
|
||||
in = ctoi(p, NULL);
|
||||
if (in < 0 || in > 255) return -1;
|
||||
|
||||
on = ctoi(q, NULL);
|
||||
if (in < 0 && on > 255) return -1;
|
||||
|
||||
buf[in] = on;
|
||||
}
|
||||
else return -1;
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* - converts a string into an int.
|
||||
* - supports dec and hex bytes, hex UCS2, single-quoted byte and UTF8 chars.
|
||||
* - returns the converted value
|
||||
* - if `is_unicode != NULL', use it to tell whether it was unicode
|
||||
*
|
||||
* CAVEAT: will report valid UTF mappings using only 1 byte as 8-bit ones.
|
||||
*/
|
||||
long int ctoi(unsigned char *s, int *is_unicode)
|
||||
{
|
||||
int i;
|
||||
size_t ls;
|
||||
|
||||
ls = strlen(s);
|
||||
if (is_unicode) *is_unicode = 0;
|
||||
|
||||
/* hex-specified UCS2 */
|
||||
if ((strncmp(s,"U+",2) == 0) &&
|
||||
(strspn(s+2,"0123456789abcdefABCDEF") == ls-2))
|
||||
{
|
||||
sscanf(s+2,"%x",&i);
|
||||
if (is_unicode) *is_unicode = 1;
|
||||
}
|
||||
|
||||
/* hex-specified byte */
|
||||
else if ((ls <= 4) && (strncmp(s,"0x",2) == 0) &&
|
||||
(strspn(s+2,"0123456789abcdefABCDEF") == ls-2))
|
||||
sscanf(s+2,"%x",&i);
|
||||
|
||||
/* oct-specified number (byte) */
|
||||
else if ((*s == '0') &&
|
||||
(strspn(s,"01234567") == ls))
|
||||
sscanf(s,"%o",&i);
|
||||
|
||||
/* dec-specified number (byte) */
|
||||
else if (strspn(s,"0123456789") == ls)
|
||||
sscanf(s,"%d",&i);
|
||||
|
||||
/* single-byte quoted char */
|
||||
else if ((strlen(s) == 3) && (s[0] == '\'') && (s[2] == '\''))
|
||||
i=s[1];
|
||||
|
||||
/* multi-byte UTF8 quoted char */
|
||||
else if ((s[0] == '\'') && (s[ls-1] == '\''))
|
||||
{
|
||||
s[ls-1] = 0; /* ensure we'll not "parse UTF too far" */
|
||||
i = utf8_to_ucs2(s+1);
|
||||
if (is_unicode) *is_unicode = 1;
|
||||
}
|
||||
else
|
||||
return(-1);
|
||||
|
||||
return(i);
|
||||
}
|
||||
|
||||
|
||||
void saveoldmap(int fd, char *omfil)
|
||||
{
|
||||
FILE *fp;
|
||||
char buf[E_TABSZ];
|
||||
#ifdef GIO_UNISCRNMAP
|
||||
unicode xbuf[E_TABSZ];
|
||||
int is_old_map = 0;
|
||||
|
||||
if (ioctl(fd,GIO_UNISCRNMAP,xbuf))
|
||||
{
|
||||
perror("GIO_UNISCRNMAP ioctl error");
|
||||
#endif
|
||||
if (ioctl(fd,GIO_SCRNMAP,buf))
|
||||
{
|
||||
perror("GIO_SCRNMAP ioctl error");
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
is_old_map = 1;
|
||||
#ifdef GIO_UNISCRNMAP
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((fp = fopen(omfil, "w")) == NULL)
|
||||
{
|
||||
perror(omfil);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#ifdef GIO_UNISCRNMAP
|
||||
if (is_old_map)
|
||||
{
|
||||
#endif
|
||||
if (fwrite(buf,E_TABSZ,1,fp) != 1)
|
||||
{
|
||||
perror("Error writing map to file");
|
||||
exit(1);
|
||||
}
|
||||
#ifdef GIO_UNISCRNMAP
|
||||
}
|
||||
else
|
||||
if (fwrite(xbuf, sizeof(unicode) * E_TABSZ,1,fp) != 1)
|
||||
{
|
||||
perror("Error writing map to file");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
unicode utf8_to_ucs2 (char* buf)
|
||||
{
|
||||
int utf_count = 0;
|
||||
long utf_char;
|
||||
unicode tc;
|
||||
unsigned char c;
|
||||
|
||||
do
|
||||
{
|
||||
c = *buf;
|
||||
buf++;
|
||||
|
||||
/* if byte should be part of multi-byte sequence */
|
||||
if(c & 0x80)
|
||||
{
|
||||
/* if we have already started to parse a UTF8 sequence */
|
||||
if (utf_count > 0 && (c & 0xc0) == 0x80)
|
||||
{
|
||||
utf_char = (utf_char << 6) | (c & 0x3f);
|
||||
utf_count--;
|
||||
if (utf_count == 0)
|
||||
tc = utf_char;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
else /* Possibly 1st char of a UTF8 sequence */
|
||||
{
|
||||
if ((c & 0xe0) == 0xc0)
|
||||
{
|
||||
utf_count = 1;
|
||||
utf_char = (c & 0x1f);
|
||||
}
|
||||
else if ((c & 0xf0) == 0xe0)
|
||||
{
|
||||
utf_count = 2;
|
||||
utf_char = (c & 0x0f);
|
||||
}
|
||||
else if ((c & 0xf8) == 0xf0)
|
||||
{
|
||||
utf_count = 3;
|
||||
utf_char = (c & 0x07);
|
||||
}
|
||||
else if ((c & 0xfc) == 0xf8)
|
||||
{
|
||||
utf_count = 4;
|
||||
utf_char = (c & 0x03);
|
||||
}
|
||||
else if ((c & 0xfe) == 0xfc)
|
||||
{
|
||||
utf_count = 5;
|
||||
utf_char = (c & 0x01);
|
||||
}
|
||||
else
|
||||
utf_count = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else /* not part of multi-byte sequence - treat as ASCII
|
||||
* this makes incomplete sequences to be ignored
|
||||
*/
|
||||
{
|
||||
tc = c;
|
||||
utf_count = 0;
|
||||
}
|
||||
}
|
||||
while (utf_count);
|
||||
|
||||
return tc;
|
||||
}
|
||||
|
||||
@@ -1,234 +0,0 @@
|
||||
/*
|
||||
* loadfont.c - Eugene Crosser & Andries Brouwer
|
||||
*
|
||||
* Version 0.96bb
|
||||
*
|
||||
* Loads the console font, and possibly the corresponding screen map(s).
|
||||
* (Adapted for busybox by Matej Vela.)
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <memory.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/kd.h>
|
||||
#include <endian.h>
|
||||
|
||||
#define PSF_MAGIC1 0x36
|
||||
#define PSF_MAGIC2 0x04
|
||||
|
||||
#define PSF_MODE512 0x01
|
||||
#define PSF_MODEHASTAB 0x02
|
||||
#define PSF_MAXMODE 0x03
|
||||
#define PSF_SEPARATOR 0xFFFF
|
||||
|
||||
static const char loadfont_usage[] = "loadfont\n"
|
||||
"\n"
|
||||
"\tLoad a console font from standard input.\n"
|
||||
"\n";
|
||||
|
||||
struct psf_header
|
||||
{
|
||||
unsigned char magic1, magic2; /* Magic number */
|
||||
unsigned char mode; /* PSF font mode */
|
||||
unsigned char charsize; /* Character size */
|
||||
};
|
||||
|
||||
#define PSF_MAGIC_OK(x) ((x).magic1 == PSF_MAGIC1 && (x).magic2 == PSF_MAGIC2)
|
||||
|
||||
static void loadnewfont(int fd);
|
||||
|
||||
extern int
|
||||
loadfont_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open("/dev/tty0", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
loadnewfont(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
do_loadfont(int fd, char *inbuf, int unit, int fontsize) {
|
||||
char buf[16384];
|
||||
int i;
|
||||
|
||||
memset(buf,0,sizeof(buf));
|
||||
|
||||
if (unit < 1 || unit > 32) {
|
||||
fprintf(stderr, "Bad character size %d\n", unit);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
for (i = 0; i < fontsize; i++)
|
||||
memcpy(buf+(32*i), inbuf+(unit*i), unit);
|
||||
|
||||
#if defined( PIO_FONTX ) && !defined( __sparc__ )
|
||||
{
|
||||
struct consolefontdesc cfd;
|
||||
|
||||
cfd.charcount = fontsize;
|
||||
cfd.charheight = unit;
|
||||
cfd.chardata = buf;
|
||||
|
||||
if (ioctl(fd, PIO_FONTX, &cfd) == 0)
|
||||
return; /* success */
|
||||
perror("PIO_FONTX ioctl error (trying PIO_FONT)");
|
||||
}
|
||||
#endif
|
||||
if (ioctl(fd, PIO_FONT, buf)) {
|
||||
perror("PIO_FONT ioctl error");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize) {
|
||||
struct unimapinit advice;
|
||||
struct unimapdesc ud;
|
||||
struct unipair *up;
|
||||
int ct = 0, maxct;
|
||||
int glyph;
|
||||
u_short unicode;
|
||||
|
||||
maxct = tailsz; /* more than enough */
|
||||
up = (struct unipair *) malloc(maxct * sizeof(struct unipair));
|
||||
if (!up) {
|
||||
fprintf(stderr, "Out of memory?\n");
|
||||
exit(1);
|
||||
}
|
||||
for (glyph = 0; glyph < fontsize; glyph++) {
|
||||
while (tailsz >= 2) {
|
||||
unicode = (((u_short) inbuf[1]) << 8) + inbuf[0];
|
||||
tailsz -= 2;
|
||||
inbuf += 2;
|
||||
if (unicode == PSF_SEPARATOR)
|
||||
break;
|
||||
up[ct].unicode = unicode;
|
||||
up[ct].fontpos = glyph;
|
||||
ct++;
|
||||
}
|
||||
}
|
||||
|
||||
/* Note: after PIO_UNIMAPCLR and before PIO_UNIMAP
|
||||
this printf did not work on many kernels */
|
||||
|
||||
advice.advised_hashsize = 0;
|
||||
advice.advised_hashstep = 0;
|
||||
advice.advised_hashlevel = 0;
|
||||
if(ioctl(fd, PIO_UNIMAPCLR, &advice)) {
|
||||
#ifdef ENOIOCTLCMD
|
||||
if (errno == ENOIOCTLCMD) {
|
||||
fprintf(stderr, "It seems this kernel is older than 1.1.92\n");
|
||||
fprintf(stderr, "No Unicode mapping table loaded.\n");
|
||||
} else
|
||||
#endif
|
||||
perror("PIO_UNIMAPCLR");
|
||||
exit(1);
|
||||
}
|
||||
ud.entry_ct = ct;
|
||||
ud.entries = up;
|
||||
if(ioctl(fd, PIO_UNIMAP, &ud)) {
|
||||
#if 0
|
||||
if (errno == ENOMEM) {
|
||||
/* change advice parameters */
|
||||
}
|
||||
#endif
|
||||
perror("PIO_UNIMAP");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
loadnewfont(int fd) {
|
||||
int unit;
|
||||
char inbuf[32768]; /* primitive */
|
||||
int inputlth, offset;
|
||||
|
||||
/*
|
||||
* We used to look at the length of the input file
|
||||
* with stat(); now that we accept compressed files,
|
||||
* just read the entire file.
|
||||
*/
|
||||
inputlth = fread(inbuf, 1, sizeof(inbuf), stdin);
|
||||
if (ferror(stdin)) {
|
||||
perror("Error reading input font");
|
||||
exit(1);
|
||||
}
|
||||
/* use malloc/realloc in case of giant files;
|
||||
maybe these do not occur: 16kB for the font,
|
||||
and 16kB for the map leaves 32 unicode values
|
||||
for each font position */
|
||||
if (!feof(stdin)) {
|
||||
perror("Font too large");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* test for psf first */
|
||||
{
|
||||
struct psf_header psfhdr;
|
||||
int fontsize;
|
||||
int hastable;
|
||||
int head0, head;
|
||||
|
||||
if (inputlth < sizeof(struct psf_header))
|
||||
goto no_psf;
|
||||
|
||||
psfhdr = * (struct psf_header *) &inbuf[0];
|
||||
|
||||
if (!PSF_MAGIC_OK(psfhdr))
|
||||
goto no_psf;
|
||||
|
||||
if (psfhdr.mode > PSF_MAXMODE) {
|
||||
fprintf(stderr, "Unsupported psf file mode\n");
|
||||
exit(1);
|
||||
}
|
||||
fontsize = ((psfhdr.mode & PSF_MODE512) ? 512 : 256);
|
||||
#if !defined( PIO_FONTX ) || defined( __sparc__ )
|
||||
if (fontsize != 256) {
|
||||
fprintf(stderr, "Only fontsize 256 supported\n");
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
hastable = (psfhdr.mode & PSF_MODEHASTAB);
|
||||
unit = psfhdr.charsize;
|
||||
head0 = sizeof(struct psf_header);
|
||||
head = head0 + fontsize*unit;
|
||||
if (head > inputlth || (!hastable && head != inputlth)) {
|
||||
fprintf(stderr, "Input file: bad length\n");
|
||||
exit(1);
|
||||
}
|
||||
do_loadfont(fd, inbuf + head0, unit, fontsize);
|
||||
if (hastable)
|
||||
do_loadtable(fd, inbuf + head, inputlth-head, fontsize);
|
||||
return;
|
||||
}
|
||||
no_psf:
|
||||
|
||||
/* file with three code pages? */
|
||||
if (inputlth == 9780) {
|
||||
offset = 40;
|
||||
unit = 16;
|
||||
} else {
|
||||
/* bare font */
|
||||
if (inputlth & 0377) {
|
||||
fprintf(stderr, "Bad input file size\n");
|
||||
exit(1);
|
||||
}
|
||||
offset = 0;
|
||||
unit = inputlth/256;
|
||||
}
|
||||
do_loadfont(fd, inbuf+offset, unit, 256);
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* Mini loadkmap implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1998 Enrique Zanardi <ezanardi@ull.es>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <linux/kd.h>
|
||||
#include <linux/keyboard.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
|
||||
static const char loadkmap_usage[] = "loadkmap\n"
|
||||
"\n"
|
||||
"\tLoad a binary keyboard translation table from standard input.\n"
|
||||
"\n";
|
||||
|
||||
|
||||
int
|
||||
loadkmap_main(int argc, char * * argv)
|
||||
{
|
||||
struct kbentry ke;
|
||||
u_short *ibuff;
|
||||
int i,j,fd,readsz,pos,ibuffsz=NR_KEYS * sizeof(u_short);
|
||||
char flags[MAX_NR_KEYMAPS],magic[]="bkeymap",buff[7];
|
||||
|
||||
fd = open("/dev/tty0", O_RDWR);
|
||||
if (fd < 0) {
|
||||
fprintf(stderr, "Error opening /dev/tty0: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
read(0,buff,7);
|
||||
if (0 != strncmp(buff,magic,7)) {
|
||||
fprintf(stderr, "This is not a valid binary keymap.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( MAX_NR_KEYMAPS != read(0,flags,MAX_NR_KEYMAPS) ) {
|
||||
fprintf(stderr, "Error reading keymap flags: %s\n", strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
ibuff=(u_short *) malloc(ibuffsz);
|
||||
if (!ibuff) {
|
||||
fprintf(stderr, "Out of memory.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for(i=0; i<MAX_NR_KEYMAPS; i++) {
|
||||
if (flags[i]==1){
|
||||
pos=0;
|
||||
while (pos < ibuffsz) {
|
||||
if ( (readsz = read(0,(char *)ibuff+pos,ibuffsz-pos)) < 0 ) {
|
||||
fprintf(stderr, "Error reading keymap: %s\n",
|
||||
strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
pos += readsz;
|
||||
}
|
||||
for(j=0; j<NR_KEYS; j++) {
|
||||
ke.kb_index = j;
|
||||
ke.kb_table = i;
|
||||
ke.kb_value = ibuff[j];
|
||||
ioctl(fd, KDSKBENT, &ke);
|
||||
}
|
||||
}
|
||||
}
|
||||
close (fd);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Mini chroot implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n\n"
|
||||
"Run COMMAND with root directory set to NEWROOT.\n";
|
||||
|
||||
|
||||
|
||||
int chroot_main(int argc, char **argv)
|
||||
{
|
||||
if ( (argc < 2) || (**(argv+1) == '-') ) {
|
||||
usage( chroot_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
if (chroot (*argv) || (chdir ("/"))) {
|
||||
fprintf(stderr, "chroot: cannot change root directory to %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
if (argc >= 1) {
|
||||
fprintf(stderr, "command: %s\n", *argv);
|
||||
execvp (*argv, argv);
|
||||
}
|
||||
else {
|
||||
char *prog;
|
||||
prog = getenv ("SHELL");
|
||||
if (!prog)
|
||||
prog = "/bin/sh";
|
||||
execlp (prog, prog, NULL);
|
||||
}
|
||||
fprintf(stderr, "chroot: cannot execute %s: %s\n",
|
||||
*argv, strerror(errno));
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
-127
@@ -1,127 +0,0 @@
|
||||
/*
|
||||
* Mini cp implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <dirent.h>
|
||||
|
||||
static const char cp_usage[] = "cp [OPTION]... SOURCE DEST\n"
|
||||
" or: cp [OPTION]... SOURCE... DIRECTORY\n\n"
|
||||
"Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n"
|
||||
"\n"
|
||||
"\t-a\tsame as -dpR\n"
|
||||
"\t-d\tpreserve links\n"
|
||||
"\t-p\tpreserve file attributes if possible\n"
|
||||
"\t-R\tcopy directories recursively\n";
|
||||
|
||||
|
||||
static int recursiveFlag = FALSE;
|
||||
static int followLinks = FALSE;
|
||||
static int preserveFlag = FALSE;
|
||||
static const char *srcName;
|
||||
static const char *destName;
|
||||
static int destDirFlag = FALSE;
|
||||
static int srcDirFlag = FALSE;
|
||||
|
||||
static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
char newdestName[NAME_MAX];
|
||||
char* newsrcName = NULL;
|
||||
|
||||
strcpy(newdestName, destName);
|
||||
if ( srcDirFlag == TRUE ) {
|
||||
if (recursiveFlag!=TRUE ) {
|
||||
fprintf(stderr, "cp: %s: omitting directory\n", srcName);
|
||||
return( TRUE);
|
||||
}
|
||||
strcat(newdestName, strstr(fileName, srcName) + strlen(srcName));
|
||||
}
|
||||
|
||||
if (destDirFlag==TRUE && srcDirFlag == FALSE) {
|
||||
if (newdestName[strlen(newdestName)-1] != '/' ) {
|
||||
strcat(newdestName, "/");
|
||||
}
|
||||
newsrcName = strrchr(srcName, '/');
|
||||
if (newsrcName && *newsrcName != '\0')
|
||||
strcat(newdestName, newsrcName);
|
||||
else
|
||||
strcat(newdestName, srcName);
|
||||
}
|
||||
|
||||
return (copyFile(fileName, newdestName, preserveFlag, followLinks));
|
||||
}
|
||||
|
||||
extern int cp_main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 3) {
|
||||
usage (cp_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 'a':
|
||||
followLinks = TRUE;
|
||||
preserveFlag = TRUE;
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
case 'd':
|
||||
followLinks = TRUE;
|
||||
break;
|
||||
case 'p':
|
||||
preserveFlag = TRUE;
|
||||
break;
|
||||
case 'R':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage (cp_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
|
||||
destName = argv[argc - 1];
|
||||
destDirFlag = isDirectory(destName);
|
||||
|
||||
if ((argc > 3) && destDirFlag==FALSE) {
|
||||
fprintf(stderr, "%s: not a directory\n", destName);
|
||||
exit (FALSE);
|
||||
}
|
||||
|
||||
while (argc-- > 1) {
|
||||
srcName = *(argv++);
|
||||
srcDirFlag = isDirectory(srcName);
|
||||
if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE,
|
||||
fileAction, fileAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
exit( TRUE);
|
||||
}
|
||||
@@ -1,287 +0,0 @@
|
||||
/*
|
||||
* Mini date implementation for busybox
|
||||
*
|
||||
* by Matthew Grant <grantma@anathoth.gen.nz>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
/* This 'date' command supports only 2 time setting formats,
|
||||
all the GNU strftime stuff (its in libc, lets use it),
|
||||
setting time using UTC and displaying int, as well as
|
||||
an RFC 822 complient date output for shell scripting
|
||||
mail commands */
|
||||
|
||||
static const char date_usage[] = "date [OPTION]... [+FORMAT]\n"
|
||||
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n\n"
|
||||
"Display the current time in the given FORMAT, or set the system date.\n"
|
||||
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
|
||||
"\t-s\t\tset time described by STRING\n"
|
||||
"\t-u\t\tprint or set Coordinated Universal Time\n";
|
||||
|
||||
|
||||
/* Input parsing code is always bulky - used heavy duty libc stuff as
|
||||
much as possible, missed out a lot of bounds checking */
|
||||
|
||||
/* Default input handling to save suprising some people */
|
||||
|
||||
struct tm *
|
||||
date_conv_time(struct tm *tm_time, const char *t_string) {
|
||||
int nr;
|
||||
|
||||
nr = sscanf(t_string, "%2d%2d%2d%2d%d",
|
||||
&(tm_time->tm_mon),
|
||||
&(tm_time->tm_mday),
|
||||
&(tm_time->tm_hour),
|
||||
&(tm_time->tm_min),
|
||||
&(tm_time->tm_year));
|
||||
|
||||
if(nr < 4 || nr > 5) {
|
||||
fprintf(stderr, "date: invalid date `%s'\n", t_string);
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
/* correct for century - minor Y2K problem here? */
|
||||
if(tm_time->tm_year >= 1900)
|
||||
tm_time->tm_year -= 1900;
|
||||
/* adjust date */
|
||||
tm_time->tm_mon -= 1;
|
||||
|
||||
return(tm_time);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* The new stuff for LRP */
|
||||
|
||||
struct tm *
|
||||
date_conv_ftime(struct tm *tm_time, const char *t_string) {
|
||||
struct tm itm_time, jtm_time, ktm_time, \
|
||||
ltm_time, mtm_time, ntm_time;
|
||||
|
||||
itm_time = *tm_time;
|
||||
jtm_time = *tm_time;
|
||||
ktm_time = *tm_time;
|
||||
ltm_time = *tm_time;
|
||||
mtm_time = *tm_time;
|
||||
ntm_time = *tm_time;
|
||||
|
||||
/* Parse input and assign appropriately to tm_time */
|
||||
|
||||
if(sscanf(t_string, "%d:%d:%d",
|
||||
&itm_time.tm_hour,
|
||||
&itm_time.tm_min,
|
||||
&itm_time.tm_sec) == 3 ) {
|
||||
|
||||
*tm_time = itm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d:%d",
|
||||
&jtm_time.tm_hour,
|
||||
&jtm_time.tm_min) == 2) {
|
||||
|
||||
*tm_time = jtm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d-%d:%d:%d",
|
||||
&ktm_time.tm_mon,
|
||||
&ktm_time.tm_mday,
|
||||
&ktm_time.tm_hour,
|
||||
&ktm_time.tm_min,
|
||||
&ktm_time.tm_sec) == 5) {
|
||||
|
||||
ktm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = ktm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d-%d:%d",
|
||||
<m_time.tm_mon,
|
||||
<m_time.tm_mday,
|
||||
<m_time.tm_hour,
|
||||
<m_time.tm_min) == 4) {
|
||||
|
||||
ltm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = ltm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d.%d-%d:%d:%d",
|
||||
&mtm_time.tm_year,
|
||||
&mtm_time.tm_mon,
|
||||
&mtm_time.tm_mday,
|
||||
&mtm_time.tm_hour,
|
||||
&mtm_time.tm_min,
|
||||
&mtm_time.tm_sec) == 6) {
|
||||
|
||||
mtm_time.tm_year -= 1900; /* Adjust years */
|
||||
mtm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = mtm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d.%d-%d:%d",
|
||||
&ntm_time.tm_year,
|
||||
&ntm_time.tm_mon,
|
||||
&ntm_time.tm_mday,
|
||||
&ntm_time.tm_hour,
|
||||
&ntm_time.tm_min) == 5) {
|
||||
ntm_time.tm_year -= 1900; /* Adjust years */
|
||||
ntm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = ntm_time;
|
||||
return(tm_time);
|
||||
|
||||
}
|
||||
|
||||
fprintf(stderr, "date: invalid date `%s'\n", t_string);
|
||||
|
||||
exit( FALSE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
date_main(int argc, char * * argv)
|
||||
{
|
||||
char *date_str = NULL;
|
||||
char *date_fmt = NULL;
|
||||
char *t_buff;
|
||||
int i;
|
||||
int set_time = 0;
|
||||
int rfc822 = 0;
|
||||
int utc = 0;
|
||||
int use_arg = 0;
|
||||
time_t tm;
|
||||
struct tm tm_time;
|
||||
|
||||
/* Interpret command line args */
|
||||
i = --argc;
|
||||
argv++;
|
||||
while (i > 0 && **argv) {
|
||||
if (**argv == '-') {
|
||||
while (i>0 && *++(*argv)) switch (**argv) {
|
||||
case 'R':
|
||||
rfc822 = 1;
|
||||
break;
|
||||
case 's':
|
||||
set_time = 1;
|
||||
if(date_str != NULL) usage ( date_usage);
|
||||
date_str = optarg;
|
||||
break;
|
||||
case 'u':
|
||||
utc = 1;
|
||||
if (putenv ("TZ=UTC0") != 0) {
|
||||
fprintf(stderr,"date: memory exhausted\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
/* Look ma, no break. Don't fix it either. */
|
||||
case 'd':
|
||||
use_arg = 1;
|
||||
if(date_str != NULL) usage ( date_usage);
|
||||
date_str = optarg;
|
||||
break;
|
||||
case '-':
|
||||
usage ( date_usage);
|
||||
}
|
||||
} else {
|
||||
if ( (date_fmt == NULL) && (strcmp(*argv, "+")==0) )
|
||||
date_fmt=*argv;
|
||||
else if (date_str == NULL) {
|
||||
set_time = 1;
|
||||
date_str=*argv;
|
||||
} else {
|
||||
usage ( date_usage);
|
||||
}
|
||||
}
|
||||
i--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
|
||||
/* Now we have parsed all the information except the date format
|
||||
which depends on whether the clock is being set or read */
|
||||
|
||||
time(&tm);
|
||||
memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
|
||||
/* Zero out fields - take her back to midnight!*/
|
||||
if(date_str != NULL) {
|
||||
tm_time.tm_sec = 0;
|
||||
tm_time.tm_min = 0;
|
||||
tm_time.tm_hour = 0;
|
||||
}
|
||||
|
||||
/* Process any date input to UNIX time since 1 Jan 1970 */
|
||||
if(date_str != NULL) {
|
||||
|
||||
if(strchr(date_str, ':') != NULL) {
|
||||
date_conv_ftime(&tm_time, date_str);
|
||||
} else {
|
||||
date_conv_time(&tm_time, date_str);
|
||||
}
|
||||
|
||||
/* Correct any day of week and day of year etc fields */
|
||||
tm = mktime(&tm_time);
|
||||
if (tm < 0 ) {
|
||||
fprintf(stderr, "date: invalid date `%s'\n", date_str);
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
/* if setting time, set it */
|
||||
if(set_time) {
|
||||
if( stime(&tm) < 0) {
|
||||
fprintf(stderr, "date: can't set date.\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Display output */
|
||||
|
||||
/* Deal with format string */
|
||||
if(date_fmt == NULL) {
|
||||
date_fmt = (rfc822
|
||||
? (utc
|
||||
? "%a, %_d %b %Y %H:%M:%S GMT"
|
||||
: "%a, %_d %b %Y %H:%M:%S %z")
|
||||
: "%a %b %e %H:%M:%S %Z %Y");
|
||||
|
||||
} else if ( *date_fmt == '\0' ) {
|
||||
/* Imitate what GNU 'date' does with NO format string! */
|
||||
printf ("\n");
|
||||
exit( TRUE);
|
||||
}
|
||||
|
||||
/* Handle special conversions */
|
||||
|
||||
if( strncmp( date_fmt, "%f", 2) == 0 ) {
|
||||
date_fmt = "%Y.%m.%d-%H:%M:%S";
|
||||
}
|
||||
|
||||
/* Print OUTPUT (after ALL that!) */
|
||||
t_buff = malloc(201);
|
||||
strftime(t_buff, 200, date_fmt, &tm_time);
|
||||
printf("%s\n", t_buff);
|
||||
|
||||
exit( TRUE);
|
||||
|
||||
}
|
||||
|
||||
-194
@@ -1,194 +0,0 @@
|
||||
/*
|
||||
* Mini dd implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* based in part on code taken from sash.
|
||||
*
|
||||
* Copyright (c) 1999 by David I. Bell
|
||||
* Permission is granted to use, distribute, or modify this source,
|
||||
* provided that this copyright notice remains intact.
|
||||
*
|
||||
* Permission to distribute this code under the GPL has been granted.
|
||||
*
|
||||
* 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 <features.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
typedef unsigned long long int uintmax_t;
|
||||
#endif
|
||||
|
||||
static const char dd_usage[] =
|
||||
"dd [if=name] [of=name] [bs=n] [count=n]\n\n"
|
||||
"Copy a file, converting and formatting according to options\n\n"
|
||||
"\tif=FILE\tread from FILE instead of stdin\n"
|
||||
"\tof=FILE\twrite to FILE instead of stout\n"
|
||||
"\tbs=n\tread and write N BYTES at a time\n"
|
||||
"\tcount=n\tcopy only n input blocks\n"
|
||||
//"\tskip=n\tskip n input blocks\n"
|
||||
"\n"
|
||||
"BYTES may be suffixed by w (x2), k (x1024), b (x512), or m (x1024^2).\n";
|
||||
|
||||
|
||||
|
||||
extern int dd_main (int argc, char **argv)
|
||||
{
|
||||
const char *inFile = NULL;
|
||||
const char *outFile = NULL;
|
||||
char *cp;
|
||||
int inFd;
|
||||
int outFd;
|
||||
int inCc = 0;
|
||||
int outCc;
|
||||
size_t blockSize = 512;
|
||||
//uintmax_t skipBlocks = 0;
|
||||
uintmax_t count = (uintmax_t)-1;
|
||||
uintmax_t intotal;
|
||||
uintmax_t outTotal;
|
||||
unsigned char *buf;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (argc) {
|
||||
if (inFile == NULL && (strncmp(*argv, "if", 2) == 0))
|
||||
inFile=((strchr(*argv, '='))+1);
|
||||
else if (outFile == NULL && (strncmp(*argv, "of", 2) == 0))
|
||||
outFile=((strchr(*argv, '='))+1);
|
||||
else if (strncmp("count", *argv, 5) == 0) {
|
||||
count = getNum ((strchr(*argv, '='))+1);
|
||||
if (count <= 0) {
|
||||
fprintf (stderr, "Bad count value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
else if (strncmp(*argv, "bs", 2) == 0) {
|
||||
blockSize = getNum ((strchr(*argv, '='))+1);
|
||||
if (blockSize <= 0) {
|
||||
fprintf (stderr, "Bad block size value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
else if (strncmp(*argv, "skip", 4) == 0) {
|
||||
skipBlocks = atoi( *argv);
|
||||
if (skipBlocks <= 0) {
|
||||
fprintf (stderr, "Bad skip value %d\n", skipBlocks);
|
||||
goto usage;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
goto usage;
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
buf = malloc (blockSize);
|
||||
if (buf == NULL) {
|
||||
fprintf (stderr, "Cannot allocate buffer\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
intotal = 0;
|
||||
outTotal = 0;
|
||||
|
||||
if (inFile == NULL)
|
||||
inFd = fileno(stdin);
|
||||
else
|
||||
inFd = open (inFile, 0);
|
||||
|
||||
if (inFd < 0) {
|
||||
perror (inFile);
|
||||
free (buf);
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
if (outFile == NULL)
|
||||
outFd = fileno(stdout);
|
||||
else
|
||||
outFd = creat (outFile, 0666);
|
||||
|
||||
if (outFd < 0) {
|
||||
perror (outFile);
|
||||
close (inFd);
|
||||
free (buf);
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
//lseek(inFd, skipBlocks*blockSize, SEEK_SET);
|
||||
//
|
||||
//TODO: Convert to using fullRead & fullWrite
|
||||
// from utilitity.c
|
||||
// -Erik
|
||||
while (outTotal < count * blockSize) {
|
||||
inCc = read (inFd, buf, blockSize);
|
||||
if (inCc < 0) {
|
||||
perror (inFile);
|
||||
goto cleanup;
|
||||
} else if (inCc == 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
intotal += inCc;
|
||||
cp = buf;
|
||||
|
||||
while (intotal > outTotal) {
|
||||
if (outTotal + inCc > count * blockSize)
|
||||
inCc = count * blockSize - outTotal;
|
||||
outCc = write (outFd, cp, inCc);
|
||||
if (outCc < 0) {
|
||||
perror (outFile);
|
||||
goto cleanup;
|
||||
} else if (outCc == 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
inCc -= outCc;
|
||||
cp += outCc;
|
||||
outTotal += outCc;
|
||||
}
|
||||
}
|
||||
|
||||
if (inCc < 0)
|
||||
perror (inFile);
|
||||
|
||||
cleanup:
|
||||
close (inFd);
|
||||
close (outFd);
|
||||
free (buf);
|
||||
|
||||
printf ("%ld+%d records in\n", (long)(intotal / blockSize),
|
||||
(intotal % blockSize) != 0);
|
||||
printf ("%ld+%d records out\n", (long)(outTotal / blockSize),
|
||||
(outTotal % blockSize) != 0);
|
||||
exit( TRUE);
|
||||
usage:
|
||||
|
||||
usage( dd_usage);
|
||||
}
|
||||
|
||||
|
||||
-109
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Mini df implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* based on original code by (I think) Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
* 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 <mntent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/vfs.h>
|
||||
#include <fstab.h>
|
||||
|
||||
static const char df_usage[] = "df [filesystem ...]\n"
|
||||
"\n" "\tPrint the filesystem space used and space available.\n";
|
||||
|
||||
extern const char mtab_file[]; /* Defined in utility.c */
|
||||
|
||||
static int df(char *device, const char *mountPoint)
|
||||
{
|
||||
struct statfs s;
|
||||
long blocks_used;
|
||||
long blocks_percent_used;
|
||||
struct fstab* fstabItem;
|
||||
|
||||
if (statfs(mountPoint, &s) != 0) {
|
||||
perror(mountPoint);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (s.f_blocks > 0) {
|
||||
blocks_used = s.f_blocks - s.f_bfree;
|
||||
blocks_percent_used = (long)
|
||||
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
|
||||
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
|
||||
if (strcmp (device, "/dev/root") == 0) {
|
||||
fstabItem = getfsfile ("/");
|
||||
if (fstabItem != NULL)
|
||||
device = fstabItem->fs_spec;
|
||||
}
|
||||
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
|
||||
device,
|
||||
(long) (s.f_blocks * (s.f_bsize / 1024.0)),
|
||||
(long) ((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)),
|
||||
(long) (s.f_bavail * (s.f_bsize / 1024.0)),
|
||||
blocks_percent_used, mountPoint);
|
||||
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
extern int df_main(int argc, char **argv)
|
||||
{
|
||||
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
|
||||
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
|
||||
|
||||
if (argc > 1) {
|
||||
struct mntent *mountEntry;
|
||||
int status;
|
||||
|
||||
while (argc > 1) {
|
||||
if ((mountEntry = findMountPoint(argv[1], mtab_file)) ==
|
||||
0) {
|
||||
fprintf(stderr, "%s: can't find mount point.\n", argv[1]);
|
||||
exit( FALSE);
|
||||
}
|
||||
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
if (status != 0)
|
||||
exit( status);
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
exit( TRUE);
|
||||
} else {
|
||||
FILE *mountTable;
|
||||
struct mntent *mountEntry;
|
||||
|
||||
mountTable = setmntent(mtab_file, "r");
|
||||
if (mountTable == 0) {
|
||||
perror(mtab_file);
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
while ((mountEntry = getmntent(mountTable))) {
|
||||
df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
}
|
||||
endmntent(mountTable);
|
||||
}
|
||||
|
||||
exit( TRUE);
|
||||
}
|
||||
-143
@@ -1,143 +0,0 @@
|
||||
/*
|
||||
* Mini du implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#if 0
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
typedef void (Display)(size_t, char *);
|
||||
|
||||
static const char du_usage[] =
|
||||
"Usage: du [OPTION]... [FILE]...\n\n"
|
||||
"\t-s\tdisplay only a total for each argument\n"
|
||||
;
|
||||
|
||||
static int du_depth = 0;
|
||||
|
||||
static Display *print;
|
||||
|
||||
static void
|
||||
print_normal(size_t size, char *filename)
|
||||
{
|
||||
fprintf(stdout, "%-7d %s\n", (size >> 1), filename);
|
||||
}
|
||||
|
||||
static void
|
||||
print_summary(size_t size, char *filename)
|
||||
{
|
||||
if (du_depth == 1) {
|
||||
print_normal(size, filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* tiny recursive du */
|
||||
static size_t
|
||||
du(char *filename)
|
||||
{
|
||||
struct stat statbuf;
|
||||
size_t sum;
|
||||
|
||||
if ((lstat(filename, &statbuf)) != 0) {
|
||||
fprintf(stdout, "du: %s: %s\n", filename, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
|
||||
du_depth++;
|
||||
sum = statbuf.st_blocks;
|
||||
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
|
||||
dir = opendir(filename);
|
||||
if (!dir) { return 0; }
|
||||
while ((entry = readdir(dir))) {
|
||||
char newfile[512];
|
||||
char *name = entry->d_name;
|
||||
|
||||
if ( (strcmp(name, "..") == 0)
|
||||
|| (strcmp(name, ".") == 0))
|
||||
{ continue; }
|
||||
|
||||
sprintf(newfile, "%s/%s", filename, name);
|
||||
sum += du(newfile);
|
||||
}
|
||||
closedir(dir);
|
||||
print(sum, filename);
|
||||
}
|
||||
du_depth--;
|
||||
return sum;
|
||||
}
|
||||
|
||||
int
|
||||
du_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char opt;
|
||||
|
||||
/* default behaviour */
|
||||
print = print_normal;
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 's':
|
||||
print = print_summary;
|
||||
break;
|
||||
case 'h':
|
||||
usage(du_usage);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "du: invalid option -- %c\n", opt);
|
||||
usage(du_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* go through remaining args (if any) */
|
||||
if (i >= argc) {
|
||||
du(".");
|
||||
} else {
|
||||
int sum;
|
||||
for ( ; i < argc; i++) {
|
||||
sum = du(argv[i]);
|
||||
if ((sum) && (isDirectory(argv[i]))) { print_normal(sum, argv[i]); }
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: du.c,v 1.8 1999/12/17 18:44:15 erik Exp $ */
|
||||
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* Mini head implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
const char head_usage[] =
|
||||
"Usage: head [FILE]...\n\n"
|
||||
"Print 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";
|
||||
|
||||
int
|
||||
head(int len, FILE *src)
|
||||
{
|
||||
int i;
|
||||
char buffer[1024];
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
fgets(buffer, 1024, src);
|
||||
if (feof(src)) { break; }
|
||||
fputs(buffer, stdout);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* BusyBoxed head(1) */
|
||||
int
|
||||
head_main(int argc, char **argv)
|
||||
{
|
||||
int i = 1;
|
||||
char opt;
|
||||
int len = 10;
|
||||
|
||||
/* 1st option is potentially special */
|
||||
if ((argc > 1) && (argv[1][0] == '-') && isDecimal(argv[1][1])) {
|
||||
int tmplen = atoi(&argv[1][1]);
|
||||
if (tmplen) { len = tmplen; }
|
||||
i = 2;
|
||||
}
|
||||
|
||||
/* parse argv[] */
|
||||
for ( ; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case '-':
|
||||
case 'h':
|
||||
usage(head_usage);
|
||||
default:
|
||||
fprintf(stderr, "head: invalid option -- %c\n", opt);
|
||||
usage(head_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* get rest of argv[] or stdin if nothing's left */
|
||||
if (i >= argc) {
|
||||
head(len, stdin);
|
||||
|
||||
} else {
|
||||
int need_headers = ((argc - i) > 1);
|
||||
for ( ; i < argc; i++) {
|
||||
FILE *src;
|
||||
src = fopen(argv[i], "r");
|
||||
if (!src) {
|
||||
fprintf(stderr,"head: %s: %s\n", argv[i], strerror(errno));
|
||||
} else {
|
||||
/* emulating GNU behaviour */
|
||||
if (need_headers) {
|
||||
fprintf(stdout, "==> %s <==\n", argv[i]);
|
||||
}
|
||||
head(len, src);
|
||||
if (i < argc - 1) {
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: head.c,v 1.4 1999/12/17 18:52:06 erik Exp $ */
|
||||
@@ -1,14 +0,0 @@
|
||||
#include "internal.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern int
|
||||
length_main(int argc, char * * argv)
|
||||
{
|
||||
if ( **(argv+1) == '-' ) {
|
||||
usage("length string\n");
|
||||
}
|
||||
printf("%d\n", strlen(argv[1]));
|
||||
return( TRUE);
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
/*
|
||||
* Mini ln implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n"
|
||||
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n"
|
||||
"Options:\n"
|
||||
"\t-s\tmake symbolic links instead of hard links\n"
|
||||
"\t-f\tremove existing destination files\n";
|
||||
|
||||
|
||||
static int symlinkFlag = FALSE;
|
||||
static int removeoldFlag = FALSE;
|
||||
|
||||
|
||||
extern int ln_main(int argc, char **argv)
|
||||
{
|
||||
int status;
|
||||
static char* linkName;
|
||||
|
||||
if (argc < 3) {
|
||||
usage (ln_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 's':
|
||||
symlinkFlag = TRUE;
|
||||
break;
|
||||
case 'f':
|
||||
removeoldFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage (ln_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
|
||||
linkName = argv[argc - 1];
|
||||
|
||||
if ((argc > 3) && !(isDirectory(linkName))) {
|
||||
fprintf(stderr, "%s: not a directory\n", linkName);
|
||||
exit (FALSE);
|
||||
}
|
||||
|
||||
while (argc-- >= 2) {
|
||||
if (removeoldFlag==TRUE ) {
|
||||
status = ( unlink(linkName) && errno != ENOENT );
|
||||
if ( status != 0 ) {
|
||||
perror(linkName);
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
if ( symlinkFlag==TRUE)
|
||||
status = symlink(*argv, linkName);
|
||||
else
|
||||
status = link(*argv, linkName);
|
||||
if ( status != 0 ) {
|
||||
perror(linkName);
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
exit( TRUE);
|
||||
}
|
||||
-511
@@ -1,511 +0,0 @@
|
||||
/*
|
||||
* tiny-ls.c version 0.1.0: A minimalist 'ls'
|
||||
* Copyright (C) 1996 Brian Candler <B.Candler@pobox.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*/
|
||||
|
||||
/*
|
||||
* To achieve a small memory footprint, this version of 'ls' doesn't do any
|
||||
* file sorting, and only has the most essential command line switches
|
||||
* (i.e. the ones I couldn't live without :-) All features which involve
|
||||
* linking in substantial chunks of libc can be disabled.
|
||||
*
|
||||
* Although I don't really want to add new features to this program to
|
||||
* keep it small, I *am* interested to receive bug fixes and ways to make
|
||||
* it more portable.
|
||||
*
|
||||
* KNOWN BUGS:
|
||||
* 1. messy output if you mix files and directories on the command line
|
||||
* 2. ls -l of a directory doesn't give "total <blocks>" header
|
||||
* 3. ls of a symlink to a directory doesn't list directory contents
|
||||
* 4. hidden files can make column width too large
|
||||
* NON-OPTIMAL BEHAVIOUR:
|
||||
* 1. autowidth reads directories twice
|
||||
* 2. if you do a short directory listing without filetype characters
|
||||
* appended, there's no need to stat each one
|
||||
* PORTABILITY:
|
||||
* 1. requires lstat (BSD) - how do you do it without?
|
||||
*/
|
||||
|
||||
#define TERMINAL_WIDTH 80 /* use 79 if your terminal has linefold bug */
|
||||
#define COLUMN_WIDTH 14 /* default if AUTOWIDTH not defined */
|
||||
#define COLUMN_GAP 2 /* includes the file type char, if present */
|
||||
#define HAS_REWINDDIR
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
#include "internal.h"
|
||||
#if !defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||
# include <linux/types.h>
|
||||
#else
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
|
||||
#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
#define APPCHAR(mode) ("\0|\0\0/\0\0\0\0\0@\0=\0\0\0" [TYPEINDEX(mode)])
|
||||
#endif
|
||||
|
||||
#ifndef MAJOR
|
||||
#define MAJOR(dev) (((dev)>>8)&0xff)
|
||||
#define MINOR(dev) ((dev)&0xff)
|
||||
#endif
|
||||
|
||||
#define FMT_AUTO 0
|
||||
#define FMT_LONG 1 /* one record per line, extended info */
|
||||
#define FMT_SINGLE 2 /* one record per line */
|
||||
#define FMT_ROWS 3 /* print across rows */
|
||||
#define FMT_COLUMNS 3 /* fill columns (same, since we don't sort) */
|
||||
|
||||
#define TIME_MOD 0
|
||||
#define TIME_CHANGE 1
|
||||
#define TIME_ACCESS 2
|
||||
|
||||
#define DISP_FTYPE 1 /* show character for file type */
|
||||
#define DISP_EXEC 2 /* show '*' if regular executable file */
|
||||
#define DISP_HIDDEN 4 /* show files starting . (except . and ..) */
|
||||
#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 DISP_DIRNAME 128 /* show directory name (for internal use) */
|
||||
#define DIR_RECURSE 256 /* -R (not yet implemented) */
|
||||
|
||||
static unsigned char display_fmt = FMT_AUTO;
|
||||
static unsigned short opts = 0;
|
||||
static unsigned short column = 0;
|
||||
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
static unsigned short terminal_width = 0, column_width = 0;
|
||||
#else
|
||||
#define terminal_width TERMINAL_WIDTH
|
||||
#define column_width COLUMN_WIDTH
|
||||
#endif
|
||||
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
static unsigned char time_fmt = TIME_MOD;
|
||||
#endif
|
||||
|
||||
#define wr(data,len) fwrite(data, 1, len, stdout)
|
||||
|
||||
static void writenum(long val, short minwidth)
|
||||
{
|
||||
char scratch[128];
|
||||
|
||||
char *p = scratch + sizeof(scratch);
|
||||
short len = 0;
|
||||
short neg = (val < 0);
|
||||
|
||||
if (neg) val = -val;
|
||||
do
|
||||
*--p = (val % 10) + '0', len++, val /= 10;
|
||||
while (val);
|
||||
if (neg)
|
||||
*--p = '-', len++;
|
||||
while (len < minwidth)
|
||||
*--p = ' ', len++;
|
||||
wr(p, len);
|
||||
column += len;
|
||||
}
|
||||
|
||||
static void newline(void)
|
||||
{
|
||||
if (column > 0) {
|
||||
wr("\n", 1);
|
||||
column = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void tab(short col)
|
||||
{
|
||||
static const char spaces[] = " ";
|
||||
#define nspaces ((sizeof spaces)-1) /* null terminator! */
|
||||
|
||||
short n = col - column;
|
||||
|
||||
if (n > 0) {
|
||||
column = col;
|
||||
while (n > nspaces) {
|
||||
wr(spaces, nspaces);
|
||||
n -= nspaces;
|
||||
}
|
||||
/* must be 1...(sizeof spaces) left */
|
||||
wr(spaces, n);
|
||||
}
|
||||
#undef nspaces
|
||||
}
|
||||
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
static char append_char(mode_t mode)
|
||||
{
|
||||
if (!(opts & DISP_FTYPE))
|
||||
return '\0';
|
||||
if ((opts & DISP_EXEC) && S_ISREG(mode) && (mode & (S_IXUSR|S_IXGRP|S_IXOTH)))
|
||||
return '*';
|
||||
return APPCHAR(mode);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
**
|
||||
** Display a file or directory as a single item
|
||||
** (in either long or short format)
|
||||
**
|
||||
**/
|
||||
|
||||
static void list_single(const char *name, struct stat *info, const char *fullname)
|
||||
{
|
||||
char scratch[PATH_MAX];
|
||||
short len = strlen(name);
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
char append = append_char(info->st_mode);
|
||||
#endif
|
||||
|
||||
if (display_fmt == FMT_LONG) {
|
||||
mode_t mode = info->st_mode;
|
||||
newline();
|
||||
wr(modeString(mode), 10);
|
||||
column=10;
|
||||
writenum((long)info->st_nlink,(short)5);
|
||||
fputs(" ", stdout);
|
||||
#ifdef BB_FEATURE_LS_USERNAME
|
||||
if (!(opts & DISP_NUMERIC)) {
|
||||
memset ( scratch, 0, sizeof (scratch));
|
||||
my_getpwuid( scratch, info->st_uid);
|
||||
if (*scratch) {
|
||||
fputs(scratch, stdout);
|
||||
if ( strlen( scratch) <= 8 )
|
||||
wr(" ", 8-strlen( scratch));
|
||||
}
|
||||
else {
|
||||
writenum((long) info->st_uid,(short)8);
|
||||
fputs(" ", stdout);
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
writenum((long) info->st_uid,(short)8);
|
||||
fputs(" ", stdout);
|
||||
}
|
||||
#ifdef BB_FEATURE_LS_USERNAME
|
||||
if (!(opts & DISP_NUMERIC)) {
|
||||
memset ( scratch, 0, sizeof (scratch));
|
||||
my_getgrgid( scratch, info->st_gid);
|
||||
if (*scratch) {
|
||||
fputs(scratch, stdout);
|
||||
if ( strlen( scratch) <= 8 )
|
||||
wr(" ", 8-strlen( scratch));
|
||||
}
|
||||
else
|
||||
writenum((long) info->st_gid,(short)8);
|
||||
} else
|
||||
#endif
|
||||
writenum((long) info->st_gid,(short)8);
|
||||
//tab(26);
|
||||
if (S_ISBLK(mode) || S_ISCHR(mode)) {
|
||||
writenum((long)MAJOR(info->st_rdev),(short)3);
|
||||
fputs(", ", stdout);
|
||||
writenum((long)MINOR(info->st_rdev),(short)3);
|
||||
}
|
||||
else
|
||||
writenum((long)info->st_size,(short)8);
|
||||
fputs(" ", stdout);
|
||||
//tab(32);
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
{
|
||||
time_t cal;
|
||||
char *string;
|
||||
|
||||
switch(time_fmt) {
|
||||
case TIME_CHANGE:
|
||||
cal=info->st_ctime; break;
|
||||
case TIME_ACCESS:
|
||||
cal=info->st_atime; break;
|
||||
default:
|
||||
cal=info->st_mtime; break;
|
||||
}
|
||||
string=ctime(&cal);
|
||||
if (opts & DISP_FULLTIME)
|
||||
wr(string,24);
|
||||
else {
|
||||
time_t age = time(NULL) - cal;
|
||||
wr(string+4,7); /* mmm_dd_ */
|
||||
if(age < 3600L*24*365/2 && age > -15*60)
|
||||
/* hh:mm if less than 6 months old */
|
||||
wr(string+11,5);
|
||||
else
|
||||
/* _yyyy otherwise */
|
||||
wr(string+19,5);
|
||||
}
|
||||
wr(" ", 1);
|
||||
}
|
||||
#else
|
||||
fputs("--- -- ----- ", stdout);
|
||||
#endif
|
||||
wr(name, len);
|
||||
if (S_ISLNK(mode)) {
|
||||
wr(" -> ", 4);
|
||||
len = readlink(fullname, scratch, sizeof scratch);
|
||||
if (len > 0) fwrite(scratch, 1, len, stdout);
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
/* show type of destination */
|
||||
if (opts & DISP_FTYPE) {
|
||||
if (!stat(fullname, info)) {
|
||||
append = append_char(info->st_mode);
|
||||
if (append)
|
||||
fputc(append, stdout);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
else if (append)
|
||||
wr(&append, 1);
|
||||
#endif
|
||||
} else {
|
||||
static short nexttab = 0;
|
||||
|
||||
/* sort out column alignment */
|
||||
if (column == 0)
|
||||
; /* nothing to do */
|
||||
else if (display_fmt == FMT_SINGLE)
|
||||
newline();
|
||||
else {
|
||||
if (nexttab + column_width > terminal_width
|
||||
#ifndef BB_FEATURE_AUTOWIDTH
|
||||
|| nexttab + len >= terminal_width
|
||||
#endif
|
||||
)
|
||||
newline();
|
||||
else
|
||||
tab(nexttab);
|
||||
}
|
||||
/* work out where next column starts */
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
/* we know the calculated width is big enough */
|
||||
nexttab = column + column_width + COLUMN_GAP;
|
||||
#else
|
||||
/* might cover more than one fixed-width column */
|
||||
nexttab = column;
|
||||
do
|
||||
nexttab += column_width + COLUMN_GAP;
|
||||
while (nexttab < (column + len + COLUMN_GAP));
|
||||
#endif
|
||||
/* now write the data */
|
||||
wr(name, len);
|
||||
column = column + len;
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
if (append)
|
||||
wr(&append, 1), column++;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
**
|
||||
** List the given file or directory, expanding a directory
|
||||
** to show its contents if required
|
||||
**
|
||||
**/
|
||||
|
||||
static int list_item(const char *name)
|
||||
{
|
||||
struct stat info;
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
char fullname[MAXNAMLEN+1], *fnend;
|
||||
|
||||
if (lstat(name, &info))
|
||||
goto listerr;
|
||||
|
||||
if (!S_ISDIR(info.st_mode) ||
|
||||
(opts & DIR_NOLIST)) {
|
||||
list_single(name, &info, name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Otherwise, it's a directory we want to list the contents of */
|
||||
|
||||
if (opts & DISP_DIRNAME) { /* identify the directory */
|
||||
if (column)
|
||||
wr("\n\n", 2), column = 0;
|
||||
wr(name, strlen(name));
|
||||
wr(":\n", 2);
|
||||
}
|
||||
|
||||
dir = opendir(name);
|
||||
if (!dir) goto listerr;
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
column_width = 0;
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
short w = strlen(entry->d_name);
|
||||
if (column_width < w)
|
||||
column_width = w;
|
||||
}
|
||||
#ifdef HAS_REWINDDIR
|
||||
rewinddir(dir);
|
||||
#else
|
||||
closedir(dir);
|
||||
dir = opendir(name);
|
||||
if (!dir) goto listerr;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* List the contents */
|
||||
|
||||
strcpy(fullname,name); /* *** ignore '.' by itself */
|
||||
fnend=fullname+strlen(fullname);
|
||||
if (fnend[-1] != '/')
|
||||
*fnend++ = '/';
|
||||
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
const char *en=entry->d_name;
|
||||
if (en[0] == '.') {
|
||||
if (!en[1] || (en[1] == '.' && !en[2])) { /* . or .. */
|
||||
if (!(opts & DISP_DOT))
|
||||
continue;
|
||||
}
|
||||
else if (!(opts & DISP_HIDDEN))
|
||||
continue;
|
||||
}
|
||||
/* FIXME: avoid stat if not required */
|
||||
strcpy(fnend, entry->d_name);
|
||||
if (lstat(fullname, &info))
|
||||
goto direrr; /* (shouldn't fail) */
|
||||
list_single(entry->d_name, &info, fullname);
|
||||
}
|
||||
closedir(dir);
|
||||
return 0;
|
||||
|
||||
direrr:
|
||||
closedir(dir);
|
||||
listerr:
|
||||
newline();
|
||||
perror(name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char ls_usage[] = "ls [-1a"
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
"c"
|
||||
#endif
|
||||
"d"
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
"e"
|
||||
#endif
|
||||
"ln"
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
"p"
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
"u"
|
||||
#endif
|
||||
"xAC"
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
"F"
|
||||
#endif
|
||||
#ifdef FEATURE_RECURSIVE
|
||||
"R"
|
||||
#endif
|
||||
"] [filenames...]\n";
|
||||
|
||||
extern int
|
||||
ls_main(int argc, char * * argv)
|
||||
{
|
||||
int argi=1, i;
|
||||
|
||||
/* process options */
|
||||
while (argi < argc && argv[argi][0] == '-') {
|
||||
const char *p = &argv[argi][1];
|
||||
|
||||
if (!*p) goto print_usage_message; /* "-" by itself not allowed */
|
||||
if (*p == '-') {
|
||||
if (!p[1]) { /* "--" forces end of options */
|
||||
argi++;
|
||||
break;
|
||||
}
|
||||
/* it's a long option name - we don't support them */
|
||||
goto print_usage_message;
|
||||
}
|
||||
|
||||
while (*p)
|
||||
switch (*p++) {
|
||||
case 'l': display_fmt = FMT_LONG; break;
|
||||
case '1': display_fmt = FMT_SINGLE; break;
|
||||
case 'x': display_fmt = FMT_ROWS; break;
|
||||
case 'C': display_fmt = FMT_COLUMNS; break;
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
case 'p': opts |= DISP_FTYPE; break;
|
||||
case 'F': opts |= DISP_FTYPE|DISP_EXEC; break;
|
||||
#endif
|
||||
case 'A': opts |= DISP_HIDDEN; break;
|
||||
case 'a': opts |= DISP_HIDDEN|DISP_DOT; break;
|
||||
case 'n': opts |= DISP_NUMERIC; break;
|
||||
case 'd': opts |= DIR_NOLIST; break;
|
||||
#ifdef FEATURE_RECURSIVE
|
||||
case 'R': opts |= DIR_RECURSE; break;
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
case 'u': time_fmt = TIME_ACCESS; break;
|
||||
case 'c': time_fmt = TIME_CHANGE; break;
|
||||
case 'e': opts |= DISP_FULLTIME; break;
|
||||
#endif
|
||||
default: goto print_usage_message;
|
||||
}
|
||||
|
||||
argi++;
|
||||
}
|
||||
|
||||
/* choose a display format */
|
||||
if (display_fmt == FMT_AUTO)
|
||||
display_fmt = isatty(fileno(stdout)) ? FMT_COLUMNS : FMT_SINGLE;
|
||||
if (argi < argc - 1)
|
||||
opts |= DISP_DIRNAME; /* 2 or more items? label directories */
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
/* could add a -w option and/or TIOCGWINSZ call */
|
||||
if (terminal_width < 1) terminal_width = TERMINAL_WIDTH;
|
||||
|
||||
for (i = argi; i < argc; i++) {
|
||||
int len = strlen(argv[i]);
|
||||
if (column_width < len)
|
||||
column_width = len;
|
||||
}
|
||||
#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();
|
||||
exit( i);
|
||||
|
||||
print_usage_message:
|
||||
usage (ls_usage);
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Mini mkdir implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
static const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n\n"
|
||||
"Create the DIRECTORY(ies), if they do not already exist\n\n"
|
||||
"Options:\n"
|
||||
"\t-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
|
||||
"\t-p\tno error if existing, make parent directories as needed\n";
|
||||
|
||||
|
||||
static int parentFlag = FALSE;
|
||||
static mode_t mode = 0777;
|
||||
|
||||
|
||||
extern int mkdir_main(int argc, char **argv)
|
||||
{
|
||||
int i=FALSE;
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (argc > 0 && **argv == '-') {
|
||||
while (i==FALSE && *++(*argv)) {
|
||||
switch (**argv) {
|
||||
case 'm':
|
||||
if (--argc == 0)
|
||||
usage( mkdir_usage);
|
||||
/* Find the specified modes */
|
||||
mode = 0;
|
||||
if ( parse_mode(*(++argv), &mode) == FALSE ) {
|
||||
fprintf(stderr, "Unknown mode: %s\n", *argv);
|
||||
exit( FALSE);
|
||||
}
|
||||
/* Set the umask for this process so it doesn't
|
||||
* screw up whatever the user just entered. */
|
||||
umask(0);
|
||||
i=TRUE;
|
||||
break;
|
||||
case 'p':
|
||||
parentFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage( mkdir_usage);
|
||||
}
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
|
||||
if (argc < 1) {
|
||||
usage( mkdir_usage);
|
||||
}
|
||||
|
||||
while (argc > 0) {
|
||||
int status;
|
||||
struct stat statBuf;
|
||||
char buf[NAME_MAX];
|
||||
|
||||
strcpy (buf, *argv);
|
||||
status=stat(buf, &statBuf);
|
||||
if (parentFlag == FALSE && status != -1 && status != ENOENT ) {
|
||||
fprintf(stderr, "%s: File exists\n", buf);
|
||||
exit( FALSE);
|
||||
}
|
||||
if (parentFlag == TRUE) {
|
||||
strcat( buf, "/");
|
||||
createPath(buf, mode);
|
||||
}
|
||||
else {
|
||||
if (mkdir (buf, mode) != 0 && parentFlag == FALSE) {
|
||||
perror(buf);
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
exit( TRUE);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Mini mkfifo implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char mkfifo_usage[] = "mkfifo [OPTIONS] name\n\n"
|
||||
"Create the named fifo\n\n"
|
||||
"Options:\n"
|
||||
"\t-m\tcreate the fifo with the specified mode; default = a=rw-umask\n";
|
||||
|
||||
extern int mkfifo_main(int argc, char **argv)
|
||||
{
|
||||
char *thisarg;
|
||||
mode_t mode = 0666;
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (argc > 1) {
|
||||
if (**argv != '-') usage(mkfifo_usage);
|
||||
thisarg = *argv; thisarg++;
|
||||
switch (*thisarg) {
|
||||
case 'm':
|
||||
argc--; argv++;
|
||||
parse_mode(*argv, &mode);
|
||||
break;
|
||||
default:
|
||||
usage (mkfifo_usage);
|
||||
}
|
||||
argc--; argv++;
|
||||
}
|
||||
if (argc < 1) usage (mkfifo_usage);
|
||||
if (mkfifo(*argv, mode) < 0) {
|
||||
perror("mkfifo");
|
||||
exit(255);
|
||||
} else {
|
||||
exit(TRUE);
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Mini mknod implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static const char mknod_usage[] = "mknod NAME TYPE MAJOR MINOR\n\n"
|
||||
"Make block or character special files.\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";
|
||||
|
||||
int
|
||||
mknod_main(int argc, char** argv)
|
||||
{
|
||||
mode_t mode = 0;
|
||||
dev_t dev = 0;
|
||||
|
||||
if ( argc != 5 || **(argv+1) == '-' ) {
|
||||
usage (mknod_usage);
|
||||
}
|
||||
switch(argv[2][0]) {
|
||||
case 'c':
|
||||
case 'u':
|
||||
mode = S_IFCHR;
|
||||
break;
|
||||
case 'b':
|
||||
mode = S_IFBLK;
|
||||
break;
|
||||
case 'p':
|
||||
mode = S_IFIFO;
|
||||
break;
|
||||
default:
|
||||
usage (mknod_usage);
|
||||
}
|
||||
|
||||
if ( mode == S_IFCHR || mode == S_IFBLK ) {
|
||||
dev = (atoi(argv[3]) << 8) | atoi(argv[4]);
|
||||
if ( argc != 5 ) {
|
||||
usage (mknod_usage);
|
||||
}
|
||||
}
|
||||
|
||||
mode |= 0666;
|
||||
|
||||
if ( mknod(argv[1], mode, dev) != 0 ) {
|
||||
perror(argv[1]);
|
||||
return( FALSE);
|
||||
}
|
||||
return( TRUE);
|
||||
}
|
||||
-112
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* Mini mv implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <dirent.h>
|
||||
|
||||
static const char mv_usage[] = "mv SOURCE DEST\n"
|
||||
" or: mv SOURCE... DIRECTORY\n\n"
|
||||
"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n";
|
||||
|
||||
|
||||
static const char *srcName;
|
||||
static const char *destName;
|
||||
static int destDirFlag = FALSE;
|
||||
static int srcDirFlag = FALSE;
|
||||
|
||||
static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
char newdestName[NAME_MAX];
|
||||
char* newsrcName = NULL;
|
||||
|
||||
strcpy(newdestName, destName);
|
||||
if ( srcDirFlag == TRUE ) {
|
||||
strcat(newdestName, strstr(fileName, srcName) + strlen(srcName));
|
||||
}
|
||||
|
||||
if (destDirFlag==TRUE && srcDirFlag == FALSE) {
|
||||
if (newdestName[strlen(newdestName)-1] != '/' ) {
|
||||
strcat(newdestName, "/");
|
||||
}
|
||||
newsrcName = strrchr(srcName, '/');
|
||||
if (newsrcName && *newsrcName != '\0')
|
||||
strcat(newdestName, newsrcName);
|
||||
else
|
||||
strcat(newdestName, srcName);
|
||||
}
|
||||
|
||||
return (copyFile(fileName, newdestName, TRUE, TRUE));
|
||||
}
|
||||
|
||||
static int rmfileAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
if (unlink( fileName) < 0 ) {
|
||||
perror( fileName);
|
||||
return ( FALSE);
|
||||
}
|
||||
return ( TRUE);
|
||||
}
|
||||
|
||||
static int rmdirAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
if (rmdir( fileName) < 0 ) {
|
||||
perror( fileName);
|
||||
return ( FALSE);
|
||||
}
|
||||
return ( TRUE);
|
||||
}
|
||||
|
||||
|
||||
extern int mv_main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 3) {
|
||||
usage (mv_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
destName = argv[argc - 1];
|
||||
destDirFlag = isDirectory(destName);
|
||||
|
||||
if ((argc > 3) && destDirFlag==FALSE) {
|
||||
fprintf(stderr, "%s: not a directory\n", destName);
|
||||
exit (FALSE);
|
||||
}
|
||||
|
||||
while (argc-- > 1) {
|
||||
srcName = *(argv++);
|
||||
srcDirFlag = isDirectory(srcName);
|
||||
if (recursiveAction(srcName, TRUE, TRUE, FALSE,
|
||||
fileAction, fileAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
}
|
||||
if (recursiveAction(srcName, TRUE, TRUE, TRUE,
|
||||
rmfileAction, rmdirAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
exit( TRUE);
|
||||
}
|
||||
@@ -1,529 +0,0 @@
|
||||
/* printf - format and print data
|
||||
Copyright (C) 90, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Usage: printf format [argument...]
|
||||
|
||||
A front end to the printf function that lets it be used from the shell.
|
||||
|
||||
Backslash escapes:
|
||||
|
||||
\" = double quote
|
||||
\\ = backslash
|
||||
\a = alert (bell)
|
||||
\b = backspace
|
||||
\c = produce no further output
|
||||
\f = form feed
|
||||
\n = new line
|
||||
\r = carriage return
|
||||
\t = horizontal tab
|
||||
\v = vertical tab
|
||||
\0ooo = octal number (ooo is 0 to 3 digits)
|
||||
\xhhh = hexadecimal number (hhh is 1 to 3 digits)
|
||||
|
||||
Additional directive:
|
||||
|
||||
%b = print an argument string, interpreting backslash escapes
|
||||
|
||||
The `format' argument is re-used as many times as necessary
|
||||
to convert all of the given arguments.
|
||||
|
||||
David MacKenzie <djm@gnu.ai.mit.edu> */
|
||||
|
||||
|
||||
// 19990508 Busy Boxed! Dave Cinege
|
||||
|
||||
#include "internal.h"
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <libintl.h>
|
||||
|
||||
|
||||
#ifndef S_IFMT
|
||||
# define S_IFMT 0170000
|
||||
#endif
|
||||
#if !defined(S_ISBLK) && defined(S_IFBLK)
|
||||
# define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
|
||||
#endif
|
||||
#if !defined(S_ISCHR) && defined(S_IFCHR)
|
||||
# define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
|
||||
#endif
|
||||
#if !defined(S_ISDIR) && defined(S_IFDIR)
|
||||
# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
||||
#endif
|
||||
#if !defined(S_ISREG) && defined(S_IFREG)
|
||||
# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
#endif
|
||||
#if !defined(S_ISFIFO) && defined(S_IFIFO)
|
||||
# define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
|
||||
#endif
|
||||
#if !defined(S_ISLNK) && defined(S_IFLNK)
|
||||
# define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
|
||||
#endif
|
||||
#if !defined(S_ISSOCK) && defined(S_IFSOCK)
|
||||
# define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
|
||||
#endif
|
||||
#if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
|
||||
# define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
|
||||
# define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
|
||||
#endif
|
||||
#if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
|
||||
# define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
|
||||
#endif
|
||||
|
||||
#define IN_CTYPE_DOMAIN(c) 1
|
||||
|
||||
#ifdef isblank
|
||||
# define ISBLANK(c) (IN_CTYPE_DOMAIN (c) && isblank (c))
|
||||
#else
|
||||
# define ISBLANK(c) ((c) == ' ' || (c) == '\t')
|
||||
#endif
|
||||
#ifdef isgraph
|
||||
# define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isgraph (c))
|
||||
#else
|
||||
# define ISGRAPH(c) (IN_CTYPE_DOMAIN (c) && isprint (c) && !isspace (c))
|
||||
#endif
|
||||
|
||||
#define ISPRINT(c) (IN_CTYPE_DOMAIN (c) && isprint (c))
|
||||
#define ISALNUM(c) (IN_CTYPE_DOMAIN (c) && isalnum (c))
|
||||
#define ISALPHA(c) (IN_CTYPE_DOMAIN (c) && isalpha (c))
|
||||
#define ISCNTRL(c) (IN_CTYPE_DOMAIN (c) && iscntrl (c))
|
||||
#define ISLOWER(c) (IN_CTYPE_DOMAIN (c) && islower (c))
|
||||
#define ISPUNCT(c) (IN_CTYPE_DOMAIN (c) && ispunct (c))
|
||||
#define ISSPACE(c) (IN_CTYPE_DOMAIN (c) && isspace (c))
|
||||
#define ISUPPER(c) (IN_CTYPE_DOMAIN (c) && isupper (c))
|
||||
#define ISXDIGIT(c) (IN_CTYPE_DOMAIN (c) && isxdigit (c))
|
||||
#define ISDIGIT_LOCALE(c) (IN_CTYPE_DOMAIN (c) && isdigit (c))
|
||||
#define ISDIGIT(c) ((unsigned) (c) - '0' <= 9)
|
||||
|
||||
#define isodigit(c) ((c) >= '0' && (c) <= '7')
|
||||
#define hextobin(c) ((c)>='a'&&(c)<='f' ? (c)-'a'+10 : (c)>='A'&&(c)<='F' ? (c)-'A'+10 : (c)-'0')
|
||||
#define octtobin(c) ((c) - '0')
|
||||
|
||||
char *xmalloc ();
|
||||
|
||||
static double xstrtod __P ((char *s));
|
||||
static int print_esc __P ((char *escstart));
|
||||
static int print_formatted __P ((char *format, int argc, char **argv));
|
||||
static long xstrtol __P ((char *s));
|
||||
static unsigned long xstrtoul __P ((char *s));
|
||||
static void print_direc __P ((char *start, size_t length, int field_width, int precision, char *argument));
|
||||
static void print_esc_char __P ((int c));
|
||||
static void print_esc_string __P ((char *str));
|
||||
static void verify __P ((char *s, char *end));
|
||||
|
||||
/* The value to return to the calling program. */
|
||||
static int exit_status;
|
||||
|
||||
static const char printf_usage[] = "printf format [argument...]\n";
|
||||
|
||||
int
|
||||
printf_main(int argc, char** argv)
|
||||
{
|
||||
char *format;
|
||||
int args_used;
|
||||
|
||||
exit_status = 0;
|
||||
if ( **(argv+1) == '-' ) {
|
||||
usage (printf_usage);
|
||||
}
|
||||
|
||||
format = argv[1];
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
|
||||
do
|
||||
{
|
||||
args_used = print_formatted (format, argc, argv);
|
||||
argc -= args_used;
|
||||
argv += args_used;
|
||||
}
|
||||
while (args_used > 0 && argc > 0);
|
||||
|
||||
/*
|
||||
if (argc > 0)
|
||||
fprintf(stderr, "excess args ignored");
|
||||
*/
|
||||
|
||||
exit (exit_status);
|
||||
}
|
||||
|
||||
/* Print the text in FORMAT, using ARGV (with ARGC elements) for
|
||||
arguments to any `%' directives.
|
||||
Return the number of elements of ARGV used. */
|
||||
|
||||
static int
|
||||
print_formatted (char *format, int argc, char **argv)
|
||||
{
|
||||
int save_argc = argc; /* Preserve original value. */
|
||||
char *f; /* Pointer into `format'. */
|
||||
char *direc_start; /* Start of % directive. */
|
||||
size_t direc_length; /* Length of % directive. */
|
||||
int field_width; /* Arg to first '*', or -1 if none. */
|
||||
int precision; /* Arg to second '*', or -1 if none. */
|
||||
|
||||
for (f = format; *f; ++f)
|
||||
{
|
||||
switch (*f)
|
||||
{
|
||||
case '%':
|
||||
direc_start = f++;
|
||||
direc_length = 1;
|
||||
field_width = precision = -1;
|
||||
if (*f == '%')
|
||||
{
|
||||
putchar ('%');
|
||||
break;
|
||||
}
|
||||
if (*f == 'b')
|
||||
{
|
||||
if (argc > 0)
|
||||
{
|
||||
print_esc_string (*argv);
|
||||
++argv;
|
||||
--argc;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (strchr ("-+ #", *f))
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
if (*f == '*')
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
if (argc > 0)
|
||||
{
|
||||
field_width = xstrtoul (*argv);
|
||||
++argv;
|
||||
--argc;
|
||||
}
|
||||
else
|
||||
field_width = 0;
|
||||
}
|
||||
else
|
||||
while (ISDIGIT (*f))
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
if (*f == '.')
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
if (*f == '*')
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
if (argc > 0)
|
||||
{
|
||||
precision = xstrtoul (*argv);
|
||||
++argv;
|
||||
--argc;
|
||||
}
|
||||
else
|
||||
precision = 0;
|
||||
}
|
||||
else
|
||||
while (ISDIGIT (*f))
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
}
|
||||
if (*f == 'l' || *f == 'L' || *f == 'h')
|
||||
{
|
||||
++f;
|
||||
++direc_length;
|
||||
}
|
||||
/*
|
||||
if (!strchr ("diouxXfeEgGcs", *f))
|
||||
fprintf(stderr, "%%%c: invalid directive", *f);
|
||||
*/
|
||||
++direc_length;
|
||||
if (argc > 0)
|
||||
{
|
||||
print_direc (direc_start, direc_length, field_width,
|
||||
precision, *argv);
|
||||
++argv;
|
||||
--argc;
|
||||
}
|
||||
else
|
||||
print_direc (direc_start, direc_length, field_width,
|
||||
precision, "");
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
f += print_esc (f);
|
||||
break;
|
||||
|
||||
default:
|
||||
putchar (*f);
|
||||
}
|
||||
}
|
||||
|
||||
return save_argc - argc;
|
||||
}
|
||||
|
||||
/* Print a \ escape sequence starting at ESCSTART.
|
||||
Return the number of characters in the escape sequence
|
||||
besides the backslash. */
|
||||
|
||||
static int
|
||||
print_esc (char *escstart)
|
||||
{
|
||||
register char *p = escstart + 1;
|
||||
int esc_value = 0; /* Value of \nnn escape. */
|
||||
int esc_length; /* Length of \nnn escape. */
|
||||
|
||||
/* \0ooo and \xhhh escapes have maximum length of 3 chars. */
|
||||
if (*p == 'x')
|
||||
{
|
||||
for (esc_length = 0, ++p;
|
||||
esc_length < 3 && ISXDIGIT (*p);
|
||||
++esc_length, ++p)
|
||||
esc_value = esc_value * 16 + hextobin (*p);
|
||||
/* if (esc_length == 0)
|
||||
fprintf(stderr, "missing hex in esc");
|
||||
*/
|
||||
putchar (esc_value);
|
||||
}
|
||||
else if (*p == '0')
|
||||
{
|
||||
for (esc_length = 0, ++p;
|
||||
esc_length < 3 && isodigit (*p);
|
||||
++esc_length, ++p)
|
||||
esc_value = esc_value * 8 + octtobin (*p);
|
||||
putchar (esc_value);
|
||||
}
|
||||
else if (strchr ("\"\\abcfnrtv", *p))
|
||||
print_esc_char (*p++);
|
||||
/* else
|
||||
fprintf(stderr, "\\%c: invalid esc", *p);
|
||||
*/
|
||||
return p - escstart - 1;
|
||||
}
|
||||
|
||||
/* Output a single-character \ escape. */
|
||||
|
||||
static void
|
||||
print_esc_char (int c)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case 'a': /* Alert. */
|
||||
putchar (7);
|
||||
break;
|
||||
case 'b': /* Backspace. */
|
||||
putchar (8);
|
||||
break;
|
||||
case 'c': /* Cancel the rest of the output. */
|
||||
exit (0);
|
||||
break;
|
||||
case 'f': /* Form feed. */
|
||||
putchar (12);
|
||||
break;
|
||||
case 'n': /* New line. */
|
||||
putchar (10);
|
||||
break;
|
||||
case 'r': /* Carriage return. */
|
||||
putchar (13);
|
||||
break;
|
||||
case 't': /* Horizontal tab. */
|
||||
putchar (9);
|
||||
break;
|
||||
case 'v': /* Vertical tab. */
|
||||
putchar (11);
|
||||
break;
|
||||
default:
|
||||
putchar (c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Print string STR, evaluating \ escapes. */
|
||||
|
||||
static void
|
||||
print_esc_string (char *str)
|
||||
{
|
||||
for (; *str; str++)
|
||||
if (*str == '\\')
|
||||
str += print_esc (str);
|
||||
else
|
||||
putchar (*str);
|
||||
}
|
||||
|
||||
static void
|
||||
print_direc (char *start, size_t length, int field_width, int precision, char *argument)
|
||||
{
|
||||
char *p; /* Null-terminated copy of % directive. */
|
||||
|
||||
p = xmalloc ((unsigned) (length + 1));
|
||||
strncpy (p, start, length);
|
||||
p[length] = 0;
|
||||
|
||||
switch (p[length - 1])
|
||||
{
|
||||
case 'd':
|
||||
case 'i':
|
||||
if (field_width < 0)
|
||||
{
|
||||
if (precision < 0)
|
||||
printf (p, xstrtol (argument));
|
||||
else
|
||||
printf (p, precision, xstrtol (argument));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (precision < 0)
|
||||
printf (p, field_width, xstrtol (argument));
|
||||
else
|
||||
printf (p, field_width, precision, xstrtol (argument));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'o':
|
||||
case 'u':
|
||||
case 'x':
|
||||
case 'X':
|
||||
if (field_width < 0)
|
||||
{
|
||||
if (precision < 0)
|
||||
printf (p, xstrtoul (argument));
|
||||
else
|
||||
printf (p, precision, xstrtoul (argument));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (precision < 0)
|
||||
printf (p, field_width, xstrtoul (argument));
|
||||
else
|
||||
printf (p, field_width, precision, xstrtoul (argument));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'g':
|
||||
case 'G':
|
||||
if (field_width < 0)
|
||||
{
|
||||
if (precision < 0)
|
||||
printf (p, xstrtod (argument));
|
||||
else
|
||||
printf (p, precision, xstrtod (argument));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (precision < 0)
|
||||
printf (p, field_width, xstrtod (argument));
|
||||
else
|
||||
printf (p, field_width, precision, xstrtod (argument));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
printf (p, *argument);
|
||||
break;
|
||||
|
||||
case 's':
|
||||
if (field_width < 0)
|
||||
{
|
||||
if (precision < 0)
|
||||
printf (p, argument);
|
||||
else
|
||||
printf (p, precision, argument);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (precision < 0)
|
||||
printf (p, field_width, argument);
|
||||
else
|
||||
printf (p, field_width, precision, argument);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
free (p);
|
||||
}
|
||||
|
||||
static unsigned long
|
||||
xstrtoul (char *s)
|
||||
{
|
||||
char *end;
|
||||
unsigned long val;
|
||||
|
||||
errno = 0;
|
||||
val = strtoul (s, &end, 0);
|
||||
verify (s, end);
|
||||
return val;
|
||||
}
|
||||
|
||||
static long
|
||||
xstrtol (char *s)
|
||||
{
|
||||
char *end;
|
||||
long val;
|
||||
|
||||
errno = 0;
|
||||
val = strtol (s, &end, 0);
|
||||
verify (s, end);
|
||||
return val;
|
||||
}
|
||||
|
||||
static double
|
||||
xstrtod (char *s)
|
||||
{
|
||||
char *end;
|
||||
double val;
|
||||
|
||||
errno = 0;
|
||||
val = strtod (s, &end);
|
||||
verify (s, end);
|
||||
return val;
|
||||
}
|
||||
|
||||
static void
|
||||
verify (char *s, char *end)
|
||||
{
|
||||
if (errno)
|
||||
{
|
||||
fprintf(stderr, "%s", s);
|
||||
exit_status = 1;
|
||||
}
|
||||
else if (*end)
|
||||
{
|
||||
/*
|
||||
if (s == end)
|
||||
fprintf(stderr, "%s: expected numeric", s);
|
||||
else
|
||||
fprintf(stderr, "%s: not completely converted", s);
|
||||
*/
|
||||
exit_status = 1;
|
||||
}
|
||||
}
|
||||
|
||||
-102
@@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Mini rm implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char* rm_usage = "rm [OPTION]... FILE...\n\n"
|
||||
"Remove (unlink) the FILE(s).\n\n"
|
||||
"Options:\n"
|
||||
"\t-f\t\tremove existing destinations, never prompt\n"
|
||||
"\t-r or -R\tremove the contents of directories recursively\n";
|
||||
|
||||
|
||||
static int recursiveFlag = FALSE;
|
||||
static int forceFlag = FALSE;
|
||||
static const char *srcName;
|
||||
|
||||
|
||||
static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
if (unlink( fileName) < 0 ) {
|
||||
perror( fileName);
|
||||
return ( FALSE);
|
||||
}
|
||||
return ( TRUE);
|
||||
}
|
||||
|
||||
static int dirAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
if (rmdir( fileName) < 0 ) {
|
||||
perror( fileName);
|
||||
return ( FALSE);
|
||||
}
|
||||
return ( TRUE);
|
||||
}
|
||||
|
||||
extern int rm_main(int argc, char **argv)
|
||||
{
|
||||
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) {
|
||||
srcName = *(argv++);
|
||||
if (forceFlag == TRUE && lstat(srcName, &statbuf) != 0 && errno == ENOENT) {
|
||||
/* do not reports errors for non-existent files if -f, just skip them */
|
||||
}
|
||||
else {
|
||||
if (recursiveAction( srcName, recursiveFlag, FALSE,
|
||||
TRUE, fileAction, dirAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
exit( TRUE);
|
||||
}
|
||||
@@ -1,312 +0,0 @@
|
||||
/*
|
||||
* Mini sort implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char sort_usage[] =
|
||||
"Usage: sort [OPTION]... [FILE]...\n\n"
|
||||
;
|
||||
|
||||
/* typedefs _______________________________________________________________ */
|
||||
|
||||
/* line node */
|
||||
typedef struct Line {
|
||||
char *data; /* line data */
|
||||
struct Line *next; /* pointer to next line node */
|
||||
} Line;
|
||||
|
||||
/* singly-linked list of lines */
|
||||
typedef struct {
|
||||
int len; /* number of Lines */
|
||||
Line **sorted; /* array fed to qsort */
|
||||
|
||||
Line *head; /* head of List */
|
||||
Line *current; /* current Line */
|
||||
} List;
|
||||
|
||||
/* comparison function */
|
||||
typedef int (Compare)(const void *, const void *);
|
||||
|
||||
|
||||
/* methods ________________________________________________________________ */
|
||||
|
||||
static const int max = 1024;
|
||||
|
||||
/* mallocate Line */
|
||||
static Line *
|
||||
line_alloc()
|
||||
{
|
||||
Line *self;
|
||||
self = malloc(1 * sizeof(Line));
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Initialize Line with string */
|
||||
static Line *
|
||||
line_init(Line *self, const char *string)
|
||||
{
|
||||
self->data = malloc((strlen(string) + 1) * sizeof(char));
|
||||
if (self->data == NULL) { return NULL; }
|
||||
strcpy(self->data, string);
|
||||
self->next = NULL;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* Construct Line from FILE* */
|
||||
static Line *
|
||||
line_newFromFile(FILE *src)
|
||||
{
|
||||
char buffer[max];
|
||||
Line *self;
|
||||
|
||||
if (fgets(buffer, max, src)) {
|
||||
self = line_alloc();
|
||||
if (self == NULL) { return NULL; }
|
||||
line_init(self, buffer);
|
||||
return self;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Line destructor */
|
||||
static Line *
|
||||
line_release(Line *self)
|
||||
{
|
||||
if (self->data) {
|
||||
free(self->data);
|
||||
free(self);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
/* Comparison */
|
||||
|
||||
/* ascii order */
|
||||
static int
|
||||
compare_ascii(const void *a, const void *b)
|
||||
{
|
||||
Line **doh;
|
||||
Line *x, *y;
|
||||
|
||||
doh = (Line **) a;
|
||||
x = *doh;
|
||||
doh = (Line **) b;
|
||||
y = *doh;
|
||||
|
||||
// fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data);
|
||||
return strcmp(x->data, y->data);
|
||||
}
|
||||
|
||||
/* numeric order */
|
||||
static int
|
||||
compare_numeric(const void *a, const void *b)
|
||||
{
|
||||
Line **doh;
|
||||
Line *x, *y;
|
||||
int xint, yint;
|
||||
|
||||
doh = (Line **) a;
|
||||
x = *doh;
|
||||
doh = (Line **) b;
|
||||
y = *doh;
|
||||
|
||||
xint = strtoul(x->data, NULL, 10);
|
||||
yint = strtoul(y->data, NULL, 10);
|
||||
|
||||
return (xint - yint);
|
||||
}
|
||||
|
||||
|
||||
/* List */
|
||||
|
||||
/* */
|
||||
static List *
|
||||
list_init(List *self)
|
||||
{
|
||||
self->len = 0;
|
||||
self->sorted = NULL;
|
||||
self->head = NULL;
|
||||
self->current = NULL;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* for simplicity, the List gains ownership of the line */
|
||||
static List *
|
||||
list_insert(List *self, Line *line)
|
||||
{
|
||||
if (line == NULL) { return NULL; }
|
||||
|
||||
/* first insertion */
|
||||
if (self->head == NULL) {
|
||||
self->head = line;
|
||||
self->current = line;
|
||||
|
||||
/* all subsequent insertions */
|
||||
} else {
|
||||
self->current->next = line;
|
||||
self->current = line;
|
||||
}
|
||||
self->len++;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* order the list according to compare() */
|
||||
static List *
|
||||
list_sort(List *self, Compare *compare)
|
||||
{
|
||||
int i;
|
||||
Line *line;
|
||||
|
||||
/* mallocate array of Line*s */
|
||||
self->sorted = (Line **) malloc(self->len * sizeof(Line*));
|
||||
if (self->sorted == NULL) { return NULL; }
|
||||
|
||||
/* fill array w/ List's contents */
|
||||
i = 0;
|
||||
line = self->head;
|
||||
while (line) {
|
||||
self->sorted[i++] = line;
|
||||
line = line->next;
|
||||
}
|
||||
|
||||
/* apply qsort */
|
||||
qsort(self->sorted, self->len, sizeof(Line*), compare);
|
||||
return self;
|
||||
}
|
||||
|
||||
/* precondition: list must be sorted */
|
||||
static List *
|
||||
list_writeToFile(List *self, FILE* dst)
|
||||
{
|
||||
int i;
|
||||
Line **line = self->sorted;
|
||||
|
||||
if (self->sorted == NULL) { return NULL; }
|
||||
for (i = 0; i < self->len; i++) {
|
||||
fprintf(dst, "%s", line[i]->data);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/* deallocate */
|
||||
static void
|
||||
list_release(List *self)
|
||||
{
|
||||
Line *i;
|
||||
Line *die;
|
||||
|
||||
i = self->head;
|
||||
while (i) {
|
||||
die = i;
|
||||
i = die->next;
|
||||
line_release(die);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* I need a list
|
||||
* to insert lines into
|
||||
* then I need to sort this list
|
||||
* and finally print it
|
||||
*/
|
||||
|
||||
int
|
||||
sort_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char opt;
|
||||
List list;
|
||||
Line *l;
|
||||
Compare *compare;
|
||||
|
||||
/* init */
|
||||
compare = compare_ascii;
|
||||
list_init(&list);
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 'g':
|
||||
/* what's the diff between -g && -n? */
|
||||
compare = compare_numeric;
|
||||
break;
|
||||
case 'h':
|
||||
usage(sort_usage);
|
||||
break;
|
||||
case 'n':
|
||||
/* what's the diff between -g && -n? */
|
||||
compare = compare_numeric;
|
||||
break;
|
||||
case 'r':
|
||||
/* reverse */
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "sort: invalid option -- %c\n", opt);
|
||||
usage(sort_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* this could be factored better */
|
||||
|
||||
/* work w/ stdin */
|
||||
if (i >= argc) {
|
||||
while ( (l = line_newFromFile(stdin))) {
|
||||
list_insert(&list, l);
|
||||
}
|
||||
list_sort(&list, compare);
|
||||
list_writeToFile(&list, stdout);
|
||||
list_release(&list);
|
||||
|
||||
/* work w/ what's left in argv[] */
|
||||
} else {
|
||||
FILE *src;
|
||||
|
||||
for ( ; i < argc; i++) {
|
||||
src = fopen(argv[i], "r");
|
||||
if (src == NULL) { break; }
|
||||
while ( (l = line_newFromFile(src))) {
|
||||
list_insert(&list, l);
|
||||
}
|
||||
fclose(src);
|
||||
}
|
||||
list_sort(&list, compare);
|
||||
list_writeToFile(&list, stdout);
|
||||
list_release(&list);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: sort.c,v 1.8 1999/12/23 22:46:10 beppu Exp $ */
|
||||
@@ -1,910 +0,0 @@
|
||||
/* tail -- output the last part of file(s)
|
||||
Copyright (C) 89, 90, 91, 95, 1996 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
Original version by Paul Rubin <phr@ocf.berkeley.edu>.
|
||||
Extensions by David MacKenzie <djm@gnu.ai.mit.edu>.
|
||||
tail -f for multiple files by Ian Lance Taylor <ian@airs.com>.
|
||||
|
||||
Rewrote the option parser, removed locales support,
|
||||
and generally busyboxed, Erik Andersen <andersen@lineo.com>
|
||||
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
|
||||
/* Disable assertions. Some systems have broken assert macros. */
|
||||
#define NDEBUG 1
|
||||
|
||||
|
||||
static void error(int i, int errnum, char* fmt, ...)
|
||||
{
|
||||
va_list arguments;
|
||||
|
||||
va_start(arguments, fmt);
|
||||
vfprintf(stderr, fmt, arguments);
|
||||
fprintf(stderr, "\n%s\n", strerror( errnum));
|
||||
va_end(arguments);
|
||||
exit(i);
|
||||
}
|
||||
|
||||
|
||||
#define XWRITE(fd, buffer, n_bytes) \
|
||||
do \
|
||||
{ \
|
||||
assert ((fd) == 1); \
|
||||
assert ((n_bytes) >= 0); \
|
||||
if (n_bytes > 0 && fwrite ((buffer), 1, (n_bytes), stdout) == 0) \
|
||||
error (EXIT_FAILURE, errno, "write error"); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
/* Number of items to tail. */
|
||||
#define DEFAULT_N_LINES 10
|
||||
|
||||
/* Size of atomic reads. */
|
||||
#ifndef BUFSIZ
|
||||
#define BUFSIZ (512 * 8)
|
||||
#endif
|
||||
|
||||
/* If nonzero, interpret the numeric argument as the number of lines.
|
||||
Otherwise, interpret it as the number of bytes. */
|
||||
static int count_lines;
|
||||
|
||||
/* If nonzero, read from the end of one file until killed. */
|
||||
static int forever;
|
||||
|
||||
/* If nonzero, read from the end of multiple files until killed. */
|
||||
static int forever_multiple;
|
||||
|
||||
/* Array of file descriptors if forever_multiple is 1. */
|
||||
static int *file_descs;
|
||||
|
||||
/* Array of file sizes if forever_multiple is 1. */
|
||||
static off_t *file_sizes;
|
||||
|
||||
/* If nonzero, count from start of file instead of end. */
|
||||
static int from_start;
|
||||
|
||||
/* If nonzero, print filename headers. */
|
||||
static int print_headers;
|
||||
|
||||
/* When to print the filename banners. */
|
||||
enum header_mode
|
||||
{
|
||||
multiple_files, always, never
|
||||
};
|
||||
|
||||
char *xmalloc ();
|
||||
|
||||
/* The name this program was run with. */
|
||||
char *program_name;
|
||||
|
||||
/* Nonzero if we have ever read standard input. */
|
||||
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\
|
||||
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\
|
||||
-c=N[kbm] output the last N bytes\n\
|
||||
-f output appended data as the file grows\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";
|
||||
|
||||
static void
|
||||
write_header (const char *filename, const char *comment)
|
||||
{
|
||||
static int first_file = 1;
|
||||
|
||||
printf ("%s==> %s%s%s <==\n", (first_file ? "" : "\n"), filename,
|
||||
(comment ? ": " : ""),
|
||||
(comment ? comment : ""));
|
||||
first_file = 0;
|
||||
}
|
||||
|
||||
/* Print the last N_LINES lines from the end of file FD.
|
||||
Go backward through the file, reading `BUFSIZ' bytes at a time (except
|
||||
probably the first), until we hit the start of the file or have
|
||||
read NUMBER newlines.
|
||||
POS starts out as the length of the file (the offset of the last
|
||||
byte of the file + 1).
|
||||
Return 0 if successful, 1 if an error occurred. */
|
||||
|
||||
static int
|
||||
file_lines (const char *filename, int fd, long int n_lines, off_t pos)
|
||||
{
|
||||
char buffer[BUFSIZ];
|
||||
int bytes_read;
|
||||
int i; /* Index into `buffer' for scanning. */
|
||||
|
||||
if (n_lines == 0)
|
||||
return 0;
|
||||
|
||||
/* Set `bytes_read' to the size of the last, probably partial, buffer;
|
||||
0 < `bytes_read' <= `BUFSIZ'. */
|
||||
bytes_read = pos % BUFSIZ;
|
||||
if (bytes_read == 0)
|
||||
bytes_read = BUFSIZ;
|
||||
/* Make `pos' a multiple of `BUFSIZ' (0 if the file is short), so that all
|
||||
reads will be on block boundaries, which might increase efficiency. */
|
||||
pos -= bytes_read;
|
||||
lseek (fd, pos, SEEK_SET);
|
||||
bytes_read = fullRead (fd, buffer, bytes_read);
|
||||
if (bytes_read == -1)
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Count the incomplete line on files that don't end with a newline. */
|
||||
if (bytes_read && buffer[bytes_read - 1] != '\n')
|
||||
--n_lines;
|
||||
|
||||
do
|
||||
{
|
||||
/* Scan backward, counting the newlines in this bufferfull. */
|
||||
for (i = bytes_read - 1; i >= 0; i--)
|
||||
{
|
||||
/* Have we counted the requested number of newlines yet? */
|
||||
if (buffer[i] == '\n' && n_lines-- == 0)
|
||||
{
|
||||
/* If this newline wasn't the last character in the buffer,
|
||||
print the text after it. */
|
||||
if (i != bytes_read - 1)
|
||||
XWRITE (STDOUT_FILENO, &buffer[i + 1], bytes_read - (i + 1));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* Not enough newlines in that bufferfull. */
|
||||
if (pos == 0)
|
||||
{
|
||||
/* Not enough lines in the file; print the entire file. */
|
||||
lseek (fd, (off_t) 0, SEEK_SET);
|
||||
return 0;
|
||||
}
|
||||
pos -= BUFSIZ;
|
||||
lseek (fd, pos, SEEK_SET);
|
||||
}
|
||||
while ((bytes_read = fullRead (fd, buffer, BUFSIZ)) > 0);
|
||||
if (bytes_read == -1)
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Print the last N_LINES lines from the end of the standard input,
|
||||
open for reading as pipe FD.
|
||||
Buffer the text as a linked list of LBUFFERs, adding them as needed.
|
||||
Return 0 if successful, 1 if an error occured. */
|
||||
|
||||
static int
|
||||
pipe_lines (const char *filename, int fd, long int n_lines)
|
||||
{
|
||||
struct linebuffer
|
||||
{
|
||||
int nbytes, nlines;
|
||||
char buffer[BUFSIZ];
|
||||
struct linebuffer *next;
|
||||
};
|
||||
typedef struct linebuffer LBUFFER;
|
||||
LBUFFER *first, *last, *tmp;
|
||||
int i; /* Index into buffers. */
|
||||
int total_lines = 0; /* Total number of newlines in all buffers. */
|
||||
int errors = 0;
|
||||
|
||||
first = last = (LBUFFER *) xmalloc (sizeof (LBUFFER));
|
||||
first->nbytes = first->nlines = 0;
|
||||
first->next = NULL;
|
||||
tmp = (LBUFFER *) xmalloc (sizeof (LBUFFER));
|
||||
|
||||
/* Input is always read into a fresh buffer. */
|
||||
while ((tmp->nbytes = fullRead (fd, tmp->buffer, BUFSIZ)) > 0)
|
||||
{
|
||||
tmp->nlines = 0;
|
||||
tmp->next = NULL;
|
||||
|
||||
/* Count the number of newlines just read. */
|
||||
for (i = 0; i < tmp->nbytes; i++)
|
||||
if (tmp->buffer[i] == '\n')
|
||||
++tmp->nlines;
|
||||
total_lines += tmp->nlines;
|
||||
|
||||
/* If there is enough room in the last buffer read, just append the new
|
||||
one to it. This is because when reading from a pipe, `nbytes' can
|
||||
often be very small. */
|
||||
if (tmp->nbytes + last->nbytes < BUFSIZ)
|
||||
{
|
||||
memcpy (&last->buffer[last->nbytes], tmp->buffer, tmp->nbytes);
|
||||
last->nbytes += tmp->nbytes;
|
||||
last->nlines += tmp->nlines;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If there's not enough room, link the new buffer onto the end of
|
||||
the list, then either free up the oldest buffer for the next
|
||||
read if that would leave enough lines, or else malloc a new one.
|
||||
Some compaction mechanism is possible but probably not
|
||||
worthwhile. */
|
||||
last = last->next = tmp;
|
||||
if (total_lines - first->nlines > n_lines)
|
||||
{
|
||||
tmp = first;
|
||||
total_lines -= first->nlines;
|
||||
first = first->next;
|
||||
}
|
||||
else
|
||||
tmp = (LBUFFER *) xmalloc (sizeof (LBUFFER));
|
||||
}
|
||||
}
|
||||
if (tmp->nbytes == -1)
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
errors = 1;
|
||||
free ((char *) tmp);
|
||||
goto free_lbuffers;
|
||||
}
|
||||
|
||||
free ((char *) tmp);
|
||||
|
||||
/* This prevents a core dump when the pipe contains no newlines. */
|
||||
if (n_lines == 0)
|
||||
goto free_lbuffers;
|
||||
|
||||
/* Count the incomplete line on files that don't end with a newline. */
|
||||
if (last->buffer[last->nbytes - 1] != '\n')
|
||||
{
|
||||
++last->nlines;
|
||||
++total_lines;
|
||||
}
|
||||
|
||||
/* Run through the list, printing lines. First, skip over unneeded
|
||||
buffers. */
|
||||
for (tmp = first; total_lines - tmp->nlines > n_lines; tmp = tmp->next)
|
||||
total_lines -= tmp->nlines;
|
||||
|
||||
/* Find the correct beginning, then print the rest of the file. */
|
||||
if (total_lines > n_lines)
|
||||
{
|
||||
char *cp;
|
||||
|
||||
/* Skip `total_lines' - `n_lines' newlines. We made sure that
|
||||
`total_lines' - `n_lines' <= `tmp->nlines'. */
|
||||
cp = tmp->buffer;
|
||||
for (i = total_lines - n_lines; i; --i)
|
||||
while (*cp++ != '\n')
|
||||
/* Do nothing. */ ;
|
||||
i = cp - tmp->buffer;
|
||||
}
|
||||
else
|
||||
i = 0;
|
||||
XWRITE (STDOUT_FILENO, &tmp->buffer[i], tmp->nbytes - i);
|
||||
|
||||
for (tmp = tmp->next; tmp; tmp = tmp->next)
|
||||
XWRITE (STDOUT_FILENO, tmp->buffer, tmp->nbytes);
|
||||
|
||||
free_lbuffers:
|
||||
while (first)
|
||||
{
|
||||
tmp = first->next;
|
||||
free ((char *) first);
|
||||
first = tmp;
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
/* Print the last N_BYTES characters from the end of pipe FD.
|
||||
This is a stripped down version of pipe_lines.
|
||||
Return 0 if successful, 1 if an error occurred. */
|
||||
|
||||
static int
|
||||
pipe_bytes (const char *filename, int fd, off_t n_bytes)
|
||||
{
|
||||
struct charbuffer
|
||||
{
|
||||
int nbytes;
|
||||
char buffer[BUFSIZ];
|
||||
struct charbuffer *next;
|
||||
};
|
||||
typedef struct charbuffer CBUFFER;
|
||||
CBUFFER *first, *last, *tmp;
|
||||
int i; /* Index into buffers. */
|
||||
int total_bytes = 0; /* Total characters in all buffers. */
|
||||
int errors = 0;
|
||||
|
||||
first = last = (CBUFFER *) xmalloc (sizeof (CBUFFER));
|
||||
first->nbytes = 0;
|
||||
first->next = NULL;
|
||||
tmp = (CBUFFER *) xmalloc (sizeof (CBUFFER));
|
||||
|
||||
/* Input is always read into a fresh buffer. */
|
||||
while ((tmp->nbytes = fullRead (fd, tmp->buffer, BUFSIZ)) > 0)
|
||||
{
|
||||
tmp->next = NULL;
|
||||
|
||||
total_bytes += tmp->nbytes;
|
||||
/* If there is enough room in the last buffer read, just append the new
|
||||
one to it. This is because when reading from a pipe, `nbytes' can
|
||||
often be very small. */
|
||||
if (tmp->nbytes + last->nbytes < BUFSIZ)
|
||||
{
|
||||
memcpy (&last->buffer[last->nbytes], tmp->buffer, tmp->nbytes);
|
||||
last->nbytes += tmp->nbytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If there's not enough room, link the new buffer onto the end of
|
||||
the list, then either free up the oldest buffer for the next
|
||||
read if that would leave enough characters, or else malloc a new
|
||||
one. Some compaction mechanism is possible but probably not
|
||||
worthwhile. */
|
||||
last = last->next = tmp;
|
||||
if (total_bytes - first->nbytes > n_bytes)
|
||||
{
|
||||
tmp = first;
|
||||
total_bytes -= first->nbytes;
|
||||
first = first->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (CBUFFER *) xmalloc (sizeof (CBUFFER));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tmp->nbytes == -1)
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
errors = 1;
|
||||
free ((char *) tmp);
|
||||
goto free_cbuffers;
|
||||
}
|
||||
|
||||
free ((char *) tmp);
|
||||
|
||||
/* Run through the list, printing characters. First, skip over unneeded
|
||||
buffers. */
|
||||
for (tmp = first; total_bytes - tmp->nbytes > n_bytes; tmp = tmp->next)
|
||||
total_bytes -= tmp->nbytes;
|
||||
|
||||
/* Find the correct beginning, then print the rest of the file.
|
||||
We made sure that `total_bytes' - `n_bytes' <= `tmp->nbytes'. */
|
||||
if (total_bytes > n_bytes)
|
||||
i = total_bytes - n_bytes;
|
||||
else
|
||||
i = 0;
|
||||
XWRITE (STDOUT_FILENO, &tmp->buffer[i], tmp->nbytes - i);
|
||||
|
||||
for (tmp = tmp->next; tmp; tmp = tmp->next)
|
||||
XWRITE (STDOUT_FILENO, tmp->buffer, tmp->nbytes);
|
||||
|
||||
free_cbuffers:
|
||||
while (first)
|
||||
{
|
||||
tmp = first->next;
|
||||
free ((char *) first);
|
||||
first = tmp;
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
/* Skip N_BYTES characters from the start of pipe FD, and print
|
||||
any extra characters that were read beyond that.
|
||||
Return 1 on error, 0 if ok. */
|
||||
|
||||
static int
|
||||
start_bytes (const char *filename, int fd, off_t n_bytes)
|
||||
{
|
||||
char buffer[BUFSIZ];
|
||||
int bytes_read = 0;
|
||||
|
||||
while (n_bytes > 0 && (bytes_read = fullRead (fd, buffer, BUFSIZ)) > 0)
|
||||
n_bytes -= bytes_read;
|
||||
if (bytes_read == -1)
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
return 1;
|
||||
}
|
||||
else if (n_bytes < 0)
|
||||
XWRITE (STDOUT_FILENO, &buffer[bytes_read + n_bytes], -n_bytes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Skip N_LINES lines at the start of file or pipe FD, and print
|
||||
any extra characters that were read beyond that.
|
||||
Return 1 on error, 0 if ok. */
|
||||
|
||||
static int
|
||||
start_lines (const char *filename, int fd, long int n_lines)
|
||||
{
|
||||
char buffer[BUFSIZ];
|
||||
int bytes_read = 0;
|
||||
int bytes_to_skip = 0;
|
||||
|
||||
while (n_lines && (bytes_read = fullRead (fd, buffer, BUFSIZ)) > 0)
|
||||
{
|
||||
bytes_to_skip = 0;
|
||||
while (bytes_to_skip < bytes_read)
|
||||
if (buffer[bytes_to_skip++] == '\n' && --n_lines == 0)
|
||||
break;
|
||||
}
|
||||
if (bytes_read == -1)
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
return 1;
|
||||
}
|
||||
else if (bytes_to_skip < bytes_read)
|
||||
{
|
||||
XWRITE (STDOUT_FILENO, &buffer[bytes_to_skip],
|
||||
bytes_read - bytes_to_skip);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Display file FILENAME from the current position in FD to the end.
|
||||
If `forever' is nonzero, keep reading from the end of the file
|
||||
until killed. Return the number of bytes read from the file. */
|
||||
|
||||
static long
|
||||
dump_remainder (const char *filename, int fd)
|
||||
{
|
||||
char buffer[BUFSIZ];
|
||||
int bytes_read;
|
||||
long total;
|
||||
|
||||
total = 0;
|
||||
output:
|
||||
while ((bytes_read = fullRead (fd, buffer, BUFSIZ)) > 0)
|
||||
{
|
||||
XWRITE (STDOUT_FILENO, buffer, bytes_read);
|
||||
total += bytes_read;
|
||||
}
|
||||
if (bytes_read == -1)
|
||||
error (EXIT_FAILURE, errno, "%s", filename);
|
||||
if (forever)
|
||||
{
|
||||
fflush (stdout);
|
||||
sleep (1);
|
||||
goto output;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (forever_multiple)
|
||||
fflush (stdout);
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
/* Tail NFILES (>1) files forever until killed. The file names are in
|
||||
NAMES. The open file descriptors are in `file_descs', and the size
|
||||
at which we stopped tailing them is in `file_sizes'. We loop over
|
||||
each of them, doing an fstat to see if they have changed size. If
|
||||
none of them have changed size in one iteration, we sleep for a
|
||||
second and try again. We do this until the user interrupts us. */
|
||||
|
||||
static void
|
||||
tail_forever (char **names, int nfiles)
|
||||
{
|
||||
int last;
|
||||
|
||||
last = -1;
|
||||
|
||||
while (1)
|
||||
{
|
||||
int i;
|
||||
int changed;
|
||||
|
||||
changed = 0;
|
||||
for (i = 0; i < nfiles; i++)
|
||||
{
|
||||
struct stat stats;
|
||||
|
||||
if (file_descs[i] < 0)
|
||||
continue;
|
||||
if (fstat (file_descs[i], &stats) < 0)
|
||||
{
|
||||
error (0, errno, "%s", names[i]);
|
||||
file_descs[i] = -1;
|
||||
continue;
|
||||
}
|
||||
if (stats.st_size == file_sizes[i])
|
||||
continue;
|
||||
|
||||
/* This file has changed size. Print out what we can, and
|
||||
then keep looping. */
|
||||
|
||||
changed = 1;
|
||||
|
||||
if (stats.st_size < file_sizes[i])
|
||||
{
|
||||
write_header (names[i], "file truncated");
|
||||
last = i;
|
||||
lseek (file_descs[i], stats.st_size, SEEK_SET);
|
||||
file_sizes[i] = stats.st_size;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i != last)
|
||||
{
|
||||
if (print_headers)
|
||||
write_header (names[i], NULL);
|
||||
last = i;
|
||||
}
|
||||
file_sizes[i] += dump_remainder (names[i], file_descs[i]);
|
||||
}
|
||||
|
||||
/* If none of the files changed size, sleep. */
|
||||
if (! changed)
|
||||
sleep (1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Output the last N_BYTES bytes of file FILENAME open for reading in FD.
|
||||
Return 0 if successful, 1 if an error occurred. */
|
||||
|
||||
static int
|
||||
tail_bytes (const char *filename, int fd, off_t n_bytes)
|
||||
{
|
||||
struct stat stats;
|
||||
|
||||
/* FIXME: resolve this like in dd.c. */
|
||||
/* Use fstat instead of checking for errno == ESPIPE because
|
||||
lseek doesn't work on some special files but doesn't return an
|
||||
error, either. */
|
||||
if (fstat (fd, &stats))
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (from_start)
|
||||
{
|
||||
if (S_ISREG (stats.st_mode))
|
||||
lseek (fd, n_bytes, SEEK_CUR);
|
||||
else if (start_bytes (filename, fd, n_bytes))
|
||||
return 1;
|
||||
dump_remainder (filename, fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (S_ISREG (stats.st_mode))
|
||||
{
|
||||
off_t current_pos, end_pos;
|
||||
size_t bytes_remaining;
|
||||
|
||||
if ((current_pos = lseek (fd, (off_t) 0, SEEK_CUR)) != -1
|
||||
&& (end_pos = lseek (fd, (off_t) 0, SEEK_END)) != -1)
|
||||
{
|
||||
off_t diff;
|
||||
/* Be careful here. The current position may actually be
|
||||
beyond the end of the file. */
|
||||
bytes_remaining = (diff = end_pos - current_pos) < 0 ? 0 : diff;
|
||||
}
|
||||
else
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (bytes_remaining <= n_bytes)
|
||||
{
|
||||
/* From the current position to end of file, there are no
|
||||
more bytes than have been requested. So reposition the
|
||||
file pointer to the incoming current position and print
|
||||
everything after that. */
|
||||
lseek (fd, current_pos, SEEK_SET);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* There are more bytes remaining than were requested.
|
||||
Back up. */
|
||||
lseek (fd, -n_bytes, SEEK_END);
|
||||
}
|
||||
dump_remainder (filename, fd);
|
||||
}
|
||||
else
|
||||
return pipe_bytes (filename, fd, n_bytes);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Output the last N_LINES lines of file FILENAME open for reading in FD.
|
||||
Return 0 if successful, 1 if an error occurred. */
|
||||
|
||||
static int
|
||||
tail_lines (const char *filename, int fd, long int n_lines)
|
||||
{
|
||||
struct stat stats;
|
||||
off_t length;
|
||||
|
||||
if (fstat (fd, &stats))
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (from_start)
|
||||
{
|
||||
if (start_lines (filename, fd, n_lines))
|
||||
return 1;
|
||||
dump_remainder (filename, fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Use file_lines only if FD refers to a regular file with
|
||||
its file pointer positioned at beginning of file. */
|
||||
/* FIXME: adding the lseek conjunct is a kludge.
|
||||
Once there's a reasonable test suite, fix the true culprit:
|
||||
file_lines. file_lines shouldn't presume that the input
|
||||
file pointer is initially positioned to beginning of file. */
|
||||
if (S_ISREG (stats.st_mode)
|
||||
&& lseek (fd, (off_t) 0, SEEK_CUR) == (off_t) 0)
|
||||
{
|
||||
length = lseek (fd, (off_t) 0, SEEK_END);
|
||||
if (length != 0 && file_lines (filename, fd, n_lines, length))
|
||||
return 1;
|
||||
dump_remainder (filename, fd);
|
||||
}
|
||||
else
|
||||
return pipe_lines (filename, fd, n_lines);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Display the last N_UNITS units of file FILENAME, open for reading
|
||||
in FD.
|
||||
Return 0 if successful, 1 if an error occurred. */
|
||||
|
||||
static int
|
||||
tail (const char *filename, int fd, off_t n_units)
|
||||
{
|
||||
if (count_lines)
|
||||
return tail_lines (filename, fd, (long) n_units);
|
||||
else
|
||||
return tail_bytes (filename, fd, n_units);
|
||||
}
|
||||
|
||||
/* Display the last N_UNITS units of file FILENAME.
|
||||
"-" for FILENAME means the standard input.
|
||||
FILENUM is this file's index in the list of files the user gave.
|
||||
Return 0 if successful, 1 if an error occurred. */
|
||||
|
||||
static int
|
||||
tail_file (const char *filename, off_t n_units, int filenum)
|
||||
{
|
||||
int fd, errors;
|
||||
struct stat stats;
|
||||
|
||||
if (!strcmp (filename, "-"))
|
||||
{
|
||||
have_read_stdin = 1;
|
||||
filename = "standard input";
|
||||
if (print_headers)
|
||||
write_header (filename, NULL);
|
||||
errors = tail (filename, 0, n_units);
|
||||
if (forever_multiple)
|
||||
{
|
||||
if (fstat (0, &stats) < 0)
|
||||
{
|
||||
error (0, errno, "standard input");
|
||||
errors = 1;
|
||||
}
|
||||
else if (!S_ISREG (stats.st_mode))
|
||||
{
|
||||
error (0, 0,
|
||||
"standard input: cannot follow end of non-regular file");
|
||||
errors = 1;
|
||||
}
|
||||
if (errors)
|
||||
file_descs[filenum] = -1;
|
||||
else
|
||||
{
|
||||
file_descs[filenum] = 0;
|
||||
file_sizes[filenum] = stats.st_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Not standard input. */
|
||||
fd = open (filename, O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
if (forever_multiple)
|
||||
file_descs[filenum] = -1;
|
||||
error (0, errno, "%s", filename);
|
||||
errors = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (print_headers)
|
||||
write_header (filename, NULL);
|
||||
errors = tail (filename, fd, n_units);
|
||||
if (forever_multiple)
|
||||
{
|
||||
if (fstat (fd, &stats) < 0)
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
errors = 1;
|
||||
}
|
||||
else if (!S_ISREG (stats.st_mode))
|
||||
{
|
||||
error (0, 0, "%s: cannot follow end of non-regular file",
|
||||
filename);
|
||||
errors = 1;
|
||||
}
|
||||
if (errors)
|
||||
{
|
||||
close (fd);
|
||||
file_descs[filenum] = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
file_descs[filenum] = fd;
|
||||
file_sizes[filenum] = stats.st_size;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (close (fd))
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
errors = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
extern int
|
||||
tail_main (int argc, char **argv)
|
||||
{
|
||||
int stopit = 0;
|
||||
enum header_mode header_mode = multiple_files;
|
||||
int exit_status = 0;
|
||||
/* If from_start, the number of items to skip before printing; otherwise,
|
||||
the number of items at the end of the file to print. Initially, -1
|
||||
means the value has not been set. */
|
||||
off_t n_units = -1;
|
||||
int n_files;
|
||||
char **file;
|
||||
|
||||
program_name = argv[0];
|
||||
have_read_stdin = 0;
|
||||
count_lines = 1;
|
||||
forever = forever_multiple = from_start = print_headers = 0;
|
||||
|
||||
/* Parse any options */
|
||||
//fprintf(stderr, "argc=%d, argv=%s\n", argc, *argv);
|
||||
while (--argc > 0 && ( **(++argv) == '-' || **argv == '+' )) {
|
||||
if (**argv == '+') {
|
||||
from_start = 1;
|
||||
}
|
||||
stopit = 0;
|
||||
while (stopit == 0 && *(++(*argv))) {
|
||||
switch (**argv) {
|
||||
case 'c':
|
||||
count_lines = 0;
|
||||
|
||||
if (--argc < 1) {
|
||||
usage(tail_usage);
|
||||
}
|
||||
n_units = getNum(*(++argv));
|
||||
stopit = 1;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
forever = 1;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
count_lines = 1;
|
||||
|
||||
if (--argc < 1) {
|
||||
usage(tail_usage);
|
||||
}
|
||||
n_units = atol(*(++argv));
|
||||
stopit = 1;
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
header_mode = never;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
header_mode = always;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage (tail_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (n_units == -1)
|
||||
n_units = DEFAULT_N_LINES;
|
||||
|
||||
/* To start printing with item N_UNITS from the start of the file, skip
|
||||
N_UNITS - 1 items. `tail +0' is actually meaningless, but for Unix
|
||||
compatibility it's treated the same as `tail +1'. */
|
||||
if (from_start)
|
||||
{
|
||||
if (n_units)
|
||||
--n_units;
|
||||
}
|
||||
|
||||
n_files = argc;
|
||||
file = argv;
|
||||
|
||||
if (n_files > 1 && forever)
|
||||
{
|
||||
forever_multiple = 1;
|
||||
forever = 0;
|
||||
file_descs = (int *) xmalloc (n_files * sizeof (int));
|
||||
file_sizes = (off_t *) xmalloc (n_files * sizeof (off_t));
|
||||
}
|
||||
|
||||
if (header_mode == always
|
||||
|| (header_mode == multiple_files && n_files > 1))
|
||||
print_headers = 1;
|
||||
|
||||
if (n_files == 0)
|
||||
{
|
||||
exit_status |= tail_file ("-", n_units, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < n_files; i++)
|
||||
exit_status |= tail_file (file[i], n_units, i);
|
||||
|
||||
if (forever_multiple)
|
||||
tail_forever (file, n_files);
|
||||
}
|
||||
|
||||
if (have_read_stdin && close (0) < 0)
|
||||
error (EXIT_FAILURE, errno, "-");
|
||||
if (fclose (stdout) == EOF)
|
||||
error (EXIT_FAILURE, errno, "write error");
|
||||
exit (exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
||||
-126
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
* Mini tee implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static const char tee_usage[] =
|
||||
"tee [OPTION]... [FILE]...\n\n"
|
||||
"Copy standard input to each FILE, and also to standard output.\n\n"
|
||||
"Options:\n"
|
||||
"\t-a\tappend to the given FILEs, do not overwrite\n"
|
||||
#if 0
|
||||
"\t-i\tignore interrupt signals\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
/* FileList _______________________________________________________________ */
|
||||
|
||||
#define FL_MAX 1024
|
||||
static FILE *FileList[FL_MAX];
|
||||
static int FL_end;
|
||||
|
||||
typedef void (FL_Function)(FILE *file, char c);
|
||||
|
||||
|
||||
/* apply a function to everything in FileList */
|
||||
static void
|
||||
FL_apply(FL_Function *f, char c)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i <= FL_end; i++) {
|
||||
f(FileList[i], c);
|
||||
}
|
||||
}
|
||||
|
||||
/* FL_Function for writing to files*/
|
||||
static void
|
||||
tee_fwrite(FILE *file, char c)
|
||||
{
|
||||
fputc(c, file);
|
||||
}
|
||||
|
||||
/* FL_Function for closing files */
|
||||
static void
|
||||
tee_fclose(FILE *file, char c)
|
||||
{
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
/* ________________________________________________________________________ */
|
||||
|
||||
/* BusyBoxed tee(1) */
|
||||
int
|
||||
tee_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char c;
|
||||
char opt;
|
||||
char opt_fopen[2] = "w";
|
||||
FILE *file;
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 'a':
|
||||
opt_fopen[0] = 'a';
|
||||
break;
|
||||
#if 0
|
||||
case 'i':
|
||||
fprintf(stderr, "ignore interrupt not implemented\n");
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
usage(tee_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* init FILE pointers */
|
||||
FL_end = 0;
|
||||
FileList[0] = stdout;
|
||||
for ( ; i < argc; i++) {
|
||||
/* add a file to FileList */
|
||||
file = fopen(argv[i], opt_fopen);
|
||||
if (!file) { continue; }
|
||||
if (FL_end < FL_MAX) {
|
||||
FileList[++FL_end] = file;
|
||||
}
|
||||
}
|
||||
|
||||
/* read and redirect */
|
||||
while ((c = (char) getchar()) && (!feof(stdin))) {
|
||||
FL_apply(tee_fwrite, c);
|
||||
}
|
||||
|
||||
/* clean up */
|
||||
FL_apply(tee_fclose, 0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: tee.c,v 1.4 1999/12/10 08:25:07 andersen Exp $ */
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Mini touch implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <utime.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
static const char touch_usage[] = "touch [-c] file [file ...]\n\n"
|
||||
"Update the last-modified date on the given file[s].\n";
|
||||
|
||||
|
||||
|
||||
extern int
|
||||
touch_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
int create=TRUE;
|
||||
|
||||
if (argc < 2) {
|
||||
usage( touch_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv)) switch (**argv) {
|
||||
case 'c':
|
||||
create = FALSE;
|
||||
break;
|
||||
default:
|
||||
usage( touch_usage);
|
||||
exit( FALSE);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,166 +0,0 @@
|
||||
/* uname -- print system information
|
||||
Copyright (C) 1989-1999 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
||||
|
||||
/* Option Example
|
||||
|
||||
-s, --sysname SunOS
|
||||
-n, --nodename rocky8
|
||||
-r, --release 4.0
|
||||
-v, --version
|
||||
-m, --machine sun
|
||||
-a, --all SunOS rocky8 4.0 sun
|
||||
|
||||
The default behavior is equivalent to `-s'.
|
||||
|
||||
David MacKenzie <djm@gnu.ai.mit.edu> */
|
||||
|
||||
/* Busyboxed by Erik Andersen */
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#if defined (HAVE_SYSINFO) && defined (HAVE_SYS_SYSTEMINFO_H)
|
||||
# include <sys/systeminfo.h>
|
||||
#endif
|
||||
|
||||
|
||||
static const char uname_usage[] =
|
||||
"uname [OPTION]...\n\n"
|
||||
"Print certain system information. With no OPTION, same as -s.\n\n"
|
||||
"Options:\n"
|
||||
"\t-a\tprint all information\n"
|
||||
"\t-m\tthe machine (hardware) type\n"
|
||||
"\t-n\tprint the machine's network node hostname\n"
|
||||
"\t-r\tprint the operating system release\n"
|
||||
"\t-s\tprint the operating system name\n"
|
||||
"\t-p\tprint the host processor type\n"
|
||||
"\t-v\tprint the operating system version\n";
|
||||
|
||||
|
||||
static void print_element(unsigned int mask, char *element);
|
||||
|
||||
/* Values that are bitwise or'd into `toprint'. */
|
||||
/* Operating system name. */
|
||||
#define PRINT_SYSNAME 1
|
||||
|
||||
/* Node name on a communications network. */
|
||||
#define PRINT_NODENAME 2
|
||||
|
||||
/* Operating system release. */
|
||||
#define PRINT_RELEASE 4
|
||||
|
||||
/* Operating system version. */
|
||||
#define PRINT_VERSION 8
|
||||
|
||||
/* Machine hardware name. */
|
||||
#define PRINT_MACHINE 16
|
||||
|
||||
/* Host processor type. */
|
||||
#define PRINT_PROCESSOR 32
|
||||
|
||||
/* Mask indicating which elements of the name to print. */
|
||||
static unsigned char toprint;
|
||||
|
||||
|
||||
int uname_main(int argc, char **argv)
|
||||
{
|
||||
struct utsname name;
|
||||
char processor[256];
|
||||
#if defined(__sparc__) && defined(__linux__)
|
||||
char *fake_sparc = getenv("FAKE_SPARC");
|
||||
#endif
|
||||
|
||||
toprint = 0;
|
||||
|
||||
/* Parse any options */
|
||||
//fprintf(stderr, "argc=%d, argv=%s\n", argc, *argv);
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
while (*(++(*argv))) {
|
||||
switch (**argv) {
|
||||
case 's':
|
||||
toprint |= PRINT_SYSNAME;
|
||||
break;
|
||||
case 'n':
|
||||
toprint |= PRINT_NODENAME;
|
||||
break;
|
||||
case 'r':
|
||||
toprint |= PRINT_RELEASE;
|
||||
break;
|
||||
case 'v':
|
||||
toprint |= PRINT_VERSION;
|
||||
break;
|
||||
case 'm':
|
||||
toprint |= PRINT_MACHINE;
|
||||
break;
|
||||
case 'p':
|
||||
toprint |= PRINT_PROCESSOR;
|
||||
break;
|
||||
case 'a':
|
||||
toprint = (PRINT_SYSNAME | PRINT_NODENAME | PRINT_RELEASE |
|
||||
PRINT_PROCESSOR | PRINT_VERSION |
|
||||
PRINT_MACHINE);
|
||||
break;
|
||||
default:
|
||||
usage(uname_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (toprint == 0)
|
||||
toprint = PRINT_SYSNAME;
|
||||
|
||||
if (uname(&name) == -1)
|
||||
perror("cannot get system name");
|
||||
|
||||
#if defined (HAVE_SYSINFO) && defined (SI_ARCHITECTURE)
|
||||
if (sysinfo(SI_ARCHITECTURE, processor, sizeof(processor)) == -1)
|
||||
perror("cannot get processor type");
|
||||
}
|
||||
|
||||
#else
|
||||
strcpy(processor, "unknown");
|
||||
#endif
|
||||
|
||||
#if defined(__sparc__) && defined(__linux__)
|
||||
if (fake_sparc != NULL
|
||||
&& (fake_sparc[0] == 'y'
|
||||
|| fake_sparc[0] == 'Y')) strcpy(name.machine, "sparc");
|
||||
#endif
|
||||
|
||||
print_element(PRINT_SYSNAME, name.sysname);
|
||||
print_element(PRINT_NODENAME, name.nodename);
|
||||
print_element(PRINT_RELEASE, name.release);
|
||||
print_element(PRINT_VERSION, name.version);
|
||||
print_element(PRINT_MACHINE, name.machine);
|
||||
print_element(PRINT_PROCESSOR, processor);
|
||||
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/* If the name element set in MASK is selected for printing in `toprint',
|
||||
print ELEMENT; then print a space unless it is the last element to
|
||||
be printed, in which case print a newline. */
|
||||
|
||||
static void print_element(unsigned int mask, char *element)
|
||||
{
|
||||
if (toprint & mask) {
|
||||
toprint &= ~mask;
|
||||
printf("%s%c", element, toprint ? ' ' : '\n');
|
||||
}
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
/*
|
||||
* Mini uniq implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char uniq_usage[] =
|
||||
"Usage: uniq [OPTION]... [INPUT [OUTPUT]]\n"
|
||||
"Discard all but one of successive identical lines from INPUT (or\n"
|
||||
"standard input), writing to OUTPUT (or standard output).\n"
|
||||
"\n"
|
||||
"\t-h\tdisplay this help and exit\n"
|
||||
"\n"
|
||||
"A field is a run of whitespace, then non-whitespace characters.\n"
|
||||
"Fields are skipped before chars.\n"
|
||||
;
|
||||
|
||||
/* max chars in line */
|
||||
#define UNIQ_MAX 4096
|
||||
|
||||
typedef void (Print)(FILE *, const char *);
|
||||
|
||||
typedef int (Decide)(const char *, const char *);
|
||||
|
||||
/* container for two lines to be compared */
|
||||
typedef struct {
|
||||
char *a;
|
||||
char *b;
|
||||
int recurrence;
|
||||
FILE *in;
|
||||
FILE *out;
|
||||
void *func;
|
||||
} Subject;
|
||||
|
||||
/* set up all the variables of a uniq operation */
|
||||
static Subject *
|
||||
subject_init(Subject *self, FILE *in, FILE *out, void *func)
|
||||
{
|
||||
self->a = NULL;
|
||||
self->b = NULL;
|
||||
self->in = in;
|
||||
self->out = out;
|
||||
self->func = func;
|
||||
self->recurrence = 0;
|
||||
return self;
|
||||
}
|
||||
|
||||
/* point a and b to the appropriate lines;
|
||||
* count the recurrences (if any) of a string;
|
||||
*/
|
||||
static Subject *
|
||||
subject_next(Subject *self)
|
||||
{
|
||||
/* tmp line holders */
|
||||
static char line[2][UNIQ_MAX];
|
||||
static int alternator = 0;
|
||||
|
||||
if (fgets(line[alternator], UNIQ_MAX, self->in)) {
|
||||
self->a = self->b;
|
||||
self->b = line[alternator];
|
||||
alternator ^= 1;
|
||||
return self;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static Subject *
|
||||
subject_last(Subject *self)
|
||||
{
|
||||
self->a = self->b;
|
||||
self->b = NULL;
|
||||
return self;
|
||||
}
|
||||
|
||||
static Subject *
|
||||
subject_study(Subject *self)
|
||||
{
|
||||
if (self->a == NULL) {
|
||||
return self;
|
||||
}
|
||||
if (self->b == NULL) {
|
||||
fprintf(self->out, "%s", self->a);
|
||||
return self;
|
||||
}
|
||||
if (strcmp(self->a, self->b) == 0) {
|
||||
self->recurrence++;
|
||||
} else {
|
||||
fprintf(self->out, "%s", self->a);
|
||||
self->recurrence = 0;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
static int
|
||||
set_file_pointers(int schema, FILE **in, FILE **out, char **argv)
|
||||
{
|
||||
switch (schema) {
|
||||
case 0:
|
||||
*in = stdin;
|
||||
*out = stdout;
|
||||
break;
|
||||
case 1:
|
||||
*in = fopen(argv[0], "r");
|
||||
*out = stdout;
|
||||
break;
|
||||
case 2:
|
||||
*in = fopen(argv[0], "r");
|
||||
*out = fopen(argv[1], "w");
|
||||
break;
|
||||
}
|
||||
if (*in == NULL) {
|
||||
fprintf(stderr, "uniq: %s: %s\n", argv[0], strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
if (*out == NULL) {
|
||||
fprintf(stderr, "uniq: %s: %s\n", argv[1], strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* one variable is the decision algo */
|
||||
/* another variable is the printing algo */
|
||||
|
||||
/* I don't think I have to have more than a 1 line memory
|
||||
this is the one constant */
|
||||
|
||||
/* it seems like GNU/uniq only takes one or two files as an option */
|
||||
|
||||
/* ________________________________________________________________________ */
|
||||
int
|
||||
uniq_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char opt;
|
||||
FILE *in, *out;
|
||||
Subject s;
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case '-':
|
||||
case 'h':
|
||||
usage(uniq_usage);
|
||||
default:
|
||||
usage(uniq_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* 0 src: stdin; dst: stdout */
|
||||
/* 1 src: file; dst: stdout */
|
||||
/* 2 src: file; dst: file */
|
||||
if (set_file_pointers((argc - 1), &in, &out, &argv[i])) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
subject_init(&s, in, out, NULL);
|
||||
while (subject_next(&s)) {
|
||||
subject_study(&s);
|
||||
}
|
||||
subject_last(&s);
|
||||
subject_study(&s);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: uniq.c,v 1.4 2000/01/07 01:57:32 beppu Exp $ */
|
||||
-162
@@ -1,162 +0,0 @@
|
||||
/*
|
||||
* Mini wc implementation for busybox
|
||||
*
|
||||
* by Edward Betts <edward@debian.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static const char wc_usage[] = "wc [OPTION]... [FILE]...\n\n"
|
||||
"Print line, word, and byte counts for each FILE, and a total line if\n"
|
||||
"more than one FILE is specified. With no FILE, read standard input.\n"
|
||||
"\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-L\tprint the length of the longest line\n"
|
||||
"\t-w\tprint the word counts\n";
|
||||
|
||||
static int total_lines, total_words, total_chars, max_length;
|
||||
static int print_lines, print_words, print_chars, print_length;
|
||||
|
||||
void print_counts (int lines, int words, int chars, int length,
|
||||
const char *name) {
|
||||
char const *space = "";
|
||||
if (print_lines) {
|
||||
printf ("%7d", lines);
|
||||
space = " ";
|
||||
}
|
||||
if (print_words) {
|
||||
printf ("%s%7d", space, words);
|
||||
space = " ";
|
||||
}
|
||||
if (print_chars) {
|
||||
printf ("%s%7d", space, chars);
|
||||
space = " ";
|
||||
}
|
||||
if (print_length)
|
||||
printf ("%s%7d", space, length);
|
||||
if (*name)
|
||||
printf (" %s", name);
|
||||
putchar ('\n');
|
||||
}
|
||||
|
||||
static void wc_file(FILE *file, const char *name)
|
||||
{
|
||||
int lines, words, chars, length;
|
||||
int in_word = 0, linepos = 0;
|
||||
int c;
|
||||
lines = words = chars = length = 0;
|
||||
while ((c = getc(file)) != EOF) {
|
||||
chars++;
|
||||
switch (c) {
|
||||
case '\n':
|
||||
lines++;
|
||||
case '\r':
|
||||
case '\f':
|
||||
if (linepos > length)
|
||||
length = linepos;
|
||||
linepos = 0;
|
||||
goto word_separator;
|
||||
case '\t':
|
||||
linepos += 8 - (linepos % 8);
|
||||
goto word_separator;
|
||||
case ' ':
|
||||
linepos++;
|
||||
case '\v':
|
||||
word_separator:
|
||||
if (in_word) {
|
||||
in_word = 0;
|
||||
words++;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
linepos++;
|
||||
in_word = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (linepos > length)
|
||||
length = linepos;
|
||||
if (in_word)
|
||||
words++;
|
||||
print_counts (lines, words, chars, length, name);
|
||||
total_lines += lines;
|
||||
total_words += words;
|
||||
total_chars += chars;
|
||||
if (length > max_length)
|
||||
max_length = length;
|
||||
fclose(file);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
int wc_main(int argc, char **argv) {
|
||||
FILE *file;
|
||||
total_lines = total_words = total_chars = max_length = 0;
|
||||
print_lines = print_words = print_chars = print_length = 0;
|
||||
|
||||
while (--argc && **(++argv) == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 'c':
|
||||
print_chars = 1;
|
||||
break;
|
||||
case 'l':
|
||||
print_lines = 1;
|
||||
break;
|
||||
case 'L':
|
||||
print_length = 1;
|
||||
break;
|
||||
case 'w':
|
||||
print_words = 1;
|
||||
break;
|
||||
default:
|
||||
usage (wc_usage);
|
||||
}
|
||||
}
|
||||
|
||||
if (!print_lines && !print_words && !print_chars && !print_length)
|
||||
print_lines = print_words = print_chars = 1;
|
||||
|
||||
if (argc == 0) {
|
||||
wc_file(stdin, "");
|
||||
exit(TRUE);
|
||||
}
|
||||
else if (argc == 1) {
|
||||
file = fopen(*argv, "r");
|
||||
if (file == NULL) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
}
|
||||
wc_file(file, *argv);
|
||||
}
|
||||
else {
|
||||
while (argc-- > 0 && *argv != '\0' && strlen(*argv)) {
|
||||
file = fopen(*argv, "r");
|
||||
if (file == NULL) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
}
|
||||
wc_file(file, *argv);
|
||||
argv++;
|
||||
}
|
||||
print_counts (total_lines, total_words, total_chars,
|
||||
max_length, "total");
|
||||
}
|
||||
exit(TRUE);
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Mini whoami implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 Edward Betts <edward@debian.org>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <pwd.h>
|
||||
|
||||
static const char whoami_usage[] = "whoami\n\n"
|
||||
"Print the user name associated with the current effective user id.\n"
|
||||
"Same as id -un.\n";
|
||||
|
||||
extern int whoami_main(int argc, char **argv) {
|
||||
struct passwd *pw;
|
||||
uid_t uid;
|
||||
|
||||
if (argc > 1) usage (whoami_usage);
|
||||
|
||||
uid = geteuid ();
|
||||
pw = getpwuid (uid);
|
||||
if (pw) {
|
||||
puts (pw->pw_name);
|
||||
exit (TRUE);
|
||||
}
|
||||
fprintf (stderr, "%s: cannot find username for UID %u\n", argv[0], (unsigned) uid);
|
||||
exit (FALSE);
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Mini yes implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2000 Edward Betts <edward@debian.org>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern int yes_main(int argc, char **argv) {
|
||||
int i;
|
||||
if (argc == 1)
|
||||
while (1)
|
||||
if (puts ("y") == EOF) {
|
||||
perror ("yes");
|
||||
exit(FALSE);
|
||||
}
|
||||
|
||||
while (1)
|
||||
for (i = 1; i < argc; i++)
|
||||
if (fputs (argv[i], stdout) == EOF || putchar (i == argc - 1 ? '\n' : ' ') == EOF) {
|
||||
perror ("yes");
|
||||
exit(FALSE);
|
||||
}
|
||||
exit(TRUE);
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini cp implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* Copyright (C) 2000 by Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -21,107 +21,97 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <utime.h>
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static const char cp_usage[] = "cp [OPTION]... SOURCE DEST\n"
|
||||
" or: cp [OPTION]... SOURCE... DIRECTORY\n\n"
|
||||
"Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n"
|
||||
"\n"
|
||||
"\t-a\tsame as -dpR\n"
|
||||
"\t-d\tpreserve links\n"
|
||||
"\t-p\tpreserve file attributes if possible\n"
|
||||
"\t-R\tcopy directories recursively\n";
|
||||
|
||||
|
||||
static int recursiveFlag = FALSE;
|
||||
static int followLinks = FALSE;
|
||||
static int preserveFlag = FALSE;
|
||||
static const char *srcName;
|
||||
static const char *destName;
|
||||
static int destDirFlag = FALSE;
|
||||
static int srcDirFlag = FALSE;
|
||||
|
||||
static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
char newdestName[NAME_MAX];
|
||||
char* newsrcName = NULL;
|
||||
|
||||
strcpy(newdestName, destName);
|
||||
if ( srcDirFlag == TRUE ) {
|
||||
if (recursiveFlag!=TRUE ) {
|
||||
fprintf(stderr, "cp: %s: omitting directory\n", srcName);
|
||||
return( TRUE);
|
||||
}
|
||||
strcat(newdestName, strstr(fileName, srcName) + strlen(srcName));
|
||||
}
|
||||
|
||||
if (destDirFlag==TRUE && srcDirFlag == FALSE) {
|
||||
if (newdestName[strlen(newdestName)-1] != '/' ) {
|
||||
strcat(newdestName, "/");
|
||||
}
|
||||
newsrcName = strrchr(srcName, '/');
|
||||
if (newsrcName && *newsrcName != '\0')
|
||||
strcat(newdestName, newsrcName);
|
||||
else
|
||||
strcat(newdestName, srcName);
|
||||
}
|
||||
|
||||
return (copyFile(fileName, newdestName, preserveFlag, followLinks));
|
||||
}
|
||||
#include "busybox.h"
|
||||
|
||||
extern int cp_main(int argc, char **argv)
|
||||
{
|
||||
if (argc < 3) {
|
||||
usage (cp_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
int status = 0;
|
||||
int opt;
|
||||
int flags = 0;
|
||||
int i;
|
||||
|
||||
/* Parse any options */
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 'a':
|
||||
followLinks = TRUE;
|
||||
preserveFlag = TRUE;
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
case 'd':
|
||||
followLinks = TRUE;
|
||||
break;
|
||||
case 'p':
|
||||
preserveFlag = TRUE;
|
||||
break;
|
||||
case 'R':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
default:
|
||||
usage (cp_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
while ((opt = getopt(argc, argv, "adfipRr")) != -1)
|
||||
switch (opt) {
|
||||
case 'a':
|
||||
flags |= FILEUTILS_PRESERVE_STATUS | FILEUTILS_RECUR;
|
||||
/* fallthrough */
|
||||
case 'd':
|
||||
flags |= FILEUTILS_PRESERVE_SYMLINKS;
|
||||
break;
|
||||
case 'f':
|
||||
flags |= FILEUTILS_FORCE;
|
||||
break;
|
||||
case 'i':
|
||||
flags |= FILEUTILS_INTERACTIVE;
|
||||
break;
|
||||
case 'p':
|
||||
flags |= FILEUTILS_PRESERVE_STATUS;
|
||||
break;
|
||||
case 'R':
|
||||
flags |= FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS;
|
||||
break;
|
||||
case 'r':
|
||||
flags |= FILEUTILS_RECUR;
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
|
||||
if (optind + 2 > argc)
|
||||
show_usage();
|
||||
|
||||
/* If there are only two arguments and... */
|
||||
if (optind + 2 == argc) {
|
||||
struct stat source_stat;
|
||||
struct stat dest_stat;
|
||||
int source_exists = 1;
|
||||
int dest_exists = 1;
|
||||
|
||||
destName = argv[argc - 1];
|
||||
destDirFlag = isDirectory(destName);
|
||||
if (((flags & FILEUTILS_PRESERVE_SYMLINKS) &&
|
||||
lstat(argv[optind], &source_stat) < 0) ||
|
||||
(!(flags & FILEUTILS_PRESERVE_SYMLINKS) &&
|
||||
stat(argv[optind], &source_stat))) {
|
||||
if (errno != ENOENT)
|
||||
perror_msg_and_die("unable to stat `%s'", argv[optind]);
|
||||
source_exists = 0;
|
||||
}
|
||||
|
||||
if ((argc > 3) && destDirFlag==FALSE) {
|
||||
fprintf(stderr, "%s: not a directory\n", destName);
|
||||
exit (FALSE);
|
||||
}
|
||||
|
||||
while (argc-- > 1) {
|
||||
srcName = *(argv++);
|
||||
srcDirFlag = isDirectory(srcName);
|
||||
if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE,
|
||||
fileAction, fileAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
if (stat(argv[optind + 1], &dest_stat) < 0) {
|
||||
if (errno != ENOENT)
|
||||
perror_msg_and_die("unable to stat `%s'", argv[optind + 1]);
|
||||
dest_exists = 0;
|
||||
}
|
||||
|
||||
/* ...if neither is a directory or... */
|
||||
if (((!source_exists || !S_ISDIR(source_stat.st_mode)) &&
|
||||
(!dest_exists || !S_ISDIR(dest_stat.st_mode))) ||
|
||||
/* ...recursing, the first is a directory, and the
|
||||
* second doesn't exist, then... */
|
||||
((flags & FILEUTILS_RECUR) && S_ISDIR(source_stat.st_mode) &&
|
||||
!dest_exists)) {
|
||||
/* ...do a simple copy. */
|
||||
if (copy_file(argv[optind], argv[optind + 1], flags) < 0)
|
||||
status = 1;
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
exit( TRUE);
|
||||
|
||||
for (i = optind; i < argc - 1; i++) {
|
||||
char *dest = concat_path_file(argv[argc - 1],
|
||||
get_last_path_component(argv[i]));
|
||||
if (copy_file(argv[i], dest, flags) < 0)
|
||||
status = 1;
|
||||
free(dest);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini cpio implementation for busybox
|
||||
*
|
||||
* Copyright (C) 2001 by Glenn McGrath
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Limitations:
|
||||
* Doesn't check CRC's
|
||||
* Only supports new ASCII and CRC formats
|
||||
*
|
||||
*/
|
||||
#include <fcntl.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include "busybox.h"
|
||||
|
||||
extern int cpio_main(int argc, char **argv)
|
||||
{
|
||||
FILE *src_stream = stdin;
|
||||
char **extract_names = NULL;
|
||||
int extract_function = 0;
|
||||
int num_of_entries = 0;
|
||||
int opt = 0;
|
||||
mode_t oldmask = 0;
|
||||
|
||||
while ((opt = getopt(argc, argv, "idmuvtF:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'i': // extract
|
||||
extract_function |= extract_all_to_fs;
|
||||
break;
|
||||
case 'd': // create _leading_ directories
|
||||
extract_function |= extract_create_leading_dirs;
|
||||
oldmask = umask(077); /* Make make_directory act like GNU cpio */
|
||||
break;
|
||||
case 'm': // preserve modification time
|
||||
extract_function |= extract_preserve_date;
|
||||
break;
|
||||
case 'v': // verbosly list files
|
||||
extract_function |= extract_verbose_list;
|
||||
break;
|
||||
case 'u': // unconditional
|
||||
extract_function |= extract_unconditional;
|
||||
break;
|
||||
case 't': // list files
|
||||
extract_function |= extract_list;
|
||||
break;
|
||||
case 'F':
|
||||
src_stream = xfopen(optarg, "r");
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
if ((extract_function & extract_all_to_fs) && (extract_function & extract_list)) {
|
||||
extract_function ^= extract_all_to_fs; /* If specify t, don't extract*/
|
||||
}
|
||||
|
||||
if ((extract_function & extract_all_to_fs) && (extract_function & extract_verbose_list)) {
|
||||
/* The meaning of v changes on extract */
|
||||
extract_function ^= extract_verbose_list;
|
||||
extract_function |= extract_list;
|
||||
}
|
||||
|
||||
while (optind < argc) {
|
||||
extract_names = xrealloc(extract_names, sizeof(char *) * (num_of_entries + 2));
|
||||
extract_names[num_of_entries] = xstrdup(argv[optind]);
|
||||
num_of_entries++;
|
||||
extract_names[num_of_entries] = NULL;
|
||||
optind++;
|
||||
}
|
||||
|
||||
unarchive(src_stream, stdout, &get_header_cpio, extract_function, "./", extract_names);
|
||||
if (oldmask) {
|
||||
umask(oldmask); /* Restore umask if we changed it */
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,356 @@
|
||||
/*
|
||||
* cut.c - minimalist version of cut
|
||||
*
|
||||
* Copyright (C) 1999,2000 by Lineo, inc. and Mark Whitley
|
||||
* Copyright (C) 1999,2000,2001 by Mark Whitley <markw@codepoet.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 <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h> /* getopt */
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include "busybox.h"
|
||||
|
||||
|
||||
/* globals from other files */
|
||||
extern int optind;
|
||||
extern char *optarg;
|
||||
|
||||
|
||||
/* option vars */
|
||||
static char part = 0; /* (b)yte, (c)har, (f)ields */
|
||||
static unsigned int supress_non_delimited_lines = 0;
|
||||
static char delim = '\t'; /* delimiter, default is tab */
|
||||
|
||||
struct cut_list {
|
||||
int startpos;
|
||||
int endpos;
|
||||
};
|
||||
|
||||
static const int BOL = 0;
|
||||
static const int EOL = INT_MAX;
|
||||
static const int NON_RANGE = -1;
|
||||
|
||||
static struct cut_list *cut_lists = NULL; /* growable array holding a series of lists */
|
||||
static unsigned int nlists = 0; /* number of elements in above list */
|
||||
|
||||
|
||||
static int cmpfunc(const void *a, const void *b)
|
||||
{
|
||||
struct cut_list *la = (struct cut_list *)a;
|
||||
struct cut_list *lb = (struct cut_list *)b;
|
||||
|
||||
if (la->startpos > lb->startpos)
|
||||
return 1;
|
||||
if (la->startpos < lb->startpos)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* parse_lists() - parses a list and puts values into startpos and endpos.
|
||||
* valid list formats: N, N-, N-M, -M
|
||||
* more than one list can be seperated by commas
|
||||
*/
|
||||
static void parse_lists(char *lists)
|
||||
{
|
||||
char *ltok = NULL;
|
||||
char *ntok = NULL;
|
||||
char *junk;
|
||||
int s = 0, e = 0;
|
||||
|
||||
/* take apart the lists, one by one (they are seperated with commas */
|
||||
while ((ltok = strsep(&lists, ",")) != NULL) {
|
||||
|
||||
/* it's actually legal to pass an empty list */
|
||||
if (strlen(ltok) == 0)
|
||||
continue;
|
||||
|
||||
/* get the start pos */
|
||||
ntok = strsep(<ok, "-");
|
||||
if (ntok == NULL) {
|
||||
fprintf(stderr, "Help ntok is null for starting position! What do I do?\n");
|
||||
} else if (strlen(ntok) == 0) {
|
||||
s = BOL;
|
||||
} else {
|
||||
s = strtoul(ntok, &junk, 10);
|
||||
if(*junk != '\0' || s < 0)
|
||||
error_msg_and_die("invalid byte or field list");
|
||||
|
||||
/* account for the fact that arrays are zero based, while the user
|
||||
* expects the first char on the line to be char # 1 */
|
||||
if (s != 0)
|
||||
s--;
|
||||
}
|
||||
|
||||
/* get the end pos */
|
||||
ntok = strsep(<ok, "-");
|
||||
if (ntok == NULL) {
|
||||
e = NON_RANGE;
|
||||
} else if (strlen(ntok) == 0) {
|
||||
e = EOL;
|
||||
} else {
|
||||
e = strtoul(ntok, &junk, 10);
|
||||
if(*junk != '\0' || e < 0)
|
||||
error_msg_and_die("invalid byte or field list");
|
||||
/* if the user specified and end position of 0, that means "til the
|
||||
* end of the line */
|
||||
if (e == 0)
|
||||
e = INT_MAX;
|
||||
e--; /* again, arrays are zero based, lines are 1 based */
|
||||
if (e == s)
|
||||
e = NON_RANGE;
|
||||
}
|
||||
|
||||
/* if there's something left to tokenize, the user past an invalid list */
|
||||
if (ltok)
|
||||
error_msg_and_die("invalid byte or field list");
|
||||
|
||||
/* add the new list */
|
||||
cut_lists = xrealloc(cut_lists, sizeof(struct cut_list) * (++nlists));
|
||||
cut_lists[nlists-1].startpos = s;
|
||||
cut_lists[nlists-1].endpos = e;
|
||||
}
|
||||
|
||||
/* make sure we got some cut positions out of all that */
|
||||
if (nlists == 0)
|
||||
error_msg_and_die("missing list of positions");
|
||||
|
||||
/* now that the lists are parsed, we need to sort them to make life easier
|
||||
* on us when it comes time to print the chars / fields / lines */
|
||||
qsort(cut_lists, nlists, sizeof(struct cut_list), cmpfunc);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static void cut_line_by_chars(const char *line)
|
||||
{
|
||||
int c, l;
|
||||
/* set up a list so we can keep track of what's been printed */
|
||||
char *printed = xcalloc(strlen(line), sizeof(char));
|
||||
|
||||
/* print the chars specified in each cut list */
|
||||
for (c = 0; c < nlists; c++) {
|
||||
l = cut_lists[c].startpos;
|
||||
while (l < strlen(line)) {
|
||||
if (!printed[l]) {
|
||||
putchar(line[l]);
|
||||
printed[l] = 'X';
|
||||
}
|
||||
l++;
|
||||
if (cut_lists[c].endpos == NON_RANGE || l > cut_lists[c].endpos)
|
||||
break;
|
||||
}
|
||||
}
|
||||
putchar('\n'); /* cuz we were handed a chomped line */
|
||||
free(printed);
|
||||
}
|
||||
|
||||
|
||||
static void cut_line_by_fields(char *line)
|
||||
{
|
||||
int c, f;
|
||||
int ndelim = -1; /* zero-based / one-based problem */
|
||||
int nfields_printed = 0;
|
||||
char *field = NULL;
|
||||
char d[2] = { delim, 0 };
|
||||
char *printed;
|
||||
|
||||
/* test the easy case first: does this line contain any delimiters? */
|
||||
if (strchr(line, delim) == NULL) {
|
||||
if (!supress_non_delimited_lines)
|
||||
puts(line);
|
||||
return;
|
||||
}
|
||||
|
||||
/* set up a list so we can keep track of what's been printed */
|
||||
printed = xcalloc(strlen(line), sizeof(char));
|
||||
|
||||
/* process each list on this line, for as long as we've got a line to process */
|
||||
for (c = 0; c < nlists && line; c++) {
|
||||
f = cut_lists[c].startpos;
|
||||
do {
|
||||
|
||||
/* find the field we're looking for */
|
||||
while (line && ndelim < f) {
|
||||
field = strsep(&line, d);
|
||||
ndelim++;
|
||||
}
|
||||
|
||||
/* we found it, and it hasn't been printed yet */
|
||||
if (field && ndelim == f && !printed[ndelim]) {
|
||||
/* if this isn't our first time through, we need to print the
|
||||
* delimiter after the last field that was printed */
|
||||
if (nfields_printed > 0)
|
||||
putchar(delim);
|
||||
fputs(field, stdout);
|
||||
printed[ndelim] = 'X';
|
||||
nfields_printed++;
|
||||
}
|
||||
|
||||
f++;
|
||||
|
||||
/* keep going as long as we have a line to work with, this is a
|
||||
* list, and we're not at the end of that list */
|
||||
} while (line && cut_lists[c].endpos != NON_RANGE && f <= cut_lists[c].endpos);
|
||||
}
|
||||
|
||||
/* if we printed anything at all, we need to finish it with a newline cuz
|
||||
* we were handed a chomped line */
|
||||
putchar('\n');
|
||||
|
||||
free(printed);
|
||||
}
|
||||
|
||||
|
||||
static void cut_file_by_lines(const char *line, unsigned int linenum)
|
||||
{
|
||||
static int c = 0;
|
||||
static int l = -1;
|
||||
|
||||
/* I can't initialize this above cuz the "initializer isn't
|
||||
* constant" *sigh* */
|
||||
if (l == -1)
|
||||
l = cut_lists[c].startpos;
|
||||
|
||||
/* get out if we have no more lists to process or if the lines are lower
|
||||
* than what we're interested in */
|
||||
if (c >= nlists || linenum < l)
|
||||
return;
|
||||
|
||||
/* if the line we're looking for is lower than the one we were passed, it
|
||||
* means we displayed it already, so move on */
|
||||
while (l < linenum) {
|
||||
l++;
|
||||
/* move on to the next list if we're at the end of this one */
|
||||
if (cut_lists[c].endpos == NON_RANGE || l > cut_lists[c].endpos) {
|
||||
c++;
|
||||
/* get out if there's no more lists to process */
|
||||
if (c >= nlists)
|
||||
return;
|
||||
l = cut_lists[c].startpos;
|
||||
/* get out if the current line is lower than the one we just became
|
||||
* interested in */
|
||||
if (linenum < l)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* If we made it here, it means we've found the line we're looking for, so print it */
|
||||
puts(line);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* snippy-snip
|
||||
*/
|
||||
static void cut_file(FILE *file)
|
||||
{
|
||||
char *line = NULL;
|
||||
unsigned int linenum = 0; /* keep these zero-based to be consistent */
|
||||
|
||||
/* go through every line in the file */
|
||||
while ((line = get_line_from_file(file)) != NULL) {
|
||||
chomp(line);
|
||||
|
||||
/* cut based on chars/bytes XXX: only works when sizeof(char) == byte */
|
||||
if (part == 'c' || part == 'b')
|
||||
cut_line_by_chars(line);
|
||||
|
||||
/* cut based on fields */
|
||||
else if (part == 'f') {
|
||||
if (delim == '\n')
|
||||
cut_file_by_lines(line, linenum);
|
||||
else
|
||||
cut_line_by_fields(line);
|
||||
}
|
||||
|
||||
linenum++;
|
||||
free(line);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern int cut_main(int argc, char **argv)
|
||||
{
|
||||
int opt;
|
||||
|
||||
while ((opt = getopt(argc, argv, "b:c:d:f:ns")) > 0) {
|
||||
switch (opt) {
|
||||
case 'b':
|
||||
case 'c':
|
||||
case 'f':
|
||||
/* make sure they didn't ask for two types of lists */
|
||||
if (part != 0) {
|
||||
error_msg_and_die("only one type of list may be specified");
|
||||
}
|
||||
part = (char)opt;
|
||||
parse_lists(optarg);
|
||||
break;
|
||||
case 'd':
|
||||
if (strlen(optarg) > 1) {
|
||||
error_msg_and_die("the delimiter must be a single character");
|
||||
}
|
||||
delim = optarg[0];
|
||||
break;
|
||||
case 'n':
|
||||
/* no-op */
|
||||
break;
|
||||
case 's':
|
||||
supress_non_delimited_lines++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (part == 0) {
|
||||
error_msg_and_die("you must specify a list of bytes, characters, or fields");
|
||||
}
|
||||
|
||||
/* non-field (char or byte) cutting has some special handling */
|
||||
if (part != 'f') {
|
||||
if (supress_non_delimited_lines) {
|
||||
error_msg_and_die("suppressing non-delimited lines makes sense"
|
||||
" only when operating on fields");
|
||||
}
|
||||
if (delim != '\t' && part != 'f') {
|
||||
error_msg_and_die("a delimiter may be specified only when operating on fields");
|
||||
}
|
||||
}
|
||||
|
||||
/* argv[(optind)..(argc-1)] should be names of file to process. If no
|
||||
* files were specified or '-' was specified, take input from stdin.
|
||||
* Otherwise, we process all the files specified. */
|
||||
if (argv[optind] == NULL || (strcmp(argv[optind], "-") == 0)) {
|
||||
cut_file(stdin);
|
||||
}
|
||||
else {
|
||||
int i;
|
||||
FILE *file;
|
||||
for (i = optind; i < argc; i++) {
|
||||
file = wfopen(argv[i], "r");
|
||||
if(file) {
|
||||
cut_file(file);
|
||||
fclose(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini date implementation for busybox
|
||||
*
|
||||
@@ -19,13 +20,15 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include "busybox.h"
|
||||
|
||||
|
||||
/* This 'date' command supports only 2 time setting formats,
|
||||
@@ -34,254 +37,211 @@
|
||||
an RFC 822 complient date output for shell scripting
|
||||
mail commands */
|
||||
|
||||
static const char date_usage[] = "date [OPTION]... [+FORMAT]\n"
|
||||
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n\n"
|
||||
"Display the current time in the given FORMAT, or set the system date.\n"
|
||||
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
|
||||
"\t-s\t\tset time described by STRING\n"
|
||||
"\t-u\t\tprint or set Coordinated Universal Time\n";
|
||||
|
||||
|
||||
/* Input parsing code is always bulky - used heavy duty libc stuff as
|
||||
much as possible, missed out a lot of bounds checking */
|
||||
|
||||
/* Default input handling to save suprising some people */
|
||||
|
||||
struct tm *
|
||||
date_conv_time(struct tm *tm_time, const char *t_string) {
|
||||
int nr;
|
||||
static struct tm *date_conv_time(struct tm *tm_time, const char *t_string)
|
||||
{
|
||||
int nr;
|
||||
|
||||
nr = sscanf(t_string, "%2d%2d%2d%2d%d",
|
||||
&(tm_time->tm_mon),
|
||||
&(tm_time->tm_mday),
|
||||
&(tm_time->tm_hour),
|
||||
&(tm_time->tm_min),
|
||||
&(tm_time->tm_year));
|
||||
nr = sscanf(t_string, "%2d%2d%2d%2d%d",
|
||||
&(tm_time->tm_mon),
|
||||
&(tm_time->tm_mday),
|
||||
&(tm_time->tm_hour),
|
||||
&(tm_time->tm_min), &(tm_time->tm_year));
|
||||
|
||||
if(nr < 4 || nr > 5) {
|
||||
fprintf(stderr, "date: invalid date `%s'\n", t_string);
|
||||
exit( FALSE);
|
||||
}
|
||||
if (nr < 4 || nr > 5) {
|
||||
error_msg_and_die(invalid_date, t_string);
|
||||
}
|
||||
|
||||
/* correct for century - minor Y2K problem here? */
|
||||
if(tm_time->tm_year >= 1900)
|
||||
tm_time->tm_year -= 1900;
|
||||
/* adjust date */
|
||||
tm_time->tm_mon -= 1;
|
||||
|
||||
return(tm_time);
|
||||
/* correct for century - minor Y2K problem here? */
|
||||
if (tm_time->tm_year >= 1900)
|
||||
tm_time->tm_year -= 1900;
|
||||
/* adjust date */
|
||||
tm_time->tm_mon -= 1;
|
||||
|
||||
return (tm_time);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* The new stuff for LRP */
|
||||
|
||||
struct tm *
|
||||
date_conv_ftime(struct tm *tm_time, const char *t_string) {
|
||||
struct tm itm_time, jtm_time, ktm_time, \
|
||||
ltm_time, mtm_time, ntm_time;
|
||||
|
||||
itm_time = *tm_time;
|
||||
jtm_time = *tm_time;
|
||||
ktm_time = *tm_time;
|
||||
ltm_time = *tm_time;
|
||||
mtm_time = *tm_time;
|
||||
ntm_time = *tm_time;
|
||||
|
||||
/* Parse input and assign appropriately to tm_time */
|
||||
|
||||
if(sscanf(t_string, "%d:%d:%d",
|
||||
&itm_time.tm_hour,
|
||||
&itm_time.tm_min,
|
||||
&itm_time.tm_sec) == 3 ) {
|
||||
|
||||
*tm_time = itm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d:%d",
|
||||
&jtm_time.tm_hour,
|
||||
&jtm_time.tm_min) == 2) {
|
||||
|
||||
*tm_time = jtm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d-%d:%d:%d",
|
||||
&ktm_time.tm_mon,
|
||||
&ktm_time.tm_mday,
|
||||
&ktm_time.tm_hour,
|
||||
&ktm_time.tm_min,
|
||||
&ktm_time.tm_sec) == 5) {
|
||||
|
||||
ktm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = ktm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d-%d:%d",
|
||||
<m_time.tm_mon,
|
||||
<m_time.tm_mday,
|
||||
<m_time.tm_hour,
|
||||
<m_time.tm_min) == 4) {
|
||||
|
||||
ltm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = ltm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d.%d-%d:%d:%d",
|
||||
&mtm_time.tm_year,
|
||||
&mtm_time.tm_mon,
|
||||
&mtm_time.tm_mday,
|
||||
&mtm_time.tm_hour,
|
||||
&mtm_time.tm_min,
|
||||
&mtm_time.tm_sec) == 6) {
|
||||
|
||||
mtm_time.tm_year -= 1900; /* Adjust years */
|
||||
mtm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = mtm_time;
|
||||
return(tm_time);
|
||||
|
||||
} else if (sscanf(t_string, "%d.%d.%d-%d:%d",
|
||||
&ntm_time.tm_year,
|
||||
&ntm_time.tm_mon,
|
||||
&ntm_time.tm_mday,
|
||||
&ntm_time.tm_hour,
|
||||
&ntm_time.tm_min) == 5) {
|
||||
ntm_time.tm_year -= 1900; /* Adjust years */
|
||||
ntm_time.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
*tm_time = ntm_time;
|
||||
return(tm_time);
|
||||
|
||||
}
|
||||
|
||||
fprintf(stderr, "date: invalid date `%s'\n", t_string);
|
||||
|
||||
exit( FALSE);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
date_main(int argc, char * * argv)
|
||||
static struct tm *date_conv_ftime(struct tm *tm_time, const char *t_string)
|
||||
{
|
||||
char *date_str = NULL;
|
||||
char *date_fmt = NULL;
|
||||
char *t_buff;
|
||||
int i;
|
||||
int set_time = 0;
|
||||
int rfc822 = 0;
|
||||
int utc = 0;
|
||||
int use_arg = 0;
|
||||
time_t tm;
|
||||
struct tm tm_time;
|
||||
|
||||
/* Interpret command line args */
|
||||
i = --argc;
|
||||
argv++;
|
||||
while (i > 0 && **argv) {
|
||||
if (**argv == '-') {
|
||||
while (i>0 && *++(*argv)) switch (**argv) {
|
||||
case 'R':
|
||||
rfc822 = 1;
|
||||
break;
|
||||
case 's':
|
||||
set_time = 1;
|
||||
if(date_str != NULL) usage ( date_usage);
|
||||
date_str = optarg;
|
||||
break;
|
||||
case 'u':
|
||||
utc = 1;
|
||||
if (putenv ("TZ=UTC0") != 0) {
|
||||
fprintf(stderr,"date: memory exhausted\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
/* Look ma, no break. Don't fix it either. */
|
||||
case 'd':
|
||||
use_arg = 1;
|
||||
if(date_str != NULL) usage ( date_usage);
|
||||
date_str = optarg;
|
||||
break;
|
||||
case '-':
|
||||
usage ( date_usage);
|
||||
}
|
||||
struct tm t;
|
||||
|
||||
/* Parse input and assign appropriately to tm_time */
|
||||
|
||||
if (t=*tm_time,sscanf(t_string, "%d:%d:%d",
|
||||
&t.tm_hour, &t.tm_min, &t.tm_sec) == 3) {
|
||||
/* no adjustments needed */
|
||||
|
||||
} else if (t=*tm_time,sscanf(t_string, "%d:%d",
|
||||
&t.tm_hour, &t.tm_min) == 2) {
|
||||
/* no adjustments needed */
|
||||
|
||||
|
||||
} else if (t=*tm_time,sscanf(t_string, "%d.%d-%d:%d:%d",
|
||||
&t.tm_mon,
|
||||
&t.tm_mday,
|
||||
&t.tm_hour,
|
||||
&t.tm_min, &t.tm_sec) == 5) {
|
||||
|
||||
t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
|
||||
} else if (t=*tm_time,sscanf(t_string, "%d.%d-%d:%d",
|
||||
&t.tm_mon,
|
||||
&t.tm_mday,
|
||||
&t.tm_hour, &t.tm_min) == 4) {
|
||||
|
||||
t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
|
||||
} else if (t=*tm_time,sscanf(t_string, "%d.%d.%d-%d:%d:%d",
|
||||
&t.tm_year,
|
||||
&t.tm_mon,
|
||||
&t.tm_mday,
|
||||
&t.tm_hour,
|
||||
&t.tm_min, &t.tm_sec) == 6) {
|
||||
|
||||
t.tm_year -= 1900; /* Adjust years */
|
||||
t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
|
||||
} else if (t=*tm_time,sscanf(t_string, "%d.%d.%d-%d:%d",
|
||||
&t.tm_year,
|
||||
&t.tm_mon,
|
||||
&t.tm_mday,
|
||||
&t.tm_hour, &t.tm_min) == 5) {
|
||||
t.tm_year -= 1900; /* Adjust years */
|
||||
t.tm_mon -= 1; /* Adjust dates from 1-12 to 0-11 */
|
||||
|
||||
} else {
|
||||
if ( (date_fmt == NULL) && (strcmp(*argv, "+")==0) )
|
||||
date_fmt=*argv;
|
||||
else if (date_str == NULL) {
|
||||
set_time = 1;
|
||||
date_str=*argv;
|
||||
} else {
|
||||
usage ( date_usage);
|
||||
}
|
||||
error_msg_and_die(invalid_date, t_string);
|
||||
}
|
||||
i--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
|
||||
/* Now we have parsed all the information except the date format
|
||||
which depends on whether the clock is being set or read */
|
||||
|
||||
time(&tm);
|
||||
memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
|
||||
/* Zero out fields - take her back to midnight!*/
|
||||
if(date_str != NULL) {
|
||||
tm_time.tm_sec = 0;
|
||||
tm_time.tm_min = 0;
|
||||
tm_time.tm_hour = 0;
|
||||
}
|
||||
|
||||
/* Process any date input to UNIX time since 1 Jan 1970 */
|
||||
if(date_str != NULL) {
|
||||
|
||||
if(strchr(date_str, ':') != NULL) {
|
||||
date_conv_ftime(&tm_time, date_str);
|
||||
} else {
|
||||
date_conv_time(&tm_time, date_str);
|
||||
}
|
||||
|
||||
/* Correct any day of week and day of year etc fields */
|
||||
tm = mktime(&tm_time);
|
||||
if (tm < 0 ) {
|
||||
fprintf(stderr, "date: invalid date `%s'\n", date_str);
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
/* if setting time, set it */
|
||||
if(set_time) {
|
||||
if( stime(&tm) < 0) {
|
||||
fprintf(stderr, "date: can't set date.\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Display output */
|
||||
|
||||
/* Deal with format string */
|
||||
if(date_fmt == NULL) {
|
||||
date_fmt = (rfc822
|
||||
? (utc
|
||||
? "%a, %_d %b %Y %H:%M:%S GMT"
|
||||
: "%a, %_d %b %Y %H:%M:%S %z")
|
||||
: "%a %b %e %H:%M:%S %Z %Y");
|
||||
|
||||
} else if ( *date_fmt == '\0' ) {
|
||||
/* Imitate what GNU 'date' does with NO format string! */
|
||||
printf ("\n");
|
||||
exit( TRUE);
|
||||
}
|
||||
|
||||
/* Handle special conversions */
|
||||
|
||||
if( strncmp( date_fmt, "%f", 2) == 0 ) {
|
||||
date_fmt = "%Y.%m.%d-%H:%M:%S";
|
||||
}
|
||||
|
||||
/* Print OUTPUT (after ALL that!) */
|
||||
t_buff = malloc(201);
|
||||
strftime(t_buff, 200, date_fmt, &tm_time);
|
||||
printf("%s\n", t_buff);
|
||||
|
||||
exit( TRUE);
|
||||
|
||||
*tm_time = t;
|
||||
return (tm_time);
|
||||
}
|
||||
|
||||
|
||||
int date_main(int argc, char **argv)
|
||||
{
|
||||
char *date_str = NULL;
|
||||
char *date_fmt = NULL;
|
||||
char *t_buff;
|
||||
int c;
|
||||
int set_time = 0;
|
||||
int rfc822 = 0;
|
||||
int utc = 0;
|
||||
int use_arg = 0;
|
||||
time_t tm;
|
||||
struct tm tm_time;
|
||||
|
||||
/* Interpret command line args */
|
||||
while ((c = getopt(argc, argv, "Rs:ud:")) != EOF) {
|
||||
switch (c) {
|
||||
case 'R':
|
||||
rfc822 = 1;
|
||||
break;
|
||||
case 's':
|
||||
set_time = 1;
|
||||
if ((date_str != NULL) || ((date_str = optarg) == NULL)) {
|
||||
show_usage();
|
||||
}
|
||||
break;
|
||||
case 'u':
|
||||
utc = 1;
|
||||
if (putenv("TZ=UTC0") != 0)
|
||||
error_msg_and_die(memory_exhausted);
|
||||
break;
|
||||
case 'd':
|
||||
use_arg = 1;
|
||||
if ((date_str != NULL) || ((date_str = optarg) == NULL))
|
||||
show_usage();
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
if ((date_fmt == NULL) && (optind < argc) && (argv[optind][0] == '+'))
|
||||
date_fmt = &argv[optind][1]; /* Skip over the '+' */
|
||||
else if (date_str == NULL) {
|
||||
set_time = 1;
|
||||
date_str = argv[optind];
|
||||
}
|
||||
#if 0
|
||||
else {
|
||||
error_msg("date_str='%s' date_fmt='%s'\n", date_str, date_fmt);
|
||||
show_usage();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Now we have parsed all the information except the date format
|
||||
which depends on whether the clock is being set or read */
|
||||
|
||||
time(&tm);
|
||||
memcpy(&tm_time, localtime(&tm), sizeof(tm_time));
|
||||
/* Zero out fields - take her back to midnight! */
|
||||
if (date_str != NULL) {
|
||||
tm_time.tm_sec = 0;
|
||||
tm_time.tm_min = 0;
|
||||
tm_time.tm_hour = 0;
|
||||
}
|
||||
|
||||
/* Process any date input to UNIX time since 1 Jan 1970 */
|
||||
if (date_str != NULL) {
|
||||
|
||||
if (strchr(date_str, ':') != NULL) {
|
||||
date_conv_ftime(&tm_time, date_str);
|
||||
} else {
|
||||
date_conv_time(&tm_time, date_str);
|
||||
}
|
||||
|
||||
/* Correct any day of week and day of year etc. fields */
|
||||
tm = mktime(&tm_time);
|
||||
if (tm < 0)
|
||||
error_msg_and_die(invalid_date, date_str);
|
||||
if ( utc ) {
|
||||
if (putenv("TZ=UTC0") != 0)
|
||||
error_msg_and_die(memory_exhausted);
|
||||
}
|
||||
|
||||
/* if setting time, set it */
|
||||
if (set_time) {
|
||||
if (stime(&tm) < 0) {
|
||||
perror_msg("cannot set date");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Display output */
|
||||
|
||||
/* Deal with format string */
|
||||
if (date_fmt == NULL) {
|
||||
date_fmt = (rfc822
|
||||
? (utc
|
||||
? "%a, %e %b %Y %H:%M:%S GMT"
|
||||
: "%a, %e %b %Y %H:%M:%S %z")
|
||||
: "%a %b %e %H:%M:%S %Z %Y");
|
||||
|
||||
} else if (*date_fmt == '\0') {
|
||||
/* Imitate what GNU 'date' does with NO format string! */
|
||||
printf("\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/* Handle special conversions */
|
||||
|
||||
if (strncmp(date_fmt, "%f", 2) == 0) {
|
||||
date_fmt = "%Y.%m.%d-%H:%M:%S";
|
||||
}
|
||||
|
||||
/* Print OUTPUT (after ALL that!) */
|
||||
t_buff = xmalloc(201);
|
||||
strftime(t_buff, 200, date_fmt, &tm_time);
|
||||
puts(t_buff);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <math.h>
|
||||
#include "busybox.h"
|
||||
|
||||
/* Tiny RPN calculator, because "expr" didn't give me bitwise operations. */
|
||||
|
||||
static double stack[100];
|
||||
static unsigned int pointer;
|
||||
|
||||
static void push(double a)
|
||||
{
|
||||
if (pointer >= (sizeof(stack) / sizeof(*stack)))
|
||||
error_msg_and_die("stack overflow");
|
||||
stack[pointer++] = a;
|
||||
}
|
||||
|
||||
static double pop()
|
||||
{
|
||||
if (pointer == 0)
|
||||
error_msg_and_die("stack underflow");
|
||||
return stack[--pointer];
|
||||
}
|
||||
|
||||
static void add()
|
||||
{
|
||||
push(pop() + pop());
|
||||
}
|
||||
|
||||
static void sub()
|
||||
{
|
||||
double subtrahend = pop();
|
||||
|
||||
push(pop() - subtrahend);
|
||||
}
|
||||
|
||||
static void mul()
|
||||
{
|
||||
push(pop() * pop());
|
||||
}
|
||||
|
||||
static void divide()
|
||||
{
|
||||
double divisor = pop();
|
||||
|
||||
push(pop() / divisor);
|
||||
}
|
||||
|
||||
static void and()
|
||||
{
|
||||
push((unsigned int) pop() & (unsigned int) pop());
|
||||
}
|
||||
|
||||
static void or()
|
||||
{
|
||||
push((unsigned int) pop() | (unsigned int) pop());
|
||||
}
|
||||
|
||||
static void eor()
|
||||
{
|
||||
push((unsigned int) pop() ^ (unsigned int) pop());
|
||||
}
|
||||
|
||||
static void not()
|
||||
{
|
||||
push(~(unsigned int) pop());
|
||||
}
|
||||
|
||||
static void print()
|
||||
{
|
||||
printf("%g\n", pop());
|
||||
}
|
||||
|
||||
struct op {
|
||||
const char *name;
|
||||
void (*function) ();
|
||||
};
|
||||
|
||||
static const struct op operators[] = {
|
||||
{"+", add},
|
||||
{"add", add},
|
||||
{"-", sub},
|
||||
{"sub", sub},
|
||||
{"*", mul},
|
||||
{"mul", mul},
|
||||
{"/", divide},
|
||||
{"div", divide},
|
||||
{"and", and},
|
||||
{"or", or},
|
||||
{"not", not},
|
||||
{"eor", eor},
|
||||
{0, 0}
|
||||
};
|
||||
|
||||
static void stack_machine(const char *argument)
|
||||
{
|
||||
char *endPointer = 0;
|
||||
double d;
|
||||
const struct op *o = operators;
|
||||
|
||||
if (argument == 0) {
|
||||
print();
|
||||
return;
|
||||
}
|
||||
|
||||
d = strtod(argument, &endPointer);
|
||||
|
||||
if (endPointer != argument) {
|
||||
push(d);
|
||||
return;
|
||||
}
|
||||
|
||||
while (o->name != 0) {
|
||||
if (strcmp(o->name, argument) == 0) {
|
||||
(*(o->function)) ();
|
||||
return;
|
||||
}
|
||||
o++;
|
||||
}
|
||||
error_msg_and_die("%s: syntax error.", argument);
|
||||
}
|
||||
|
||||
/* return pointer to next token in buffer and set *buffer to one char
|
||||
* past the end of the above mentioned token
|
||||
*/
|
||||
static char *get_token(char **buffer)
|
||||
{
|
||||
char *start = NULL;
|
||||
char *current = *buffer;
|
||||
|
||||
while (isspace(*current)) { current++; }
|
||||
if (*current != 0) {
|
||||
start = current;
|
||||
while (!isspace(*current) && current != 0) { current++; }
|
||||
*buffer = current;
|
||||
}
|
||||
return start;
|
||||
}
|
||||
|
||||
/* In Perl one might say, scalar m|\s*(\S+)\s*|g */
|
||||
static int number_of_tokens(char *buffer)
|
||||
{
|
||||
int i = 0;
|
||||
char *b = buffer;
|
||||
while (get_token(&b)) { i++; }
|
||||
return i;
|
||||
}
|
||||
|
||||
int dc_main(int argc, char **argv)
|
||||
{
|
||||
/* take stuff from stdin if no args are given */
|
||||
if (argc <= 1) {
|
||||
int i, len;
|
||||
char *line = NULL;
|
||||
char *cursor = NULL;
|
||||
char *token = NULL;
|
||||
while ((line = get_line_from_file(stdin))) {
|
||||
cursor = line;
|
||||
len = number_of_tokens(line);
|
||||
for (i = 0; i < len; i++) {
|
||||
token = get_token(&cursor);
|
||||
*cursor++ = 0;
|
||||
stack_machine(token);
|
||||
}
|
||||
free(line);
|
||||
}
|
||||
} else {
|
||||
if (*argv[1]=='-')
|
||||
show_usage();
|
||||
while (argc >= 2) {
|
||||
stack_machine(argv[1]);
|
||||
argv++;
|
||||
argc--;
|
||||
}
|
||||
}
|
||||
stack_machine(0);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,15 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini dd implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* based in part on code taken from sash.
|
||||
*
|
||||
* Copyright (c) 1999 by David I. Bell
|
||||
* Permission is granted to use, distribute, or modify this source,
|
||||
* provided that this copyright notice remains intact.
|
||||
*
|
||||
* Permission to distribute this code under the GPL has been granted.
|
||||
* Copyright (C) 2000 by Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -27,168 +21,151 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "internal.h"
|
||||
#include <features.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
typedef unsigned long long int uintmax_t;
|
||||
#endif
|
||||
|
||||
static const char dd_usage[] =
|
||||
"dd [if=name] [of=name] [bs=n] [count=n]\n\n"
|
||||
"Copy a file, converting and formatting according to options\n\n"
|
||||
"\tif=FILE\tread from FILE instead of stdin\n"
|
||||
"\tof=FILE\twrite to FILE instead of stout\n"
|
||||
"\tbs=n\tread and write N BYTES at a time\n"
|
||||
"\tcount=n\tcopy only n input blocks\n"
|
||||
//"\tskip=n\tskip n input blocks\n"
|
||||
"\n"
|
||||
"BYTES may be suffixed by w (x2), k (x1024), b (x512), or m (x1024^2).\n";
|
||||
#include "busybox.h"
|
||||
|
||||
|
||||
static const struct suffix_mult dd_suffixes[] = {
|
||||
{ "c", 1 },
|
||||
{ "w", 2 },
|
||||
{ "b", 512 },
|
||||
{ "kD", 1000 },
|
||||
{ "k", 1024 },
|
||||
{ "MD", 1000000 },
|
||||
{ "M", 1048576 },
|
||||
{ "GD", 1000000000 },
|
||||
{ "G", 1073741824 },
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
extern int dd_main (int argc, char **argv)
|
||||
int dd_main(int argc, char **argv)
|
||||
{
|
||||
const char *inFile = NULL;
|
||||
const char *outFile = NULL;
|
||||
char *cp;
|
||||
int inFd;
|
||||
int outFd;
|
||||
int inCc = 0;
|
||||
int outCc;
|
||||
size_t blockSize = 512;
|
||||
//uintmax_t skipBlocks = 0;
|
||||
uintmax_t count = (uintmax_t)-1;
|
||||
uintmax_t intotal;
|
||||
uintmax_t outTotal;
|
||||
unsigned char *buf;
|
||||
int i, ifd, ofd, oflag, sync_flag = FALSE, trunc = TRUE, noerror = FALSE;
|
||||
size_t in_full = 0, in_part = 0, out_full = 0, out_part = 0;
|
||||
size_t bs = 512, count = -1;
|
||||
ssize_t n;
|
||||
off_t seek = 0, skip = 0;
|
||||
char *infile = NULL, *outfile = NULL, *buf;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
/* Parse any options */
|
||||
while (argc) {
|
||||
if (inFile == NULL && (strncmp(*argv, "if", 2) == 0))
|
||||
inFile=((strchr(*argv, '='))+1);
|
||||
else if (outFile == NULL && (strncmp(*argv, "of", 2) == 0))
|
||||
outFile=((strchr(*argv, '='))+1);
|
||||
else if (strncmp("count", *argv, 5) == 0) {
|
||||
count = getNum ((strchr(*argv, '='))+1);
|
||||
if (count <= 0) {
|
||||
fprintf (stderr, "Bad count value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (strncmp("bs=", argv[i], 3) == 0)
|
||||
bs = parse_number(argv[i]+3, dd_suffixes);
|
||||
else if (strncmp("count=", argv[i], 6) == 0)
|
||||
count = parse_number(argv[i]+6, dd_suffixes);
|
||||
else if (strncmp("seek=", argv[i], 5) == 0)
|
||||
seek = parse_number(argv[i]+5, dd_suffixes);
|
||||
else if (strncmp("skip=", argv[i], 5) == 0)
|
||||
skip = parse_number(argv[i]+5, dd_suffixes);
|
||||
else if (strncmp("if=", argv[i], 3) == 0)
|
||||
infile = argv[i]+3;
|
||||
else if (strncmp("of=", argv[i], 3) == 0)
|
||||
outfile = argv[i]+3;
|
||||
else if (strncmp("conv=", argv[i], 5) == 0) {
|
||||
buf = argv[i]+5;
|
||||
while (1) {
|
||||
if (strncmp("notrunc", buf, 7) == 0) {
|
||||
trunc = FALSE;
|
||||
buf += 7;
|
||||
} else if (strncmp("sync", buf, 4) == 0) {
|
||||
sync_flag = TRUE;
|
||||
buf += 4;
|
||||
} else if (strncmp("noerror", buf, 7) == 0) {
|
||||
noerror = TRUE;
|
||||
buf += 7;
|
||||
} else {
|
||||
error_msg_and_die("invalid conversion `%s'", argv[i]+5);
|
||||
}
|
||||
if (buf[0] == '\0')
|
||||
break;
|
||||
if (buf[0] == ',')
|
||||
buf++;
|
||||
}
|
||||
} else
|
||||
show_usage();
|
||||
}
|
||||
else if (strncmp(*argv, "bs", 2) == 0) {
|
||||
blockSize = getNum ((strchr(*argv, '='))+1);
|
||||
if (blockSize <= 0) {
|
||||
fprintf (stderr, "Bad block size value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
|
||||
buf = xmalloc(bs);
|
||||
|
||||
if (infile != NULL) {
|
||||
if ((ifd = open(infile, O_RDONLY)) < 0)
|
||||
perror_msg_and_die("%s", infile);
|
||||
} else {
|
||||
ifd = STDIN_FILENO;
|
||||
infile = "standard input";
|
||||
}
|
||||
#if 0
|
||||
else if (strncmp(*argv, "skip", 4) == 0) {
|
||||
skipBlocks = atoi( *argv);
|
||||
if (skipBlocks <= 0) {
|
||||
fprintf (stderr, "Bad skip value %d\n", skipBlocks);
|
||||
goto usage;
|
||||
}
|
||||
|
||||
if (outfile != NULL) {
|
||||
oflag = O_WRONLY | O_CREAT;
|
||||
|
||||
if (!seek && trunc)
|
||||
oflag |= O_TRUNC;
|
||||
|
||||
if ((ofd = open(outfile, oflag, 0666)) < 0)
|
||||
perror_msg_and_die("%s", outfile);
|
||||
|
||||
if (seek && trunc) {
|
||||
if (ftruncate(ofd, seek * bs) < 0) {
|
||||
struct stat st;
|
||||
if (fstat (ofd, &st) < 0 || S_ISREG (st.st_mode) ||
|
||||
S_ISDIR (st.st_mode))
|
||||
perror_msg_and_die("%s", outfile);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ofd = STDOUT_FILENO;
|
||||
outfile = "standard output";
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
goto usage;
|
||||
|
||||
if (skip) {
|
||||
if (lseek(ifd, skip * bs, SEEK_CUR) < 0)
|
||||
perror_msg_and_die("%s", infile);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
buf = malloc (blockSize);
|
||||
if (buf == NULL) {
|
||||
fprintf (stderr, "Cannot allocate buffer\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
intotal = 0;
|
||||
outTotal = 0;
|
||||
|
||||
if (inFile == NULL)
|
||||
inFd = fileno(stdin);
|
||||
else
|
||||
inFd = open (inFile, 0);
|
||||
|
||||
if (inFd < 0) {
|
||||
perror (inFile);
|
||||
free (buf);
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
if (outFile == NULL)
|
||||
outFd = fileno(stdout);
|
||||
else
|
||||
outFd = creat (outFile, 0666);
|
||||
|
||||
if (outFd < 0) {
|
||||
perror (outFile);
|
||||
close (inFd);
|
||||
free (buf);
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
//lseek(inFd, skipBlocks*blockSize, SEEK_SET);
|
||||
//
|
||||
//TODO: Convert to using fullRead & fullWrite
|
||||
// from utilitity.c
|
||||
// -Erik
|
||||
while (outTotal < count * blockSize) {
|
||||
inCc = read (inFd, buf, blockSize);
|
||||
if (inCc < 0) {
|
||||
perror (inFile);
|
||||
goto cleanup;
|
||||
} else if (inCc == 0) {
|
||||
goto cleanup;
|
||||
if (seek) {
|
||||
if (lseek(ofd, seek * bs, SEEK_CUR) < 0)
|
||||
perror_msg_and_die("%s", outfile);
|
||||
}
|
||||
intotal += inCc;
|
||||
cp = buf;
|
||||
|
||||
while (intotal > outTotal) {
|
||||
if (outTotal + inCc > count * blockSize)
|
||||
inCc = count * blockSize - outTotal;
|
||||
outCc = write (outFd, cp, inCc);
|
||||
if (outCc < 0) {
|
||||
perror (outFile);
|
||||
goto cleanup;
|
||||
} else if (outCc == 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
inCc -= outCc;
|
||||
cp += outCc;
|
||||
outTotal += outCc;
|
||||
while (in_full + in_part != count) {
|
||||
if (noerror) {
|
||||
/* Pre-zero the buffer when doing the noerror thing */
|
||||
memset(buf, '\0', bs);
|
||||
}
|
||||
n = safe_read(ifd, buf, bs);
|
||||
if (n < 0) {
|
||||
if (noerror) {
|
||||
n = bs;
|
||||
perror_msg("%s", infile);
|
||||
} else {
|
||||
perror_msg_and_die("%s", infile);
|
||||
}
|
||||
}
|
||||
if (n == 0)
|
||||
break;
|
||||
if (n == bs)
|
||||
in_full++;
|
||||
else
|
||||
in_part++;
|
||||
if (sync_flag) {
|
||||
memset(buf + n, '\0', bs - n);
|
||||
n = bs;
|
||||
}
|
||||
n = full_write(ofd, buf, n);
|
||||
if (n < 0)
|
||||
perror_msg_and_die("%s", outfile);
|
||||
if (n == bs)
|
||||
out_full++;
|
||||
else
|
||||
out_part++;
|
||||
}
|
||||
}
|
||||
|
||||
if (inCc < 0)
|
||||
perror (inFile);
|
||||
fprintf(stderr, "%ld+%ld records in\n", (long)in_full, (long)in_part);
|
||||
fprintf(stderr, "%ld+%ld records out\n", (long)out_full, (long)out_part);
|
||||
|
||||
cleanup:
|
||||
close (inFd);
|
||||
close (outFd);
|
||||
free (buf);
|
||||
|
||||
printf ("%ld+%d records in\n", (long)(intotal / blockSize),
|
||||
(intotal % blockSize) != 0);
|
||||
printf ("%ld+%d records out\n", (long)(outTotal / blockSize),
|
||||
(outTotal % blockSize) != 0);
|
||||
exit( TRUE);
|
||||
usage:
|
||||
|
||||
usage( dd_usage);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
+28
-35
@@ -1,50 +1,43 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
|
||||
* Renamed deallocvt.
|
||||
*/
|
||||
#include "internal.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/vt.h>
|
||||
#include <stdio.h>
|
||||
#include "busybox.h"
|
||||
|
||||
extern int getfd(void);
|
||||
char *progname;
|
||||
/* From <linux/vt.h> */
|
||||
static const int VT_DISALLOCATE = 0x5608; /* free memory associated to vt */
|
||||
|
||||
int
|
||||
deallocvt_main(int argc, char *argv[]) {
|
||||
int fd, num, i;
|
||||
int deallocvt_main(int argc, char *argv[])
|
||||
{
|
||||
int fd, num, i;
|
||||
|
||||
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
|
||||
usage ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
|
||||
}
|
||||
//if ((argc > 2) || ((argv == 2) && (**(argv + 1) == '-')))
|
||||
if (argc > 2)
|
||||
show_usage();
|
||||
|
||||
progname = argv[0];
|
||||
fd = get_console_fd();
|
||||
|
||||
fd = get_console_fd("/dev/console");
|
||||
|
||||
if (argc == 1) {
|
||||
/* deallocate all unused consoles */
|
||||
if (ioctl(fd,VT_DISALLOCATE,0)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
exit(1);
|
||||
if (argc == 1) {
|
||||
/* deallocate all unused consoles */
|
||||
if (ioctl(fd, VT_DISALLOCATE, 0))
|
||||
perror_msg_and_die("VT_DISALLOCATE");
|
||||
} else {
|
||||
for (i = 1; i < argc; i++) {
|
||||
num = atoi(argv[i]);
|
||||
if (num == 0)
|
||||
error_msg("0: illegal VT number");
|
||||
else if (num == 1)
|
||||
error_msg("VT 1 cannot be deallocated");
|
||||
else if (ioctl(fd, VT_DISALLOCATE, num))
|
||||
perror_msg_and_die("VT_DISALLOCATE");
|
||||
}
|
||||
}
|
||||
} else
|
||||
for (i = 1; i < argc; i++) {
|
||||
num = atoi(argv[i]);
|
||||
if (num == 0)
|
||||
fprintf(stderr, "%s: 0: illegal VT number\n", progname);
|
||||
else if (num == 1)
|
||||
fprintf(stderr, "%s: VT 1 cannot be deallocated\n", progname);
|
||||
else
|
||||
if (ioctl(fd,VT_DISALLOCATE,num)) {
|
||||
perror("VT_DISALLOCATE");
|
||||
fprintf(stderr, "%s: could not deallocate console %d\n",
|
||||
progname, num);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Vendored
+493
@@ -0,0 +1,493 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
// This file defines the feature set to be compiled into busybox.
|
||||
// When you turn things off here, they won't be compiled in at all.
|
||||
//
|
||||
//// This file is parsed by sed. You MUST use single line comments.
|
||||
// i.e., //#define BB_BLAH
|
||||
//
|
||||
//
|
||||
// BusyBox Applications
|
||||
//#define BB_ADJTIMEX
|
||||
#define BB_AR
|
||||
//#define BB_ASH
|
||||
//#define BB_BASENAME
|
||||
#define BB_CAT
|
||||
#define BB_CHGRP
|
||||
#define BB_CHMOD
|
||||
#define BB_CHOWN
|
||||
#define BB_CHROOT
|
||||
//#define BB_CHVT
|
||||
#define BB_CLEAR
|
||||
//#define BB_CMP
|
||||
#define BB_CP
|
||||
//#define BB_CPIO
|
||||
#define BB_CUT
|
||||
//#define BB_DATE
|
||||
//#define BB_DC
|
||||
//#define BB_DD
|
||||
//#define BB_DEALLOCVT
|
||||
#define BB_DF
|
||||
#define BB_DIRNAME
|
||||
#define BB_DMESG
|
||||
//#define BB_DOS2UNIX
|
||||
//#define BB_DPKG
|
||||
//#define BB_DPKG_DEB
|
||||
//#define BB_DUTMP
|
||||
//#define BB_DU
|
||||
//#define BB_DUMPKMAP
|
||||
#define BB_ECHO
|
||||
//#define BB_ENV
|
||||
#define BB_EXPR
|
||||
//#define BB_FBSET
|
||||
//#define BB_FDFLUSH
|
||||
#define BB_FIND
|
||||
#define BB_FREE
|
||||
//#define BB_FREERAMDISK
|
||||
//#define BB_FSCK_MINIX
|
||||
//#define BB_GETOPT
|
||||
#define BB_GREP
|
||||
#define BB_GUNZIP
|
||||
#define BB_GZIP
|
||||
#define BB_HALT
|
||||
#define BB_HEAD
|
||||
//#define BB_HOSTID
|
||||
#define BB_HOSTNAME
|
||||
//#define BB_HUSH
|
||||
#define BB_ID
|
||||
#define BB_IFCONFIG
|
||||
#define BB_INIT
|
||||
//#define BB_INSMOD
|
||||
#define BB_KILL
|
||||
#define BB_KILLALL
|
||||
#define BB_KLOGD
|
||||
//#define BB_LASH
|
||||
//#define BB_LENGTH
|
||||
#define BB_LN
|
||||
//#define BB_LOADACM
|
||||
//#define BB_LOADFONT
|
||||
#define BB_LOADKMAP
|
||||
#define BB_LOGGER
|
||||
//#define BB_LOGNAME
|
||||
#define BB_LOSETUP
|
||||
#define BB_LS
|
||||
//#define BB_LSMOD
|
||||
//#define BB_MAKEDEVS
|
||||
#define BB_MD5SUM
|
||||
#define BB_MKDIR
|
||||
//#define BB_MKFIFO
|
||||
//#define BB_MKFS_MINIX
|
||||
#define BB_MKNOD
|
||||
#define BB_MKSWAP
|
||||
//#define BB_MKTEMP
|
||||
//#define BB_MODPROBE
|
||||
#define BB_MORE
|
||||
#define BB_MOUNT
|
||||
//#define BB_MSH
|
||||
//#define BB_MT
|
||||
#define BB_MV
|
||||
//#define BB_NC
|
||||
//#define BB_NSLOOKUP
|
||||
//#define BB_PIDOF
|
||||
#define BB_PING
|
||||
//#define BB_PIVOT_ROOT
|
||||
#define BB_POWEROFF
|
||||
//#define BB_PRINTF
|
||||
#define BB_PS
|
||||
#define BB_PWD
|
||||
//#define BB_RDATE
|
||||
//#define BB_READLINK
|
||||
#define BB_REBOOT
|
||||
//#define BB_RENICE
|
||||
#define BB_RESET
|
||||
#define BB_RM
|
||||
#define BB_RMDIR
|
||||
//#define BB_RMMOD
|
||||
#define BB_ROUTE
|
||||
//#define BB_RPM2CPIO
|
||||
#define BB_SED
|
||||
//#define BB_SETKEYCODES
|
||||
#define BB_SLEEP
|
||||
#define BB_SORT
|
||||
//#define BB_STTY
|
||||
#define BB_SWAPONOFF
|
||||
#define BB_SYNC
|
||||
#define BB_SYSLOGD
|
||||
#define BB_TAIL
|
||||
#define BB_TAR
|
||||
//#define BB_TEE
|
||||
#define BB_TEST
|
||||
//#define BB_TELNET
|
||||
//#define BB_TFTP
|
||||
//#define BB_TIME
|
||||
//#define BB_TOP
|
||||
#define BB_TOUCH
|
||||
#define BB_TR
|
||||
//#define BB_TRACEROUTE
|
||||
#define BB_TRUE_FALSE
|
||||
#define BB_TTY
|
||||
//#define BB_UNIX2DOS
|
||||
//#define BB_UUENCODE
|
||||
//#define BB_UUDECODE
|
||||
#define BB_UMOUNT
|
||||
#define BB_UNIQ
|
||||
#define BB_UNAME
|
||||
//#define BB_UPDATE
|
||||
#define BB_UPTIME
|
||||
//#define BB_USLEEP
|
||||
//#define BB_VI
|
||||
//#define BB_WATCHDOG
|
||||
#define BB_WC
|
||||
#define BB_WGET
|
||||
#define BB_WHICH
|
||||
#define BB_WHOAMI
|
||||
//#define BB_XARGS
|
||||
//#define BB_YES
|
||||
// End of Applications List
|
||||
//
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------
|
||||
// This is where feature definitions go. Generally speaking,
|
||||
// turning this stuff off makes things a bit smaller (and less
|
||||
// pretty/useful).
|
||||
//
|
||||
//
|
||||
// If you enabled one or more of the shells, you may select which one
|
||||
// should be run when sh is invoked:
|
||||
//#define BB_FEATURE_SH_IS_ASH
|
||||
//#define BB_FEATURE_SH_IS_HUSH
|
||||
//#define BB_FEATURE_SH_IS_LASH
|
||||
//#define BB_FEATURE_SH_IS_MSH
|
||||
//
|
||||
// BusyBox will, by default, malloc space for its buffers. This costs code
|
||||
// size for the call to xmalloc. You can use the following feature to have
|
||||
// them put on the stack. For some very small machines with limited stack
|
||||
// space, this can be deadly. For most folks, this works just fine...
|
||||
//#define BB_FEATURE_BUFFERS_GO_ON_STACK
|
||||
// The third alternative for buffer allocation is to use BSS. This works
|
||||
// beautifully for computers with a real MMU (and OS support), but wastes
|
||||
// runtime RAM for uCLinux. This behavior was the only one available for
|
||||
// BusyBox versions 0.48 and earlier.
|
||||
//#define BB_FEATURE_BUFFERS_GO_IN_BSS
|
||||
//
|
||||
// Turn this on to use Erik's very cool devps, and devmtab kernel drivers,
|
||||
// thereby eliminating the need for the /proc filesystem and thereby saving
|
||||
// lots and lots memory for more important things. NOTE: If you enable this
|
||||
// feature, you _must_ have patched the kernel to include the devps patch that
|
||||
// is included in the busybox/kernel-patches directory. You will also need to
|
||||
// create some device special files in /dev on your embedded system:
|
||||
// mknod /dev/mtab c 10 22
|
||||
// mknod /dev/ps c 10 21
|
||||
// I emailed Linus and this patch will not be going into the stock kernel.
|
||||
//#define BB_FEATURE_USE_DEVPS_PATCH
|
||||
//
|
||||
// show verbose usage messages
|
||||
//#define BB_FEATURE_VERBOSE_USAGE
|
||||
//
|
||||
// Use termios to manipulate the screen ('more' is prettier with this on)
|
||||
#define BB_FEATURE_USE_TERMIOS
|
||||
//
|
||||
// calculate terminal & column widths (for more, ls, and telnet)
|
||||
#define BB_FEATURE_AUTOWIDTH
|
||||
//
|
||||
// show username/groupnames for ls
|
||||
#define BB_FEATURE_LS_USERNAME
|
||||
//
|
||||
// show file timestamps in ls
|
||||
#define BB_FEATURE_LS_TIMESTAMPS
|
||||
//
|
||||
// enable ls -p and -F
|
||||
#define BB_FEATURE_LS_FILETYPES
|
||||
//
|
||||
// sort the file names
|
||||
#define BB_FEATURE_LS_SORTFILES
|
||||
//
|
||||
// enable ls -R
|
||||
#define BB_FEATURE_LS_RECURSIVE
|
||||
//
|
||||
// enable ls -L
|
||||
#define BB_FEATURE_LS_FOLLOWLINKS
|
||||
//
|
||||
// Use color to identify different file types
|
||||
#define BB_FEATURE_LS_COLOR
|
||||
//
|
||||
// Disable for a smaller (but less functional) ping
|
||||
#define BB_FEATURE_FANCY_PING
|
||||
//
|
||||
// Make init use a simplified /etc/inittab file (recommended).
|
||||
#define BB_FEATURE_USE_INITTAB
|
||||
//
|
||||
//Enable init being called as /linuxrc
|
||||
#define BB_FEATURE_LINUXRC
|
||||
//
|
||||
//Have init enable core dumping for child processes (for debugging only)
|
||||
//#define BB_FEATURE_INIT_COREDUMPS
|
||||
//
|
||||
//Make sure nothing is printed to the console on boot
|
||||
//#define BB_FEATURE_EXTRA_QUIET
|
||||
//
|
||||
// enable syslogd -R remotehost
|
||||
//#define BB_FEATURE_REMOTE_LOG
|
||||
//
|
||||
// enable syslogd -C
|
||||
//#define BB_FEATURE_IPC_SYSLOG
|
||||
//
|
||||
//Disable for a simple tail implementation (2.34k vs 3k for the full one).
|
||||
//Both provide 'tail -f', but this cuts out -c, -q, -s, and -v.
|
||||
#define BB_FEATURE_FANCY_TAIL
|
||||
//
|
||||
// Enable support for loop devices in mount
|
||||
#define BB_FEATURE_MOUNT_LOOP
|
||||
//
|
||||
// Enable support for a real /etc/mtab file instead of /proc/mounts
|
||||
//#define BB_FEATURE_MTAB_SUPPORT
|
||||
//
|
||||
// Enable support for mounting remote NFS volumes.
|
||||
// You may need to mount with "-o nolock" if you are
|
||||
// not running a local portmapper daemon...
|
||||
//
|
||||
// If you are using uClibc, be sure that you've already compiled
|
||||
// uClibc with INCLUDE_RPC=true (contained in the Config file)
|
||||
#define BB_FEATURE_NFSMOUNT
|
||||
//
|
||||
// Enable support forced filesystem unmounting
|
||||
// (i.e., in case of an unreachable NFS system).
|
||||
#define BB_FEATURE_MOUNT_FORCE
|
||||
//
|
||||
// Enable support for creation of tar files.
|
||||
#define BB_FEATURE_TAR_CREATE
|
||||
//
|
||||
// Enable support for "--exclude" and "-X" for excluding files
|
||||
//#define BB_FEATURE_TAR_EXCLUDE
|
||||
//
|
||||
// Enable support for tar -z option (currently only works for inflating)
|
||||
#define BB_FEATURE_TAR_GZIP
|
||||
//
|
||||
// Enable reverse sort
|
||||
//#define BB_FEATURE_SORT_REVERSE
|
||||
//
|
||||
// Enable uniqe sort
|
||||
//#define BB_FEATURE_SORT_UNIQUE
|
||||
//
|
||||
// Enable command line editing in the shell.
|
||||
// Only relevant if a shell is enabled. On by default.
|
||||
//#define BB_FEATURE_COMMAND_EDITING
|
||||
//
|
||||
// Enable tab completion in the shell. This is now working quite nicely.
|
||||
// This feature adds a bit over 4k. Only relevant if a shell is enabled.
|
||||
//#define BB_FEATURE_COMMAND_TAB_COMPLETION
|
||||
//
|
||||
// Attempts to match usernames in a ~-prefixed path
|
||||
//#define BB_FEATURE_COMMAND_USERNAME_COMPLETION
|
||||
//
|
||||
//Allow the shell to invoke all the compiled in BusyBox applets as if they
|
||||
//were shell builtins. Nice for staticly linking an emergency rescue shell,
|
||||
//among other things. Off by default.
|
||||
// Only relevant if a shell is enabled.
|
||||
//#define BB_FEATURE_SH_STANDALONE_SHELL
|
||||
//
|
||||
//When this is enabled, busybox shell applets can be called using full path
|
||||
//names. This causes applets (i.e., most busybox commands) to override
|
||||
//real commands on the filesystem. For example, if you run run /bin/cat, it
|
||||
//will use BusyBox cat even if /bin/cat exists on the filesystem and is _not_
|
||||
//busybox. Some systems want this, others do not. Choose wisely. :-) This
|
||||
//only has meaning when BB_FEATURE_SH_STANDALONE_SHELL is enabled.
|
||||
// Only relevant if a shell is enabled. Off by default.
|
||||
//#define BB_FEATURE_SH_APPLETS_ALWAYS_WIN
|
||||
//
|
||||
// Uncomment this option for a fancy shell prompt that includes the
|
||||
// current username and hostname. On systems that don't have usernames
|
||||
// or hostnames, this can look hideous.
|
||||
// Only relevant if a shell is enabled.
|
||||
//#define BB_FEATURE_SH_FANCY_PROMPT
|
||||
//
|
||||
// Uncomment this option to disable job control. Job control lets you
|
||||
// run jobs in the background (which completely useless for is all you
|
||||
// are doing is running scripts). Disabing this is bad for interactive
|
||||
// use, since when you hit ^C in an application, it will also kill the
|
||||
// shell. This adds about 2.5k on an x86 system.
|
||||
//#define BB_FEATURE_ASH_JOB_CONTROL
|
||||
//
|
||||
//Turn on extra fbset options
|
||||
//#define BB_FEATURE_FBSET_FANCY
|
||||
//
|
||||
//Turn on fbset readmode support
|
||||
//#define BB_FEATURE_FBSET_READMODE
|
||||
//
|
||||
// Support insmod/lsmod/rmmod for post 2.1 kernels
|
||||
//#define BB_FEATURE_NEW_MODULE_INTERFACE
|
||||
//
|
||||
// Support insmod/lsmod/rmmod for pre 2.1 kernels
|
||||
//#define BB_FEATURE_OLD_MODULE_INTERFACE
|
||||
//
|
||||
// Support module version checking
|
||||
//#define BB_FEATURE_INSMOD_VERSION_CHECKING
|
||||
//
|
||||
// Support for uClinux memory usage optimization, which will load the image
|
||||
// directly into the kernel memory. This divides memory requrements by three.
|
||||
// If you are not running uClinux (i.e., your CPU has an MMU) leave this
|
||||
// disabled...
|
||||
//#define BB_FEATURE_INSMOD_LOADINKMEM
|
||||
//
|
||||
// Support for Minix filesystem, version 2
|
||||
//#define BB_FEATURE_MINIX2
|
||||
//
|
||||
// Enable ifconfig status reporting output -- this feature adds 7k.
|
||||
#define BB_FEATURE_IFCONFIG_STATUS
|
||||
//
|
||||
// Enable ifconfig slip-specific options "keepalive" and "outfill"
|
||||
//#define BB_FEATURE_IFCONFIG_SLIP
|
||||
//
|
||||
// Enable ifconfig options "mem_start", "io_addr", and "irq".
|
||||
#define BB_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ
|
||||
//
|
||||
// Enable ifconfig option "hw". Currently works for only with "ether".
|
||||
#define BB_FEATURE_IFCONFIG_HW
|
||||
//
|
||||
// Allows "broadcast +" to set broadcast automatically based on hostaddr
|
||||
// and netmask, at a cost of about 100 bytes of code (i386).
|
||||
//#define BB_FEATURE_IFCONFIG_BROADCAST_PLUS
|
||||
//
|
||||
// Enable busybox --install [-s]
|
||||
// to create links (or symlinks) for all the commands that are
|
||||
// compiled into the binary. (needs /proc filesystem)
|
||||
#define BB_FEATURE_INSTALLER
|
||||
//
|
||||
// Enable a nifty progress meter in wget (adds just under 2k)
|
||||
#define BB_FEATURE_WGET_STATUSBAR
|
||||
//
|
||||
// Enable HTTP authentication in wget
|
||||
#define BB_FEATURE_WGET_AUTHENTICATION
|
||||
//
|
||||
// Clean up all memory before exiting -- usually not needed
|
||||
// as the OS can clean up... Don't enable this unless you
|
||||
// have a really good reason for cleaning things up manually.
|
||||
//#define BB_FEATURE_CLEAN_UP
|
||||
//
|
||||
// Support for human readable output by ls, du, etc.(example 13k, 23M, 235G)
|
||||
#define BB_FEATURE_HUMAN_READABLE
|
||||
//
|
||||
// Support for the find -type option.
|
||||
#define BB_FEATURE_FIND_TYPE
|
||||
//
|
||||
// Support for the find -perm option.
|
||||
#define BB_FEATURE_FIND_PERM
|
||||
//
|
||||
// Support for the find -mtime option.
|
||||
#define BB_FEATURE_FIND_MTIME
|
||||
//
|
||||
//// Support for the find -newer option.
|
||||
#define BB_FEATURE_FIND_NEWER
|
||||
//
|
||||
// Support for the -A -B and -C context flags in grep
|
||||
//#define BB_FEATURE_GREP_CONTEXT
|
||||
//
|
||||
// Support for the EGREP applet (alias to the grep applet)
|
||||
//#define BB_FEATURE_GREP_EGREP_ALIAS
|
||||
//
|
||||
// Tell tftp what commands that should be supported.
|
||||
#define BB_FEATURE_TFTP_PUT
|
||||
#define BB_FEATURE_TFTP_GET
|
||||
//
|
||||
// features for vi
|
||||
//#define BB_FEATURE_VI_COLON // ":" colon commands, no "ex" mode
|
||||
//#define BB_FEATURE_VI_YANKMARK // Yank/Put commands and Mark cmds
|
||||
//#define BB_FEATURE_VI_SEARCH // search and replace cmds
|
||||
//#define BB_FEATURE_VI_USE_SIGNALS // catch signals
|
||||
//#define BB_FEATURE_VI_DOT_CMD // remember previous cmd and "." cmd
|
||||
//#define BB_FEATURE_VI_READONLY // vi -R and "view" mode
|
||||
//#define BB_FEATURE_VI_SETOPTS // set-able options, ai ic showmatch
|
||||
//#define BB_FEATURE_VI_SET // :set
|
||||
//#define BB_FEATURE_VI_WIN_RESIZE // handle window resize
|
||||
//
|
||||
// Enable a if you system have setuped locale
|
||||
//#define BB_LOCALE_SUPPORT
|
||||
//
|
||||
// Support for TELNET to pass TERM type to remote host. Adds 384 bytes.
|
||||
#define BB_FEATURE_TELNET_TTYPE
|
||||
//
|
||||
// Support for devfs.
|
||||
//#define BB_FEATURE_DEVFS
|
||||
//
|
||||
// End of Features List
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------
|
||||
// Nothing beyond this point should ever be touched by
|
||||
// mere mortals so leave this stuff alone.
|
||||
//
|
||||
#include <features.h>
|
||||
#if defined(__uClinux__)
|
||||
#undef BB_RPM2CPIO /* Uses gz_open(), which uses fork() */
|
||||
#undef BB_DPKG_DEB /* Uses gz_open(), which uses fork() */
|
||||
#undef BB_FEATURE_TAR_GZIP /* Uses fork() */
|
||||
#undef BB_UPDATE /* Uses daemon() */
|
||||
#endif
|
||||
#if defined BB_ASH || defined BB_HUSH || defined BB_LASH || defined BB_MSH
|
||||
#if defined BB_FEATURE_COMMAND_EDITING
|
||||
#define BB_CMDEDIT
|
||||
#else
|
||||
#undef BB_FEATURE_COMMAND_EDITING
|
||||
#undef BB_FEATURE_COMMAND_TAB_COMPLETION
|
||||
#undef BB_FEATURE_COMMAND_USERNAME_COMPLETION
|
||||
#undef BB_FEATURE_SH_FANCY_PROMPT
|
||||
#endif
|
||||
#else
|
||||
#undef BB_FEATURE_SH_APPLETS_ALWAYS_WIN
|
||||
#undef BB_FEATURE_SH_STANDALONE_SHELL
|
||||
#undef BB_FEATURE_SH_FANCY_PROMPT
|
||||
#endif
|
||||
//
|
||||
#if (defined BB_ASH || defined BB_HUSH || defined BB_MSH) && ! defined BB_TEST
|
||||
#define BB_TEST
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_KILLALL
|
||||
#ifndef BB_KILL
|
||||
#define BB_KILL
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#ifndef BB_INIT
|
||||
#undef BB_FEATURE_LINUXRC
|
||||
#endif
|
||||
//
|
||||
#if defined BB_MOUNT && defined BB_FEATURE_NFSMOUNT
|
||||
#define BB_NFSMOUNT
|
||||
#endif
|
||||
//
|
||||
#if defined BB_FEATURE_AUTOWIDTH
|
||||
#ifndef BB_FEATURE_USE_TERMIOS
|
||||
#define BB_FEATURE_USE_TERMIOS
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#if defined BB_INSMOD || defined BB_LSMOD
|
||||
#if ! defined BB_FEATURE_NEW_MODULE_INTERFACE && ! defined BB_FEATURE_OLD_MODULE_INTERFACE
|
||||
#define BB_FEATURE_NEW_MODULE_INTERFACE
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_UNIX2DOS
|
||||
#define BB_DOS2UNIX
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_SYSLOGD
|
||||
#if defined BB_FEATURE_IPC_SYSLOG
|
||||
#define BB_LOGREAD
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#if defined BB_ASH && defined BB_FEATURE_SH_IS_ASH
|
||||
# define shell_main ash_main
|
||||
#elif defined BB_HUSH && defined BB_FEATURE_SH_IS_HUSH
|
||||
# define shell_main hush_main
|
||||
#elif defined BB_LASH && defined BB_FEATURE_SH_IS_LASH
|
||||
# define shell_main lash_main
|
||||
#elif defined BB_MSH && defined BB_FEATURE_SH_IS_MSH
|
||||
# define shell_main msh_main
|
||||
#endif
|
||||
Vendored
+493
@@ -0,0 +1,493 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
// This file defines the feature set to be compiled into busybox.
|
||||
// When you turn things off here, they won't be compiled in at all.
|
||||
//
|
||||
//// This file is parsed by sed. You MUST use single line comments.
|
||||
// i.e., //#define BB_BLAH
|
||||
//
|
||||
//
|
||||
// BusyBox Applications
|
||||
//#define BB_ADJTIMEX
|
||||
#define BB_AR
|
||||
#define BB_ASH
|
||||
#define BB_BASENAME
|
||||
#define BB_CAT
|
||||
#define BB_CHGRP
|
||||
#define BB_CHMOD
|
||||
#define BB_CHOWN
|
||||
#define BB_CHROOT
|
||||
#define BB_CHVT
|
||||
#define BB_CLEAR
|
||||
#define BB_CMP
|
||||
#define BB_CP
|
||||
#define BB_CPIO
|
||||
#define BB_CUT
|
||||
#define BB_DATE
|
||||
#define BB_DC
|
||||
#define BB_DD
|
||||
#define BB_DEALLOCVT
|
||||
#define BB_DF
|
||||
#define BB_DIRNAME
|
||||
#define BB_DMESG
|
||||
#define BB_DOS2UNIX
|
||||
#define BB_DPKG
|
||||
#define BB_DPKG_DEB
|
||||
#define BB_DUTMP
|
||||
#define BB_DU
|
||||
#define BB_DUMPKMAP
|
||||
#define BB_ECHO
|
||||
#define BB_ENV
|
||||
#define BB_EXPR
|
||||
#define BB_FBSET
|
||||
#define BB_FDFLUSH
|
||||
#define BB_FIND
|
||||
#define BB_FREE
|
||||
#define BB_FREERAMDISK
|
||||
#define BB_FSCK_MINIX
|
||||
#define BB_GETOPT
|
||||
#define BB_GREP
|
||||
#define BB_GUNZIP
|
||||
#define BB_GZIP
|
||||
#define BB_HALT
|
||||
#define BB_HEAD
|
||||
#define BB_HOSTID
|
||||
#define BB_HOSTNAME
|
||||
//#define BB_HUSH
|
||||
#define BB_ID
|
||||
#define BB_IFCONFIG
|
||||
#define BB_INIT
|
||||
//#define BB_INSMOD
|
||||
#define BB_KILL
|
||||
#define BB_KILLALL
|
||||
#define BB_KLOGD
|
||||
//#define BB_LASH
|
||||
#define BB_LENGTH
|
||||
#define BB_LN
|
||||
#define BB_LOADACM
|
||||
#define BB_LOADFONT
|
||||
#define BB_LOADKMAP
|
||||
#define BB_LOGGER
|
||||
#define BB_LOGNAME
|
||||
#define BB_LOSETUP
|
||||
#define BB_LS
|
||||
#define BB_LSMOD
|
||||
#define BB_MAKEDEVS
|
||||
#define BB_MD5SUM
|
||||
#define BB_MKDIR
|
||||
#define BB_MKFIFO
|
||||
#define BB_MKFS_MINIX
|
||||
#define BB_MKNOD
|
||||
#define BB_MKSWAP
|
||||
#define BB_MKTEMP
|
||||
#define BB_MODPROBE
|
||||
#define BB_MORE
|
||||
#define BB_MOUNT
|
||||
//#define BB_MSH
|
||||
#define BB_MT
|
||||
#define BB_MV
|
||||
#define BB_NC
|
||||
#define BB_NSLOOKUP
|
||||
#define BB_PIDOF
|
||||
#define BB_PING
|
||||
#define BB_PIVOT_ROOT
|
||||
#define BB_POWEROFF
|
||||
#define BB_PRINTF
|
||||
#define BB_PS
|
||||
#define BB_PWD
|
||||
#define BB_RDATE
|
||||
#define BB_READLINK
|
||||
#define BB_REBOOT
|
||||
#define BB_RENICE
|
||||
#define BB_RESET
|
||||
#define BB_RM
|
||||
#define BB_RMDIR
|
||||
#define BB_RMMOD
|
||||
#define BB_ROUTE
|
||||
#define BB_RPM2CPIO
|
||||
#define BB_SED
|
||||
#define BB_SETKEYCODES
|
||||
#define BB_SLEEP
|
||||
#define BB_SORT
|
||||
#define BB_STTY
|
||||
#define BB_SWAPONOFF
|
||||
#define BB_SYNC
|
||||
#define BB_SYSLOGD
|
||||
#define BB_TAIL
|
||||
#define BB_TAR
|
||||
#define BB_TEE
|
||||
#define BB_TEST
|
||||
#define BB_TELNET
|
||||
#define BB_TFTP
|
||||
#define BB_TIME
|
||||
#define BB_TOP
|
||||
#define BB_TOUCH
|
||||
#define BB_TR
|
||||
#define BB_TRACEROUTE
|
||||
#define BB_TRUE_FALSE
|
||||
#define BB_TTY
|
||||
#define BB_UNIX2DOS
|
||||
#define BB_UUENCODE
|
||||
#define BB_UUDECODE
|
||||
#define BB_UMOUNT
|
||||
#define BB_UNIQ
|
||||
#define BB_UNAME
|
||||
#define BB_UPDATE
|
||||
#define BB_UPTIME
|
||||
#define BB_USLEEP
|
||||
#define BB_VI
|
||||
#define BB_WATCHDOG
|
||||
#define BB_WC
|
||||
#define BB_WGET
|
||||
#define BB_WHICH
|
||||
#define BB_WHOAMI
|
||||
#define BB_XARGS
|
||||
#define BB_YES
|
||||
// End of Applications List
|
||||
//
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------
|
||||
// This is where feature definitions go. Generally speaking,
|
||||
// turning this stuff off makes things a bit smaller (and less
|
||||
// pretty/useful).
|
||||
//
|
||||
//
|
||||
// If you enabled one or more of the shells, you may select which one
|
||||
// should be run when sh is invoked:
|
||||
#define BB_FEATURE_SH_IS_ASH
|
||||
//#define BB_FEATURE_SH_IS_HUSH
|
||||
//#define BB_FEATURE_SH_IS_LASH
|
||||
//#define BB_FEATURE_SH_IS_MSH
|
||||
//
|
||||
// BusyBox will, by default, malloc space for its buffers. This costs code
|
||||
// size for the call to xmalloc. You can use the following feature to have
|
||||
// them put on the stack. For some very small machines with limited stack
|
||||
// space, this can be deadly. For most folks, this works just fine...
|
||||
//#define BB_FEATURE_BUFFERS_GO_ON_STACK
|
||||
// The third alternative for buffer allocation is to use BSS. This works
|
||||
// beautifully for computers with a real MMU (and OS support), but wastes
|
||||
// runtime RAM for uCLinux. This behavior was the only one available for
|
||||
// BusyBox versions 0.48 and earlier.
|
||||
//#define BB_FEATURE_BUFFERS_GO_IN_BSS
|
||||
//
|
||||
// Turn this on to use Erik's very cool devps, and devmtab kernel drivers,
|
||||
// thereby eliminating the need for the /proc filesystem and thereby saving
|
||||
// lots and lots memory for more important things. NOTE: If you enable this
|
||||
// feature, you _must_ have patched the kernel to include the devps patch that
|
||||
// is included in the busybox/kernel-patches directory. You will also need to
|
||||
// create some device special files in /dev on your embedded system:
|
||||
// mknod /dev/mtab c 10 22
|
||||
// mknod /dev/ps c 10 21
|
||||
// I emailed Linus and this patch will not be going into the stock kernel.
|
||||
//#define BB_FEATURE_USE_DEVPS_PATCH
|
||||
//
|
||||
// show verbose usage messages
|
||||
#define BB_FEATURE_VERBOSE_USAGE
|
||||
//
|
||||
// Use termios to manipulate the screen ('more' is prettier with this on)
|
||||
#define BB_FEATURE_USE_TERMIOS
|
||||
//
|
||||
// calculate terminal & column widths (for more, ls, and telnet)
|
||||
#define BB_FEATURE_AUTOWIDTH
|
||||
//
|
||||
// show username/groupnames for ls
|
||||
#define BB_FEATURE_LS_USERNAME
|
||||
//
|
||||
// show file timestamps in ls
|
||||
#define BB_FEATURE_LS_TIMESTAMPS
|
||||
//
|
||||
// enable ls -p and -F
|
||||
#define BB_FEATURE_LS_FILETYPES
|
||||
//
|
||||
// sort the file names
|
||||
#define BB_FEATURE_LS_SORTFILES
|
||||
//
|
||||
// enable ls -R
|
||||
#define BB_FEATURE_LS_RECURSIVE
|
||||
//
|
||||
// enable ls -L
|
||||
#define BB_FEATURE_LS_FOLLOWLINKS
|
||||
//
|
||||
// Use color to identify different file types
|
||||
#define BB_FEATURE_LS_COLOR
|
||||
//
|
||||
// Disable for a smaller (but less functional) ping
|
||||
#define BB_FEATURE_FANCY_PING
|
||||
//
|
||||
// Make init use a simplified /etc/inittab file (recommended).
|
||||
#define BB_FEATURE_USE_INITTAB
|
||||
//
|
||||
//Enable init being called as /linuxrc
|
||||
#define BB_FEATURE_LINUXRC
|
||||
//
|
||||
//Have init enable core dumping for child processes (for debugging only)
|
||||
//#define BB_FEATURE_INIT_COREDUMPS
|
||||
//
|
||||
//Make sure nothing is printed to the console on boot
|
||||
//#define BB_FEATURE_EXTRA_QUIET
|
||||
//
|
||||
// enable syslogd -R remotehost
|
||||
#define BB_FEATURE_REMOTE_LOG
|
||||
//
|
||||
// enable syslogd -C
|
||||
//#define BB_FEATURE_IPC_SYSLOG
|
||||
//
|
||||
//Disable for a simple tail implementation (2.34k vs 3k for the full one).
|
||||
//Both provide 'tail -f', but this cuts out -c, -q, -s, and -v.
|
||||
#define BB_FEATURE_FANCY_TAIL
|
||||
//
|
||||
// Enable support for loop devices in mount
|
||||
#define BB_FEATURE_MOUNT_LOOP
|
||||
//
|
||||
// Enable support for a real /etc/mtab file instead of /proc/mounts
|
||||
//#define BB_FEATURE_MTAB_SUPPORT
|
||||
//
|
||||
// Enable support for mounting remote NFS volumes.
|
||||
// You may need to mount with "-o nolock" if you are
|
||||
// not running a local portmapper daemon...
|
||||
//
|
||||
// If you are using uClibc, be sure that you've already compiled
|
||||
// uClibc with INCLUDE_RPC=true (contained in the Config file)
|
||||
#define BB_FEATURE_NFSMOUNT
|
||||
//
|
||||
// Enable support forced filesystem unmounting
|
||||
// (i.e., in case of an unreachable NFS system).
|
||||
#define BB_FEATURE_MOUNT_FORCE
|
||||
//
|
||||
// Enable support for creation of tar files.
|
||||
#define BB_FEATURE_TAR_CREATE
|
||||
//
|
||||
// Enable support for "--exclude" and "-X" for excluding files
|
||||
#define BB_FEATURE_TAR_EXCLUDE
|
||||
//
|
||||
// Enable support for tar -z option (currently only works for inflating)
|
||||
#define BB_FEATURE_TAR_GZIP
|
||||
//
|
||||
// Enable reverse sort
|
||||
#define BB_FEATURE_SORT_REVERSE
|
||||
//
|
||||
// Enable uniqe sort
|
||||
#define BB_FEATURE_SORT_UNIQUE
|
||||
//
|
||||
// Enable command line editing in the shell.
|
||||
// Only relevant if a shell is enabled. On by default.
|
||||
#define BB_FEATURE_COMMAND_EDITING
|
||||
//
|
||||
// Enable tab completion in the shell. This is now working quite nicely.
|
||||
// This feature adds a bit over 4k. Only relevant if a shell is enabled.
|
||||
#define BB_FEATURE_COMMAND_TAB_COMPLETION
|
||||
//
|
||||
// Attempts to match usernames in a ~-prefixed path
|
||||
#define BB_FEATURE_COMMAND_USERNAME_COMPLETION
|
||||
//
|
||||
//Allow the shell to invoke all the compiled in BusyBox applets as if they
|
||||
//were shell builtins. Nice for staticly linking an emergency rescue shell,
|
||||
//among other things. Off by default.
|
||||
// Only relevant if a shell is enabled.
|
||||
#define BB_FEATURE_SH_STANDALONE_SHELL
|
||||
//
|
||||
//When this is enabled, busybox shell applets can be called using full path
|
||||
//names. This causes applets (i.e., most busybox commands) to override
|
||||
//real commands on the filesystem. For example, if you run run /bin/cat, it
|
||||
//will use BusyBox cat even if /bin/cat exists on the filesystem and is _not_
|
||||
//busybox. Some systems want this, others do not. Choose wisely. :-) This
|
||||
//only has meaning when BB_FEATURE_SH_STANDALONE_SHELL is enabled.
|
||||
// Only relevant if a shell is enabled. Off by default.
|
||||
#define BB_FEATURE_SH_APPLETS_ALWAYS_WIN
|
||||
//
|
||||
// Uncomment this option for a fancy shell prompt that includes the
|
||||
// current username and hostname. On systems that don't have usernames
|
||||
// or hostnames, this can look hideous.
|
||||
// Only relevant if a shell is enabled.
|
||||
#define BB_FEATURE_SH_FANCY_PROMPT
|
||||
//
|
||||
// Uncomment this option to disable job control. Job control lets you
|
||||
// run jobs in the background (which completely useless for is all you
|
||||
// are doing is running scripts). Disabing this is bad for interactive
|
||||
// use, since when you hit ^C in an application, it will also kill the
|
||||
// shell. This adds about 2.5k on an x86 system.
|
||||
#define BB_FEATURE_ASH_JOB_CONTROL
|
||||
//
|
||||
//Turn on extra fbset options
|
||||
//#define BB_FEATURE_FBSET_FANCY
|
||||
//
|
||||
//Turn on fbset readmode support
|
||||
#define BB_FEATURE_FBSET_READMODE
|
||||
//
|
||||
// Support insmod/lsmod/rmmod for post 2.1 kernels
|
||||
#define BB_FEATURE_NEW_MODULE_INTERFACE
|
||||
//
|
||||
// Support insmod/lsmod/rmmod for pre 2.1 kernels
|
||||
//#define BB_FEATURE_OLD_MODULE_INTERFACE
|
||||
//
|
||||
// Support module version checking
|
||||
//#define BB_FEATURE_INSMOD_VERSION_CHECKING
|
||||
//
|
||||
// Support for uClinux memory usage optimization, which will load the image
|
||||
// directly into the kernel memory. This divides memory requrements by three.
|
||||
// If you are not running uClinux (i.e., your CPU has an MMU) leave this
|
||||
// disabled...
|
||||
//#define BB_FEATURE_INSMOD_LOADINKMEM
|
||||
//
|
||||
// Support for Minix filesystem, version 2
|
||||
#define BB_FEATURE_MINIX2
|
||||
//
|
||||
// Enable ifconfig status reporting output -- this feature adds 7k.
|
||||
#define BB_FEATURE_IFCONFIG_STATUS
|
||||
//
|
||||
// Enable ifconfig slip-specific options "keepalive" and "outfill"
|
||||
#define BB_FEATURE_IFCONFIG_SLIP
|
||||
//
|
||||
// Enable ifconfig options "mem_start", "io_addr", and "irq".
|
||||
#define BB_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ
|
||||
//
|
||||
// Enable ifconfig option "hw". Currently works for only with "ether".
|
||||
#define BB_FEATURE_IFCONFIG_HW
|
||||
//
|
||||
// Allows "broadcast +" to set broadcast automatically based on hostaddr
|
||||
// and netmask, at a cost of about 100 bytes of code (i386).
|
||||
#define BB_FEATURE_IFCONFIG_BROADCAST_PLUS
|
||||
//
|
||||
// Enable busybox --install [-s]
|
||||
// to create links (or symlinks) for all the commands that are
|
||||
// compiled into the binary. (needs /proc filesystem)
|
||||
//#define BB_FEATURE_INSTALLER
|
||||
//
|
||||
// Enable a nifty progress meter in wget (adds just under 2k)
|
||||
#define BB_FEATURE_WGET_STATUSBAR
|
||||
//
|
||||
// Enable HTTP authentication in wget
|
||||
#define BB_FEATURE_WGET_AUTHENTICATION
|
||||
//
|
||||
// Clean up all memory before exiting -- usually not needed
|
||||
// as the OS can clean up... Don't enable this unless you
|
||||
// have a really good reason for cleaning things up manually.
|
||||
//#define BB_FEATURE_CLEAN_UP
|
||||
//
|
||||
// Support for human readable output by ls, du, etc.(example 13k, 23M, 235G)
|
||||
#define BB_FEATURE_HUMAN_READABLE
|
||||
//
|
||||
// Support for the find -type option.
|
||||
#define BB_FEATURE_FIND_TYPE
|
||||
//
|
||||
// Support for the find -perm option.
|
||||
#define BB_FEATURE_FIND_PERM
|
||||
//
|
||||
// Support for the find -mtime option.
|
||||
#define BB_FEATURE_FIND_MTIME
|
||||
//
|
||||
//// Support for the find -newer option.
|
||||
#define BB_FEATURE_FIND_NEWER
|
||||
//
|
||||
// Support for the -A -B and -C context flags in grep
|
||||
#define BB_FEATURE_GREP_CONTEXT
|
||||
//
|
||||
// Support for the EGREP applet (alias to the grep applet)
|
||||
#define BB_FEATURE_GREP_EGREP_ALIAS
|
||||
//
|
||||
// Tell tftp what commands that should be supported.
|
||||
#define BB_FEATURE_TFTP_PUT
|
||||
#define BB_FEATURE_TFTP_GET
|
||||
//
|
||||
// features for vi
|
||||
#define BB_FEATURE_VI_COLON // ":" colon commands, no "ex" mode
|
||||
#define BB_FEATURE_VI_YANKMARK // Yank/Put commands and Mark cmds
|
||||
#define BB_FEATURE_VI_SEARCH // search and replace cmds
|
||||
#define BB_FEATURE_VI_USE_SIGNALS // catch signals
|
||||
#define BB_FEATURE_VI_DOT_CMD // remember previous cmd and "." cmd
|
||||
#define BB_FEATURE_VI_READONLY // vi -R and "view" mode
|
||||
#define BB_FEATURE_VI_SETOPTS // set-able options, ai ic showmatch
|
||||
#define BB_FEATURE_VI_SET // :set
|
||||
#define BB_FEATURE_VI_WIN_RESIZE // handle window resize
|
||||
//
|
||||
// Enable a if you system have setuped locale
|
||||
//#define BB_LOCALE_SUPPORT
|
||||
//
|
||||
// Support for TELNET to pass TERM type to remote host. Adds 384 bytes.
|
||||
#define BB_FEATURE_TELNET_TTYPE
|
||||
//
|
||||
// Support for devfs.
|
||||
//#define BB_FEATURE_DEVFS
|
||||
//
|
||||
// End of Features List
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------
|
||||
// Nothing beyond this point should ever be touched by
|
||||
// mere mortals so leave this stuff alone.
|
||||
//
|
||||
#include <features.h>
|
||||
#if defined(__uClinux__)
|
||||
#undef BB_RPM2CPIO /* Uses gz_open(), which uses fork() */
|
||||
#undef BB_DPKG_DEB /* Uses gz_open(), which uses fork() */
|
||||
#undef BB_FEATURE_TAR_GZIP /* Uses fork() */
|
||||
#undef BB_UPDATE /* Uses daemon() */
|
||||
#endif
|
||||
#if defined BB_ASH || defined BB_HUSH || defined BB_LASH || defined BB_MSH
|
||||
#if defined BB_FEATURE_COMMAND_EDITING
|
||||
#define BB_CMDEDIT
|
||||
#else
|
||||
#undef BB_FEATURE_COMMAND_EDITING
|
||||
#undef BB_FEATURE_COMMAND_TAB_COMPLETION
|
||||
#undef BB_FEATURE_COMMAND_USERNAME_COMPLETION
|
||||
#undef BB_FEATURE_SH_FANCY_PROMPT
|
||||
#endif
|
||||
#else
|
||||
#undef BB_FEATURE_SH_APPLETS_ALWAYS_WIN
|
||||
#undef BB_FEATURE_SH_STANDALONE_SHELL
|
||||
#undef BB_FEATURE_SH_FANCY_PROMPT
|
||||
#endif
|
||||
//
|
||||
#if (defined BB_ASH || defined BB_HUSH || defined BB_MSH) && ! defined BB_TEST
|
||||
#define BB_TEST
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_KILLALL
|
||||
#ifndef BB_KILL
|
||||
#define BB_KILL
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#ifndef BB_INIT
|
||||
#undef BB_FEATURE_LINUXRC
|
||||
#endif
|
||||
//
|
||||
#if defined BB_MOUNT && defined BB_FEATURE_NFSMOUNT
|
||||
#define BB_NFSMOUNT
|
||||
#endif
|
||||
//
|
||||
#if defined BB_FEATURE_AUTOWIDTH
|
||||
#ifndef BB_FEATURE_USE_TERMIOS
|
||||
#define BB_FEATURE_USE_TERMIOS
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#if defined BB_INSMOD || defined BB_LSMOD
|
||||
#if ! defined BB_FEATURE_NEW_MODULE_INTERFACE && ! defined BB_FEATURE_OLD_MODULE_INTERFACE
|
||||
#define BB_FEATURE_NEW_MODULE_INTERFACE
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_UNIX2DOS
|
||||
#define BB_DOS2UNIX
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_SYSLOGD
|
||||
#if defined BB_FEATURE_IPC_SYSLOG
|
||||
#define BB_LOGREAD
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#if defined BB_ASH && defined BB_FEATURE_SH_IS_ASH
|
||||
# define shell_main ash_main
|
||||
#elif defined BB_HUSH && defined BB_FEATURE_SH_IS_HUSH
|
||||
# define shell_main hush_main
|
||||
#elif defined BB_LASH && defined BB_FEATURE_SH_IS_LASH
|
||||
# define shell_main lash_main
|
||||
#elif defined BB_MSH && defined BB_FEATURE_SH_IS_MSH
|
||||
# define shell_main msh_main
|
||||
#endif
|
||||
Vendored
+493
@@ -0,0 +1,493 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
// This file defines the feature set to be compiled into busybox.
|
||||
// When you turn things off here, they won't be compiled in at all.
|
||||
//
|
||||
//// This file is parsed by sed. You MUST use single line comments.
|
||||
// i.e., //#define BB_BLAH
|
||||
//
|
||||
//
|
||||
// BusyBox Applications
|
||||
//#define BB_ADJTIMEX
|
||||
#define BB_AR
|
||||
//#define BB_ASH
|
||||
#define BB_BASENAME
|
||||
#define BB_CAT
|
||||
//#define BB_CHGRP
|
||||
#define BB_CHMOD
|
||||
#define BB_CHOWN
|
||||
#define BB_CHROOT
|
||||
#define BB_CHVT
|
||||
//#define BB_CLEAR
|
||||
//#define BB_CMP
|
||||
#define BB_CP
|
||||
//#define BB_CPIO
|
||||
#define BB_CUT
|
||||
//#define BB_DATE
|
||||
//#define BB_DC
|
||||
//#define BB_DD
|
||||
//#define BB_DEALLOCVT
|
||||
#define BB_DF
|
||||
#define BB_DIRNAME
|
||||
#define BB_DMESG
|
||||
//#define BB_DOS2UNIX
|
||||
//#define BB_DPKG
|
||||
//#define BB_DPKG_DEB
|
||||
//#define BB_DUTMP
|
||||
//#define BB_DU
|
||||
//#define BB_DUMPKMAP
|
||||
#define BB_ECHO
|
||||
#define BB_ENV
|
||||
#define BB_EXPR
|
||||
//#define BB_FBSET
|
||||
//#define BB_FDFLUSH
|
||||
#define BB_FIND
|
||||
#define BB_FREE
|
||||
#define BB_FREERAMDISK
|
||||
//#define BB_FSCK_MINIX
|
||||
//#define BB_GETOPT
|
||||
#define BB_GREP
|
||||
#define BB_GUNZIP
|
||||
//#define BB_GZIP
|
||||
//#define BB_HALT
|
||||
#define BB_HEAD
|
||||
//#define BB_HOSTID
|
||||
//#define BB_HOSTNAME
|
||||
//#define BB_HUSH
|
||||
#define BB_ID
|
||||
#define BB_IFCONFIG
|
||||
#define BB_INIT
|
||||
//#define BB_INSMOD
|
||||
#define BB_KILL
|
||||
//#define BB_KILLALL
|
||||
#define BB_KLOGD
|
||||
//#define BB_LASH
|
||||
//#define BB_LENGTH
|
||||
#define BB_LN
|
||||
//#define BB_LOADACM
|
||||
//#define BB_LOADFONT
|
||||
//#define BB_LOADKMAP
|
||||
//#define BB_LOGGER
|
||||
//#define BB_LOGNAME
|
||||
//#define BB_LOSETUP
|
||||
#define BB_LS
|
||||
#define BB_LSMOD
|
||||
//#define BB_MAKEDEVS
|
||||
#define BB_MD5SUM
|
||||
#define BB_MKDIR
|
||||
//#define BB_MKFIFO
|
||||
//#define BB_MKFS_MINIX
|
||||
#define BB_MKNOD
|
||||
//#define BB_MKSWAP
|
||||
//#define BB_MKTEMP
|
||||
//#define BB_MODPROBE
|
||||
//#define BB_MORE
|
||||
#define BB_MOUNT
|
||||
//#define BB_MSH
|
||||
//#define BB_MT
|
||||
#define BB_MV
|
||||
//#define BB_NC
|
||||
//#define BB_NSLOOKUP
|
||||
#define BB_PIDOF
|
||||
#define BB_PING
|
||||
#define BB_PIVOT_ROOT
|
||||
//#define BB_POWEROFF
|
||||
//#define BB_PRINTF
|
||||
#define BB_PS
|
||||
#define BB_PWD
|
||||
//#define BB_RDATE
|
||||
//#define BB_READLINK
|
||||
#define BB_REBOOT
|
||||
//#define BB_RENICE
|
||||
//#define BB_RESET
|
||||
#define BB_RM
|
||||
#define BB_RMDIR
|
||||
//#define BB_RMMOD
|
||||
#define BB_ROUTE
|
||||
//#define BB_RPM2CPIO
|
||||
#define BB_SED
|
||||
//#define BB_SETKEYCODES
|
||||
//#define BB_SLEEP
|
||||
#define BB_SORT
|
||||
//#define BB_STTY
|
||||
//#define BB_SWAPONOFF
|
||||
#define BB_SYNC
|
||||
#define BB_SYSLOGD
|
||||
#define BB_TAIL
|
||||
#define BB_TAR
|
||||
//#define BB_TEE
|
||||
//#define BB_TEST
|
||||
#define BB_TELNET
|
||||
//#define BB_TFTP
|
||||
//#define BB_TIME
|
||||
//#define BB_TOP
|
||||
#define BB_TOUCH
|
||||
#define BB_TR
|
||||
//#define BB_TRACEROUTE
|
||||
#define BB_TRUE_FALSE
|
||||
//#define BB_TTY
|
||||
//#define BB_UNIX2DOS
|
||||
//#define BB_UUENCODE
|
||||
//#define BB_UUDECODE
|
||||
#define BB_UMOUNT
|
||||
//#define BB_UNIQ
|
||||
#define BB_UNAME
|
||||
//#define BB_UPDATE
|
||||
//#define BB_UPTIME
|
||||
//#define BB_USLEEP
|
||||
//#define BB_VI
|
||||
//#define BB_WATCHDOG
|
||||
#define BB_WC
|
||||
#define BB_WGET
|
||||
//#define BB_WHICH
|
||||
//#define BB_WHOAMI
|
||||
//#define BB_XARGS
|
||||
//#define BB_YES
|
||||
// End of Applications List
|
||||
//
|
||||
//
|
||||
//
|
||||
// ---------------------------------------------------------
|
||||
// This is where feature definitions go. Generally speaking,
|
||||
// turning this stuff off makes things a bit smaller (and less
|
||||
// pretty/useful).
|
||||
//
|
||||
//
|
||||
// If you enabled one or more of the shells, you may select which one
|
||||
// should be run when sh is invoked:
|
||||
//#define BB_FEATURE_SH_IS_ASH
|
||||
//#define BB_FEATURE_SH_IS_HUSH
|
||||
//#define BB_FEATURE_SH_IS_LASH
|
||||
#define BB_FEATURE_SH_IS_MSH
|
||||
//
|
||||
// BusyBox will, by default, malloc space for its buffers. This costs code
|
||||
// size for the call to xmalloc. You can use the following feature to have
|
||||
// them put on the stack. For some very small machines with limited stack
|
||||
// space, this can be deadly. For most folks, this works just fine...
|
||||
//#define BB_FEATURE_BUFFERS_GO_ON_STACK
|
||||
// The third alternative for buffer allocation is to use BSS. This works
|
||||
// beautifully for computers with a real MMU (and OS support), but wastes
|
||||
// runtime RAM for uCLinux. This behavior was the only one available for
|
||||
// BusyBox versions 0.48 and earlier.
|
||||
//#define BB_FEATURE_BUFFERS_GO_IN_BSS
|
||||
//
|
||||
// Turn this on to use Erik's very cool devps, and devmtab kernel drivers,
|
||||
// thereby eliminating the need for the /proc filesystem and thereby saving
|
||||
// lots and lots memory for more important things. NOTE: If you enable this
|
||||
// feature, you _must_ have patched the kernel to include the devps patch that
|
||||
// is included in the busybox/kernel-patches directory. You will also need to
|
||||
// create some device special files in /dev on your embedded system:
|
||||
// mknod /dev/mtab c 10 22
|
||||
// mknod /dev/ps c 10 21
|
||||
// I emailed Linus and this patch will not be going into the stock kernel.
|
||||
//#define BB_FEATURE_USE_DEVPS_PATCH
|
||||
//
|
||||
// show verbose usage messages
|
||||
//#define BB_FEATURE_VERBOSE_USAGE
|
||||
//
|
||||
// Use termios to manipulate the screen ('more' is prettier with this on)
|
||||
#define BB_FEATURE_USE_TERMIOS
|
||||
//
|
||||
// calculate terminal & column widths (for more, ls, and telnet)
|
||||
#define BB_FEATURE_AUTOWIDTH
|
||||
//
|
||||
// show username/groupnames for ls
|
||||
#define BB_FEATURE_LS_USERNAME
|
||||
//
|
||||
// show file timestamps in ls
|
||||
#define BB_FEATURE_LS_TIMESTAMPS
|
||||
//
|
||||
// enable ls -p and -F
|
||||
//#define BB_FEATURE_LS_FILETYPES
|
||||
//
|
||||
// sort the file names
|
||||
#define BB_FEATURE_LS_SORTFILES
|
||||
//
|
||||
// enable ls -R
|
||||
//#define BB_FEATURE_LS_RECURSIVE
|
||||
//
|
||||
// enable ls -L
|
||||
#define BB_FEATURE_LS_FOLLOWLINKS
|
||||
//
|
||||
// Use color to identify different file types
|
||||
#define BB_FEATURE_LS_COLOR
|
||||
//
|
||||
// Disable for a smaller (but less functional) ping
|
||||
#define BB_FEATURE_FANCY_PING
|
||||
//
|
||||
// Make init use a simplified /etc/inittab file (recommended).
|
||||
#define BB_FEATURE_USE_INITTAB
|
||||
//
|
||||
//Enable init being called as /linuxrc
|
||||
#define BB_FEATURE_LINUXRC
|
||||
//
|
||||
//Have init enable core dumping for child processes (for debugging only)
|
||||
//#define BB_FEATURE_INIT_COREDUMPS
|
||||
//
|
||||
//Make sure nothing is printed to the console on boot
|
||||
//#define BB_FEATURE_EXTRA_QUIET
|
||||
//
|
||||
// enable syslogd -R remotehost
|
||||
//#define BB_FEATURE_REMOTE_LOG
|
||||
//
|
||||
// enable syslogd -C
|
||||
//#define BB_FEATURE_IPC_SYSLOG
|
||||
//
|
||||
//Disable for a simple tail implementation (2.34k vs 3k for the full one).
|
||||
//Both provide 'tail -f', but this cuts out -c, -q, -s, and -v.
|
||||
//#define BB_FEATURE_FANCY_TAIL
|
||||
//
|
||||
// Enable support for loop devices in mount
|
||||
#define BB_FEATURE_MOUNT_LOOP
|
||||
//
|
||||
// Enable support for a real /etc/mtab file instead of /proc/mounts
|
||||
//#define BB_FEATURE_MTAB_SUPPORT
|
||||
//
|
||||
// Enable support for mounting remote NFS volumes.
|
||||
// You may need to mount with "-o nolock" if you are
|
||||
// not running a local portmapper daemon...
|
||||
//
|
||||
// If you are using uClibc, be sure that you've already compiled
|
||||
// uClibc with INCLUDE_RPC=true (contained in the Config file)
|
||||
#define BB_FEATURE_NFSMOUNT
|
||||
//
|
||||
// Enable support forced filesystem unmounting
|
||||
// (i.e., in case of an unreachable NFS system).
|
||||
#define BB_FEATURE_MOUNT_FORCE
|
||||
//
|
||||
// Enable support for creation of tar files.
|
||||
//#define BB_FEATURE_TAR_CREATE
|
||||
//
|
||||
// Enable support for "--exclude" and "-X" for excluding files
|
||||
//#define BB_FEATURE_TAR_EXCLUDE
|
||||
//
|
||||
// Enable support for tar -z option (currently only works for inflating)
|
||||
#define BB_FEATURE_TAR_GZIP
|
||||
//
|
||||
// Enable reverse sort
|
||||
//#define BB_FEATURE_SORT_REVERSE
|
||||
//
|
||||
// Enable uniqe sort
|
||||
//#define BB_FEATURE_SORT_UNIQUE
|
||||
//
|
||||
// Enable command line editing in the shell.
|
||||
// Only relevant if a shell is enabled. On by default.
|
||||
#define BB_FEATURE_COMMAND_EDITING
|
||||
//
|
||||
// Enable tab completion in the shell. This is now working quite nicely.
|
||||
// This feature adds a bit over 4k. Only relevant if a shell is enabled.
|
||||
#define BB_FEATURE_COMMAND_TAB_COMPLETION
|
||||
//
|
||||
// Attempts to match usernames in a ~-prefixed path
|
||||
//#define BB_FEATURE_COMMAND_USERNAME_COMPLETION
|
||||
//
|
||||
//Allow the shell to invoke all the compiled in BusyBox applets as if they
|
||||
//were shell builtins. Nice for staticly linking an emergency rescue shell,
|
||||
//among other things. Off by default.
|
||||
// Only relevant if a shell is enabled.
|
||||
//#define BB_FEATURE_SH_STANDALONE_SHELL
|
||||
//
|
||||
//When this is enabled, busybox shell applets can be called using full path
|
||||
//names. This causes applets (i.e., most busybox commands) to override
|
||||
//real commands on the filesystem. For example, if you run run /bin/cat, it
|
||||
//will use BusyBox cat even if /bin/cat exists on the filesystem and is _not_
|
||||
//busybox. Some systems want this, others do not. Choose wisely. :-) This
|
||||
//only has meaning when BB_FEATURE_SH_STANDALONE_SHELL is enabled.
|
||||
// Only relevant if a shell is enabled. Off by default.
|
||||
//#define BB_FEATURE_SH_APPLETS_ALWAYS_WIN
|
||||
//
|
||||
// Uncomment this option for a fancy shell prompt that includes the
|
||||
// current username and hostname. On systems that don't have usernames
|
||||
// or hostnames, this can look hideous.
|
||||
// Only relevant if a shell is enabled.
|
||||
//#define BB_FEATURE_SH_FANCY_PROMPT
|
||||
//
|
||||
// Uncomment this option to disable job control. Job control lets you
|
||||
// run jobs in the background (which completely useless for is all you
|
||||
// are doing is running scripts). Disabing this is bad for interactive
|
||||
// use, since when you hit ^C in an application, it will also kill the
|
||||
// shell. This adds about 2.5k on an x86 system.
|
||||
#define BB_FEATURE_ASH_JOB_CONTROL
|
||||
//
|
||||
//Turn on extra fbset options
|
||||
//#define BB_FEATURE_FBSET_FANCY
|
||||
//
|
||||
//Turn on fbset readmode support
|
||||
//#define BB_FEATURE_FBSET_READMODE
|
||||
//
|
||||
// Support insmod/lsmod/rmmod for post 2.1 kernels
|
||||
//#define BB_FEATURE_NEW_MODULE_INTERFACE
|
||||
//
|
||||
// Support insmod/lsmod/rmmod for pre 2.1 kernels
|
||||
//#define BB_FEATURE_OLD_MODULE_INTERFACE
|
||||
//
|
||||
// Support module version checking
|
||||
//#define BB_FEATURE_INSMOD_VERSION_CHECKING
|
||||
//
|
||||
// Support for uClinux memory usage optimization, which will load the image
|
||||
// directly into the kernel memory. This divides memory requrements by three.
|
||||
// If you are not running uClinux (i.e., your CPU has an MMU) leave this
|
||||
// disabled...
|
||||
//#define BB_FEATURE_INSMOD_LOADINKMEM
|
||||
//
|
||||
// Support for Minix filesystem, version 2
|
||||
//#define BB_FEATURE_MINIX2
|
||||
//
|
||||
// Enable ifconfig status reporting output -- this feature adds 7k.
|
||||
#define BB_FEATURE_IFCONFIG_STATUS
|
||||
//
|
||||
// Enable ifconfig slip-specific options "keepalive" and "outfill"
|
||||
//#define BB_FEATURE_IFCONFIG_SLIP
|
||||
//
|
||||
// Enable ifconfig options "mem_start", "io_addr", and "irq".
|
||||
#define BB_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ
|
||||
//
|
||||
// Enable ifconfig option "hw". Currently works for only with "ether".
|
||||
#define BB_FEATURE_IFCONFIG_HW
|
||||
//
|
||||
// Allows "broadcast +" to set broadcast automatically based on hostaddr
|
||||
// and netmask, at a cost of about 100 bytes of code (i386).
|
||||
//#define BB_FEATURE_IFCONFIG_BROADCAST_PLUS
|
||||
//
|
||||
// Enable busybox --install [-s]
|
||||
// to create links (or symlinks) for all the commands that are
|
||||
// compiled into the binary. (needs /proc filesystem)
|
||||
//#define BB_FEATURE_INSTALLER
|
||||
//
|
||||
// Enable a nifty progress meter in wget (adds just under 2k)
|
||||
#define BB_FEATURE_WGET_STATUSBAR
|
||||
//
|
||||
// Enable HTTP authentication in wget
|
||||
//#define BB_FEATURE_WGET_AUTHENTICATION
|
||||
//
|
||||
// Clean up all memory before exiting -- usually not needed
|
||||
// as the OS can clean up... Don't enable this unless you
|
||||
// have a really good reason for cleaning things up manually.
|
||||
//#define BB_FEATURE_CLEAN_UP
|
||||
//
|
||||
// Support for human readable output by ls, du, etc.(example 13k, 23M, 235G)
|
||||
#define BB_FEATURE_HUMAN_READABLE
|
||||
//
|
||||
// Support for the find -type option.
|
||||
#define BB_FEATURE_FIND_TYPE
|
||||
//
|
||||
// Support for the find -perm option.
|
||||
#define BB_FEATURE_FIND_PERM
|
||||
//
|
||||
// Support for the find -mtime option.
|
||||
#define BB_FEATURE_FIND_MTIME
|
||||
//
|
||||
//// Support for the find -newer option.
|
||||
#define BB_FEATURE_FIND_NEWER
|
||||
//
|
||||
// Support for the -A -B and -C context flags in grep
|
||||
//#define BB_FEATURE_GREP_CONTEXT
|
||||
//
|
||||
// Support for the EGREP applet (alias to the grep applet)
|
||||
//#define BB_FEATURE_GREP_EGREP_ALIAS
|
||||
//
|
||||
// Tell tftp what commands that should be supported.
|
||||
#define BB_FEATURE_TFTP_PUT
|
||||
#define BB_FEATURE_TFTP_GET
|
||||
//
|
||||
// features for vi
|
||||
#define BB_FEATURE_VI_COLON // ":" colon commands, no "ex" mode
|
||||
#define BB_FEATURE_VI_YANKMARK // Yank/Put commands and Mark cmds
|
||||
#define BB_FEATURE_VI_SEARCH // search and replace cmds
|
||||
#define BB_FEATURE_VI_USE_SIGNALS // catch signals
|
||||
#define BB_FEATURE_VI_DOT_CMD // remember previous cmd and "." cmd
|
||||
#define BB_FEATURE_VI_READONLY // vi -R and "view" mode
|
||||
#define BB_FEATURE_VI_SETOPTS // set-able options, ai ic showmatch
|
||||
#define BB_FEATURE_VI_SET // :set
|
||||
#define BB_FEATURE_VI_WIN_RESIZE // handle window resize
|
||||
//
|
||||
// Enable a if you system have setuped locale
|
||||
//#define BB_LOCALE_SUPPORT
|
||||
//
|
||||
// Support for TELNET to pass TERM type to remote host. Adds 384 bytes.
|
||||
#define BB_FEATURE_TELNET_TTYPE
|
||||
//
|
||||
// Support for devfs.
|
||||
//#define BB_FEATURE_DEVFS
|
||||
//
|
||||
// End of Features List
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//---------------------------------------------------
|
||||
// Nothing beyond this point should ever be touched by
|
||||
// mere mortals so leave this stuff alone.
|
||||
//
|
||||
#include <features.h>
|
||||
#if defined(__uClinux__)
|
||||
#undef BB_RPM2CPIO /* Uses gz_open(), which uses fork() */
|
||||
#undef BB_DPKG_DEB /* Uses gz_open(), which uses fork() */
|
||||
#undef BB_FEATURE_TAR_GZIP /* Uses fork() */
|
||||
#undef BB_UPDATE /* Uses daemon() */
|
||||
#endif
|
||||
#if defined BB_ASH || defined BB_HUSH || defined BB_LASH || defined BB_MSH
|
||||
#if defined BB_FEATURE_COMMAND_EDITING
|
||||
#define BB_CMDEDIT
|
||||
#else
|
||||
#undef BB_FEATURE_COMMAND_EDITING
|
||||
#undef BB_FEATURE_COMMAND_TAB_COMPLETION
|
||||
#undef BB_FEATURE_COMMAND_USERNAME_COMPLETION
|
||||
#undef BB_FEATURE_SH_FANCY_PROMPT
|
||||
#endif
|
||||
#else
|
||||
#undef BB_FEATURE_SH_APPLETS_ALWAYS_WIN
|
||||
#undef BB_FEATURE_SH_STANDALONE_SHELL
|
||||
#undef BB_FEATURE_SH_FANCY_PROMPT
|
||||
#endif
|
||||
//
|
||||
#if (defined BB_ASH || defined BB_HUSH || defined BB_MSH) && ! defined BB_TEST
|
||||
#define BB_TEST
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_KILLALL
|
||||
#ifndef BB_KILL
|
||||
#define BB_KILL
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#ifndef BB_INIT
|
||||
#undef BB_FEATURE_LINUXRC
|
||||
#endif
|
||||
//
|
||||
#if defined BB_MOUNT && defined BB_FEATURE_NFSMOUNT
|
||||
#define BB_NFSMOUNT
|
||||
#endif
|
||||
//
|
||||
#if defined BB_FEATURE_AUTOWIDTH
|
||||
#ifndef BB_FEATURE_USE_TERMIOS
|
||||
#define BB_FEATURE_USE_TERMIOS
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#if defined BB_INSMOD || defined BB_LSMOD
|
||||
#if ! defined BB_FEATURE_NEW_MODULE_INTERFACE && ! defined BB_FEATURE_OLD_MODULE_INTERFACE
|
||||
#define BB_FEATURE_NEW_MODULE_INTERFACE
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_UNIX2DOS
|
||||
#define BB_DOS2UNIX
|
||||
#endif
|
||||
//
|
||||
#ifdef BB_SYSLOGD
|
||||
#if defined BB_FEATURE_IPC_SYSLOG
|
||||
#define BB_LOGREAD
|
||||
#endif
|
||||
#endif
|
||||
//
|
||||
#if defined BB_ASH && defined BB_FEATURE_SH_IS_ASH
|
||||
# define shell_main ash_main
|
||||
#elif defined BB_HUSH && defined BB_FEATURE_SH_IS_HUSH
|
||||
# define shell_main hush_main
|
||||
#elif defined BB_LASH && defined BB_FEATURE_SH_IS_LASH
|
||||
# define shell_main lash_main
|
||||
#elif defined BB_MSH && defined BB_FEATURE_SH_IS_MSH
|
||||
# define shell_main msh_main
|
||||
#endif
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
BusyBox for Debian
|
||||
----------------------
|
||||
|
||||
BusyBox is being developed and maintained by Erik Andersen
|
||||
<andersee@debian.org>.
|
||||
|
||||
If you have a problem with BusyBox, send email to the Debian bug tracking
|
||||
system that lives at <submit@bugs.busybox.net>
|
||||
|
||||
Erik Andersen <andersee@debian.org>, Sun, 18 Jun 2000 21:52:00 -0600
|
||||
Vendored
+318
@@ -0,0 +1,318 @@
|
||||
busybox (1:0.60.5-2) unstable; urgency=low
|
||||
|
||||
* It turns out that for the .udeb, we don't want to disable
|
||||
BB_FEATURE_LINUXRC, we just want to kill the /linuxrc link.
|
||||
Thanks to Matt Kraai for tracking this one down. (closes: #161611)
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Thu, 31 Oct 2002 02:25:01 -0700
|
||||
|
||||
busybox (1:0.60.5-1) unstable; urgency=low
|
||||
|
||||
* New version released. See Changelog for non-Debian specific details.
|
||||
* zcat no longer tries to delete source files (closes: #164968)
|
||||
* Eliminate /linuxrc from the .udeb (closes: #163890)
|
||||
* Fix description of the --install option (closes: #164178)
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Sat, 26 Oct 2002 06:23:51 -0600
|
||||
|
||||
busybox (1:0.60.4-1.1) unstable; urgency=low
|
||||
|
||||
* NMU
|
||||
* Fix cp -a so it handles symlinks properly (closes: #163501)
|
||||
|
||||
-- Tollef Fog Heen <tfheen@debian.org> Sun, 6 Oct 2002 16:08:45 +0200
|
||||
|
||||
busybox (1:0.60.4-1) unstable; urgency=low
|
||||
|
||||
* New version released. See Changelog for non-Debian specific details.
|
||||
* enable uname for the debian-installer (closes: #158706)
|
||||
* enable losetup for the boot floppies (closes: #138060)
|
||||
* init behaves itself better consoles go missing (closes: #129626)
|
||||
* In 'free', buffers change as buffered data increases (closes: #148396)
|
||||
* Functions for debootstrap added to the .udeb (closes: #124388)
|
||||
* This bug is not reproducable (closes: #127522)
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Wed, 18 Sep 2002 14:13:05 -0600
|
||||
|
||||
busybox (1:0.60.3-1) unstable; urgency=low
|
||||
|
||||
* New version released. See Changelog for non-Debian specific details.
|
||||
* makedevs no longer segfaults (closes: #123921)
|
||||
* wget no longer crashes (closes: #138943)
|
||||
* wget now checks the safe_fwrite return code (closes: #143179)
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Sat, 27 Apr 2002 01:33:34 -0600
|
||||
|
||||
busybox (1:0.60.2-3) testing unstable; urgency=low
|
||||
|
||||
* Fix wc stdin handling (closes: #123387).
|
||||
* Fix wget to do just one DNS lookup (closes: #124068)
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Sun, 16 Dec 2001 22:51:03 -0700
|
||||
|
||||
busybox (1:0.60.2-2) unstable; urgency=low
|
||||
|
||||
* Several small bugfixes (closes: #120353, #120369, #122638,
|
||||
* Reworked wc.c to fix the severe efficiency problems and make it
|
||||
smaller. This one is mainly for the boot-floppies (closes: #120441)
|
||||
* Enable hostname (closes: #120511)
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Thu, 6 Dec 2001 00:06:33 -0700
|
||||
|
||||
busybox (1:0.60.2-1) unstable; urgency=low
|
||||
|
||||
* New version released. See Changelog for non-Debian specific details.
|
||||
* dpkg.c now uses an int for getopt (closes: #118975)
|
||||
* s390 console reboot msg is now appropriate (closes: #118859)
|
||||
* the manpage is no longer empty (closes: #117013)
|
||||
* no more .o files in the source tarball (closes: #112046)
|
||||
* the .udeb contents are exactly as Joey wants them (closes: #105352)
|
||||
* busybox ash is the default shell for the -static package,
|
||||
so it can cope with /etc/profile just fine (closes: #95745)
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Tue, 20 Nov 2001 03:41:29 -0700
|
||||
|
||||
busybox (1:0.60.1-8) unstable; urgency=low
|
||||
|
||||
* Adjusted some apps for the debian installer's .udeb package.
|
||||
Enabled ifconfig, route.
|
||||
Disabled chgrp, clear, date, dd, du, gzip, halt, head, killall,
|
||||
loadkmap, logger, mkswap, more, poweroff, reset, sleep, sort,
|
||||
swapon, swapoff, touch, tty, uniq, uname, uptime, vi, wc, which,
|
||||
whoami, xargs, and yes.
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Thu, 18 Oct 2001 22:59:06 -0600
|
||||
|
||||
busybox (1:0.60.1-7) unstable; urgency=low
|
||||
|
||||
* Re-enable wget's status bar for today's dbootstrap change. (closes: #115717)
|
||||
* Enable initrd support (even if they are a bad idea). (closes: #114727)
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Mon, 15 Oct 2001 20:45:57 -0600
|
||||
|
||||
busybox (1:0.60.1-6) unstable; urgency=low
|
||||
|
||||
* Re-enable wc, gzip, tty, and expr. (closes: #114906)
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Wed, 10 Oct 2001 02:47:50 -0600
|
||||
|
||||
busybox (1:0.60.1-5) unstable; urgency=low
|
||||
|
||||
* Time to make this official. This enables several applets, such
|
||||
as ifconfig and route, and disables several others.
|
||||
* Revert ash to the version in the busybox stable branch. For the
|
||||
-3 non-release, I tried the one from busybox unstable (which lived
|
||||
up to its name). (closes: #112503)
|
||||
* Enable id, disable ash (closes: #114260, #113698)
|
||||
* Backport several bugfixes from unstable
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Fri, 5 Oct 2001 23:03:15 -0600
|
||||
|
||||
busybox (1:0.60.1-4) unstable; urgency=low
|
||||
|
||||
* Doh! With busybox ash, we need test and echo enabled...
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Wed, 26 Sep 2001 00:05:04 -0600
|
||||
|
||||
busybox (1:0.60.1-3) unstable; urgency=low
|
||||
|
||||
* This upload is to test whether disabling several applets, and
|
||||
enabling several others will help. Enabled is ifconfig, route,
|
||||
and ash. Disabled is basename, date, echo, env, expr, gzip,
|
||||
lsmod, and wc.
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Tue, 25 Sep 2001 17:45:16 -0600
|
||||
|
||||
busybox (1:0.60.1-2) unstable; urgency=low
|
||||
|
||||
* Disabled several applets to make busybox be a bit thinner, since the
|
||||
powerpc boot floppies are _very_ tight on space (closes: #112503)
|
||||
* Teach 'mount' about usbdevfs (closes: #111055)
|
||||
* Busybox supports full online help, but due to space constraints on
|
||||
the boot floppies, it will not be enabled. People can read the
|
||||
busybox documentation if they need full details. (closes: #111350)
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Sun, 23 Sep 2001 23:32:15 -0600
|
||||
|
||||
busybox (1:0.60.1-1) unstable; urgency=low
|
||||
|
||||
* New stable version released. See changelog for details.
|
||||
* Enabled 'ar' for the udeb
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Thu, 23 Aug 2001 15:44:14 -0600
|
||||
|
||||
busybox (1:0.60.0-1) unstable; urgency=low
|
||||
|
||||
* New stable version released. See changelog for details.
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Thu, 2 Aug 2001 12:12:37 -0600
|
||||
|
||||
busybox (1:0.52-1.1) unstable; urgency=high
|
||||
|
||||
* Non-maintainer upload
|
||||
* Fixed wget -P handling (closes: #106223).
|
||||
|
||||
-- Matt Kraai <kraai@debian.org> Wed, 25 Jul 2001 11:01:38 -0600
|
||||
|
||||
busybox (1:0.52-1) unstable; urgency=high
|
||||
|
||||
* New version released. See changelog for details.
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Sat, 7 Jul 2001 01:23:45 -0600
|
||||
|
||||
busybox (1:0.51-10) unstable; urgency=high
|
||||
|
||||
* Fix a compile problem with gcc 3.0 on hppa (closes: #102045)
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Sat, 23 Jun 2001 23:55:57 -0600
|
||||
|
||||
busybox (1:0.51-9) unstable; urgency=high
|
||||
|
||||
* tar was creating leading directories with 0777 permissions as
|
||||
as reult of faulty umask handling. This fixes it, repairing
|
||||
a grave security problem in the woody the boot floppies.
|
||||
(closes: #101169)
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Wed, 20 Jun 2001 16:17:38 -0600
|
||||
|
||||
busybox (1:0.51-8) unstable; urgency=high
|
||||
|
||||
* Fix cp from /proc, where size=0 (closes: #100369)
|
||||
* Add some padding to struct sysinfo for m68k.
|
||||
* Apparently some bugs failed to be closed when master choked
|
||||
(closes: #99627, #99637, #98571)
|
||||
* Disable the busybox shell for the .deb, since it is not needed
|
||||
for the boot floppies.
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Mon, 11 Jun 2001 13:26:07 -0600
|
||||
|
||||
busybox (1:0.51-7) unstable; urgency=high
|
||||
|
||||
* Fix tar permission setting for existing directories (closes: #99627)
|
||||
* Do not remove the .cvsignore files on 'make release' (closes: #99637)
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Mon, 4 Jun 2001 10:55:19 -0600
|
||||
|
||||
busybox (1:0.51-6) testing unstable; urgency=high
|
||||
|
||||
* Update the version in testing so DHCP in the woody boot-floppies will work.
|
||||
* Enable expr for the boot-floppies (closes: #98433)
|
||||
* It builds on arm just fine now (closes: #97510)
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Wed, 23 May 2001 14:50:13 -0600
|
||||
|
||||
busybox (1:0.51-5) unstable; urgency=low
|
||||
|
||||
* Backport a sed fix from 0.52pre
|
||||
* Backport chroot fix from 0.52pre
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Wed, 16 May 2001 23:50:33 -0600
|
||||
|
||||
busybox (1:0.51-4) unstable; urgency=low
|
||||
|
||||
* Backport from 0.52pre an endianness bugfix for md5sum
|
||||
* Backport some updates to grep and sed
|
||||
* Fix 'wget -O -' so it sets the quiet flag
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Mon, 14 May 2001 14:17:36 -0600
|
||||
|
||||
busybox (1:0.51-3) unstable; urgency=low
|
||||
|
||||
* This is the "I am an idiot" release.
|
||||
* Make cp and mv work again (closes: #97290)
|
||||
* Fix the version number.
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Sat, 12 May 2001 17:35:58 -0600
|
||||
|
||||
busybox (0.51-2) unstable; urgency=low
|
||||
|
||||
* Backport several release critical fixes into the 0.51 codebase
|
||||
so the boot-floppies will work again.
|
||||
* Fix a link ordering problem. (closes: #93362)
|
||||
* Fixed gunzip (closes: #94331)
|
||||
* Fixed cp permission setting (closes: #94580)
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Sat, 12 May 2001 11:22:35 -0600
|
||||
|
||||
busybox (0.51-1) unstable; urgency=low
|
||||
|
||||
* Fixes several critical bugs (see the busybox changelog
|
||||
for complete details)
|
||||
* Force USE_SYSTEM_PWD_GRP=false, so busybox bypasses
|
||||
the glibc NSS libraries. (closes: #93362)
|
||||
* Fixed a bug in sed's address range handling (closes: #91758)
|
||||
* Removed irrelevant cruft from the bottem of debian/changelog
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Tue, 10 Apr 2001 14:07:29 -0600
|
||||
|
||||
busybox (0.50-2) unstable; urgency=low
|
||||
|
||||
* Enabled freeramdisk and pivot_root in the udeb (closes: #91336)
|
||||
* Disabled lash (the busybox shell) in the udeb (closes: #91337)
|
||||
* fixed a bug in syslog, a problem with rebooting when booted as
|
||||
an initrd, and a few other minor problems.
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Sun, 25 Mar 2001 20:59:44 -0700
|
||||
|
||||
|
||||
busybox (0.50-2) unstable; urgency=low
|
||||
|
||||
* Enabled freeramdisk and pivot_root in the udeb (closes: #91336)
|
||||
* Disabled lash (the busybox shell) in the udeb (closes: #91337)
|
||||
* fixed a bug in syslog, a problem with rebooting when booted as
|
||||
an initrd, and a few other minor problems.
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Sun, 25 Mar 2001 20:59:44 -0700
|
||||
|
||||
busybox (0.50-1) unstable; urgency=low
|
||||
|
||||
* Tons on improvements all around -- See changelog for details.
|
||||
* Fix malformed Build-Depends (closes: #86930)
|
||||
* grep has worked for some time now (closes: #81084)
|
||||
* init compiles with DEBUG_INIT enabled (closes: #85794)
|
||||
* md5sum no longer displays filename when reading stdin (closes: #81283)
|
||||
* lsmod, rmmod, and insmod are no longer enabled (closes: #85642)
|
||||
* busybox and buxybox-static now conflict/replace each other (closes: #80421)
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Thu, 15 Mar 2001 14:45:00 -0700
|
||||
|
||||
busybox (0.49-1) unstable; urgency=low
|
||||
|
||||
* Lots more source updates and bug fixes. See changelog for details.
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Sat, 27 Jan 2001 01:45:53 -0700
|
||||
|
||||
busybox (0.48-1) unstable; urgency=low
|
||||
|
||||
* Lots more source updates and bug fixes. See changelog for details.
|
||||
* Now includes .udeb support for the debian-installer. The .udeb
|
||||
probably needs some more work, but this should be a good start.
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Wed, 13 Dec 2000 08:36:07 -0700
|
||||
|
||||
busybox (0.47-1) unstable; urgency=low
|
||||
|
||||
* New version released. See changelog for details.
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Mon, 25 Sep 2000 23:00:56 -0600
|
||||
|
||||
busybox (0.46-1) unstable; urgency=low
|
||||
|
||||
* New version released. See changelog for details.
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Tue, 11 Jul 2000 12:15:44 -0600
|
||||
|
||||
busybox (0.45-1) unstable; urgency=low
|
||||
|
||||
* First attempt at packaging BusyBox as a .deb. This has been in
|
||||
in the Debian boot-floppies CVS tree forever. Hopefully, having it as a
|
||||
standalone app will make life easier for me, the debian-installer team, and
|
||||
everyone else as well...
|
||||
* I have created a busybox-static that can be used as a rescue shell when you
|
||||
hose your system. Just invoke "busybox sh" to fir up the shell. This has
|
||||
every app provided by busybox staically linked in. There have been several
|
||||
times in the past that I would have loved to have this sitting on my system
|
||||
(i.e. when libc gets screwed up.)
|
||||
|
||||
-- Erik Andersen <andersee@debian.org> Tue, 27 Jun 2000 12:26:41 -0600
|
||||
|
||||
Vendored
+67
@@ -0,0 +1,67 @@
|
||||
Source: busybox
|
||||
Priority: optional
|
||||
Maintainer: Erik Andersen <andersee@debian.org>
|
||||
Build-Depends: debhelper (>= 2.1.18), dpkg-dev (>= 1.7.0)
|
||||
Standards-Version: 3.2.1.0
|
||||
|
||||
Package: busybox
|
||||
Architecture: any
|
||||
Depends: ${shlibs:Depends}
|
||||
Conflicts: busybox-static
|
||||
Replaces: busybox-static
|
||||
Section: utils
|
||||
Description: Tiny utilities for small and 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.
|
||||
.
|
||||
This package installs the BusyBox binary but does not install symlinks
|
||||
for any of the supported utilities. You can use /bin/busybox --install
|
||||
to install BusyBox to the root directory (you do not want to do this
|
||||
to your your Debian system, except in dire emergencies!).
|
||||
|
||||
Package: busybox-static
|
||||
Architecture: any
|
||||
Depends: ${shlibs:Depends}
|
||||
Conflicts: busybox
|
||||
Replaces: busybox
|
||||
Section: shells
|
||||
Priority: extra
|
||||
Description: Standalone 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.
|
||||
|
||||
Package: busybox-udeb
|
||||
Architecture: any
|
||||
Depends: ${shlibs:Depends}
|
||||
Section: debian-installer
|
||||
Priority: standard
|
||||
Description: Tiny utilities for the debian-installer
|
||||
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-udeb is used by the debian-installer, so unless you are working
|
||||
on the debian-installer, this package is not for you. Installing this
|
||||
on your Debian system is a very, very bad idea. You have been warned.
|
||||
|
||||
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
This package was debianized by Erik Andersen <andersee@debian.org> on
|
||||
Sun, 18 Jun 2000 23:31:02 -0600
|
||||
|
||||
It was downloaded from ftp://ftp.lineo.com/pub/busybox
|
||||
HomePage is at: http://busybox.lineo.com/
|
||||
|
||||
Copyright: GPL
|
||||
+194
@@ -0,0 +1,194 @@
|
||||
#!/usr/bin/make -f
|
||||
|
||||
# This is a bit unusual, in that I have to completely recompile everything
|
||||
# for each package I build (obviously static and dynamic builds require
|
||||
# things to be recompiled...)
|
||||
|
||||
# This is the debhelper compatability version to use.
|
||||
#export DH_COMPAT=1
|
||||
|
||||
bbbd=debian/busybox_builddir
|
||||
bb=debian/tmp
|
||||
bbsbd=debian/busybox_static_builddir
|
||||
bbs=debian/busybox-static
|
||||
bbubd=debian/busybox_udeb_builddir
|
||||
bbu=debian/busybox-udeb
|
||||
|
||||
clean:
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
rm -f debian/build-stamp-busybox debian/build-stamp-busybox-static debian/build-stamp-busybox-udeb
|
||||
-$(MAKE) clean
|
||||
-rm -rf $(bb) $(bbbd) $(bbs) $(bbsbd) $(bbubd) $(bbu)
|
||||
dh_clean
|
||||
|
||||
build: debian/build-stamp-busybox
|
||||
debian/build-stamp-busybox:
|
||||
dh_testdir
|
||||
mkdir -p $(bbbd)
|
||||
cp Makefile $(bbbd)
|
||||
cp debian/Config.h-deb $(bbbd)/Config.h
|
||||
-(cd $(bbbd); $(MAKE) "BB_SRC_DIR=../../" applet_source_list)
|
||||
(cd $(bbbd); $(MAKE) USE_SYSTEM_PWD_GRP=false "BB_SRC_DIR=../../")
|
||||
touch debian/build-stamp-busybox
|
||||
|
||||
install: 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...
|
||||
#(cd $(bbbd); $(MAKE) "BB_SRC_DIR=../../" "PREFIX=../../$(bb)" install)
|
||||
mkdir -p $(bb)/bin/
|
||||
cp $(bbbd)/busybox $(bb)/bin/busybox
|
||||
mkdir -p $(bb)/usr/share/doc/busybox
|
||||
cp $(bbbd)/docs/BusyBox.html $(bb)/usr/share/doc/busybox/
|
||||
mkdir -p $(bb)/usr/share/man/man1
|
||||
cp $(bbbd)/docs/BusyBox.1 $(bb)/usr/share/man/man1/busybox.1
|
||||
|
||||
# Now for the statically linked stuff
|
||||
build-static: debian/build-stamp-busybox-static
|
||||
debian/build-stamp-busybox-static:
|
||||
dh_testdir
|
||||
mkdir -p $(bbsbd)
|
||||
cp Makefile $(bbsbd)
|
||||
cp debian/Config.h-static $(bbsbd)/Config.h
|
||||
(cd $(bbsbd); $(MAKE) DOSTATIC=true USE_SYSTEM_PWD_GRP=false "BB_SRC_DIR=../../")
|
||||
touch debian/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...
|
||||
#(cd $(bbsbd); $(MAKE) "BB_SRC_DIR=../../" "PREFIX=../../$(bbs)" install)
|
||||
mkdir -p $(bbs)/bin/
|
||||
cp $(bbsbd)/busybox $(bbs)/bin/busybox
|
||||
mkdir -p $(bbs)/usr/share/doc/busybox-static
|
||||
cp $(bbsbd)/docs/BusyBox.html $(bbs)/usr/share/doc/busybox-static/
|
||||
mkdir -p $(bbs)/usr/share/man/man1/
|
||||
cp $(bbsbd)/docs/BusyBox.1 $(bbs)/usr/share/man/man1/busybox.1
|
||||
|
||||
half_clean:
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
rm -rf $(bbs) debian/build-stamp-busybox-static
|
||||
-$(MAKE) clean
|
||||
|
||||
do_static: half_clean build-static install-static
|
||||
|
||||
|
||||
|
||||
# Now for the .udeb stuff
|
||||
PACKAGE=busybox-udeb
|
||||
VERSION=$(shell dpkg-parsechangelog | grep ^Version: | cut -d ' ' -f 2 | sed -e s/[0-9]://g)
|
||||
ARCH=$(shell dpkg --print-architecture)
|
||||
FILENAME=$(PACKAGE)_$(VERSION)_$(ARCH).udeb
|
||||
|
||||
build-udeb: debian/build-stamp-busybox-udeb
|
||||
debian/build-stamp-busybox-udeb:
|
||||
dh_testdir
|
||||
mkdir -p $(bbubd)
|
||||
cp Makefile $(bbubd)
|
||||
cp debian/Config.h-udeb $(bbubd)/Config.h
|
||||
(cd $(bbubd); $(MAKE) USE_SYSTEM_PWD_GRP=false "BB_SRC_DIR=../../")
|
||||
touch debian/build-stamp-busybox-udeb
|
||||
|
||||
install-udeb: build
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_clean -k
|
||||
dh_installdirs
|
||||
(cd $(bbubd); $(MAKE) "BB_SRC_DIR=../../" "PREFIX=../../$(bbu)" install)
|
||||
rm -f $(bbu)/linuxrc
|
||||
mkdir -p $(bbu)/usr/share/man/man1/
|
||||
cp $(bbubd)/docs/BusyBox.1 $(bbu)/usr/share/man/man1/busybox.1
|
||||
|
||||
three_quarter_clean:
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
rm -rf $(bbu) debian/build-stamp-busybox-udeb
|
||||
-$(MAKE) clean
|
||||
|
||||
do_udeb: three_quarter_clean build-udeb install-udeb
|
||||
|
||||
|
||||
|
||||
# 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-udeb
|
||||
|
||||
busybox: install
|
||||
@echo "--- Building: $@"
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_installdirs
|
||||
dh_installdocs -p$@ $(bbbd)/docs/BusyBox.txt \
|
||||
$(bbbd)/docs/BusyBox.html docs/style-guide.txt \
|
||||
AUTHORS README TODO
|
||||
rm -rf `find $(bb) -name CVS`
|
||||
rm -f `find $(bb) -name .cvsignore`
|
||||
dh_installchangelogs -p$@ Changelog
|
||||
dh_undocumented -p$@
|
||||
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$@ $(bbsbd)/docs/BusyBox.txt \
|
||||
$(bbsbd)/docs/BusyBox.html docs/style-guide.txt \
|
||||
AUTHORS README TODO
|
||||
rm -rf `find $(bbs) -name CVS`
|
||||
rm -f `find $(bbs) -name .cvsignore`
|
||||
dh_installchangelogs -p$@ Changelog
|
||||
dh_undocumented -p$@
|
||||
dh_strip -p$@
|
||||
dh_compress -p$@
|
||||
dh_fixperms -p$@
|
||||
dh_installdeb -p$@
|
||||
dh_shlibdeps -p$@
|
||||
dh_gencontrol -p$@
|
||||
dh_md5sums -p$@
|
||||
dh_builddeb -p$@
|
||||
|
||||
|
||||
# Note that this builds a .udeb, which is not policy compliant or anything.
|
||||
#
|
||||
busybox-udeb: do_udeb
|
||||
@echo "--- Building: $@"
|
||||
dh_testdir
|
||||
dh_testroot
|
||||
dh_installdirs
|
||||
dh_strip -p$@
|
||||
dh_compress -p$@
|
||||
dh_fixperms -p$@
|
||||
dh_installdeb -p$@
|
||||
dh_shlibdeps -p$@
|
||||
#Make _very_ sure there are no docs lurking about.
|
||||
rm -rf $(bbu)/usr/share/man
|
||||
#dh_gencontrol -p$@
|
||||
# Don't write your stupid guesses to debian/files.
|
||||
dh_gencontrol -p$@ -- -fdebian/files~
|
||||
# Register file manually.
|
||||
dpkg-distaddfile $(FILENAME) debian-installer standard
|
||||
dh_md5sums -p$@
|
||||
dh_builddeb -p$@ --filename=$(FILENAME)
|
||||
|
||||
binary: binary-indep binary-arch
|
||||
.PHONY: build clean binary-indep binary-arch binary install
|
||||
@@ -1,8 +1,9 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini df implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
|
||||
* Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
|
||||
* based on original code by (I think) Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -21,89 +22,137 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <mntent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/vfs.h>
|
||||
#include <fstab.h>
|
||||
#include <getopt.h>
|
||||
#include "busybox.h"
|
||||
|
||||
static const char df_usage[] = "df [filesystem ...]\n"
|
||||
"\n" "\tPrint the filesystem space used and space available.\n";
|
||||
extern const char mtab_file[]; /* Defined in utility.c */
|
||||
#ifdef BB_FEATURE_HUMAN_READABLE
|
||||
static unsigned long df_disp_hr = KILOBYTE;
|
||||
#endif
|
||||
|
||||
extern const char mtab_file[]; /* Defined in utility.c */
|
||||
|
||||
static int df(char *device, const char *mountPoint)
|
||||
static int do_df(char *device, const char *mount_point)
|
||||
{
|
||||
struct statfs s;
|
||||
long blocks_used;
|
||||
long blocks_percent_used;
|
||||
struct fstab* fstabItem;
|
||||
struct statfs s;
|
||||
long blocks_used;
|
||||
long blocks_percent_used;
|
||||
|
||||
if (statfs(mountPoint, &s) != 0) {
|
||||
perror(mountPoint);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (s.f_blocks > 0) {
|
||||
blocks_used = s.f_blocks - s.f_bfree;
|
||||
blocks_percent_used = (long)
|
||||
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
|
||||
/* Note that if /etc/fstab is missing, libc can't fix up /dev/root for us */
|
||||
if (strcmp (device, "/dev/root") == 0) {
|
||||
fstabItem = getfsfile ("/");
|
||||
if (fstabItem != NULL)
|
||||
device = fstabItem->fs_spec;
|
||||
if (statfs(mount_point, &s) != 0) {
|
||||
perror_msg("%s", mount_point);
|
||||
return FALSE;
|
||||
}
|
||||
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
|
||||
device,
|
||||
(long) (s.f_blocks * (s.f_bsize / 1024.0)),
|
||||
(long) ((s.f_blocks - s.f_bfree) * (s.f_bsize / 1024.0)),
|
||||
(long) (s.f_bavail * (s.f_bsize / 1024.0)),
|
||||
blocks_percent_used, mountPoint);
|
||||
|
||||
}
|
||||
if (s.f_blocks > 0) {
|
||||
blocks_used = s.f_blocks - s.f_bfree;
|
||||
if(blocks_used == 0)
|
||||
blocks_percent_used = 0;
|
||||
else {
|
||||
blocks_percent_used = (long)
|
||||
(blocks_used * 100.0 / (blocks_used + s.f_bavail) + 0.5);
|
||||
}
|
||||
if (strcmp(device, "/dev/root") == 0) {
|
||||
/* Adjusts device to be the real root device,
|
||||
* or leaves device alone if it can't find it */
|
||||
device = find_real_root_device_name(device);
|
||||
if(device==NULL)
|
||||
return FALSE;
|
||||
}
|
||||
#ifdef BB_FEATURE_HUMAN_READABLE
|
||||
printf("%-20s %9s ", device,
|
||||
make_human_readable_str(s.f_blocks, s.f_bsize, df_disp_hr));
|
||||
|
||||
return TRUE;
|
||||
printf("%9s ",
|
||||
make_human_readable_str( (s.f_blocks - s.f_bfree), s.f_bsize, df_disp_hr));
|
||||
|
||||
printf("%9s %3ld%% %s\n",
|
||||
make_human_readable_str(s.f_bavail, s.f_bsize, df_disp_hr),
|
||||
blocks_percent_used, mount_point);
|
||||
#else
|
||||
printf("%-20s %9ld %9ld %9ld %3ld%% %s\n",
|
||||
device,
|
||||
(long) (s.f_blocks * (s.f_bsize / (double)KILOBYTE)),
|
||||
(long) ((s.f_blocks - s.f_bfree)*(s.f_bsize/(double)KILOBYTE)),
|
||||
(long) (s.f_bavail * (s.f_bsize / (double)KILOBYTE)),
|
||||
blocks_percent_used, mount_point);
|
||||
#endif
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
extern int df_main(int argc, char **argv)
|
||||
{
|
||||
printf("%-20s %-14s %s %s %s %s\n", "Filesystem",
|
||||
"1k-blocks", "Used", "Available", "Use%", "Mounted on");
|
||||
int status = EXIT_SUCCESS;
|
||||
int opt = 0;
|
||||
int i = 0;
|
||||
char disp_units_hdr[80] = "1k-blocks"; /* default display is kilobytes */
|
||||
|
||||
if (argc > 1) {
|
||||
struct mntent *mountEntry;
|
||||
int status;
|
||||
|
||||
while (argc > 1) {
|
||||
if ((mountEntry = findMountPoint(argv[1], mtab_file)) ==
|
||||
0) {
|
||||
fprintf(stderr, "%s: can't find mount point.\n", argv[1]);
|
||||
exit( FALSE);
|
||||
}
|
||||
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
if (status != 0)
|
||||
exit( status);
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
exit( TRUE);
|
||||
} else {
|
||||
FILE *mountTable;
|
||||
struct mntent *mountEntry;
|
||||
|
||||
mountTable = setmntent(mtab_file, "r");
|
||||
if (mountTable == 0) {
|
||||
perror(mtab_file);
|
||||
exit(FALSE);
|
||||
while ((opt = getopt(argc, argv, "k"
|
||||
#ifdef BB_FEATURE_HUMAN_READABLE
|
||||
"hm"
|
||||
#endif
|
||||
)) > 0)
|
||||
{
|
||||
switch (opt) {
|
||||
#ifdef BB_FEATURE_HUMAN_READABLE
|
||||
case 'h':
|
||||
df_disp_hr = 0;
|
||||
strcpy(disp_units_hdr, " Size");
|
||||
break;
|
||||
case 'm':
|
||||
df_disp_hr = MEGABYTE;
|
||||
strcpy(disp_units_hdr, "1M-blocks");
|
||||
break;
|
||||
#endif
|
||||
case 'k':
|
||||
/* default display is kilobytes */
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
while ((mountEntry = getmntent(mountTable))) {
|
||||
df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
}
|
||||
endmntent(mountTable);
|
||||
}
|
||||
printf("%-20s %-14s %s %s %s %s\n", "Filesystem", disp_units_hdr,
|
||||
"Used", "Available", "Use%", "Mounted on");
|
||||
|
||||
exit( TRUE);
|
||||
if(optind < argc) {
|
||||
struct mntent *mount_entry;
|
||||
for(i = optind; i < argc; i++)
|
||||
{
|
||||
if ((mount_entry = find_mount_point(argv[i], mtab_file)) == 0) {
|
||||
error_msg("%s: can't find mount point.", argv[i]);
|
||||
status = EXIT_FAILURE;
|
||||
} else if (!do_df(mount_entry->mnt_fsname, mount_entry->mnt_dir))
|
||||
status = EXIT_FAILURE;
|
||||
}
|
||||
} else {
|
||||
FILE *mount_table;
|
||||
struct mntent *mount_entry;
|
||||
|
||||
mount_table = setmntent(mtab_file, "r");
|
||||
if (mount_table == 0) {
|
||||
perror_msg("%s", mtab_file);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
while ((mount_entry = getmntent(mount_table))) {
|
||||
if (!do_df(mount_entry->mnt_fsname, mount_entry->mnt_dir))
|
||||
status = EXIT_FAILURE;
|
||||
}
|
||||
endmntent(mount_table);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
c-file-style: "linux"
|
||||
c-basic-offset: 4
|
||||
tab-width: 4
|
||||
End:
|
||||
*/
|
||||
@@ -0,0 +1,40 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini dirname implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
|
||||
* Copyright (C) 1999,2000,2001 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
|
||||
*
|
||||
*/
|
||||
|
||||
/* getopt not needed */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "busybox.h"
|
||||
|
||||
extern int dirname_main(int argc, char **argv)
|
||||
{
|
||||
if ((argc < 2) || (**(argv + 1) == '-'))
|
||||
show_usage();
|
||||
argv++;
|
||||
|
||||
puts (dirname (argv[0]));
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/* dmesg.c -- Print out the contents of the kernel ring buffer
|
||||
* Created: Sat Oct 9 16:19:47 1993
|
||||
* Revised: Thu Oct 28 21:52:17 1993 by faith@cs.unc.edu
|
||||
@@ -14,111 +15,81 @@
|
||||
* Support, replaced getopt, added some gotos for redundant stuff.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <linux/unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
|
||||
#if __GNU_LIBRARY__ < 5
|
||||
|
||||
#ifndef __alpha__
|
||||
# define __NR_klogctl __NR_syslog
|
||||
static inline _syscall3(int, klogctl, int, type, char *, b, int, len);
|
||||
#else /* __alpha__ */
|
||||
#define klogctl syslog
|
||||
#endif
|
||||
|
||||
# ifdef __alpha__
|
||||
# define klogctl syslog
|
||||
# endif
|
||||
#else
|
||||
# include <sys/klog.h>
|
||||
#endif
|
||||
|
||||
static const char dmesg_usage[] = "dmesg [-c] [-n level] [-s bufsize]\n";
|
||||
#include "busybox.h"
|
||||
|
||||
int dmesg_main( int argc, char** argv )
|
||||
int dmesg_main(int argc, char **argv)
|
||||
{
|
||||
char *buf;
|
||||
int bufsize=8196;
|
||||
int i;
|
||||
int n;
|
||||
int level = 0;
|
||||
int lastc;
|
||||
int cmd = 3;
|
||||
int stopDoingThat;
|
||||
char *buf;
|
||||
int c;
|
||||
int bufsize = 8196;
|
||||
int i;
|
||||
int n;
|
||||
int level = 0;
|
||||
int lastc;
|
||||
int cmd = 3;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
while ((c = getopt(argc, argv, "cn:s:")) != EOF) {
|
||||
switch (c) {
|
||||
case 'c':
|
||||
cmd = 4;
|
||||
break;
|
||||
case 'n':
|
||||
cmd = 8;
|
||||
if (optarg == NULL)
|
||||
show_usage();
|
||||
level = atoi(optarg);
|
||||
break;
|
||||
case 's':
|
||||
if (optarg == NULL)
|
||||
show_usage();
|
||||
bufsize = atoi(optarg);
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
/* Parse any options */
|
||||
while (argc && **argv == '-') {
|
||||
stopDoingThat = FALSE;
|
||||
while (stopDoingThat == FALSE && *++(*argv)) {
|
||||
switch (**argv) {
|
||||
case 'c':
|
||||
cmd = 4;
|
||||
break;
|
||||
case 'n':
|
||||
cmd = 8;
|
||||
if (--argc == 0)
|
||||
goto end;
|
||||
level = atoi (*(++argv));
|
||||
if (--argc > 0)
|
||||
++argv;
|
||||
stopDoingThat = TRUE;
|
||||
break;
|
||||
case 's':
|
||||
if (--argc == 0)
|
||||
goto end;
|
||||
bufsize = atoi (*(++argv));
|
||||
if (--argc > 0)
|
||||
++argv;
|
||||
stopDoingThat = TRUE;
|
||||
break;
|
||||
default:
|
||||
goto end;
|
||||
}
|
||||
if (optind < argc) {
|
||||
show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (argc > 1) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (cmd == 8) {
|
||||
n = klogctl( cmd, NULL, level );
|
||||
if (n < 0) {
|
||||
goto klogctl_error;
|
||||
}
|
||||
exit( TRUE );
|
||||
}
|
||||
if (cmd == 8) {
|
||||
if (klogctl(cmd, NULL, level) < 0)
|
||||
perror_msg_and_die("klogctl");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
if (bufsize < 4096) bufsize = 4096;
|
||||
buf = (char*)malloc(bufsize);
|
||||
n = klogctl( cmd, buf, bufsize );
|
||||
if (n < 0) {
|
||||
goto klogctl_error;
|
||||
}
|
||||
|
||||
lastc = '\n';
|
||||
for (i = 0; i < n; i++) {
|
||||
if ((i == 0 || buf[i - 1] == '\n') && buf[i] == '<') {
|
||||
i++;
|
||||
while (buf[i] >= '0' && buf[i] <= '9')
|
||||
i++;
|
||||
if (buf[i] == '>')
|
||||
i++;
|
||||
}
|
||||
lastc = buf[i];
|
||||
putchar( lastc );
|
||||
}
|
||||
if (lastc != '\n')
|
||||
putchar( '\n' );
|
||||
exit( TRUE);
|
||||
end:
|
||||
usage( dmesg_usage);
|
||||
exit (FALSE);
|
||||
klogctl_error:
|
||||
perror( "klogctl" );
|
||||
exit( FALSE );
|
||||
if (bufsize < 4096)
|
||||
bufsize = 4096;
|
||||
buf = (char *) xmalloc(bufsize);
|
||||
if ((n = klogctl(cmd, buf, bufsize)) < 0)
|
||||
perror_msg_and_die("klogctl");
|
||||
|
||||
lastc = '\n';
|
||||
for (i = 0; i < n; i++) {
|
||||
if (lastc == '\n' && buf[i] == '<') {
|
||||
i++;
|
||||
while (buf[i] >= '0' && buf[i] <= '9')
|
||||
i++;
|
||||
if (buf[i] == '>')
|
||||
i++;
|
||||
}
|
||||
lastc = buf[i];
|
||||
putchar(lastc);
|
||||
}
|
||||
if (lastc != '\n')
|
||||
putchar('\n');
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
BusyBox.txt
|
||||
BusyBox.1
|
||||
BusyBox.html
|
||||
busybox.txt
|
||||
busybox.ps
|
||||
busybox.pdf
|
||||
busybox
|
||||
busybox.pod
|
||||
-1025
File diff suppressed because it is too large.
Load diff
Executable
+287
@@ -0,0 +1,287 @@
|
||||
#!/usr/bin/perl -w
|
||||
|
||||
use strict;
|
||||
use Getopt::Long;
|
||||
|
||||
# collect lines continued with a '\' into an array
|
||||
sub continuation {
|
||||
my $fh = shift;
|
||||
my @line;
|
||||
|
||||
while (<$fh>) {
|
||||
my $s = $_;
|
||||
$s =~ s/\\\s*$//;
|
||||
#$s =~ s/#.*$//;
|
||||
push @line, $s;
|
||||
last unless (/\\\s*$/);
|
||||
}
|
||||
return @line;
|
||||
}
|
||||
|
||||
# regex && eval away unwanted strings from documentation
|
||||
sub beautify {
|
||||
my $text = shift;
|
||||
$text =~ s/USAGE_NOT\w+\(.*?"\s*\)//sxg;
|
||||
$text =~ s/USAGE_\w+\(\s*?(.*?)"\s*\)/$1"/sxg;
|
||||
$text =~ s/"\s*"//sg;
|
||||
my @line = split("\n", $text);
|
||||
$text = join('',
|
||||
map {
|
||||
s/^\s*"//;
|
||||
s/"\s*$//;
|
||||
s/%/%%/g;
|
||||
s/\$/\\\$/g;
|
||||
eval qq[ sprintf(qq{$_}) ]
|
||||
} @line
|
||||
);
|
||||
return $text;
|
||||
}
|
||||
|
||||
# generate POD for an applet
|
||||
sub pod_for_usage {
|
||||
my $name = shift;
|
||||
my $usage = shift;
|
||||
|
||||
# make options bold
|
||||
my $trivial = $usage->{trivial};
|
||||
$trivial =~ s/(?<!\w)(-\w+)/B<$1>/sxg;
|
||||
my @f0 =
|
||||
map { $_ !~ /^\s/ && s/(?<!\w)(-\w+)/B<$1>/g; $_ }
|
||||
split("\n", $usage->{full});
|
||||
|
||||
# add "\n" prior to certain lines to make indented
|
||||
# lines look right
|
||||
my @f1;
|
||||
my $len = @f0;
|
||||
for (my $i = 0; $i < $len; $i++) {
|
||||
push @f1, $f0[$i];
|
||||
if (($i+1) != $len && $f0[$i] !~ /^\s/ && $f0[$i+1] =~ /^\s/) {
|
||||
next if ($f0[$i] =~ /^$/);
|
||||
push(@f1, "") unless ($f0[$i+1] =~ /^\s*$/s);
|
||||
}
|
||||
}
|
||||
my $full = join("\n", @f1);
|
||||
|
||||
# prepare notes if they exist
|
||||
my $notes = (defined $usage->{notes})
|
||||
? "$usage->{notes}\n\n"
|
||||
: "";
|
||||
|
||||
# prepare examples if they exist
|
||||
my $example = (defined $usage->{example})
|
||||
?
|
||||
"Example:\n\n" .
|
||||
join ("\n",
|
||||
map { "\t$_" }
|
||||
split("\n", $usage->{example})) . "\n\n"
|
||||
: "";
|
||||
|
||||
return
|
||||
"=item B<$name>".
|
||||
"\n\n" .
|
||||
"$name $trivial".
|
||||
"\n\n" .
|
||||
$full .
|
||||
"\n\n" .
|
||||
$notes .
|
||||
$example.
|
||||
"-------------------------------".
|
||||
"\n\n"
|
||||
;
|
||||
}
|
||||
|
||||
# FIXME | generate SGML for an applet
|
||||
sub sgml_for_usage {
|
||||
my $name = shift;
|
||||
my $usage = shift;
|
||||
return
|
||||
"<fixme>\n".
|
||||
" $name\n".
|
||||
"</fixme>\n"
|
||||
;
|
||||
}
|
||||
|
||||
# the keys are applet names, and
|
||||
# the values will contain hashrefs of the form:
|
||||
#
|
||||
# {
|
||||
# trivial => "...",
|
||||
# full => "...",
|
||||
# notes => "...",
|
||||
# example => "...",
|
||||
# }
|
||||
my %docs;
|
||||
|
||||
|
||||
# get command-line options
|
||||
|
||||
my %opt;
|
||||
|
||||
GetOptions(
|
||||
\%opt,
|
||||
"help|h",
|
||||
"sgml|s",
|
||||
"pod|p",
|
||||
"verbose|v",
|
||||
);
|
||||
|
||||
if (defined $opt{help}) {
|
||||
print
|
||||
"$0 [OPTION]... [FILE]...\n",
|
||||
"\t--help\n",
|
||||
"\t--sgml\n",
|
||||
"\t--pod\n",
|
||||
"\t--verbose\n",
|
||||
;
|
||||
exit 1;
|
||||
}
|
||||
|
||||
|
||||
# collect documenation into %docs
|
||||
|
||||
foreach (@ARGV) {
|
||||
open(USAGE, $_) || die("$0: $_: $!");
|
||||
my $fh = *USAGE;
|
||||
my ($applet, $type, @line);
|
||||
while (<$fh>) {
|
||||
if (/^#define (\w+)_(\w+)_usage/) {
|
||||
$applet = $1;
|
||||
$type = $2;
|
||||
@line = continuation($fh);
|
||||
my $doc = $docs{$applet} ||= { };
|
||||
my $text = join("\n", @line);
|
||||
$doc->{$type} = beautify($text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# generate structured documentation
|
||||
|
||||
my $generator = \&pod_for_usage;
|
||||
if (defined $opt{sgml}) {
|
||||
$generator = \&sgml_for_usage;
|
||||
}
|
||||
|
||||
foreach my $applet (sort keys %docs) {
|
||||
print $generator->($applet, $docs{$applet});
|
||||
}
|
||||
|
||||
exit 0;
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
autodocifier.pl - generate docs for busybox based on usage.h
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
autodocifier.pl [OPTION]... [FILE]...
|
||||
|
||||
Example:
|
||||
|
||||
( cat docs/busybox_header.pod; \
|
||||
docs/autodocifier.pl usage.h; \
|
||||
cat docs/busybox_footer.pod ) > docs/busybox.pod
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
The purpose of this script is to automagically generate documentation
|
||||
for busybox using its usage.h as the original source for content.
|
||||
Currently, the same content has to be duplicated in 3 places in
|
||||
slightly different formats -- F<usage.h>, F<docs/busybox.pod>, and
|
||||
F<docs/busybox.sgml>. This is tedious, so Perl has come to the rescue.
|
||||
|
||||
This script was based on a script by Erik Andersen <andersee@debian.org>
|
||||
which was in turn based on a script by Mark Whitley <markw@codepoet.org>
|
||||
|
||||
=head1 OPTIONS
|
||||
|
||||
=over 4
|
||||
|
||||
=item B<--help>
|
||||
|
||||
This displays the help message.
|
||||
|
||||
=item B<--pod>
|
||||
|
||||
Generate POD (this is the default)
|
||||
|
||||
=item B<--sgml>
|
||||
|
||||
Generate SGML
|
||||
|
||||
=item B<--verbose>
|
||||
|
||||
Be verbose (not implemented)
|
||||
|
||||
=back
|
||||
|
||||
=head1 FORMAT
|
||||
|
||||
The following is an example of some data this script might parse.
|
||||
|
||||
#define length_trivial_usage \
|
||||
"STRING"
|
||||
#define length_full_usage \
|
||||
"Prints out the length of the specified STRING."
|
||||
#define length_example_usage \
|
||||
"$ length Hello\n" \
|
||||
"5\n"
|
||||
|
||||
Each entry is a cpp macro that defines a string. The macros are
|
||||
named systematically in the form:
|
||||
|
||||
$name_$type_usage
|
||||
|
||||
$name is the name of the applet. $type can be "trivial", "full", "notes",
|
||||
or "example". Every documentation macro must end with "_usage".
|
||||
|
||||
The definition of the types is as follows:
|
||||
|
||||
=over 4
|
||||
|
||||
=item B<trivial>
|
||||
|
||||
This should be a brief, one-line description of parameters that
|
||||
the command expects. This will be displayed when B<-h> is issued to
|
||||
a command. I<REQUIRED>
|
||||
|
||||
=item B<full>
|
||||
|
||||
This should contain descriptions of each option. This will also
|
||||
be displayed along with the trivial help if BB_FEATURE_TRIVIAL_HELP
|
||||
is disabled. I<REQUIRED>
|
||||
|
||||
=item B<notes>
|
||||
|
||||
This is documentation that is intended to go in the POD or SGML, but
|
||||
not be printed when a B<-h> is given to a command. To see an example
|
||||
of notes being used, see init_notes_usage. I<OPTIONAL>
|
||||
|
||||
=item B<example>
|
||||
|
||||
This should be an example of how the command is acutally used.
|
||||
This will not be printed when a B<-h> is given to a command -- it
|
||||
is inteded only for the POD or SGML documentation. I<OPTIONAL>
|
||||
|
||||
=back
|
||||
|
||||
=head1 FILES
|
||||
|
||||
F<usage.h>
|
||||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
Copyright (c) 2001 John BEPPU. All rights reserved. This program is
|
||||
free software; you can redistribute it and/or modify it under the same
|
||||
terms as Perl itself.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
John BEPPU <beppu@codepoet.org>
|
||||
|
||||
=cut
|
||||
|
||||
# $Id: autodocifier.pl,v 1.22 2001/11/19 23:57:54 andersen Exp $
|
||||
+3974
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,169 @@
|
||||
=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...
|
||||
|
||||
=head1 MAINTAINER
|
||||
|
||||
Erik Andersen <andersee@debian.org> <andersen@codepoet.org>
|
||||
|
||||
=head1 AUTHORS
|
||||
|
||||
The following people have contributed code to BusyBox whether
|
||||
they know it or not.
|
||||
|
||||
|
||||
=for html <br>
|
||||
|
||||
Erik Andersen <andersee@debian.org> <andersen@codepoet.org>
|
||||
|
||||
Tons of new stuff, major rewrite of most of the
|
||||
core apps, tons of new apps as noted in header files.
|
||||
|
||||
=for html <br>
|
||||
|
||||
John Beppu <beppu@codepoet.org>
|
||||
|
||||
du, head, nslookup, sort, tee, uniq (so Kraai could rewrite them ;-),
|
||||
documentation
|
||||
|
||||
=for html <br>
|
||||
|
||||
Edward Betts <edward@debian.org>
|
||||
|
||||
expr, hostid, logname, tty, wc, whoami, yes
|
||||
|
||||
=for html <br>
|
||||
|
||||
Brian Candler <B.Candler@pobox.com>
|
||||
|
||||
tiny-ls(ls)
|
||||
|
||||
=for html <br>
|
||||
|
||||
Randolph Chung <tausq@debian.org>
|
||||
|
||||
fbset, ping, hostname, and mkfifo
|
||||
|
||||
=for html <br>
|
||||
|
||||
Dave Cinege <dcinege@psychosis.com>
|
||||
|
||||
more(v2), makedevs, dutmp, modularization, auto links file,
|
||||
various fixes, Linux Router Project maintenance
|
||||
|
||||
=for html <br>
|
||||
|
||||
Larry Doolittle <ldoolitt@recycle.lbl.gov>
|
||||
|
||||
various fixes, shell rewrite
|
||||
|
||||
=for html <br>
|
||||
|
||||
Karl M. Hegbloom <karlheg@debian.org>
|
||||
|
||||
cp_mv.c, the test suite, various fixes to utility.c, &c.
|
||||
|
||||
=for html <br>
|
||||
|
||||
Sterling Huxley <sterling@europa.com>
|
||||
|
||||
vi (!!!)
|
||||
|
||||
=for html <br>
|
||||
|
||||
Daniel Jacobowitz <dan@debian.org>
|
||||
|
||||
mktemp.c
|
||||
|
||||
=for html <br>
|
||||
|
||||
Matt Kraai <kraai@alumni.carnegiemellon.edu>
|
||||
|
||||
documentation, bugfixes
|
||||
|
||||
=for html <br>
|
||||
|
||||
John Lombardo <john@deltanet.com>
|
||||
|
||||
dirname, tr
|
||||
|
||||
=for html <br>
|
||||
|
||||
Glenn McGrath <bug1@netconnect.com.au>
|
||||
|
||||
ar.c
|
||||
|
||||
=for html <br>
|
||||
|
||||
Vladimir Oleynik <dzo@simtreas.ru>
|
||||
|
||||
cmdedit, stty-port, locale, various fixes
|
||||
and irreconcilable critic of everything not perfect.
|
||||
|
||||
=for html <br>
|
||||
|
||||
Bruce Perens <bruce@pixar.com>
|
||||
|
||||
Original author of BusyBox. His code is still in many apps.
|
||||
|
||||
=for html <br>
|
||||
|
||||
Chip Rosenthal <chip@unicom.com>, <crosenth@covad.com>
|
||||
|
||||
wget - Contributed by permission of Covad Communications
|
||||
|
||||
=for html <br>
|
||||
|
||||
Pavel Roskin <proski@gnu.org>
|
||||
|
||||
Lots of bugs fixes and patches.
|
||||
|
||||
=for html <br>
|
||||
|
||||
Gyepi Sam <gyepi@praxis-sw.com>
|
||||
|
||||
Remote logging feature for syslogd
|
||||
|
||||
=for html <br>
|
||||
|
||||
Linus Torvalds <torvalds@transmeta.com>
|
||||
|
||||
mkswap, fsck.minix, mkfs.minix
|
||||
|
||||
=for html <br>
|
||||
|
||||
Mark Whitley <markw@codepoet.org>
|
||||
|
||||
sed remix, bug fixes, style-guide, etc.
|
||||
|
||||
=for html <br>
|
||||
|
||||
Charles P. Wright <cpwright@villagenet.com>
|
||||
|
||||
gzip, mini-netcat(nc)
|
||||
|
||||
=for html <br>
|
||||
|
||||
Enrique Zanardi <ezanardi@ull.es>
|
||||
|
||||
tarcat (since removed), loadkmap, various fixes, Debian maintenance
|
||||
|
||||
=cut
|
||||
|
||||
# $Id: busybox_footer.pod,v 1.5 2001/11/19 23:57:54 andersen Exp $
|
||||
@@ -0,0 +1,74 @@
|
||||
# vi: set sw=4 ts=4:
|
||||
|
||||
=head1 NAME
|
||||
|
||||
BusyBox - The Swiss Army Knife of Embedded Linux
|
||||
|
||||
=head1 SYNTAX
|
||||
|
||||
BusyBox <function> [arguments...] # or
|
||||
|
||||
<function> [arguments...] # if symlinked
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
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.
|
||||
|
||||
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 issuing the command as an argument on the
|
||||
command line. For example, entering
|
||||
|
||||
./BusyBox ls
|
||||
|
||||
will also cause BusyBox to behave as 'ls'.
|
||||
|
||||
=head1 COMMON OPTIONS
|
||||
|
||||
Most BusyBox commands support the B<-h> option to provide a
|
||||
terse runtime description of their behavior.
|
||||
|
||||
=head1 COMMANDS
|
||||
|
||||
Currently defined functions include:
|
||||
|
||||
adjtimex, ar, basename, busybox, cat, chgrp, chmod, chown, chroot, chvt, clear,
|
||||
cmp, cp, cpio, cut, date, dc, dd, deallocvt, df, dirname, dmesg, dos2unix, dpkg,
|
||||
dpkg-deb, du, dumpkmap, dutmp, echo, expr, false, fbset, fdflush, find, free,
|
||||
freeramdisk, fsck.minix, getopt, grep, gunzip, gzip, halt, head, hostid,
|
||||
hostname, id, ifconfig, init, insmod, kill, killall, klogd, length, ln,
|
||||
loadacm, loadfont, loadkmap, logger, logname, ls, lsmod, makedevs, md5sum,
|
||||
mkdir, mkfifo, mkfs.minix, mknod, mkswap, mktemp, more, mount, mt, mv, nc,
|
||||
nslookup, ping, pivot_root, poweroff, printf, ps, pwd, rdate, readlink, reboot,
|
||||
renice, reset, rm, rmdir, rmmod, route, rpm2cpio, sed, setkeycodes,
|
||||
sh, sleep, sort, stty, swapoff, swapon, sync, syslogd, tail, tar, tee, telnet,
|
||||
test, tftp, touch, tr, true, tty, umount, uname, uniq, unix2dos, update, uptime,
|
||||
usleep, uudecode, uuencode, watchdog, wc, wget, which, whoami, xargs, yes, zcat,
|
||||
[
|
||||
|
||||
=over 4
|
||||
|
||||
|
||||
@@ -0,0 +1,476 @@
|
||||
Contributing To Busybox
|
||||
=======================
|
||||
|
||||
This document describes what you need to do to contribute to Busybox, where
|
||||
you can help, guidelines on testing, and how to submit a well-formed patch
|
||||
that is more likely to be accepted.
|
||||
|
||||
The Busybox home page is at: http://busybox.lineo.com
|
||||
|
||||
|
||||
|
||||
Pre-Contribution Checklist
|
||||
--------------------------
|
||||
|
||||
So you want to contribute to Busybox, eh? Great, wonderful, glad you want to
|
||||
help. However, before you dive in, headlong and hotfoot, there are some things
|
||||
you need to do:
|
||||
|
||||
|
||||
Checkout the Latest Code from CVS
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
This is a necessary first step. Please do not try to work with the last
|
||||
released version, as there is a good chance that somebody has already fixed
|
||||
the bug you found. Somebody might have even added the feature you had in mind.
|
||||
Don't make your work obsolete before you start!
|
||||
|
||||
For information on how to check out Busybox from CVS, please look at the
|
||||
following links:
|
||||
|
||||
http://oss.lineo.com/cvs_anon.html
|
||||
http://oss.lineo.com/cvs_howto.html
|
||||
|
||||
|
||||
Read the Mailing List
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
No one is required to read the entire archives of the mailing list, but you
|
||||
should at least read up on what people have been talking about lately. If
|
||||
you've recently discovered a problem, chances are somebody else has too. If
|
||||
you're the first to discover a problem, post a message and let the rest of us
|
||||
know.
|
||||
|
||||
Archives can be found here:
|
||||
|
||||
http://oss.lineo.com/lists/busybox/
|
||||
|
||||
If you have a serious interest in Busybox, i.e., you are using it day-to-day or
|
||||
as part of an embedded project, it would be a good idea to join the mailing
|
||||
list.
|
||||
|
||||
A web-based sign-up form can be found here:
|
||||
|
||||
http://oss.lineo.com/mailman/listinfo/busybox
|
||||
|
||||
|
||||
Coordinate with the Applet Maintainer
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Some (not all) of the applets in Busybox are "owned" by a maintainer who has
|
||||
put significant effort into it and is probably more familiar with it than
|
||||
others. To find the maintainer of an applet, look at the top of the .c file
|
||||
for a name following the word 'Copyright' or 'Written by' or 'Maintainer'.
|
||||
|
||||
Before plunging ahead, it's a good idea to send a message to the mailing list
|
||||
that says: "Hey, I was thinking about adding the 'transmogrify' feature to the
|
||||
'foo' applet. Would this be useful? Is anyone else working on it?" You might
|
||||
want to CC the maintainer (if any) with your question.
|
||||
|
||||
|
||||
|
||||
Areas Where You Can Help
|
||||
------------------------
|
||||
|
||||
Busybox can always use improvement! If you're looking for ways to help, there
|
||||
there are a variety of areas where you could help.
|
||||
|
||||
|
||||
What Busybox Doesn't Need
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Before listing the areas where you _can_ help, it's worthwhile to mention the
|
||||
areas where you shouldn't bother. While Busybox strives to be the "Swiss Army
|
||||
Knife" of embedded Linux, there are some applets that will not be accepted:
|
||||
|
||||
- Any filesystem manipulation tools: Busybox is filesystem independent and
|
||||
we do not want to start adding mkfs/fsck tools for every (or any)
|
||||
filesystem under the sun. (fsck_minix.c and mkfs_minix.c are living on
|
||||
borrowed time.) There are far too many of these tools out there. Use
|
||||
the upstream version. Not everything has to be part of Busybox.
|
||||
|
||||
- Any partitioning tools: Partitioning a device is typically done once and
|
||||
only once, and tools which do this generally do not need to reside on the
|
||||
target device (esp a flash device). If you need a partitioning tool, grab
|
||||
one (such as fdisk, sfdisk, or cfdisk from util-linux) and use that, but
|
||||
don't try to merge it into busybox. These are nasty and complex and we
|
||||
don't want to maintain them.
|
||||
|
||||
- Any disk, device, or media-specific tools: Use the -utils or -tools package
|
||||
that was designed for your device; don't try to shoehorn them into Busybox.
|
||||
|
||||
- Any architecture specific tools: Busybox is (or should be) architecture
|
||||
independent. Do not send us tools that cannot be used across multiple
|
||||
platforms / arches.
|
||||
|
||||
- Any daemons that are not essential to basic system operation. To date, only
|
||||
syslogd and klogd meet this requirement. We do not need a web server, an
|
||||
ftp daemon, a dhcp server, a mail transport agent or a dns resolver. If you
|
||||
need one of those, you are welcome to ask the folks on the mailing list for
|
||||
recommendations, but please don't bloat up Busybox with any of these.
|
||||
|
||||
|
||||
Bug Reporting
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
If you find a bug in Busybox, you can send a bug report to our bug tracking
|
||||
system (homepage: http://bugs.lineo.com). Instructions on how to send a bug
|
||||
report to the tracking system can be found at:
|
||||
|
||||
http://bugs.lineo.com/Reporting.html
|
||||
|
||||
The README file that comes with Busybox also describes how to submit a bug.
|
||||
|
||||
A well-written bug report should include a transcript of a shell session that
|
||||
demonstrates the bad behavior and enables anyone else to duplicate the bug on
|
||||
their own machine. The following is such an example:
|
||||
|
||||
When I execute Busybox 'date' it produces unexpected results.
|
||||
|
||||
This is using GNU date:
|
||||
$ date
|
||||
Wed Mar 21 14:19:41 MST 2001
|
||||
|
||||
This is using Busybox date:
|
||||
$ date
|
||||
codswaddle
|
||||
|
||||
|
||||
Bug Triage
|
||||
~~~~~~~~~~
|
||||
|
||||
Validating and confirming bugs is nearly as important as reporting them in the
|
||||
first place. It is valuable to know if a bug can be duplicated on a different
|
||||
machine, on a different filesystem, on a different architecture, with a
|
||||
different C library, and so forth.
|
||||
|
||||
To see a listing of all the bugs currently filed against Busybox, look here:
|
||||
|
||||
http://bugs.lineo.com/db/pa/lbusybox.html
|
||||
|
||||
If you have comments to add to a bug (can / can't duplicate, think a bug
|
||||
should be closed / reopened), please send it to [bugnumber]@bugs.lineo.com.
|
||||
The message you send will automatically be forwarded to the mailing list for
|
||||
all to see.
|
||||
|
||||
|
||||
Write Documentation
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Chances are, documentation in Busybox is either missing or needs improvement.
|
||||
Either way, help is welcome.
|
||||
|
||||
Work is being done to automatically generate documentation from sources,
|
||||
especially from the usage.h file. If you want to correct the documentation,
|
||||
please make changes to the pre-generation parts, rather than the generated
|
||||
documentation. [More to come on this later...]
|
||||
|
||||
It is preferred that modifications to documentation be submitted in patch
|
||||
format (more on this below), but we're a little more lenient when it comes to
|
||||
docs. You could, for example, just say "after the listing of the mount
|
||||
options, the following example would be helpful..."
|
||||
|
||||
|
||||
Consult Existing Sources
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
For a quick listing of "needs work" spots in the sources, cd into the Busybox
|
||||
directory and run the following:
|
||||
|
||||
for i in TODO FIXME XXX; do grep $i *.[ch]; done
|
||||
|
||||
This will show all of the trouble spots or 'questionable' code. Pick a spot,
|
||||
any spot, these are all invitations for you to contribute.
|
||||
|
||||
|
||||
Consult The Bug-Tracking System
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Head to: http://bugs.lineo.com/db/pa/lBusybox.html and look at the bugs on
|
||||
there. Pick one you think you can fix, and fix it. If it's a wishlist item and
|
||||
someone's requesting a new feature, take a stab at adding it. Everything
|
||||
previously said about "reading the mailing list" and "coordinating with the
|
||||
applet maintainer" still applies.
|
||||
|
||||
|
||||
Add a New Applet
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
If you want to add a new applet to Busybox, we'd love to see it. However,
|
||||
before you write any code, please ask beforehand on the mailing list something
|
||||
like "Do you think applet 'foo' would be useful in Busybox?" or "Would you
|
||||
guys accept applet 'foo' into Busybox if I were to write it?" If the answer is
|
||||
"no" by the folks on the mailing list, then you've saved yourself some time.
|
||||
Conversely, you could get some positive responses from folks who might be
|
||||
interested in helping you implement it, or can recommend the best approach.
|
||||
Perhaps most importantly, this is your way of calling "dibs" on something and
|
||||
avoiding duplication of effort.
|
||||
|
||||
Also, before you write a line of code, please read the 'new-applet-HOWTO.txt'
|
||||
file in the docs/ directory.
|
||||
|
||||
|
||||
Janitorial Work
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
These are dirty jobs, but somebody's gotta do 'em.
|
||||
|
||||
- Converting applets to use getopt() for option processing. Type 'grep -L
|
||||
getopt *.c' to get a listing of the applets that currently don't use
|
||||
getopt. If a .c file processes no options, it should have a line that
|
||||
reads: /* no options, no getopt */ somewhere in the file.
|
||||
|
||||
- Replace any "naked" calls to malloc, calloc, realloc, str[n]dup, fopen with
|
||||
the x* equivalents found in utility.c.
|
||||
|
||||
- Security audits:
|
||||
http://www.securityfocus.com/frames/?content=/forums/secprog/secure-programming.html
|
||||
|
||||
- Synthetic code removal: http://www.perl.com/pub/2000/06/commify.html - This
|
||||
is very Perl-specific, but the advice given in here applies equally well to
|
||||
C.
|
||||
|
||||
- C library funciton use audits: Verifying that functions are being used
|
||||
properly (called with the right args), replacing unsafe library functions
|
||||
with safer versions, making sure return codes are being checked, etc.
|
||||
|
||||
- Where appropriate, replace preprocessor defined macros and values with
|
||||
compile-time equivalents.
|
||||
|
||||
- Style guide compliance. See: docs/style-guide.txt
|
||||
|
||||
- Add testcases to tests/testcases.
|
||||
|
||||
- Makefile improvements:
|
||||
http://www.canb.auug.org.au/~millerp/rmch/recu-make-cons-harm.html
|
||||
(I think the recursive problems are pretty much taken care of at this point, non?)
|
||||
|
||||
- "Ten Commandments" compliance: (this is a "maybe", certainly not as
|
||||
important as any of the previous items.)
|
||||
http://web.onetelnet.ch/~twolf/tw/c/ten_commandments.html
|
||||
|
||||
Other useful links:
|
||||
|
||||
- the comp.lang.c FAQ: http://web.onetelnet.ch/~twolf/tw/c/index.html#Sources
|
||||
|
||||
|
||||
|
||||
Submitting Patches To Busybox
|
||||
-----------------------------
|
||||
|
||||
Here are some guidelines on how to submit a patch to Busybox.
|
||||
|
||||
|
||||
Making A Patch
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
If you've got anonymous CVS access set up, making a patch is simple. Just make
|
||||
sure you're in the busybox/ directory and type 'cvs diff -bwu > mychanges.patch'.
|
||||
You can send the resulting .patch file to the mailing list with a description
|
||||
of what it does. (But not before you test it! See the next section for some
|
||||
guidelines.) It is preferred that patches be sent as attachments, but it is
|
||||
not required.
|
||||
|
||||
Also, feel free to help test other people's patches and reply to them with
|
||||
comments. You can apply a patch by saving it into your busybox/ directory and
|
||||
typing 'patch < mychanges.patch'. Then you can recompile, see if it runs, test
|
||||
if it works as advertised, and post your findings to the mailing list.
|
||||
|
||||
NOTE: Please do not include extraneous or irrelevant changes in your patches.
|
||||
Please do not try to "bundle" two patches together into one. Make single,
|
||||
discreet changes on a per-patch basis. Sometimes you need to make a patch that
|
||||
touches code in many places, but these kind of patches are rare and should be
|
||||
coordinated with a maintainer.
|
||||
|
||||
|
||||
Testing Guidelines
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
It's considered good form to test your new feature before you submit a patch
|
||||
to the mailing list, and especially before you commit a change to CVS. Here
|
||||
are some guidelines on how to test your changes.
|
||||
|
||||
- Always test Busybox applets against GNU counterparts and make sure the
|
||||
behavior / output is identical between the two.
|
||||
|
||||
- Try several different permutations and combinations of the features you're
|
||||
adding (i.e., different combinations of command-line switches) and make sure
|
||||
they all work; make sure one feature does not interfere with another.
|
||||
|
||||
- Make sure you test compiling against the source both with the feature
|
||||
turned on and turned off in Config.h and make sure Busybox compiles cleanly
|
||||
both ways.
|
||||
|
||||
- Run the multibuild.pl script in the tests directory and make sure
|
||||
everything checks out OK. (Do this from within the busybox/ directory by
|
||||
typing: 'tests/multibuild.pl'.)
|
||||
|
||||
|
||||
Making Sure Your Patch Doesn't Get Lost
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
If you don't want your patch to be lost or forgotten, send it to the bug
|
||||
tracking system (http://bugs.lineo.com). You do this by emailing your patch in
|
||||
a message to submit@bugs.lineo.com with a subject line something like this:
|
||||
|
||||
[PATCH] - Adds "transmogrify" feature to "foo"
|
||||
|
||||
In the body, you should have a pseudo-header that looks like the following:
|
||||
|
||||
Package: busybox
|
||||
Version: v0.50pre (or whatever the current version is)
|
||||
Severity: wishlist
|
||||
|
||||
The remainder of the body should read along these lines:
|
||||
|
||||
This patch adds the "transmogrify" feature to the "foo" applet. I have
|
||||
tested this on [arch] system(s) and it works. I have tested it against the
|
||||
GNU counterparts and the outputs are identical. I have run the scripts in
|
||||
the 'tests' directory and nothing breaks.
|
||||
|
||||
Detailed instructions on how to submit a bug to the tracking system are at:
|
||||
|
||||
http://bugs.lineo.com/Reporting.html
|
||||
|
||||
If you have a patch that will fix and close a reported bug, please send a
|
||||
message to [bugnumber]@bugs.lineo.com with your patch attached. It will catch
|
||||
people's attention if you have a subject line like the following:
|
||||
|
||||
[PATCH INCLUDED] - Fix attached, please apply and close this bug
|
||||
|
||||
|
||||
|
||||
Improving Your Chances of Patch Acceptance
|
||||
------------------------------------------
|
||||
|
||||
Even after you send a brilliant patch to the mailing list, sometimes it can go
|
||||
unnoticed, un-replied-to, and sometimes (sigh) even lost. This is an
|
||||
unfortunate fact of life, but there are steps you can take to help your patch
|
||||
get noticed and convince a maintainer that it should be added:
|
||||
|
||||
|
||||
Be Succinct
|
||||
~~~~~~~~~~~
|
||||
|
||||
A patch that includes small, isolated, obvious changes is more likely to be
|
||||
accepted than a patch that touches code in lots of different places or makes
|
||||
sweeping, dubious changes.
|
||||
|
||||
|
||||
Back It Up
|
||||
~~~~~~~~~~
|
||||
|
||||
Hard facts on why your patch is better than the existing code will go a long
|
||||
way toward convincing maintainers that your patch should be included.
|
||||
Specifically, patches are more likely to be accepted if they are provably more
|
||||
correct, smaller, faster, simpler, or more maintainable than the existing
|
||||
code.
|
||||
|
||||
Conversely, any patch that is supported with nothing more than "I think this
|
||||
would be cool" or "this patch is good because I say it is and I've got a Phd
|
||||
in Computer Science" will likely be ignored.
|
||||
|
||||
|
||||
Follow The Style Guide
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
It's considered good form to abide by the established coding style used in a
|
||||
project; Busybox is no exception. We have gone so far as to delineate the
|
||||
"elements of Busybox style" in the file docs/style-guide.txt. Please follow
|
||||
them.
|
||||
|
||||
|
||||
Work With Someone Else
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Working on a patch in isolation is less effective than working with someone
|
||||
else for a variety of reasons. If another Busybox user is interested in what
|
||||
you're doing, then it's two (or more) voices instead of one that can petition
|
||||
for inclusion of the patch. You'll also have more people that can test your
|
||||
changes, or even offer suggestions on better approaches you could take.
|
||||
|
||||
Getting other folks interested follows as a natural course if you've received
|
||||
responses from queries to applet maintainer or positive responses from folks
|
||||
on the mailing list.
|
||||
|
||||
We've made strident efforts to put a useful "collaboration" infrastructure in
|
||||
place in the form of mailing lists, the bug tracking system, and CVS. Please
|
||||
use these resources.
|
||||
|
||||
|
||||
Send Patches to the Bug Tracking System
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
This was mentioned above in the "Making Sure Your Patch Doesn't Get Lost"
|
||||
section, but it is worth mentioning again. A patch sent to the mailing list
|
||||
might be unnoticed and forgotten. A patch sent to the bug tracking system will
|
||||
be stored and closely connected to the bug it fixes.
|
||||
|
||||
|
||||
Be Polite
|
||||
~~~~~~~~~
|
||||
|
||||
The old saying "You'll catch more flies with honey than you will with vinegar"
|
||||
applies when submitting patches to the mailing list for approval. The way you
|
||||
present your patch is sometimes just as important as the actual patch itself
|
||||
(if not more so). Being rude to the maintainers is not an effective way to
|
||||
convince them that your patch should be included; it will likely have the
|
||||
opposite effect.
|
||||
|
||||
|
||||
|
||||
Committing Changes to CVS
|
||||
-------------------------
|
||||
|
||||
If you submit several patches that demonstrate that you are a skilled and wise
|
||||
coder, you may be invited to become a committer, thus enabling you to commit
|
||||
changes directly to CVS. This is nice because you don't have to wait for
|
||||
someone else to commit your change for you, you can just do it yourself.
|
||||
|
||||
But note that this is a priviledge that comes with some responsibilities. You
|
||||
should test your changes before you commit them. You should also talk to an
|
||||
applet maintainer before you make any kind of sweeping changes to somebody
|
||||
else's code. Big changes should still go to the mailing list first. Remember,
|
||||
being wise, polite, and discreet is more important than being clever.
|
||||
|
||||
|
||||
When To Commit
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
Generally, you should feel free to commit a change if:
|
||||
|
||||
- Your changes are small and don't touch many files
|
||||
- You are fixing a bug
|
||||
- Somebody has told you that it's okay
|
||||
- It's obviously the Right Thing
|
||||
|
||||
The more of the above are true, the better it is to just commit a change
|
||||
directly to CVS.
|
||||
|
||||
|
||||
When Not To Commit
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Even if you have commit rights, you should probably still post a patch to the
|
||||
mailing list if:
|
||||
|
||||
- Your changes are broad and touch many different files
|
||||
- You are adding a feature
|
||||
- Your changes are speculative or experimental (i.e., trying a new algorithm)
|
||||
- You are not the maintainer and your changes make the maintainer cringe
|
||||
|
||||
The more of the above are true, the better it is to post a patch to the
|
||||
mailing list instead of committing.
|
||||
|
||||
|
||||
|
||||
Final Words
|
||||
-----------
|
||||
|
||||
If all of this seems complicated, don't panic, it's really not that tough. If
|
||||
you're having difficulty following some of the steps outlined in this
|
||||
document don't worry, the folks on the Busybox mailing list are a fairly
|
||||
good-natured bunch and will work with you to help get your patches into shape
|
||||
or help you make contributions.
|
||||
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
How to Add a New Applet to BusyBox
|
||||
==================================
|
||||
|
||||
This document details the steps you must take to add a new applet to BusyBox.
|
||||
|
||||
Credits:
|
||||
Matt Kraai - initial writeup
|
||||
Mark Whitley - the remix
|
||||
|
||||
|
||||
Initial Write
|
||||
-------------
|
||||
|
||||
First, write your applet. Be sure to include copyright information at the
|
||||
top, such as who you stole the code from and so forth. Also include the
|
||||
mini-GPL boilerplate. Be sure to name the main function <applet>_main instead
|
||||
of main. And be sure to put it in <applet>.c. For a new applet mu, here is
|
||||
the code that would go in mu.c:
|
||||
|
||||
----begin example code------
|
||||
|
||||
/* vi: set sw=4 ts=4: */
|
||||
/*
|
||||
* Mini mu implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) [YEAR] by [YOUR NAME] <YOUR EMAIL>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "busybox.h"
|
||||
|
||||
int mu_main(int argc, char **argv)
|
||||
{
|
||||
int fd;
|
||||
char mu;
|
||||
|
||||
if ((fd = open("/dev/random", O_RDONLY)) < 0)
|
||||
perror_msg_and_die("/dev/random");
|
||||
|
||||
if ((n = safe_read(fd, &mu, 1)) < 1)
|
||||
perror_msg_and_die("/dev/random");
|
||||
|
||||
return mu;
|
||||
}
|
||||
|
||||
----end example code------
|
||||
|
||||
|
||||
Coding Style
|
||||
------------
|
||||
|
||||
Before you submit your applet for inclusion in BusyBox, (or better yet, before
|
||||
you _write_ your applet) please read through the style guide in the docs
|
||||
directory and make your program compliant.
|
||||
|
||||
|
||||
Some Words on libbb
|
||||
-------------------
|
||||
|
||||
As you are writing your applet, please be aware of the body of pre-existing
|
||||
useful functions in libbb. Use these instead of reinventing the wheel.
|
||||
|
||||
Additionally, if you have any useful, general-purpose functions in your
|
||||
program that could be useful in another program, consider putting them in
|
||||
libbb.
|
||||
|
||||
|
||||
Usage String(s)
|
||||
---------------
|
||||
|
||||
Next, add usage information for you applet to usage.h. This should look like
|
||||
the following:
|
||||
|
||||
#define mu_trivial_usage \
|
||||
"-[abcde] FILES"
|
||||
#define mu_full_usage \
|
||||
"Returns an indeterminate value.\n\n" \
|
||||
"Options:\n" \
|
||||
"\t-a\t\tfirst function\n" \
|
||||
"\t-b\t\tsecond function\n" \
|
||||
|
||||
If your program supports flags, the flags should be mentioned on the first
|
||||
line (-[abcde]) and a detailed description of each flag should go in the
|
||||
mu_full_usage section, one flag per line. (Numerous examples of this
|
||||
currently exist in usage.h.)
|
||||
|
||||
|
||||
Header Files
|
||||
------------
|
||||
|
||||
Next, add an entry to applets.h. Be *sure* to keep the list in alphabetical
|
||||
order, or else it will break the binary-search lookup algorithm in busybox.c
|
||||
and the Gods of BusyBox smite you. Yea, verily:
|
||||
|
||||
/* all programs above here are alphabetically "less than" 'mu' */
|
||||
#ifdef BB_MU
|
||||
APPLET("mu", mu_main, _BB_DIR_USR_BIN, mu_usage)
|
||||
#endif
|
||||
/* all programs below here are alphabetically "greater than" 'mu' */
|
||||
|
||||
|
||||
Finally, add a define for your applet to Config.h:
|
||||
|
||||
#define BB_MU
|
||||
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
If you're feeling especially nice, you should also document your applet in the
|
||||
docs directory (but nobody ever does that).
|
||||
|
||||
|
||||
The Grand Announcement
|
||||
----------------------
|
||||
|
||||
Then create a diff -urN of the files you added (<applet>.c, usage.c,
|
||||
applets.h, Config.h) and send it to the mailing list:
|
||||
busybox@oss.lineo.com. Sending patches as attachments is preferred, but
|
||||
not required.
|
||||
|
||||
|
||||
@@ -0,0 +1,680 @@
|
||||
Busybox Style Guide
|
||||
===================
|
||||
|
||||
This document describes the coding style conventions used in Busybox. If you
|
||||
add a new file to Busybox or are editing an existing file, please format your
|
||||
code according to this style. If you are the maintainer of a file that does
|
||||
not follow these guidelines, please -- at your own convenience -- modify the
|
||||
file(s) you maintain to bring them into conformance with this style guide.
|
||||
Please note that this is a low priority task.
|
||||
|
||||
To help you format the whitespace of your programs, an ".indent.pro" file is
|
||||
included in the main Busybox source directory that contains option flags to
|
||||
format code as per this style guide. This way you can run GNU indent on your
|
||||
files by typing 'indent myfile.c myfile.h' and it will magically apply all the
|
||||
right formatting rules to your file. Please _do_not_ run this on all the files
|
||||
in the directory, just your own.
|
||||
|
||||
|
||||
|
||||
Declaration Order
|
||||
-----------------
|
||||
|
||||
Here is the order in which code should be laid out in a file:
|
||||
|
||||
- commented program name and one-line description
|
||||
- commented author name and email address(es)
|
||||
- commented GPL boilerplate
|
||||
- commented longer description / notes for the program (if needed)
|
||||
- #includes of .h files with angle brackets (<>) around them
|
||||
- #includes of .h files with quotes ("") around them
|
||||
- #defines (if any, note the section below titled "Avoid the Preprocessor")
|
||||
- const and global variables
|
||||
- function declarations (if necessary)
|
||||
- function implementations
|
||||
|
||||
|
||||
|
||||
Whitespace and Formatting
|
||||
-------------------------
|
||||
|
||||
This is everybody's favorite flame topic so let's get it out of the way right
|
||||
up front.
|
||||
|
||||
|
||||
Tabs vs. Spaces in Line Indentation
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The preference in Busybox is to indent lines with tabs. Do not indent lines
|
||||
with spaces and do not indents lines using a mixture of tabs and spaces. (The
|
||||
indentation style in the Apache and Postfix source does this sort of thing:
|
||||
\s\s\s\sif (expr) {\n\tstmt; --ick.) The only exception to this rule is
|
||||
multi-line comments that use an asterisk at the beginning of each line, i.e.:
|
||||
|
||||
/t/*
|
||||
/t * This is a block comment.
|
||||
/t * Note that it has multiple lines
|
||||
/t * and that the beginning of each line has a tab plus a space
|
||||
/t * except for the opening '/*' line where the slash
|
||||
/t * is used instead of a space.
|
||||
/t */
|
||||
|
||||
Furthermore, The preference is that tabs be set to display at four spaces
|
||||
wide, but the beauty of using only tabs (and not spaces) at the beginning of
|
||||
lines is that you can set your editor to display tabs at *whatever* number of
|
||||
spaces is desired and the code will still look fine.
|
||||
|
||||
|
||||
Operator Spacing
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
||||
Put spaces between terms and operators. Example:
|
||||
|
||||
Don't do this:
|
||||
|
||||
for(i=0;i<num_items;i++){
|
||||
|
||||
Do this instead:
|
||||
|
||||
for (i = 0; i < num_items; i++) {
|
||||
|
||||
While it extends the line a bit longer, the spaced version is more
|
||||
readable. An allowable exception to this rule is the situation where
|
||||
excluding the spacing makes it more obvious that we are dealing with a
|
||||
single term (even if it is a compound term) such as:
|
||||
|
||||
if (str[idx] == '/' && str[idx-1] != '\\')
|
||||
|
||||
or
|
||||
|
||||
if ((argc-1) - (optind+1) > 0)
|
||||
|
||||
|
||||
Bracket Spacing
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
If an opening bracket starts a function, it should be on the
|
||||
next line with no spacing before it. However, if a bracket follows an opening
|
||||
control block, it should be on the same line with a single space (not a tab)
|
||||
between it and the opening control block statement. Examples:
|
||||
|
||||
Don't do this:
|
||||
|
||||
while (!done)
|
||||
{
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
Don't do this either:
|
||||
|
||||
while (!done){
|
||||
|
||||
do{
|
||||
|
||||
And for heaven's sake, don't do this:
|
||||
|
||||
while (!done)
|
||||
{
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
Do this instead:
|
||||
|
||||
while (!done) {
|
||||
|
||||
do {
|
||||
|
||||
|
||||
Spacing around Parentheses
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Put a space between C keywords and left parens, but not between function names
|
||||
and the left paren that starts it's parameter list (whether it is being
|
||||
declared or called). Examples:
|
||||
|
||||
Don't do this:
|
||||
|
||||
while(foo) {
|
||||
for(i = 0; i < n; i++) {
|
||||
|
||||
Do this instead:
|
||||
|
||||
while (foo) {
|
||||
for (i = 0; i < n; i++) {
|
||||
|
||||
But do functions like this:
|
||||
|
||||
static int my_func(int foo, char bar)
|
||||
...
|
||||
baz = my_func(1, 2);
|
||||
|
||||
Also, don't put a space between the left paren and the first term, nor between
|
||||
the last arg and the right paren.
|
||||
|
||||
Don't do this:
|
||||
|
||||
if ( x < 1 )
|
||||
strcmp( thisstr, thatstr )
|
||||
|
||||
Do this instead:
|
||||
|
||||
if (x < 1)
|
||||
strcmp(thisstr, thatstr)
|
||||
|
||||
|
||||
Cuddled Elses
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
Also, please "cuddle" your else statements by putting the else keyword on the
|
||||
same line after the right bracket that closes an 'if' statement.
|
||||
|
||||
Don't do this:
|
||||
|
||||
if (foo) {
|
||||
stmt;
|
||||
}
|
||||
else {
|
||||
stmt;
|
||||
}
|
||||
|
||||
Do this instead:
|
||||
|
||||
if (foo) {
|
||||
stmt;
|
||||
} else {
|
||||
stmt;
|
||||
}
|
||||
|
||||
The exception to this rule is if you want to include a comment before the else
|
||||
block. Example:
|
||||
|
||||
if (foo) {
|
||||
stmts...
|
||||
}
|
||||
/* otherwise, we're just kidding ourselves, so re-frob the input */
|
||||
else {
|
||||
other_stmts...
|
||||
}
|
||||
|
||||
|
||||
|
||||
Variable and Function Names
|
||||
---------------------------
|
||||
|
||||
Use the K&R style with names in all lower-case and underscores occasionally
|
||||
used to separate words (e.g., "variable_name" and "numchars" are both
|
||||
acceptable). Using underscores makes variable and function names more readable
|
||||
because it looks like whitespace; using lower-case is easy on the eyes.
|
||||
|
||||
Frowned upon:
|
||||
|
||||
hitList
|
||||
TotalChars
|
||||
szFileName
|
||||
pf_Nfol_TriState
|
||||
|
||||
Preferred:
|
||||
|
||||
hit_list
|
||||
total_chars
|
||||
file_name
|
||||
sensible_name
|
||||
|
||||
Exceptions:
|
||||
|
||||
- Enums, macros, and constant variables are occasionally written in all
|
||||
upper-case with words optionally seperatedy by underscores (i.e. FIFOTYPE,
|
||||
ISBLKDEV()).
|
||||
|
||||
- Nobody is going to get mad at you for using 'pvar' as the name of a
|
||||
variable that is a pointer to 'var'.
|
||||
|
||||
|
||||
Converting to K&R
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
The Busybox codebase is very much a mixture of code gathered from a variety of
|
||||
sources. This explains why the current codebase contains such a hodge-podge of
|
||||
different naming styles (Java, Pascal, K&R, just-plain-weird, etc.). The K&R
|
||||
guideline explained above should therefore be used on new files that are added
|
||||
to the repository. Furthermore, the maintainer of an existing file that uses
|
||||
alternate naming conventions should, at his own convenience, convert those
|
||||
names over to K&R style. Converting variable names is a very low priority
|
||||
task.
|
||||
|
||||
If you want to do a search-and-replace of a single variable name in different
|
||||
files, you can do the following in the busybox directory:
|
||||
|
||||
$ perl -pi -e 's/\bOldVar\b/new_var/g' *.[ch]
|
||||
|
||||
If you want to convert all the non-K&R vars in your file all at once, follow
|
||||
these steps:
|
||||
|
||||
- In the busybox directory type 'scripts/mk2knr.pl files-to-convert'. This
|
||||
does not do the actual conversion, rather, it generates a script called
|
||||
'convertme.pl' that shows what will be converted, giving you a chance to
|
||||
review the changes beforehand.
|
||||
|
||||
- Review the 'convertme.pl' script that gets generated in the busybox
|
||||
directory and remove / edit any of the substitutions in there. Please
|
||||
especially check for false positives (strings that should not be
|
||||
converted).
|
||||
|
||||
- Type './convertme.pl same-files-as-before' to perform the actual
|
||||
conversion.
|
||||
|
||||
- Compile and see if everything still works.
|
||||
|
||||
Please be aware of changes that have cascading effects into other files. For
|
||||
example, if you're changing the name of something in, say utility.c, you
|
||||
should probably run 'scripts/mk2knr.pl utility.c' at first, but when you run
|
||||
the 'convertme.pl' script you should run it on _all_ files like so:
|
||||
'./convertme.pl *.[ch]'.
|
||||
|
||||
|
||||
|
||||
Avoid The Preprocessor
|
||||
----------------------
|
||||
|
||||
At best, the preprocessor is a necessary evil, helping us account for platform
|
||||
and architecture differences. Using the preprocessor unnecessarily is just
|
||||
plain evil.
|
||||
|
||||
|
||||
The Folly of #define
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Use 'const <type> var' for declaring constants.
|
||||
|
||||
Don't do this:
|
||||
|
||||
#define var 80
|
||||
|
||||
Do this instead, when the variable is in a header file and will be used in
|
||||
several source files:
|
||||
|
||||
const int var = 80;
|
||||
|
||||
Or do this when the variable is used only in a single source file:
|
||||
|
||||
static const int var = 80;
|
||||
|
||||
Declaring variables as '[static] const' gives variables an actual type and
|
||||
makes the compiler do type checking for you; the preprocessor does _no_ type
|
||||
checking whatsoever, making it much more error prone. Declaring variables with
|
||||
'[static] const' also makes debugging programs much easier since the value of
|
||||
the variable can be easily queried and displayed.
|
||||
|
||||
|
||||
The Folly of Macros
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Use 'static inline' instead of a macro.
|
||||
|
||||
Don't do this:
|
||||
|
||||
#define mini_func(param1, param2) (param1 << param2)
|
||||
|
||||
Do this instead:
|
||||
|
||||
static inline int mini_func(int param1, param2)
|
||||
{
|
||||
return (param1 << param2);
|
||||
}
|
||||
|
||||
Static inline functions are greatly preferred over macros. They provide type
|
||||
safety, have no length limitations, no formatting limitations, have an actual
|
||||
return value, and under gcc they are as cheap as macros. Besides, really long
|
||||
macros with backslashes at the end of each line are ugly as sin.
|
||||
|
||||
|
||||
The Folly of #ifdef
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Code cluttered with ifdefs is difficult to read and maintain. Don't do it.
|
||||
Instead, put your ifdefs at the top of your .c file (or in a header), and
|
||||
conditionally define 'static inline' functions, (or *maybe* macros), which are
|
||||
used in the code.
|
||||
|
||||
Don't do this:
|
||||
|
||||
ret = my_func(bar, baz);
|
||||
if (!ret)
|
||||
return -1;
|
||||
#ifdef BB_FEATURE_FUNKY
|
||||
maybe_do_funky_stuff(bar, baz);
|
||||
#endif
|
||||
|
||||
Do this instead:
|
||||
|
||||
(in .h header file)
|
||||
|
||||
#ifdef BB_FEATURE_FUNKY
|
||||
static inline void maybe_do_funky_stuff (int bar, int baz)
|
||||
{
|
||||
/* lotsa code in here */
|
||||
}
|
||||
#else
|
||||
static inline void maybe_do_funky_stuff (int bar, int baz) {}
|
||||
#endif
|
||||
|
||||
(in the .c source file)
|
||||
|
||||
ret = my_func(bar, baz);
|
||||
if (!ret)
|
||||
return -1;
|
||||
maybe_do_funky_stuff(bar, baz);
|
||||
|
||||
The great thing about this approach is that the compiler will optimize away
|
||||
the "no-op" case (the empty function) when the feature is turned off.
|
||||
|
||||
Note also the use of the word 'maybe' in the function name to indicate
|
||||
conditional execution.
|
||||
|
||||
|
||||
|
||||
Notes on Strings
|
||||
----------------
|
||||
|
||||
Strings in C can get a little thorny. Here's some guidelines for dealing with
|
||||
strings in Busybox. (There is surely more that could be added to this
|
||||
section.)
|
||||
|
||||
|
||||
String Files
|
||||
~~~~~~~~~~~~
|
||||
|
||||
Put all help/usage messages in usage.c. Put other strings in messages.c.
|
||||
Putting these strings into their own file is a calculated decision designed to
|
||||
confine spelling errors to a single place and aid internationalization
|
||||
efforts, if needed. (Side Note: we might want to use a single file - maybe
|
||||
called 'strings.c' - instead of two, food for thought).
|
||||
|
||||
|
||||
Testing String Equivalence
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
There's a right way and a wrong way to test for sting equivalence with
|
||||
strcmp():
|
||||
|
||||
The wrong way:
|
||||
|
||||
if (!strcmp(string, "foo")) {
|
||||
...
|
||||
|
||||
The right way:
|
||||
|
||||
if (strcmp(string, "foo") == 0){
|
||||
...
|
||||
|
||||
The use of the "equals" (==) operator in the latter example makes it much more
|
||||
obvious that you are testing for equivalence. The former example with the
|
||||
"not" (!) operator makes it look like you are testing for an error. In a more
|
||||
perfect world, we would have a streq() function in the string library, but
|
||||
that ain't the world we're living in.
|
||||
|
||||
|
||||
Avoid Dangerous String Functions
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Unfortunately, the way C handles strings makes them prone to overruns when
|
||||
certain library functions are (mis)used. The following table offers a summary
|
||||
of some of the more notorious troublemakers:
|
||||
|
||||
function overflows preferred
|
||||
----------------------------------------
|
||||
strcpy dest string strncpy
|
||||
strcat dest string strncat
|
||||
gets string it gets fgets
|
||||
getwd buf string getcwd
|
||||
[v]sprintf str buffer [v]snprintf
|
||||
realpath path buffer use with pathconf
|
||||
[vf]scanf its arguments just avoid it
|
||||
|
||||
|
||||
The above is by no means a complete list. Be careful out there.
|
||||
|
||||
|
||||
|
||||
Avoid Big Static Buffers
|
||||
------------------------
|
||||
|
||||
First, some background to put this discussion in context: Static buffers look
|
||||
like this in code:
|
||||
|
||||
/* in a .c file outside any functions */
|
||||
static char *buffer[BUFSIZ]; /* happily used by any function in this file,
|
||||
but ick! big! */
|
||||
|
||||
The problem with these is that any time any busybox app is run, you pay a
|
||||
memory penalty for this buffer, even if the applet that uses said buffer is
|
||||
not run. This can be fixed, thusly:
|
||||
|
||||
static char *buffer;
|
||||
...
|
||||
other_func()
|
||||
{
|
||||
strcpy(buffer, lotsa_chars); /* happily uses global *buffer */
|
||||
...
|
||||
foo_main()
|
||||
{
|
||||
buffer = xmalloc(sizeof(char)*BUFSIZ);
|
||||
...
|
||||
|
||||
However, this approach trades bss segment for text segment. Rather than
|
||||
mallocing the buffers (and thus growing the text size), buffers can be
|
||||
declared on the stack in the *_main() function and made available globally by
|
||||
assigning them to a global pointer thusly:
|
||||
|
||||
static char *pbuffer;
|
||||
...
|
||||
other_func()
|
||||
{
|
||||
strcpy(pbuffer, lotsa_chars); /* happily uses global *pbuffer */
|
||||
...
|
||||
foo_main()
|
||||
{
|
||||
char *buffer[BUFSIZ]; /* declared locally, on stack */
|
||||
pbuffer = buffer; /* but available globally */
|
||||
...
|
||||
|
||||
This last approach has some advantages (low code size, space not used until
|
||||
it's needed), but can be a problem in some low resource machines that have
|
||||
very limited stack space (e.g., uCLinux).
|
||||
|
||||
A macro is declared in busybox.h that implements compile-time selection
|
||||
between xmalloc() and stack creation, so you can code the line in question as
|
||||
|
||||
RESERVE_BB_BUFFER(buffer, BUFSIZ);
|
||||
|
||||
and the right thing will happen, based on your configuration.
|
||||
|
||||
|
||||
|
||||
Miscellaneous Coding Guidelines
|
||||
-------------------------------
|
||||
|
||||
The following are important items that don't fit into any of the above
|
||||
sections.
|
||||
|
||||
|
||||
Model Busybox Applets After GNU Counterparts
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
When in doubt about the proper behavior of a Busybox program (output,
|
||||
formatting, options, etc.), model it after the equivalent GNU program.
|
||||
Doesn't matter how that program behaves on some other flavor of *NIX; doesn't
|
||||
matter what the POSIX standard says or doesn't say, just model Busybox
|
||||
programs after their GNU counterparts and it will make life easier on (nearly)
|
||||
everyone.
|
||||
|
||||
The only time we deviate from emulating the GNU behavior is when:
|
||||
|
||||
- We are deliberately not supporting a feature (such as a command line
|
||||
switch)
|
||||
- Emulating the GNU behavior is prohibitively expensive (lots more code
|
||||
would be required, lots more memory would be used, etc.)
|
||||
- The difference is minor or cosmetic
|
||||
|
||||
A note on the 'cosmetic' case: Output differences might be considered
|
||||
cosmetic, but if the output is significant enough to break other scripts that
|
||||
use the output, it should really be fixed.
|
||||
|
||||
|
||||
Scope
|
||||
~~~~~
|
||||
|
||||
If a const variable is used only in a single source file, put it in the source
|
||||
file and not in a header file. Likewise, if a const variable is used in only
|
||||
one function, do not make it global to the file. Instead, declare it inside
|
||||
the function body. Bottom line: Make a conscious effort to limit declarations
|
||||
to the smallest scope possible.
|
||||
|
||||
Inside applet files, all functions should be declared static so as to keep the
|
||||
global name space clean. The only exception to this rule is the "applet_main"
|
||||
function which must be declared extern.
|
||||
|
||||
If you write a function that performs a task that could be useful outside the
|
||||
immediate file, turn it into a general-purpose function with no ties to any
|
||||
applet and put it in the utility.c file instead.
|
||||
|
||||
|
||||
Brackets Are Your Friends
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Please use brackets on all if and else statements, even if it is only one
|
||||
line. Example:
|
||||
|
||||
Don't do this:
|
||||
|
||||
if (foo)
|
||||
stmt1;
|
||||
stmt2
|
||||
stmt3;
|
||||
|
||||
Do this instead:
|
||||
|
||||
if (foo) {
|
||||
stmt1;
|
||||
}
|
||||
stmt2
|
||||
stmt3;
|
||||
|
||||
The "bracketless" approach is error prone because someday you might add a line
|
||||
like this:
|
||||
|
||||
if (foo)
|
||||
stmt1;
|
||||
new_line();
|
||||
stmt2
|
||||
stmt3;
|
||||
|
||||
And the resulting behavior of your program would totally bewilder you. (Don't
|
||||
laugh, it happens to us all.) Remember folks, this is C, not Python.
|
||||
|
||||
|
||||
Function Declarations
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Do not use old-style function declarations that declare variable types between
|
||||
the parameter list and opening bracket. Example:
|
||||
|
||||
Don't do this:
|
||||
|
||||
int foo(parm1, parm2)
|
||||
char parm1;
|
||||
float parm2;
|
||||
{
|
||||
....
|
||||
|
||||
Do this instead:
|
||||
|
||||
int foo(char parm1, float parm2)
|
||||
{
|
||||
....
|
||||
|
||||
The only time you would ever need to use the old declaration syntax is to
|
||||
support ancient, antediluvian compilers. To our good fortune, we have access
|
||||
to more modern compilers and the old declaration syntax is neither necessary
|
||||
nor desired.
|
||||
|
||||
|
||||
Emphasizing Logical Blocks
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Organization and readability are improved by putting extra newlines around
|
||||
blocks of code that perform a single task. These are typically blocks that
|
||||
begin with a C keyword, but not always.
|
||||
|
||||
Furthermore, you should put a single comment (not necessarily one line, just
|
||||
one comment) before the block, rather than commenting each and every line.
|
||||
There is an optimal ammount of commenting that a program can have; you can
|
||||
comment too much as well as too little.
|
||||
|
||||
A picture is really worth a thousand words here, the following example
|
||||
illustrates how to emphasize logical blocks:
|
||||
|
||||
while (line = get_line_from_file(fp)) {
|
||||
|
||||
/* eat the newline, if any */
|
||||
chomp(line);
|
||||
|
||||
/* ignore blank lines */
|
||||
if (strlen(file_to_act_on) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* if the search string is in this line, print it,
|
||||
* unless we were told to be quiet */
|
||||
if (strstr(line, search) && !be_quiet) {
|
||||
puts(line);
|
||||
}
|
||||
|
||||
/* clean up */
|
||||
free(line);
|
||||
}
|
||||
|
||||
|
||||
Processing Options with getopt
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
If your applet needs to process command-line switches, please use getopt() to
|
||||
do so. Numerous examples can be seen in many of the existing applets, but
|
||||
basically it boils down to two things: at the top of the .c file, have this
|
||||
line in the midst of your #includes:
|
||||
|
||||
#include <getopt.h>
|
||||
|
||||
And a code block similar to the following near the top of your applet_main()
|
||||
routine:
|
||||
|
||||
while ((opt = getopt(argc, argv, "abc")) > 0) {
|
||||
switch (opt) {
|
||||
case 'a':
|
||||
do_a_opt = 1;
|
||||
break;
|
||||
case 'b':
|
||||
do_b_opt = 1;
|
||||
break;
|
||||
case 'c':
|
||||
do_c_opt = 1;
|
||||
break;
|
||||
default:
|
||||
show_usage(); /* in utility.c */
|
||||
}
|
||||
}
|
||||
|
||||
If your applet takes no options (such as 'init'), there should be a line
|
||||
somewhere in the file reads:
|
||||
|
||||
/* no options, no getopt */
|
||||
|
||||
That way, when people go grepping to see which applets need to be converted to
|
||||
use getopt, they won't get false positives.
|
||||
|
||||
Additional Note: Do not use the getopt_long library function and do not try to
|
||||
hand-roll your own long option parsing. Busybox applets should only support
|
||||
short options. Explanations and examples of the short options should be
|
||||
documented in usage.h.
|
||||
+197
@@ -0,0 +1,197 @@
|
||||
/*
|
||||
* dos2unix for BusyBox
|
||||
*
|
||||
* dos2unix '\n' convertor 0.5.0
|
||||
* based on Unix2Dos 0.9.0 by Peter Hanecak (made 19.2.1997)
|
||||
* Copyright 1997,.. by Peter Hanecak <hanecak@megaloman.sk>.
|
||||
* All rights reserved.
|
||||
*
|
||||
* dos2unix filters reading input from stdin and writing output to stdout.
|
||||
* Without arguments it reverts the format (e.i. if source is in UNIX format,
|
||||
* output is in DOS format and vice versa).
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* See the COPYING file for license information.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <unistd.h>
|
||||
#if (__GNU_LIBRARY__ > 5)
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
#include <sys/time.h>
|
||||
#include "busybox.h"
|
||||
|
||||
|
||||
/* We are making a lame pseudo-random string generator here. in
|
||||
* convert(), each pass through the while loop will add more and more
|
||||
* stuff into value, which is _supposed_ to wrap. We don't care about
|
||||
* it being accurate. We care about it being messy, since we then mod
|
||||
* it by the sizeof(letters) and then use that as an index into letters
|
||||
* to pick a random letter to add to out temporary file. */
|
||||
typedef unsigned long int bb_uint64_t;
|
||||
|
||||
static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
|
||||
// if fn is NULL then input is stdin and output is stdout
|
||||
static int convert(char *fn, int ConvType)
|
||||
{
|
||||
int c, fd;
|
||||
struct timeval tv;
|
||||
char tempFn[BUFSIZ];
|
||||
static bb_uint64_t value=0;
|
||||
FILE *in = stdin, *out = stdout;
|
||||
|
||||
if (fn != NULL) {
|
||||
if ((in = wfopen(fn, "rw")) == NULL) {
|
||||
return -1;
|
||||
}
|
||||
safe_strncpy(tempFn, fn, sizeof(tempFn));
|
||||
c = strlen(tempFn);
|
||||
tempFn[c] = '.';
|
||||
while(1) {
|
||||
if (c >=BUFSIZ)
|
||||
error_msg_and_die("unique name not found");
|
||||
/* Get some semi random stuff to try and make a
|
||||
* random filename based (and in the same dir as)
|
||||
* the input file... */
|
||||
gettimeofday (&tv, NULL);
|
||||
value += ((bb_uint64_t) tv.tv_usec << 16) ^ tv.tv_sec ^ getpid ();
|
||||
tempFn[++c] = letters[value % 62];
|
||||
tempFn[c+1] = '\0';
|
||||
value /= 62;
|
||||
|
||||
if ((fd = open(tempFn, O_RDWR | O_CREAT | O_EXCL, 0600)) < 0 ) {
|
||||
continue;
|
||||
}
|
||||
out = fdopen(fd, "w+");
|
||||
if (!out) {
|
||||
close(fd);
|
||||
remove(tempFn);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while ((c = fgetc(in)) != EOF) {
|
||||
if (c == '\r') {
|
||||
if ((ConvType == CT_UNIX2DOS) && (fn != NULL)) {
|
||||
// file is alredy in DOS format so it is not necessery to touch it
|
||||
remove(tempFn);
|
||||
if (fclose(in) < 0 || fclose(out) < 0) {
|
||||
perror_msg(NULL);
|
||||
return -2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (!ConvType)
|
||||
ConvType = CT_DOS2UNIX;
|
||||
break;
|
||||
}
|
||||
if (c == '\n') {
|
||||
if ((ConvType == CT_DOS2UNIX) && (fn != NULL)) {
|
||||
// file is alredy in UNIX format so it is not necessery to touch it
|
||||
remove(tempFn);
|
||||
if ((fclose(in) < 0) || (fclose(out) < 0)) {
|
||||
perror_msg(NULL);
|
||||
return -2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (!ConvType) {
|
||||
ConvType = CT_UNIX2DOS;
|
||||
}
|
||||
if (ConvType == CT_UNIX2DOS) {
|
||||
fputc('\r', out);
|
||||
}
|
||||
fputc('\n', out);
|
||||
break;
|
||||
}
|
||||
fputc(c, out);
|
||||
}
|
||||
if (c != EOF)
|
||||
while ((c = fgetc(in)) != EOF) {
|
||||
if (c == '\r')
|
||||
continue;
|
||||
if (c == '\n') {
|
||||
if (ConvType == CT_UNIX2DOS)
|
||||
fputc('\r', out);
|
||||
fputc('\n', out);
|
||||
continue;
|
||||
}
|
||||
fputc(c, out);
|
||||
}
|
||||
|
||||
if (fn != NULL) {
|
||||
if (fclose(in) < 0 || fclose(out) < 0) {
|
||||
perror_msg(NULL);
|
||||
remove(tempFn);
|
||||
return -2;
|
||||
}
|
||||
|
||||
/* Assume they are both on the same filesystem (which
|
||||
* should be true since we put them into the same directory
|
||||
* so we _should_ be ok, but you never know... */
|
||||
if (rename(tempFn, fn) < 0) {
|
||||
perror_msg("unable to rename '%s' as '%s'", tempFn, fn);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int dos2unix_main(int argc, char *argv[])
|
||||
{
|
||||
int ConvType = CT_AUTO;
|
||||
int o;
|
||||
|
||||
//See if we are supposed to be doing dos2unix or unix2dos
|
||||
if (argv[0][0]=='d') {
|
||||
ConvType = CT_DOS2UNIX;
|
||||
}
|
||||
if (argv[0][0]=='u') {
|
||||
ConvType = CT_UNIX2DOS;
|
||||
}
|
||||
|
||||
// process parameters
|
||||
while ((o = getopt(argc, argv, "du")) != EOF) {
|
||||
switch (o) {
|
||||
case 'd':
|
||||
ConvType = CT_UNIX2DOS;
|
||||
break;
|
||||
case 'u':
|
||||
ConvType = CT_DOS2UNIX;
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc) {
|
||||
while(optind < argc)
|
||||
if ((o = convert(argv[optind++], ConvType)) < 0)
|
||||
break;
|
||||
}
|
||||
else
|
||||
o = convert(NULL, ConvType);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
Loaded 100 of 371 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user