summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen1999-11-19 02:38:58 +0000
committerEric Andersen1999-11-19 02:38:58 +0000
commit08b1034f4f0b910660a8b1a537f86462fa41ebad (patch)
tree4a39b721f4654120bff47fcd7cd95906172ec16f
parentab746abfc05c28824b25e12b86a538b09fb9275d (diff)
downloadbusybox-08b1034f4f0b910660a8b1a537f86462fa41ebad.zip
busybox-08b1034f4f0b910660a8b1a537f86462fa41ebad.tar.gz
Stuf
-rw-r--r--Changelog5
-rw-r--r--archival/tar.c7
-rw-r--r--coreutils/dd.c15
-rw-r--r--coreutils/ls.c2
-rw-r--r--coreutils/mkdir.c3
-rw-r--r--coreutils/rm.c5
-rw-r--r--dd.c15
-rw-r--r--init.c35
-rw-r--r--init/init.c35
-rw-r--r--internal.h2
-rw-r--r--ls.c2
-rw-r--r--mkdir.c3
-rw-r--r--more.c2
-rw-r--r--rm.c5
-rw-r--r--tar.c7
-rw-r--r--util-linux/more.c2
-rw-r--r--utility.c4
17 files changed, 101 insertions, 48 deletions
diff --git a/Changelog b/Changelog
index efd70cb..0529d18 100644
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,8 @@
+0.37
+ * Now 'rm -R' and 'rm -r' both work.
+
+ -Erik Andrsen
+
0.36
* fixed dd so it properly defaults to stdin and stdout when no
if= and of= are set (fix thanks to Eric Delaunay).
diff --git a/archival/tar.c b/archival/tar.c
index 1fdbf8c..bbd8662 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -38,6 +38,7 @@
#include <signal.h>
#include <time.h>
#include <sys/types.h>
+#include <sys/sysmacros.h>
static const char tar_usage[] =
@@ -276,7 +277,7 @@ static void readTarFile (int fileCount, char **fileTable)
* Open the tar file for reading.
*/
if ((tarName == NULL) || !strcmp (tarName, "-")) {
- tarFd = STDIN;
+ tarFd = fileno(stdin);
} else
tarFd = open (tarName, O_RDONLY);
@@ -552,7 +553,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
* Start the output file.
*/
if (tostdoutFlag == TRUE)
- outFd = STDOUT;
+ outFd = fileno(stdout);
else {
if ( S_ISCHR(mode) || S_ISBLK(mode) || S_ISSOCK(mode) ) {
devFileFlag = TRUE;
@@ -650,7 +651,7 @@ static void writeTarFile (int fileCount, char **fileTable)
*/
if ((tarName == NULL) || !strcmp (tarName, "-")) {
tostdoutFlag = TRUE;
- tarFd = STDOUT;
+ tarFd = fileno(stdout);
} else
tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0666);
diff --git a/coreutils/dd.c b/coreutils/dd.c
index 9468cdd..39c6a62 100644
--- a/coreutils/dd.c
+++ b/coreutils/dd.c
@@ -162,8 +162,13 @@ extern int dd_main (int argc, char **argv)
intotal = 0;
outTotal = 0;
- if (inFile == NULL)
- inFd = STDIN;
+ if (inFile == NULL) {
+ struct stat statBuf;
+ inFd = fileno(stdin);
+ if (fstat(inFd, &statBuf) < 0)
+ exit( FALSE);
+ count = statBuf.st_size;
+ }
else
inFd = open (inFile, 0);
@@ -174,7 +179,7 @@ extern int dd_main (int argc, char **argv)
}
if (outFile == NULL)
- outFd = STDOUT;
+ outFd = fileno(stdout);
else
outFd = creat (outFile, 0666);
@@ -191,6 +196,8 @@ extern int dd_main (int argc, char **argv)
if (inCc < 0) {
perror (inFile);
goto cleanup;
+ } else if (inCc == 0) {
+ goto cleanup;
}
intotal += inCc;
cp = buf;
@@ -202,6 +209,8 @@ extern int dd_main (int argc, char **argv)
if (outCc < 0) {
perror (outFile);
goto cleanup;
+ } else if (outCc == 0) {
+ goto cleanup;
}
inCc -= outCc;
diff --git a/coreutils/ls.c b/coreutils/ls.c
index f09cbbc..0558bb2 100644
--- a/coreutils/ls.c
+++ b/coreutils/ls.c
@@ -475,7 +475,7 @@ ls_main(int argc, char * * argv)
/* choose a display format */
if (display_fmt == FMT_AUTO)
- display_fmt = isatty(STDOUT_FILENO) ? FMT_COLUMNS : FMT_SINGLE;
+ display_fmt = isatty(fileno(stdout)) ? FMT_COLUMNS : FMT_SINGLE;
if (argi < argc - 1)
opts |= DISP_DIRNAME; /* 2 or more items? label directories */
#ifdef FEATURE_AUTOWIDTH
diff --git a/coreutils/mkdir.c b/coreutils/mkdir.c
index 28315ca..2cd1788 100644
--- a/coreutils/mkdir.c
+++ b/coreutils/mkdir.c
@@ -85,8 +85,9 @@ extern int mkdir_main(int argc, char **argv)
fprintf(stderr, "%s: File exists\n", *argv);
exit( FALSE);
}
- if (parentFlag == TRUE)
+ if (parentFlag == TRUE) {
createPath(*argv, mode);
+ }
else {
if (mkdir (*argv, mode) != 0) {
perror(*argv);
diff --git a/coreutils/rm.c b/coreutils/rm.c
index ba5d30e..ee434fb 100644
--- a/coreutils/rm.c
+++ b/coreutils/rm.c
@@ -31,8 +31,8 @@
static const char* rm_usage = "rm [OPTION]... FILE...\n\n"
"Remove (unlink) the FILE(s).\n\n"
"Options:\n"
-"\t-f\tremove existing destinations, never prompt\n"
-"\t-r\tremove the contents of directories recursively\n";
+"\t-f\t\tremove existing destinations, never prompt\n"
+"\t-r or -R\tremove the contents of directories recursively\n";
static int recursiveFlag = FALSE;
@@ -72,6 +72,7 @@ extern int rm_main(int argc, char **argv)
while (**argv == '-') {
while (*++(*argv))
switch (**argv) {
+ case 'R':
case 'r':
recursiveFlag = TRUE;
break;
diff --git a/dd.c b/dd.c
index 9468cdd..39c6a62 100644
--- a/dd.c
+++ b/dd.c
@@ -162,8 +162,13 @@ extern int dd_main (int argc, char **argv)
intotal = 0;
outTotal = 0;
- if (inFile == NULL)
- inFd = STDIN;
+ if (inFile == NULL) {
+ struct stat statBuf;
+ inFd = fileno(stdin);
+ if (fstat(inFd, &statBuf) < 0)
+ exit( FALSE);
+ count = statBuf.st_size;
+ }
else
inFd = open (inFile, 0);
@@ -174,7 +179,7 @@ extern int dd_main (int argc, char **argv)
}
if (outFile == NULL)
- outFd = STDOUT;
+ outFd = fileno(stdout);
else
outFd = creat (outFile, 0666);
@@ -191,6 +196,8 @@ extern int dd_main (int argc, char **argv)
if (inCc < 0) {
perror (inFile);
goto cleanup;
+ } else if (inCc == 0) {
+ goto cleanup;
}
intotal += inCc;
cp = buf;
@@ -202,6 +209,8 @@ extern int dd_main (int argc, char **argv)
if (outCc < 0) {
perror (outFile);
goto cleanup;
+ } else if (outCc == 0) {
+ goto cleanup;
}
inCc -= outCc;
diff --git a/init.c b/init.c
index f6e9eff..ce2f237 100644
--- a/init.c
+++ b/init.c
@@ -130,32 +130,40 @@ void message(int device, char *fmt, ...)
void set_term( int fd)
{
struct termios tty;
+#if 0
static const char control_characters[] = {
'\003', '\034', '\177', '\030', '\004', '\0',
'\1', '\0', '\021', '\023', '\032', '\0', '\022',
'\017', '\027', '\026', '\0'
};
+#else
+ static const char control_characters[] = {
+ '\003', '\034', '\177', '\025', '\004', '\0',
+ '\1', '\0', '\021', '\023', '\032', '\0', '\022',
+ '\017', '\027', '\026', '\0'
+ };
+#endif
tcgetattr(fd, &tty);
- /* Make it be sane */
- tty.c_cflag &= CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD;
- tty.c_cflag |= HUPCL|CLOCAL;
-
- /* input modes */
- tty.c_iflag = IGNPAR|ICRNL|IXON|IXOFF|IXANY;
+ /* set control chars */
+ memcpy(tty.c_cc, control_characters, sizeof(control_characters));
/* use line dicipline 0 */
tty.c_line = 0;
+ /* Make it be sane */
+ //tty.c_cflag &= CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD;
+ //tty.c_cflag |= HUPCL|CLOCAL;
+
+ /* input modes */
+ tty.c_iflag = ICRNL|IXON|IXOFF;
+
/* output modes */
tty.c_oflag = OPOST|ONLCR;
/* local modes */
- tty.c_lflag = ISIG|ICANON|ECHO|ECHOE|ECHOK|ECHOCTL|ECHOPRT|ECHOKE|IEXTEN;
-
- /* control chars */
- memcpy(tty.c_cc, control_characters, sizeof(control_characters));
+ tty.c_lflag = ISIG|ICANON|ECHO|ECHOE|ECHOK|ECHOCTL|ECHOKE|IEXTEN;
tcsetattr(fd, TCSANOW, &tty);
}
@@ -210,7 +218,7 @@ static void console_init()
console = the_console;
/* 2.2 kernels: identify the real console backend and try to use it */
- if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
+ if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
/* this is a serial console */
snprintf( the_console, sizeof the_console, "/dev/ttyS%d", sr.line );
}
@@ -245,6 +253,7 @@ static void console_init()
/* check for serial console and disable logging to tty3 & running a
* shell to tty2 */
if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
+ message(LOG|CONSOLE, "serial console detected. Disabling 2nd virtual terminal.\r\n", console );
log = NULL;
second_console = NULL;
}
@@ -362,7 +371,7 @@ static void shutdown_system(void)
/* Allow Ctrl-Alt-Del to reboot system. */
reboot(RB_ENABLE_CAD);
#endif
- message(CONSOLE, "The system is going down NOW !!\r\n");
+ message(CONSOLE, "\r\nThe system is going down NOW !!\r\n");
sync();
/* Send signals to every process _except_ pid 1 */
message(CONSOLE, "Sending SIGHUP to all processes.\r\n");
@@ -376,7 +385,9 @@ static void shutdown_system(void)
kill(-1, SIGKILL);
#endif
sleep(1);
+ message(CONSOLE, "Disabling swap.\r\n");
waitfor(run( swap_off_cmd, console, FALSE));
+ message(CONSOLE, "Unmounting filesystems.\r\n");
waitfor(run( umount_cmd, console, FALSE));
sync();
if (kernel_version > 0 && kernel_version <= 2 * 65536 + 2 * 256 + 11) {
diff --git a/init/init.c b/init/init.c
index f6e9eff..ce2f237 100644
--- a/init/init.c
+++ b/init/init.c
@@ -130,32 +130,40 @@ void message(int device, char *fmt, ...)
void set_term( int fd)
{
struct termios tty;
+#if 0
static const char control_characters[] = {
'\003', '\034', '\177', '\030', '\004', '\0',
'\1', '\0', '\021', '\023', '\032', '\0', '\022',
'\017', '\027', '\026', '\0'
};
+#else
+ static const char control_characters[] = {
+ '\003', '\034', '\177', '\025', '\004', '\0',
+ '\1', '\0', '\021', '\023', '\032', '\0', '\022',
+ '\017', '\027', '\026', '\0'
+ };
+#endif
tcgetattr(fd, &tty);
- /* Make it be sane */
- tty.c_cflag &= CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD;
- tty.c_cflag |= HUPCL|CLOCAL;
-
- /* input modes */
- tty.c_iflag = IGNPAR|ICRNL|IXON|IXOFF|IXANY;
+ /* set control chars */
+ memcpy(tty.c_cc, control_characters, sizeof(control_characters));
/* use line dicipline 0 */
tty.c_line = 0;
+ /* Make it be sane */
+ //tty.c_cflag &= CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD;
+ //tty.c_cflag |= HUPCL|CLOCAL;
+
+ /* input modes */
+ tty.c_iflag = ICRNL|IXON|IXOFF;
+
/* output modes */
tty.c_oflag = OPOST|ONLCR;
/* local modes */
- tty.c_lflag = ISIG|ICANON|ECHO|ECHOE|ECHOK|ECHOCTL|ECHOPRT|ECHOKE|IEXTEN;
-
- /* control chars */
- memcpy(tty.c_cc, control_characters, sizeof(control_characters));
+ tty.c_lflag = ISIG|ICANON|ECHO|ECHOE|ECHOK|ECHOCTL|ECHOKE|IEXTEN;
tcsetattr(fd, TCSANOW, &tty);
}
@@ -210,7 +218,7 @@ static void console_init()
console = the_console;
/* 2.2 kernels: identify the real console backend and try to use it */
- if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
+ if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
/* this is a serial console */
snprintf( the_console, sizeof the_console, "/dev/ttyS%d", sr.line );
}
@@ -245,6 +253,7 @@ static void console_init()
/* check for serial console and disable logging to tty3 & running a
* shell to tty2 */
if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
+ message(LOG|CONSOLE, "serial console detected. Disabling 2nd virtual terminal.\r\n", console );
log = NULL;
second_console = NULL;
}
@@ -362,7 +371,7 @@ static void shutdown_system(void)
/* Allow Ctrl-Alt-Del to reboot system. */
reboot(RB_ENABLE_CAD);
#endif
- message(CONSOLE, "The system is going down NOW !!\r\n");
+ message(CONSOLE, "\r\nThe system is going down NOW !!\r\n");
sync();
/* Send signals to every process _except_ pid 1 */
message(CONSOLE, "Sending SIGHUP to all processes.\r\n");
@@ -376,7 +385,9 @@ static void shutdown_system(void)
kill(-1, SIGKILL);
#endif
sleep(1);
+ message(CONSOLE, "Disabling swap.\r\n");
waitfor(run( swap_off_cmd, console, FALSE));
+ message(CONSOLE, "Unmounting filesystems.\r\n");
waitfor(run( umount_cmd, console, FALSE));
sync();
if (kernel_version > 0 && kernel_version <= 2 * 65536 + 2 * 256 + 11) {
diff --git a/internal.h b/internal.h
index 0317ed9..feaea63 100644
--- a/internal.h
+++ b/internal.h
@@ -33,8 +33,6 @@
/* Some useful definitions */
-#define STDIN 0
-#define STDOUT 1
#define FALSE ((int) 1)
#define TRUE ((int) 0)
diff --git a/ls.c b/ls.c
index f09cbbc..0558bb2 100644
--- a/ls.c
+++ b/ls.c
@@ -475,7 +475,7 @@ ls_main(int argc, char * * argv)
/* choose a display format */
if (display_fmt == FMT_AUTO)
- display_fmt = isatty(STDOUT_FILENO) ? FMT_COLUMNS : FMT_SINGLE;
+ display_fmt = isatty(fileno(stdout)) ? FMT_COLUMNS : FMT_SINGLE;
if (argi < argc - 1)
opts |= DISP_DIRNAME; /* 2 or more items? label directories */
#ifdef FEATURE_AUTOWIDTH
diff --git a/mkdir.c b/mkdir.c
index 28315ca..2cd1788 100644
--- a/mkdir.c
+++ b/mkdir.c
@@ -85,8 +85,9 @@ extern int mkdir_main(int argc, char **argv)
fprintf(stderr, "%s: File exists\n", *argv);
exit( FALSE);
}
- if (parentFlag == TRUE)
+ if (parentFlag == TRUE) {
createPath(*argv, mode);
+ }
else {
if (mkdir (*argv, mode) != 0) {
perror(*argv);
diff --git a/more.c b/more.c
index 7d0ddb8..7fbca23 100644
--- a/more.c
+++ b/more.c
@@ -122,7 +122,7 @@ extern int more_main(int argc, char **argv)
stty(fileno(cin), &new_settings);
#ifdef BB_FEATURE_AUTOWIDTH
- ioctl(STDOUT_FILENO, TIOCGWINSZ, &win);
+ ioctl(fileno(stdout), TIOCGWINSZ, &win);
if (win.ws_row > 4)
terminal_height = win.ws_row - 2;
if (win.ws_col > 0)
diff --git a/rm.c b/rm.c
index ba5d30e..ee434fb 100644
--- a/rm.c
+++ b/rm.c
@@ -31,8 +31,8 @@
static const char* rm_usage = "rm [OPTION]... FILE...\n\n"
"Remove (unlink) the FILE(s).\n\n"
"Options:\n"
-"\t-f\tremove existing destinations, never prompt\n"
-"\t-r\tremove the contents of directories recursively\n";
+"\t-f\t\tremove existing destinations, never prompt\n"
+"\t-r or -R\tremove the contents of directories recursively\n";
static int recursiveFlag = FALSE;
@@ -72,6 +72,7 @@ extern int rm_main(int argc, char **argv)
while (**argv == '-') {
while (*++(*argv))
switch (**argv) {
+ case 'R':
case 'r':
recursiveFlag = TRUE;
break;
diff --git a/tar.c b/tar.c
index 1fdbf8c..bbd8662 100644
--- a/tar.c
+++ b/tar.c
@@ -38,6 +38,7 @@
#include <signal.h>
#include <time.h>
#include <sys/types.h>
+#include <sys/sysmacros.h>
static const char tar_usage[] =
@@ -276,7 +277,7 @@ static void readTarFile (int fileCount, char **fileTable)
* Open the tar file for reading.
*/
if ((tarName == NULL) || !strcmp (tarName, "-")) {
- tarFd = STDIN;
+ tarFd = fileno(stdin);
} else
tarFd = open (tarName, O_RDONLY);
@@ -552,7 +553,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
* Start the output file.
*/
if (tostdoutFlag == TRUE)
- outFd = STDOUT;
+ outFd = fileno(stdout);
else {
if ( S_ISCHR(mode) || S_ISBLK(mode) || S_ISSOCK(mode) ) {
devFileFlag = TRUE;
@@ -650,7 +651,7 @@ static void writeTarFile (int fileCount, char **fileTable)
*/
if ((tarName == NULL) || !strcmp (tarName, "-")) {
tostdoutFlag = TRUE;
- tarFd = STDOUT;
+ tarFd = fileno(stdout);
} else
tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0666);
diff --git a/util-linux/more.c b/util-linux/more.c
index 7d0ddb8..7fbca23 100644
--- a/util-linux/more.c
+++ b/util-linux/more.c
@@ -122,7 +122,7 @@ extern int more_main(int argc, char **argv)
stty(fileno(cin), &new_settings);
#ifdef BB_FEATURE_AUTOWIDTH
- ioctl(STDOUT_FILENO, TIOCGWINSZ, &win);
+ ioctl(fileno(stdout), TIOCGWINSZ, &win);
if (win.ws_row > 4)
terminal_height = win.ws_row - 2;
if (win.ws_col > 0)
diff --git a/utility.c b/utility.c
index b4dd0cc..004864a 100644
--- a/utility.c
+++ b/utility.c
@@ -482,6 +482,10 @@ extern void createPath (const char *name, int mode)
char buf[NAME_MAX];
strcpy (buf, name);
+ if (buf[strlen(buf)]!='/') {
+ buf[strlen(buf)] = '/';
+ buf[strlen(buf)+1] = '\0';
+ }
cp = strchr (buf, '/');