+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).
#include <signal.h>
#include <time.h>
#include <sys/types.h>
+#include <sys/sysmacros.h>
static const char tar_usage[] =
* Open the tar file for reading.
*/
if ((tarName == NULL) || !strcmp (tarName, "-")) {
- tarFd = STDIN;
+ tarFd = fileno(stdin);
} else
tarFd = open (tarName, O_RDONLY);
* 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;
*/
if ((tarName == NULL) || !strcmp (tarName, "-")) {
tostdoutFlag = TRUE;
- tarFd = STDOUT;
+ tarFd = fileno(stdout);
} else
tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0666);
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);
}
if (outFile == NULL)
- outFd = STDOUT;
+ outFd = fileno(stdout);
else
outFd = creat (outFile, 0666);
if (inCc < 0) {
perror (inFile);
goto cleanup;
+ } else if (inCc == 0) {
+ goto cleanup;
}
intotal += inCc;
cp = buf;
if (outCc < 0) {
perror (outFile);
goto cleanup;
+ } else if (outCc == 0) {
+ goto cleanup;
}
inCc -= outCc;
/* 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
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);
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;
while (**argv == '-') {
while (*++(*argv))
switch (**argv) {
+ case 'R':
case 'r':
recursiveFlag = TRUE;
break;
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);
}
if (outFile == NULL)
- outFd = STDOUT;
+ outFd = fileno(stdout);
else
outFd = creat (outFile, 0666);
if (inCc < 0) {
perror (inFile);
goto cleanup;
+ } else if (inCc == 0) {
+ goto cleanup;
}
intotal += inCc;
cp = buf;
if (outCc < 0) {
perror (outFile);
goto cleanup;
+ } else if (outCc == 0) {
+ goto cleanup;
}
inCc -= outCc;
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);
}
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 );
}
/* 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;
}
/* 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");
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) {
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);
}
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 );
}
/* 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;
}
/* 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");
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) {
/* Some useful definitions */
-#define STDIN 0
-#define STDOUT 1
#define FALSE ((int) 1)
#define TRUE ((int) 0)
/* 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
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);
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)
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;
while (**argv == '-') {
while (*++(*argv))
switch (**argv) {
+ case 'R':
case 'r':
recursiveFlag = TRUE;
break;
#include <signal.h>
#include <time.h>
#include <sys/types.h>
+#include <sys/sysmacros.h>
static const char tar_usage[] =
* Open the tar file for reading.
*/
if ((tarName == NULL) || !strcmp (tarName, "-")) {
- tarFd = STDIN;
+ tarFd = fileno(stdin);
} else
tarFd = open (tarName, O_RDONLY);
* 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;
*/
if ((tarName == NULL) || !strcmp (tarName, "-")) {
tostdoutFlag = TRUE;
- tarFd = STDOUT;
+ tarFd = fileno(stdout);
} else
tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0666);
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)
char buf[NAME_MAX];
strcpy (buf, name);
+ if (buf[strlen(buf)]!='/') {
+ buf[strlen(buf)] = '/';
+ buf[strlen(buf)+1] = '\0';
+ }
cp = strchr (buf, '/');