lib-$(CONFIG_BASENAME) += basename.o
lib-$(CONFIG_CAL) += cal.o
lib-$(CONFIG_CAT) += cat.o
+lib-$(CONFIG_LESS) += cat.o # less uses it if stdout isn't a tty
lib-$(CONFIG_CATV) += catv.o
lib-$(CONFIG_CHGRP) += chgrp.o chown.o
lib-$(CONFIG_CHMOD) += chmod.o
lib-$(CONFIG_DOS2UNIX) += dos2unix.o
lib-$(CONFIG_DU) += du.o
lib-$(CONFIG_ECHO) += echo.o
+lib-$(CONFIG_ASH) += echo.o # used by ash
lib-$(CONFIG_ENV) += env.o
lib-$(CONFIG_EXPR) += expr.o
lib-$(CONFIG_FALSE) += false.o
lib-$(CONFIG_TAIL) += tail.o
lib-$(CONFIG_TEE) += tee.o
lib-$(CONFIG_TEST) += test.o
+lib-$(CONFIG_ASH) += test.o # used by ash
lib-$(CONFIG_TOUCH) += touch.o
lib-$(CONFIG_TR) += tr.o
lib-$(CONFIG_TRUE) += true.o
/* http://www.opengroup.org/onlinepubs/007904975/utilities/cat.html */
#include "busybox.h"
-#include <unistd.h>
-int cat_main(int argc, char **argv)
+int bb_cat(char **argv)
{
FILE *f;
int retval = EXIT_SUCCESS;
- getopt32(argc, argv, "u");
-
- argv += optind;
- if (!*argv) {
- *--argv = "-";
- }
-
do {
f = fopen_or_warn_stdin(*argv);
if (f) {
return retval;
}
+
+int cat_main(int argc, char **argv)
+{
+ getopt32(argc, argv, "u");
+
+ argv += optind;
+ if (!*argv) {
+ *--argv = "-";
+ }
+
+ return bb_cat(argv);
+}
dp = warn_opendir(path);
while ((ep = readdir(dp))) {
- if ((!strcmp(ep->d_name, "..")) || (!strcmp(ep->d_name, ".")))
+ if (!strcmp(ep->d_name, "..") || LONE_CHAR(ep->d_name, '.'))
continue;
add_to_dirlist(ep->d_name, NULL, NULL, 0);
}
#include <stdlib.h>
#include "busybox.h"
-int bb_echo(int ATTRIBUTE_UNUSED argc, char **argv)
+int bb_echo(char **argv)
{
#ifndef CONFIG_FEATURE_FANCY_ECHO
#define eflag '\\'
int echo_main(int argc, char** argv)
{
- (void)bb_echo(argc, argv);
+ (void)bb_echo(argv);
fflush_stdout_and_exit(EXIT_SUCCESS);
}
if (v->type == integer)
return v->u.i == 0;
else /* string: */
- return v->u.s[0] == '\0' || strcmp(v->u.s, "0") == 0;
+ return v->u.s[0] == '\0' || LONE_CHAR(v->u.s, '0');
}
/* Coerce V to a string value (can't fail). */
{
int res;
- if (strcmp(argv[0], "[") == 0) {
- if (strcmp(argv[--argc], "]")) {
+ if (LONE_CHAR(argv[0], '[')) {
+ --argc;
+ if (NOT_LONE_CHAR(argv[argc], ']')) {
bb_error_msg("missing ]");
return 2;
}
argv[argc] = NULL;
} else if (strcmp(argv[0], "[[") == 0) {
- if (strcmp(argv[--argc], "]]")) {
+ --argc;
+ if (strcmp(argv[argc], "]]")) {
bb_error_msg("missing ]]");
return 2;
}
int test_main(int argc, char **argv)
{
- exit(bb_test(argc, argv));
+ return bb_test(argc, argv);
}
struct dirent *lv_iter;
vg_name = vg_iter->d_name;
- if (!strcmp(vg_name, ".") || !strcmp(vg_name, ".."))
+ if (LONE_CHAR(vg_name, '.') || !strcmp(vg_name, ".."))
continue;
vdirname = xmalloc(vg_len + strlen(vg_name) + 8);
sprintf(vdirname, "%s/%s/LVs", VG_DIR, vg_name);
char *lv_name, *lvm_device;
lv_name = lv_iter->d_name;
- if (!strcmp(lv_name, ".") || !strcmp(lv_name, ".."))
+ if (LONE_CHAR(lv_name, '.') || !strcmp(lv_name, ".."))
continue;
lvm_device = xmalloc(vg_len + strlen(vg_name) +
static int chattr_dir_proc(const char *dir_name, struct dirent *de,
void *private EXT2FS_ATTR((unused)))
{
- /*if (strcmp(de->d_name, ".") && strcmp(de->d_name, "..")) {*/
- if (de->d_name[0] == '.' && (de->d_name[1] == '\0' || \
- (de->d_name[1] == '.' && de->d_name[2] == '\0'))) {
+ /*if (strcmp(de->d_name, ".") || strcmp(de->d_name, "..")) {*/
+ if (de->d_name[0] == '.'
+ && (!de->d_name[1] || (de->d_name[1] == '.' && !de->d_name[2]))
+ ) {
char *path = concat_subpath_file(dir_name, de->d_name);
if (path) {
change_attributes(path);
* read/write, since if the root is mounted read/only, the
* contents of /etc/mtab may not be accurate.
*/
- if (!strcmp(mnt->mnt_dir, "/")) {
+ if (LONE_CHAR(mnt->mnt_dir, '/')) {
is_root:
#define TEST_FILE "/.ismount-test-file"
*mount_flags |= EXT2_MF_ISROOT;
*/
if (!parallel_root) {
for (fs = filesys_info; fs; fs = fs->next) {
- if (!strcmp(fs->mountpt, "/"))
+ if (LONE_CHAR(fs->mountpt, '/'))
break;
}
if (fs) {
*/
if (skip_root)
for (fs = filesys_info; fs; fs = fs->next)
- if (!strcmp(fs->mountpt, "/"))
+ if (LONE_CHAR(fs->mountpt, '/'))
fs->flags |= FLAG_DONE;
while (not_done_yet) {
//int NOT_LONE_DASH(const char *s) { return s[0] != '-' || s[1]; }
#define LONE_DASH(s) ((s)[0] == '-' && !(s)[1])
#define NOT_LONE_DASH(s) ((s)[0] != '-' || (s)[1])
+#define LONE_CHAR(s,c) ((s)[0] == (c) && !(s)[1])
+#define NOT_LONE_CHAR(s,c) ((s)[0] != (c) || (s)[1])
/* dmalloc will redefine these to it's own implementation. It is safe
* to have the prototypes here unconditionally. */
extern void bb_vinfo_msg(const char *s, va_list p);
-extern int bb_echo(int argc, char** argv);
+/* applets which are useful from another applets */
+extern int bb_cat(char** argv);
+extern int bb_echo(char** argv);
extern int bb_test(int argc, char** argv);
#ifndef BUILD_INDIVIDUAL
}
/* Check if we are supposed to be in single user mode */
- if (argc > 1 && (!strcmp(argv[1], "single") ||
- !strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
+ if (argc > 1
+ && (!strcmp(argv[1], "single") || !strcmp(argv[1], "-s") || LONE_CHAR(argv[1], '1'))
+ ) {
/* Start a shell on console */
new_init_action(RESPAWN, bb_default_login_shell, "");
} else {
char *unencrypted, *encrypted, *correct;
#ifdef CONFIG_FEATURE_SHADOWPASSWDS
- if (!strcmp(pw->pw_passwd, "x") || !strcmp(pw->pw_passwd, "*")) {
+ if (LONE_CHAR(pw->pw_passwd, 'x') || LONE_CHAR(pw->pw_passwd, '*')) {
struct spwd *sp = getspnam(pw->pw_name);
if (!sp)
bb_error_msg_and_die("no valid shadow password");
correct = sp->sp_pwdp;
- }
- else
+ } else
#endif
correct = pw->pw_passwd;
bb_perror_msg_and_die("short read");
}
- if (strncmp(ut.ut_line, "~", 1) == 0) {
+ if (ut.ut_line[0] == '~') {
if (strncmp(ut.ut_user, "shutdown", 8) == 0)
ut.ut_type = SHUTDOWN_TIME;
else if (strncmp(ut.ut_user, "reboot", 6) == 0)
while (nsep != NULL) {
nsep->se_checked = 1;
if (nsep->se_family == AF_INET) {
- if (!strcmp(nsep->se_hostaddr, "*"))
+ if (LONE_CHAR(nsep->se_hostaddr, '*'))
nsep->se_ctrladdr_in.sin_addr.s_addr = INADDR_ANY;
else if (!inet_aton(nsep->se_hostaddr, &nsep->se_ctrladdr_in.sin_addr)) {
struct hostent *hp;
if (brd_len) {
duparg("broadcast", *argv);
}
- if (strcmp(*argv, "+") == 0) {
+ if (LONE_CHAR(*argv, '+')) {
brd_len = -1;
}
else if (LONE_DASH(*argv)) {
static int
echocmd(int argc, char **argv)
{
- return bb_echo(argc, argv);
+ return bb_echo(argv);
}
#endif