Latest and greatest. Some effort at libc5 (aiming towards newlib)

compatability.
 -Erik
This commit is contained in:
Erik Andersen 2000-04-28 00:18:56 +00:00
parent 227a59b05d
commit 4f3f757d56
46 changed files with 280 additions and 172 deletions

View File

@ -37,8 +37,8 @@ ARCH := $(shell uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/')
CC = gcc
GCCMAJVERSION = $(shell $(CC) --version | sed -n "s/^[^0-9]*\([0-9]\)\.\([0-9].*\)[\.].*/\1/p")
GCCMINVERSION = $(shell $(CC) --version | sed -n "s/^[^0-9]*\([0-9]\)\.\([0-9].*\)[\.].*/\2/p")
GCCMAJVERSION = $(shell $(CC) --version | cut -f1 -d'.')
GCCMINVERSION = $(shell $(CC) --version | cut -f2 -d'.')
GCCSUPPORTSOPTSIZE = $(shell \
@ -68,6 +68,7 @@ ifndef $(STRIPTOOL)
STRIPTOOL = strip
endif
#also to try -- use --prefix=/usr/my-libc2.0.7-stuff
# -D_GNU_SOURCE is needed because environ is used in init.c
ifeq ($(DODEBUG),true)
@ -77,6 +78,8 @@ ifeq ($(DODEBUG),true)
else
CFLAGS += -Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
LDFLAGS = -s
#CFLAGS += -nostdinc -I/home/andersen/apps/newlib/src/newlib/libc/include -Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
#LDFLAGS = -nostdlib -s -L/home/andersen/apps/newlib/src/newlib/libc.a
STRIP = $(STRIPTOOL) --remove-section=.note --remove-section=.comment $(PROG)
#Only staticly link when _not_ debugging
ifeq ($(DOSTATIC),true)

View File

@ -248,12 +248,15 @@ static const struct Applet applets[] = {
#ifdef BB_SED
{"sed", sed_main, _BB_DIR_BIN},
#endif
#ifdef BB_SH
{"sh", shell_main, _BB_DIR_BIN},
#ifdef BB_SETKEYCODES
{"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN},
#endif
#ifdef BB_SFDISK
{"sfdisk", sfdisk_main, _BB_DIR_SBIN},
#endif
#ifdef BB_SH
{"sh", shell_main, _BB_DIR_BIN},
#endif
#ifdef BB_SLEEP
{"sleep", sleep_main, _BB_DIR_BIN},
#endif

View File

@ -102,7 +102,6 @@ static char *license_msg[] = {
#include <signal.h>
#include <sys/stat.h>
#include <errno.h>
#include <sys/param.h> /* for PATH_MAX */
/* #include "tailor.h" */
@ -641,8 +640,8 @@ typedef RETSIGTYPE(*sig_type) (int);
#define RW_USER (S_IRUSR | S_IWUSR) /* creation mode for open() */
#ifndef MAX_PATH_LEN /* max pathname length */
# ifdef PATH_MAX
# define MAX_PATH_LEN PATH_MAX
# ifdef BUFSIZ
# define MAX_PATH_LEN BUFSIZ
# else
# define MAX_PATH_LEN 1024
# endif

View File

@ -2272,7 +2272,6 @@ local void set_file_type (void);
* used.
*/
#define MAX(a,b) (a >= b ? a : b)
/* the arguments must not have side effects */
/* ===========================================================================

View File

@ -49,7 +49,6 @@
#include <utime.h>
#include <sys/types.h>
#include <sys/sysmacros.h>
#include <sys/param.h> /* for PATH_MAX */
static const char tar_usage[] =

View File

@ -248,12 +248,15 @@ static const struct Applet applets[] = {
#ifdef BB_SED
{"sed", sed_main, _BB_DIR_BIN},
#endif
#ifdef BB_SH
{"sh", shell_main, _BB_DIR_BIN},
#ifdef BB_SETKEYCODES
{"setkeycodes", setkeycodes_main, _BB_DIR_USR_BIN},
#endif
#ifdef BB_SFDISK
{"sfdisk", sfdisk_main, _BB_DIR_SBIN},
#endif
#ifdef BB_SH
{"sh", shell_main, _BB_DIR_BIN},
#endif
#ifdef BB_SLEEP
{"sleep", sleep_main, _BB_DIR_BIN},
#endif

View File

@ -75,6 +75,7 @@
#define BB_RMDIR
#define BB_RMMOD
#define BB_SED
#define BB_SETKEYCODES
#define BB_SFDISK
#define BB_SH
#define BB_SLEEP
@ -136,7 +137,7 @@
//#define BB_FEATURE_TRIVIAL_HELP
//
// Use termios to manipulate the screen ('more' is prettier with this on)
#define BB_FEATURE_USE_TERMIOS
//#define BB_FEATURE_USE_TERMIOS
//
// calculate terminal & column widths (for more and ls)
#define BB_FEATURE_AUTOWIDTH
@ -193,7 +194,7 @@
#define BB_FEATURE_SORT_REVERSE
//
// Enable command line editing in the shell
#define BB_FEATURE_SH_COMMAND_EDITING
//#define BB_FEATURE_SH_COMMAND_EDITING
//
// Enable tab completion in the shell (not yet
// working very well -- so don't turn this on)

2
chvt.c
View File

@ -12,8 +12,6 @@
#include <stdlib.h>
#include <fcntl.h>
extern int getfd(void);
int chvt_main(int argc, char **argv)
{
int fd, num;

View File

@ -12,8 +12,6 @@
#include <stdlib.h>
#include <fcntl.h>
extern int getfd(void);
int chvt_main(int argc, char **argv)
{
int fd, num;

View File

@ -11,7 +11,6 @@
#include <linux/vt.h>
#include <stdio.h>
extern int getfd(void);
char *progname;
int deallocvt_main(int argc, char *argv[])

View File

@ -32,7 +32,6 @@
#include <dirent.h>
#include <stdio.h>
#include <errno.h>
#include <sys/param.h> /* for PATH_MAX */
typedef void (Display) (long, char *);
@ -97,7 +96,7 @@ static long du(char *filename)
filename[--len] = '\0';
while ((entry = readdir(dir))) {
char newfile[PATH_MAX + 1];
char newfile[BUFSIZ + 1];
char *name = entry->d_name;
if ((strcmp(name, "..") == 0)
@ -105,7 +104,7 @@ static long du(char *filename)
continue;
}
if (len + strlen(name) + 1 > PATH_MAX) {
if (len + strlen(name) + 1 > BUFSIZ) {
fprintf(stderr, name_too_long, "du");
du_depth--;
return 0;
@ -182,7 +181,7 @@ int du_main(int argc, char **argv)
exit(0);
}
/* $Id: du.c,v 1.17 2000/04/13 01:18:56 erik Exp $ */
/* $Id: du.c,v 1.18 2000/04/28 00:18:56 erik Exp $ */
/*
Local Variables:
c-file-style: "linux"

View File

@ -30,7 +30,6 @@
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
#include <sys/param.h> /* for PATH_MAX */
static const char ln_usage[] =
"ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n"
@ -78,7 +77,7 @@ extern int ln_main(int argc, char **argv)
linkName = argv[argc - 1];
if (strlen(linkName) > PATH_MAX) {
if (strlen(linkName) > BUFSIZ) {
fprintf(stderr, name_too_long, "ln");
exit FALSE;
}
@ -91,10 +90,10 @@ extern int ln_main(int argc, char **argv)
}
while (argc-- >= 2) {
char srcName[PATH_MAX + 1];
char srcName[BUFSIZ + 1];
int nChars, status;
if (strlen(*argv) > PATH_MAX) {
if (strlen(*argv) > BUFSIZ) {
fprintf(stderr, name_too_long, "ln");
exit FALSE;
}
@ -102,9 +101,9 @@ extern int ln_main(int argc, char **argv)
if (followLinks == FALSE) {
strcpy(srcName, *argv);
} else {
/* Warning! This can silently truncate if > PATH_MAX, but
I don't think that there can be one > PATH_MAX anyway. */
nChars = readlink(*argv, srcName, PATH_MAX);
/* Warning! This can silently truncate if > BUFSIZ, but
I don't think that there can be one > BUFSIZ anyway. */
nChars = readlink(*argv, srcName, BUFSIZ);
srcName[nChars] = '\0';
}

View File

@ -183,7 +183,7 @@ static char append_char(mode_t mode)
static void list_single(const char *name, struct stat *info,
const char *fullname)
{
char scratch[PATH_MAX + 1];
char scratch[BUFSIZ + 1];
short len = strlen(name);
#ifdef BB_FEATURE_LS_FILETYPES

View File

@ -28,7 +28,6 @@
#include <stdio.h>
#include <errno.h>
#include <sys/param.h> /* for PATH_MAX */
static const char mkdir_usage[] =
"mkdir [OPTION] DIRECTORY...\n\n"
@ -86,9 +85,9 @@ extern int mkdir_main(int argc, char **argv)
while (argc > 0) {
int status;
struct stat statBuf;
char buf[PATH_MAX + 1];
char buf[BUFSIZ + 1];
if (strlen(*argv) > PATH_MAX - 1) {
if (strlen(*argv) > BUFSIZ - 1) {
fprintf(stderr, name_too_long, "mkdir");
exit FALSE;
}

View File

@ -24,11 +24,10 @@
#include "internal.h"
#include <stdio.h>
#include <dirent.h>
#include <sys/param.h>
extern int pwd_main(int argc, char **argv)
{
char buf[PATH_MAX + 1];
char buf[BUFSIZ + 1];
if (getcwd(buf, sizeof(buf)) == NULL) {
perror("get working directory");

18
cp_mv.c
View File

@ -74,7 +74,7 @@ static const char *baseSrcName;
static int srcDirFlag;
static struct stat srcStatBuf;
static char baseDestName[PATH_MAX + 1];
static char baseDestName[BUFSIZ + 1];
static size_t baseDestLen;
static int destDirFlag;
static struct stat destStatBuf;
@ -97,12 +97,12 @@ fill_baseDest_buf(char *_buf, size_t * _buflen) {
if ((srcBasename = strrchr(baseSrcName, '/')) == NULL) {
srcBasename = baseSrcName;
if (_buf[*_buflen - 1] != '/') {
if (++(*_buflen) > PATH_MAX)
if (++(*_buflen) > BUFSIZ)
name_too_long__exit();
strcat(_buf, "/");
}
}
if (*_buflen + strlen(srcBasename) > PATH_MAX)
if (*_buflen + strlen(srcBasename) > BUFSIZ)
name_too_long__exit();
strcat(_buf, srcBasename);
return;
@ -112,7 +112,7 @@ fill_baseDest_buf(char *_buf, size_t * _buflen) {
static int
cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
{
char destName[PATH_MAX + 1];
char destName[BUFSIZ + 1];
size_t destLen;
const char *srcBasename;
char *name;
@ -128,7 +128,7 @@ cp_mv_Action(const char *fileName, struct stat *statbuf, void* junk)
srcBasename = (strstr(fileName, baseSrcName)
+ strlen(baseSrcName));
if (destLen + strlen(srcBasename) > PATH_MAX) {
if (destLen + strlen(srcBasename) > BUFSIZ) {
fprintf(stderr, name_too_long, dz);
return FALSE;
}
@ -230,7 +230,7 @@ extern int cp_mv_main(int argc, char **argv)
followLinks = FALSE;
}
if (strlen(argv[argc - 1]) > PATH_MAX) {
if (strlen(argv[argc - 1]) > BUFSIZ) {
fprintf(stderr, name_too_long, "cp");
goto exit_false;
}
@ -252,7 +252,7 @@ extern int cp_mv_main(int argc, char **argv)
baseSrcName = *(argv++);
if ((srcLen = strlen(baseSrcName)) > PATH_MAX)
if ((srcLen = strlen(baseSrcName)) > BUFSIZ)
name_too_long__exit();
if (srcLen == 0) continue; /* "" */
@ -266,7 +266,7 @@ extern int cp_mv_main(int argc, char **argv)
int state = 0;
char *pushd, *d, *p;
if ((pushd = getcwd(NULL, PATH_MAX + 1)) == NULL) {
if ((pushd = getcwd(NULL, BUFSIZ + 1)) == NULL) {
fprintf(stderr, "%s: getcwd(): %s\n", dz, strerror(errno));
continue;
}
@ -274,7 +274,7 @@ extern int cp_mv_main(int argc, char **argv)
fprintf(stderr, "%s: chdir(%s): %s\n", dz, baseSrcName, strerror(errno));
continue;
}
if ((d = getcwd(NULL, PATH_MAX + 1)) == NULL) {
if ((d = getcwd(NULL, BUFSIZ + 1)) == NULL) {
fprintf(stderr, "%s: getcwd(): %s\n", dz, strerror(errno));
continue;
}

View File

@ -11,7 +11,6 @@
#include <linux/vt.h>
#include <stdio.h>
extern int getfd(void);
char *progname;
int deallocvt_main(int argc, char *argv[])

View File

@ -61,9 +61,9 @@ freeramdisk, deallocvt, fsck.minix, grep, gunzip, gzip, halt, head, hostid,
hostname, init, kill, killall, length, ln, loadacm, loadfont, loadkmap, logger,
logname, ls, lsmod, makedevs, math, mkdir, mkfifo, mkfs.minix, mknod, mkswap,
mktemp, mnc, more, mount, mt, mv, nslookup, ping, poweroff, printf, ps, pwd,
reboot, rm, rmdir, rmmod, sed, sh, sfdisk, sleep, sort, sync, syslogd, swapon,
swapoff, tail, tar, test, tee, touch, tr, true, tty, umount, uname, uniq,
update, uptime, usleep, wc, whoami, yes, zcat, [
reboot, rm, rmdir, rmmod, sed, setkeycodes, sh, sfdisk, sleep, sort, sync,
syslogd, swapon, swapoff, tail, tar, test, tee, touch, tr, true, tty, umount,
uname, uniq, update, uptime, usleep, wc, whoami, yes, zcat, [
=over 4
@ -1336,6 +1336,22 @@ Example:
-------------------------------
=item setkeycodes
Usage: setkeycodes SCANCODE KEYCODE ...
Set entries into the kernel's scancode-to-keycode map,
allowing unusual keyboards to generate usable keycodes.
SCANCODE may be either xx or e0xx (hexadecimal),
and KEYCODE is given in decimal
Example:
# setkeycodes e030 127
-------------------------------
=item sh
Usage: sh
@ -1833,4 +1849,4 @@ Enrique Zanardi <ezanardi@ull.es>
=cut
# $Id: busybox.pod,v 1.23 2000/04/25 23:24:55 erik Exp $
# $Id: busybox.pod,v 1.24 2000/04/28 00:18:56 erik Exp $

7
du.c
View File

@ -32,7 +32,6 @@
#include <dirent.h>
#include <stdio.h>
#include <errno.h>
#include <sys/param.h> /* for PATH_MAX */
typedef void (Display) (long, char *);
@ -97,7 +96,7 @@ static long du(char *filename)
filename[--len] = '\0';
while ((entry = readdir(dir))) {
char newfile[PATH_MAX + 1];
char newfile[BUFSIZ + 1];
char *name = entry->d_name;
if ((strcmp(name, "..") == 0)
@ -105,7 +104,7 @@ static long du(char *filename)
continue;
}
if (len + strlen(name) + 1 > PATH_MAX) {
if (len + strlen(name) + 1 > BUFSIZ) {
fprintf(stderr, name_too_long, "du");
du_depth--;
return 0;
@ -182,7 +181,7 @@ int du_main(int argc, char **argv)
exit(0);
}
/* $Id: du.c,v 1.17 2000/04/13 01:18:56 erik Exp $ */
/* $Id: du.c,v 1.18 2000/04/28 00:18:56 erik Exp $ */
/*
Local Variables:
c-file-style: "linux"

12
dutmp.c
View File

@ -14,11 +14,17 @@
#include "internal.h"
#include <stdio.h>
#include <errno.h>
#include <utmp.h>
#define BB_DECLARE_EXTERN
#define bb_need_io_error
#include "messages.c"
#if defined(__GLIBC__)
#include <utmp.h>
#else
#include <utmp-wrap.h>
#define utmp new_utmp
#endif
static const char dutmp_usage[] = "dutmp [FILE]\n\n"
"Dump utmp file format (pipe delimited) from FILE\n"
"or stdin to stdout. (i.e. 'dutmp /var/run/utmp')\n";
@ -45,8 +51,8 @@ extern int dutmp_main(int argc, char **argv)
ut.ut_type, ut.ut_pid, ut.ut_line,
ut.ut_id, ut.ut_user, ut.ut_host,
ut.ut_exit.e_termination, ut.ut_exit.e_exit,
ut.ut_session,
ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, ut.ut_addr);
ut.ut_session, ut.ut_tv.tv_sec, ut.ut_tv.tv_usec,
ut.ut_addr_v6[0]);
}
exit(TRUE);

View File

@ -23,7 +23,7 @@
#include <stdio.h>
#include <string.h>
#include <sys/mount.h>
#include <linux/fs.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@ -32,6 +32,7 @@
#include "internal.h"
static const char freeramdisk_usage[] =
"freeramdisk DEVICE\n\n"
"Free all memory used by the specified ramdisk.\n";

View File

@ -97,7 +97,6 @@
#include <termios.h>
#include <mntent.h>
#include <sys/stat.h>
#include <sys/param.h> /* for PATH_MAX */
#include <linux/fs.h>
#include <linux/minix_fs.h>
@ -145,7 +144,7 @@ static int termios_set = 0;
/* File-name data */
#define MAX_DEPTH 32
static int name_depth = 0;
// static char name_list[MAX_DEPTH][PATH_MAX + 1];
// static char name_list[MAX_DEPTH][BUFSIZ + 1];
static char **name_list = NULL;
static char *inode_buffer = NULL;
@ -178,8 +177,8 @@ static unsigned char *zone_count = NULL;
static void recursive_check(unsigned int ino);
static void recursive_check2(unsigned int ino);
#define inode_in_use(x) (bit(inode_map,(x)))
#define zone_in_use(x) (bit(zone_map,(x)-FIRSTZONE+1))
#define inode_in_use(x) (isset(inode_map,(x)))
#define zone_in_use(x) (isset(zone_map,(x)-FIRSTZONE+1))
#define mark_inode(x) (setbit(inode_map,(x)),changed=1)
#define unmark_inode(x) (clrbit(inode_map,(x)),changed=1)
@ -1239,7 +1238,7 @@ static void alloc_name_list(void)
name_list = xmalloc(sizeof(char *) * MAX_DEPTH);
for (i = 0; i < MAX_DEPTH; i++)
name_list[i] = xmalloc(sizeof(char) * PATH_MAX + 1);
name_list[i] = xmalloc(sizeof(char) * BUFSIZ + 1);
}
#if 0

View File

@ -102,7 +102,6 @@ static char *license_msg[] = {
#include <signal.h>
#include <sys/stat.h>
#include <errno.h>
#include <sys/param.h> /* for PATH_MAX */
/* #include "tailor.h" */
@ -641,8 +640,8 @@ typedef RETSIGTYPE(*sig_type) (int);
#define RW_USER (S_IRUSR | S_IWUSR) /* creation mode for open() */
#ifndef MAX_PATH_LEN /* max pathname length */
# ifdef PATH_MAX
# define MAX_PATH_LEN PATH_MAX
# ifdef BUFSIZ
# define MAX_PATH_LEN BUFSIZ
# else
# define MAX_PATH_LEN 1024
# endif

1
gzip.c
View File

@ -2272,7 +2272,6 @@ local void set_file_type (void);
* used.
*/
#define MAX(a,b) (a >= b ? a : b)
/* the arguments must not have side effects */
/* ===========================================================================

61
init.c
View File

@ -28,31 +28,50 @@
*/
#include "internal.h"
#include <asm/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <linux/serial.h> /* for serial_struct */
#include <linux/version.h>
#include <paths.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <asm/types.h>
#include <linux/serial.h> /* for serial_struct */
#include <linux/version.h>
#include <linux/reboot.h>
#include <linux/unistd.h>
#include <sys/sysinfo.h> /* For check_free_memory() */
#include <sys/fcntl.h>
#include <sys/ioctl.h>
#include <sys/kdaemon.h>
#include <sys/mount.h>
#include <sys/reboot.h>
#include <sys/sysinfo.h> /* For check_free_memory() */
#ifdef BB_SYSLOGD
# include <sys/syslog.h>
#endif
#include <sys/sysmacros.h>
#include <sys/types.h>
#include <sys/vt.h> /* for vt_stat */
#include <sys/wait.h>
#include <termios.h>
#include <unistd.h>
#ifdef BB_SYSLOGD
# include <sys/syslog.h>
#endif
#ifndef RB_HALT_SYSTEM
#define RB_HALT_SYSTEM 0xcdef0123
#define RB_ENABLE_CAD 0x89abcdef
#define RB_DISABLE_CAD 0
#define RB_POWER_OFF 0x4321fedc
#define RB_AUTOBOOT 0x01234567
#if defined(__GLIBC__)
#include <sys/reboot.h>
#define init_reboot(magic) reboot(magic)
#else
#define init_reboot(magic) reboot(0xfee1dead, 672274793, magic)
#endif
#endif
#ifndef _PATH_STDPATH
#define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin"
#endif
#if defined BB_FEATURE_INIT_COREDUMPS
@ -71,6 +90,12 @@
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
#endif
#if defined(__GLIBC__)
#include <sys/kdaemon.h>
#else
_syscall2(int, bdflush, int, func, int, data);
#endif /* __GLIBC__ */
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
@ -510,7 +535,7 @@ static void shutdown_system(void)
signal(SIGHUP, SIG_DFL);
/* Allow Ctrl-Alt-Del to reboot system. */
reboot(RB_ENABLE_CAD);
init_reboot(RB_ENABLE_CAD);
message(CONSOLE|LOG, "\r\nThe system is going down NOW !!\r\n");
sync();
@ -550,10 +575,10 @@ static void halt_signal(int sig)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
if (sig == SIGUSR2)
reboot(RB_POWER_OFF);
init_reboot(RB_POWER_OFF);
else
#endif
reboot(RB_HALT_SYSTEM);
init_reboot(RB_HALT_SYSTEM);
exit(0);
}
@ -566,7 +591,7 @@ static void reboot_signal(int sig)
/* allow time for last message to reach serial console */
sleep(2);
reboot(RB_AUTOBOOT);
init_reboot(RB_AUTOBOOT);
exit(0);
}
@ -852,7 +877,7 @@ extern int init_main(int argc, char **argv)
/* Turn off rebooting via CTL-ALT-DEL -- we get a
* SIGINT on CAD so we can shut things down gracefully... */
reboot(RB_DISABLE_CAD);
init_reboot(RB_DISABLE_CAD);
#endif
/* Figure out what kernel this is running */

View File

@ -28,31 +28,50 @@
*/
#include "internal.h"
#include <asm/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <linux/serial.h> /* for serial_struct */
#include <linux/version.h>
#include <paths.h>
#include <signal.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <asm/types.h>
#include <linux/serial.h> /* for serial_struct */
#include <linux/version.h>
#include <linux/reboot.h>
#include <linux/unistd.h>
#include <sys/sysinfo.h> /* For check_free_memory() */
#include <sys/fcntl.h>
#include <sys/ioctl.h>
#include <sys/kdaemon.h>
#include <sys/mount.h>
#include <sys/reboot.h>
#include <sys/sysinfo.h> /* For check_free_memory() */
#ifdef BB_SYSLOGD
# include <sys/syslog.h>
#endif
#include <sys/sysmacros.h>
#include <sys/types.h>
#include <sys/vt.h> /* for vt_stat */
#include <sys/wait.h>
#include <termios.h>
#include <unistd.h>
#ifdef BB_SYSLOGD
# include <sys/syslog.h>
#endif
#ifndef RB_HALT_SYSTEM
#define RB_HALT_SYSTEM 0xcdef0123
#define RB_ENABLE_CAD 0x89abcdef
#define RB_DISABLE_CAD 0
#define RB_POWER_OFF 0x4321fedc
#define RB_AUTOBOOT 0x01234567
#if defined(__GLIBC__)
#include <sys/reboot.h>
#define init_reboot(magic) reboot(magic)
#else
#define init_reboot(magic) reboot(0xfee1dead, 672274793, magic)
#endif
#endif
#ifndef _PATH_STDPATH
#define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin"
#endif
#if defined BB_FEATURE_INIT_COREDUMPS
@ -71,6 +90,12 @@
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
#endif
#if defined(__GLIBC__)
#include <sys/kdaemon.h>
#else
_syscall2(int, bdflush, int, func, int, data);
#endif /* __GLIBC__ */
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
@ -510,7 +535,7 @@ static void shutdown_system(void)
signal(SIGHUP, SIG_DFL);
/* Allow Ctrl-Alt-Del to reboot system. */
reboot(RB_ENABLE_CAD);
init_reboot(RB_ENABLE_CAD);
message(CONSOLE|LOG, "\r\nThe system is going down NOW !!\r\n");
sync();
@ -550,10 +575,10 @@ static void halt_signal(int sig)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
if (sig == SIGUSR2)
reboot(RB_POWER_OFF);
init_reboot(RB_POWER_OFF);
else
#endif
reboot(RB_HALT_SYSTEM);
init_reboot(RB_HALT_SYSTEM);
exit(0);
}
@ -566,7 +591,7 @@ static void reboot_signal(int sig)
/* allow time for last message to reach serial console */
sleep(2);
reboot(RB_AUTOBOOT);
init_reboot(RB_AUTOBOOT);
exit(0);
}
@ -852,7 +877,7 @@ extern int init_main(int argc, char **argv)
/* Turn off rebooting via CTL-ALT-DEL -- we get a
* SIGINT on CAD so we can shut things down gracefully... */
reboot(RB_DISABLE_CAD);
init_reboot(RB_DISABLE_CAD);
#endif
/* Figure out what kernel this is running */

View File

@ -67,8 +67,8 @@ unsigned long create_module(const char *name, size_t size)
#else
_syscall2(unsigned long, create_module, const char *, name, size_t, size)
#endif
static char m_filename[PATH_MAX + 1] = "\0";
static char m_fullName[PATH_MAX + 1] = "\0";
static char m_filename[BUFSIZ + 1] = "\0";
static char m_fullName[BUFSIZ + 1] = "\0";
static const char insmod_usage[] =
"insmod [OPTION]... MODULE [symbol=value]...\n\n"
"Loads the specified kernel modules into the kernel.\n\n"
@ -103,7 +103,7 @@ extern int insmod_main(int argc, char **argv)
{
int len;
char *tmp;
char m_name[PATH_MAX + 1] = "\0";
char m_name[BUFSIZ + 1] = "\0";
FILE *fp;
if (argc <= 1) {

View File

@ -31,7 +31,7 @@
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
//#include <sys/param.h>
#include <sys/param.h>
#include <mntent.h>
@ -52,6 +52,36 @@
#define isOctal(ch) (((ch) >= '0') && ((ch) <= '7'))
#define isWildCard(ch) (((ch) == '*') || ((ch) == '?') || ((ch) == '['))
/* Macros for min/max. */
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
/* I don't like nested includes, but the string and io functions are used
* too often
*/
#include <stdio.h>
#if !defined(NO_STRING_H) || defined(STDC_HEADERS)
# include <string.h>
# if !defined(STDC_HEADERS) && !defined(NO_MEMORY_H) && !defined(__GNUC__)
# include <memory.h>
# endif
# define memzero(s, n) memset ((void *)(s), 0, (n))
#else
# include <strings.h>
# define strchr index
# define strrchr rindex
# define memcpy(d, s, n) bcopy((s), (d), (n))
# define memcmp(s1, s2, n) bcmp((s1), (s2), (n))
# define memzero(s, n) bzero((s), (n))
#endif
enum Location {
_BB_DIR_ROOT = 0,
_BB_DIR_BIN,
@ -136,6 +166,7 @@ extern int rmdir_main(int argc, char **argv);
extern int rmmod_main(int argc, char** argv);
extern int sed_main(int argc, char** argv);
extern int sfdisk_main(int argc, char** argv);
extern int setkeycodes_main(int argc, char** argv);
extern int shell_main(int argc, char** argv);
extern int sleep_main(int argc, char** argv);
extern int sort_main(int argc, char** argv);
@ -243,27 +274,15 @@ int nfsmount(const char *spec, const char *node, unsigned long *flags,
#endif
#if defined (BB_FSCK_MINIX) || defined (BB_MKFS_MINIX)
static inline int bit(char * addr,unsigned int nr)
{
return (addr[nr >> 3] & (1<<(nr & 7))) != 0;
}
static inline int setbit(char * addr,unsigned int nr)
{
int __res = bit(addr, nr);
addr[nr >> 3] |= (1<<(nr & 7));
return __res != 0;
}
static inline int clrbit(char * addr,unsigned int nr)
{
int __res = bit(addr, nr);
addr[nr >> 3] &= ~(1<<(nr & 7));
return __res != 0;
}
#endif /* inline bitops junk */
/* Bit map related macros. */
#ifndef setbit
#define CHAR_BITS 8 /* Number of bits in a `char'. */
#define setbit(a,i) ((a)[(i)/CHAR_BITS] |= 1<<((i)%CHAR_BITS))
#define clrbit(a,i) ((a)[(i)/CHAR_BITS] &= ~(1<<((i)%CHAR_BITS)))
#define isset(a,i) ((a)[(i)/CHAR_BITS] & (1<<((i)%CHAR_BITS)))
#define isclr(a,i) (((a)[(i)/CHAR_BITS] & (1<<((i)%CHAR_BITS))) == 0)
#endif
#endif
#ifndef RB_POWER_OFF

13
ln.c
View File

@ -30,7 +30,6 @@
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
#include <sys/param.h> /* for PATH_MAX */
static const char ln_usage[] =
"ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n"
@ -78,7 +77,7 @@ extern int ln_main(int argc, char **argv)
linkName = argv[argc - 1];
if (strlen(linkName) > PATH_MAX) {
if (strlen(linkName) > BUFSIZ) {
fprintf(stderr, name_too_long, "ln");
exit FALSE;
}
@ -91,10 +90,10 @@ extern int ln_main(int argc, char **argv)
}
while (argc-- >= 2) {
char srcName[PATH_MAX + 1];
char srcName[BUFSIZ + 1];
int nChars, status;
if (strlen(*argv) > PATH_MAX) {
if (strlen(*argv) > BUFSIZ) {
fprintf(stderr, name_too_long, "ln");
exit FALSE;
}
@ -102,9 +101,9 @@ extern int ln_main(int argc, char **argv)
if (followLinks == FALSE) {
strcpy(srcName, *argv);
} else {
/* Warning! This can silently truncate if > PATH_MAX, but
I don't think that there can be one > PATH_MAX anyway. */
nChars = readlink(*argv, srcName, PATH_MAX);
/* Warning! This can silently truncate if > BUFSIZ, but
I don't think that there can be one > BUFSIZ anyway. */
nChars = readlink(*argv, srcName, BUFSIZ);
srcName[nChars] = '\0';
}

2
ls.c
View File

@ -183,7 +183,7 @@ static char append_char(mode_t mode)
static void list_single(const char *name, struct stat *info,
const char *fullname)
{
char scratch[PATH_MAX + 1];
char scratch[BUFSIZ + 1];
short len = strlen(name);
#ifdef BB_FEATURE_LS_FILETYPES

View File

@ -14,11 +14,17 @@
#include "internal.h"
#include <stdio.h>
#include <errno.h>
#include <utmp.h>
#define BB_DECLARE_EXTERN
#define bb_need_io_error
#include "messages.c"
#if defined(__GLIBC__)
#include <utmp.h>
#else
#include <utmp-wrap.h>
#define utmp new_utmp
#endif
static const char dutmp_usage[] = "dutmp [FILE]\n\n"
"Dump utmp file format (pipe delimited) from FILE\n"
"or stdin to stdout. (i.e. 'dutmp /var/run/utmp')\n";
@ -45,8 +51,8 @@ extern int dutmp_main(int argc, char **argv)
ut.ut_type, ut.ut_pid, ut.ut_line,
ut.ut_id, ut.ut_user, ut.ut_host,
ut.ut_exit.e_termination, ut.ut_exit.e_exit,
ut.ut_session,
ut.ut_tv.tv_sec, ut.ut_tv.tv_usec, ut.ut_addr);
ut.ut_session, ut.ut_tv.tv_sec, ut.ut_tv.tv_usec,
ut.ut_addr_v6[0]);
}
exit(TRUE);

View File

@ -28,7 +28,6 @@
#include <stdio.h>
#include <errno.h>
#include <sys/param.h> /* for PATH_MAX */
static const char mkdir_usage[] =
"mkdir [OPTION] DIRECTORY...\n\n"
@ -86,9 +85,9 @@ extern int mkdir_main(int argc, char **argv)
while (argc > 0) {
int status;
struct stat statBuf;
char buf[PATH_MAX + 1];
char buf[BUFSIZ + 1];
if (strlen(*argv) > PATH_MAX - 1) {
if (strlen(*argv) > BUFSIZ - 1) {
fprintf(stderr, name_too_long, "mkdir");
exit FALSE;
}

View File

@ -154,8 +154,8 @@ static unsigned short good_blocks_table[MAX_GOOD_BLOCKS];
static int used_good_blocks = 0;
static unsigned long req_nr_inodes = 0;
#define inode_in_use(x) (bit(inode_map,(x)))
#define zone_in_use(x) (bit(zone_map,(x)-FIRSTZONE+1))
#define inode_in_use(x) (isset(inode_map,(x)))
#define zone_in_use(x) (isset(zone_map,(x)-FIRSTZONE+1))
#define mark_inode(x) (setbit(inode_map,(x)))
#define unmark_inode(x) (clrbit(inode_map,(x)))

View File

@ -67,8 +67,8 @@ unsigned long create_module(const char *name, size_t size)
#else
_syscall2(unsigned long, create_module, const char *, name, size_t, size)
#endif
static char m_filename[PATH_MAX + 1] = "\0";
static char m_fullName[PATH_MAX + 1] = "\0";
static char m_filename[BUFSIZ + 1] = "\0";
static char m_fullName[BUFSIZ + 1] = "\0";
static const char insmod_usage[] =
"insmod [OPTION]... MODULE [symbol=value]...\n\n"
"Loads the specified kernel modules into the kernel.\n\n"
@ -103,7 +103,7 @@ extern int insmod_main(int argc, char **argv)
{
int len;
char *tmp;
char m_name[PATH_MAX + 1] = "\0";
char m_name[BUFSIZ + 1] = "\0";
FILE *fp;
if (argc <= 1) {

12
more.c
View File

@ -48,6 +48,7 @@ static const char more_usage[] = "more [file ...]\n";
#endif
FILE *cin;
struct termios initial_settings, new_settings;
void gotsig(int sig)
@ -65,7 +66,10 @@ void gotsig(int sig)
#if defined BB_FEATURE_AUTOWIDTH
static int terminal_width = 0, terminal_height = 0;
#ifdef BB_FEATURE_USE_TERMIOS
static int terminal_width = 0;
#endif
static int terminal_height = 0;
#else
#define terminal_width TERMINAL_WIDTH
#define terminal_height TERMINAL_HEIGHT
@ -80,7 +84,7 @@ extern int more_main(int argc, char **argv)
struct stat st;
FILE *file;
#ifdef BB_FEATURE_AUTOWIDTH
#if defined BB_FEATURE_AUTOWIDTH && defined BB_FEATURE_USE_TERMIOS
struct winsize win = { 0, 0 };
#endif
@ -151,7 +155,11 @@ extern int more_main(int argc, char **argv)
);
fflush(stdout);
#ifdef BB_FEATURE_USE_TERMIOS
input = getc(cin);
#else
input = getc(stdin);
#endif
#ifdef BB_FEATURE_USE_TERMIOS
/* Erase the "More" message */

View File

@ -48,6 +48,9 @@
#if defined BB_FEATURE_USE_DEVPS_PATCH
#include <linux/devmtab.h>
#endif
#ifndef MS_RDONLY
#include <linux/fs.h>
#endif
#if defined BB_FEATURE_MOUNT_LOOP

3
pwd.c
View File

@ -24,11 +24,10 @@
#include "internal.h"
#include <stdio.h>
#include <dirent.h>
#include <sys/param.h>
extern int pwd_main(int argc, char **argv)
{
char buf[PATH_MAX + 1];
char buf[BUFSIZ + 1];
if (getcwd(buf, sizeof(buf)) == NULL) {
perror("get working directory");

View File

@ -53,7 +53,7 @@ extern int ksyslog(int type, char *buf, int len);
#define __LOG_FILE "/var/log/messages"
/* Path to the unix socket */
char lfile[PATH_MAX] = "";
char lfile[BUFSIZ] = "";
static char *logFilePath = __LOG_FILE;
@ -177,7 +177,7 @@ static void doSyslogd (void)
int sock_fd;
fd_set fds;
char lfile[PATH_MAX];
char lfile[BUFSIZ];
/* Set up signal handlers. */
signal (SIGINT, quit_signal);

View File

@ -53,7 +53,7 @@ extern int ksyslog(int type, char *buf, int len);
#define __LOG_FILE "/var/log/messages"
/* Path to the unix socket */
char lfile[PATH_MAX] = "";
char lfile[BUFSIZ] = "";
static char *logFilePath = __LOG_FILE;
@ -177,7 +177,7 @@ static void doSyslogd (void)
int sock_fd;
fd_set fds;
char lfile[PATH_MAX];
char lfile[BUFSIZ];
/* Set up signal handlers. */
signal (SIGINT, quit_signal);

1
tar.c
View File

@ -49,7 +49,6 @@
#include <utime.h>
#include <sys/types.h>
#include <sys/sysmacros.h>
#include <sys/param.h> /* for PATH_MAX */
static const char tar_usage[] =

View File

@ -23,7 +23,7 @@
#include <stdio.h>
#include <string.h>
#include <sys/mount.h>
#include <linux/fs.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
@ -32,6 +32,7 @@
#include "internal.h"
static const char freeramdisk_usage[] =
"freeramdisk DEVICE\n\n"
"Free all memory used by the specified ramdisk.\n";

View File

@ -97,7 +97,6 @@
#include <termios.h>
#include <mntent.h>
#include <sys/stat.h>
#include <sys/param.h> /* for PATH_MAX */
#include <linux/fs.h>
#include <linux/minix_fs.h>
@ -145,7 +144,7 @@ static int termios_set = 0;
/* File-name data */
#define MAX_DEPTH 32
static int name_depth = 0;
// static char name_list[MAX_DEPTH][PATH_MAX + 1];
// static char name_list[MAX_DEPTH][BUFSIZ + 1];
static char **name_list = NULL;
static char *inode_buffer = NULL;
@ -178,8 +177,8 @@ static unsigned char *zone_count = NULL;
static void recursive_check(unsigned int ino);
static void recursive_check2(unsigned int ino);
#define inode_in_use(x) (bit(inode_map,(x)))
#define zone_in_use(x) (bit(zone_map,(x)-FIRSTZONE+1))
#define inode_in_use(x) (isset(inode_map,(x)))
#define zone_in_use(x) (isset(zone_map,(x)-FIRSTZONE+1))
#define mark_inode(x) (setbit(inode_map,(x)),changed=1)
#define unmark_inode(x) (clrbit(inode_map,(x)),changed=1)
@ -1239,7 +1238,7 @@ static void alloc_name_list(void)
name_list = xmalloc(sizeof(char *) * MAX_DEPTH);
for (i = 0; i < MAX_DEPTH; i++)
name_list[i] = xmalloc(sizeof(char) * PATH_MAX + 1);
name_list[i] = xmalloc(sizeof(char) * BUFSIZ + 1);
}
#if 0

View File

@ -154,8 +154,8 @@ static unsigned short good_blocks_table[MAX_GOOD_BLOCKS];
static int used_good_blocks = 0;
static unsigned long req_nr_inodes = 0;
#define inode_in_use(x) (bit(inode_map,(x)))
#define zone_in_use(x) (bit(zone_map,(x)-FIRSTZONE+1))
#define inode_in_use(x) (isset(inode_map,(x)))
#define zone_in_use(x) (isset(zone_map,(x)-FIRSTZONE+1))
#define mark_inode(x) (setbit(inode_map,(x)))
#define unmark_inode(x) (clrbit(inode_map,(x)))

View File

@ -48,6 +48,7 @@ static const char more_usage[] = "more [file ...]\n";
#endif
FILE *cin;
struct termios initial_settings, new_settings;
void gotsig(int sig)
@ -65,7 +66,10 @@ void gotsig(int sig)
#if defined BB_FEATURE_AUTOWIDTH
static int terminal_width = 0, terminal_height = 0;
#ifdef BB_FEATURE_USE_TERMIOS
static int terminal_width = 0;
#endif
static int terminal_height = 0;
#else
#define terminal_width TERMINAL_WIDTH
#define terminal_height TERMINAL_HEIGHT
@ -80,7 +84,7 @@ extern int more_main(int argc, char **argv)
struct stat st;
FILE *file;
#ifdef BB_FEATURE_AUTOWIDTH
#if defined BB_FEATURE_AUTOWIDTH && defined BB_FEATURE_USE_TERMIOS
struct winsize win = { 0, 0 };
#endif
@ -151,7 +155,11 @@ extern int more_main(int argc, char **argv)
);
fflush(stdout);
#ifdef BB_FEATURE_USE_TERMIOS
input = getc(cin);
#else
input = getc(stdin);
#endif
#ifdef BB_FEATURE_USE_TERMIOS
/* Erase the "More" message */

View File

@ -48,6 +48,9 @@
#if defined BB_FEATURE_USE_DEVPS_PATCH
#include <linux/devmtab.h>
#endif
#ifndef MS_RDONLY
#include <linux/fs.h>
#endif
#if defined BB_FEATURE_MOUNT_LOOP

View File

@ -47,7 +47,6 @@
#include <sys/stat.h>
#include <unistd.h>
#include <ctype.h>
#include <sys/param.h> /* for PATH_MAX */
#include <sys/utsname.h> /* for uname(2) */
#if defined BB_FEATURE_MOUNT_LOOP
@ -289,12 +288,12 @@ copyFile(const char *srcName, const char *destName,
return FALSE;
}
} else if (S_ISLNK(srcStatBuf.st_mode)) {
char link_val[PATH_MAX + 1];
char link_val[BUFSIZ + 1];
int link_size;
//fprintf(stderr, "copying link %s to %s\n", srcName, destName);
/* Warning: This could possibly truncate silently, to PATH_MAX chars */
link_size = readlink(srcName, &link_val[0], PATH_MAX);
/* Warning: This could possibly truncate silently, to BUFSIZ chars */
link_size = readlink(srcName, &link_val[0], BUFSIZ);
if (link_size < 0) {
perror(srcName);
return FALSE;
@ -602,13 +601,13 @@ int recursiveAction(const char *fileName,
}
}
while ((next = readdir(dir)) != NULL) {
char nextFile[PATH_MAX + 1];
char nextFile[BUFSIZ + 1];
if ((strcmp(next->d_name, "..") == 0)
|| (strcmp(next->d_name, ".") == 0)) {
continue;
}
if (strlen(fileName) + strlen(next->d_name) + 1 > PATH_MAX) {
if (strlen(fileName) + strlen(next->d_name) + 1 > BUFSIZ) {
fprintf(stderr, name_too_long, "ftw");
return FALSE;
}
@ -658,7 +657,7 @@ extern int createPath(const char *name, int mode)
{
char *cp;
char *cpOld;
char buf[PATH_MAX + 1];
char buf[BUFSIZ + 1];
int retVal = 0;
strcpy(buf, name);