diff options
author | Mark Whitley | 2000-10-09 18:56:47 +0000 |
---|---|---|
committer | Mark Whitley | 2000-10-09 18:56:47 +0000 |
commit | 872138de50b1c5bbf105b0243f5778fcb02b310b (patch) | |
tree | bae88fc4587a4d0aa9ec228c1006f4b364d0633e | |
parent | 7a86e61a54f75c6c457be177fb20f6dde27c06d3 (diff) | |
download | busybox-872138de50b1c5bbf105b0243f5778fcb02b310b.zip busybox-872138de50b1c5bbf105b0243f5778fcb02b310b.tar.gz |
Added cmp and readlink applets from Matt Kraai.
-rw-r--r-- | Config.h | 2 | ||||
-rw-r--r-- | applets/busybox.c | 6 | ||||
-rw-r--r-- | applets/usage.c | 19 | ||||
-rw-r--r-- | busybox.c | 6 | ||||
-rw-r--r-- | busybox.h | 4 | ||||
-rw-r--r-- | cmp.c | 65 | ||||
-rw-r--r-- | coreutils/cmp.c | 65 | ||||
-rw-r--r-- | include/busybox.h | 4 | ||||
-rw-r--r-- | miscutils/readlink.c | 49 | ||||
-rw-r--r-- | readlink.c | 49 | ||||
-rw-r--r-- | usage.c | 19 |
11 files changed, 286 insertions, 2 deletions
@@ -14,6 +14,7 @@ #define BB_CHROOT #define BB_CHVT #define BB_CLEAR +#define BB_CMP #define BB_CP_MV #define BB_CUT #define BB_DATE @@ -76,6 +77,7 @@ #define BB_PS #define BB_PWD #define BB_RDATE +#define BB_READLINK #define BB_REBOOT #define BB_RENICE #define BB_RESET diff --git a/applets/busybox.c b/applets/busybox.c index 825f40e..d25ddc1 100644 --- a/applets/busybox.c +++ b/applets/busybox.c @@ -40,6 +40,9 @@ const struct BB_applet applets[] = { #ifdef BB_CHVT {"chvt", chvt_main, _BB_DIR_USR_BIN, chvt_usage}, #endif +#ifdef BB_CMP + {"cmp", cmp_main, _BB_DIR_USR_BIN, cmp_usage}, +#endif #ifdef BB_CP_MV {"cp", cp_mv_main, _BB_DIR_BIN, cp_usage}, #endif @@ -235,6 +238,9 @@ const struct BB_applet applets[] = { #ifdef BB_RDATE {"rdate", rdate_main, _BB_DIR_USR_BIN, rdate_usage}, #endif +#ifdef BB_READLINK + {"readlink", readlink_main, _BB_DIR_USR_BIN, readlink_usage}, +#endif #ifdef BB_REBOOT {"reboot", reboot_main, _BB_DIR_SBIN, reboot_usage}, #endif diff --git a/applets/usage.c b/applets/usage.c index ae6cbaa..81f4cfc 100644 --- a/applets/usage.c +++ b/applets/usage.c @@ -93,6 +93,15 @@ const char clear_usage[] = ; #endif +#if defined BB_CMP +const char cmp_usage[] = + "cmp FILE1 [FILE2]\n" +#ifndef BB_FEATURE_TRIVIAL_HELP + "\nCompare files.\n" +#endif + ; +#endif + #if defined BB_CP_MV const char cp_usage[] = "cp [OPTION]... SOURCE DEST\n" @@ -959,6 +968,15 @@ const char rdate_usage[] = ; #endif +#if defined BB_READLINK +const char readlink_usage[] = + "readlink\n" +#ifndef BB_FEATURE_TRIVIAL_HELP + "\nRead a symbolic link.\n" +#endif + ; +#endif + #if defined BB_REBOOT const char reboot_usage[] = "reboot\n" @@ -967,7 +985,6 @@ const char reboot_usage[] = #endif ; #endif - #if defined BB_RENICE const char renice_usage[] = @@ -40,6 +40,9 @@ const struct BB_applet applets[] = { #ifdef BB_CHVT {"chvt", chvt_main, _BB_DIR_USR_BIN, chvt_usage}, #endif +#ifdef BB_CMP + {"cmp", cmp_main, _BB_DIR_USR_BIN, cmp_usage}, +#endif #ifdef BB_CP_MV {"cp", cp_mv_main, _BB_DIR_BIN, cp_usage}, #endif @@ -235,6 +238,9 @@ const struct BB_applet applets[] = { #ifdef BB_RDATE {"rdate", rdate_main, _BB_DIR_USR_BIN, rdate_usage}, #endif +#ifdef BB_READLINK + {"readlink", readlink_main, _BB_DIR_USR_BIN, readlink_usage}, +#endif #ifdef BB_REBOOT {"reboot", reboot_main, _BB_DIR_SBIN, reboot_usage}, #endif @@ -117,6 +117,7 @@ extern int chmod_chown_chgrp_main(int argc, char** argv); extern int chroot_main(int argc, char** argv); extern int chvt_main(int argc, char** argv); extern int clear_main(int argc, char** argv); +extern int cmp_main(int argc, char** argv); extern int cp_mv_main(int argc, char** argv); extern int cut_main(int argc, char** argv); extern int date_main(int argc, char** argv); @@ -181,6 +182,7 @@ extern int printf_main(int argc, char** argv); extern int ps_main(int argc, char** argv); extern int pwd_main(int argc, char** argv); extern int rdate_main(int argc, char** argv); +extern int readlink_main(int argc, char** argv); extern int reboot_main(int argc, char** argv); extern int renice_main(int argc, char** argv); extern int reset_main(int argc, char** argv); @@ -233,6 +235,7 @@ extern const char chown_usage[]; extern const char chroot_usage[]; extern const char chvt_usage[]; extern const char clear_usage[]; +extern const char cmp_usage[]; extern const char cp_usage[]; extern const char cut_usage[]; extern const char date_usage[]; @@ -294,6 +297,7 @@ extern const char printf_usage[]; extern const char ps_usage[]; extern const char pwd_usage[]; extern const char rdate_usage[]; +extern const char readlink_usage[]; extern const char reboot_usage[]; extern const char renice_usage[]; extern const char reset_usage[]; @@ -0,0 +1,65 @@ +/* vi: set sw=4 ts=4: */ +/* + * Mini cmp implementation for busybox + * + * + * Copyright (C) 2000 by Lineo, inc. + * Written 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 "busybox.h" +#include <stdio.h> +#include <string.h> +#include <errno.h> + +int cmp_main(int argc, char **argv) +{ + FILE *fp1 = NULL, *fp2 = stdin; + char *filename1 = argv[1], *filename2 = "-"; + int c1, c2, char_pos = 1, line_pos = 1; + + /* parse argv[] */ + if (argc < 2 || 3 < argc) + usage(cmp_usage); + + fp1 = xfopen(argv[1], "r"); + if (argv[2] != NULL) { + fp2 = xfopen(argv[2], "r"); + filename2 = argv[2]; + } + + do { + c1 = fgetc(fp1); + c2 = fgetc(fp2); + if (c1 != c2) { + 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 1; + } + char_pos++; + if (c1 == '\n') + line_pos++; + } while (c1 != EOF); + + return EXIT_SUCCESS; +} diff --git a/coreutils/cmp.c b/coreutils/cmp.c new file mode 100644 index 0000000..98b747e --- /dev/null +++ b/coreutils/cmp.c @@ -0,0 +1,65 @@ +/* vi: set sw=4 ts=4: */ +/* + * Mini cmp implementation for busybox + * + * + * Copyright (C) 2000 by Lineo, inc. + * Written 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 "busybox.h" +#include <stdio.h> +#include <string.h> +#include <errno.h> + +int cmp_main(int argc, char **argv) +{ + FILE *fp1 = NULL, *fp2 = stdin; + char *filename1 = argv[1], *filename2 = "-"; + int c1, c2, char_pos = 1, line_pos = 1; + + /* parse argv[] */ + if (argc < 2 || 3 < argc) + usage(cmp_usage); + + fp1 = xfopen(argv[1], "r"); + if (argv[2] != NULL) { + fp2 = xfopen(argv[2], "r"); + filename2 = argv[2]; + } + + do { + c1 = fgetc(fp1); + c2 = fgetc(fp2); + if (c1 != c2) { + 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 1; + } + char_pos++; + if (c1 == '\n') + line_pos++; + } while (c1 != EOF); + + return EXIT_SUCCESS; +} diff --git a/include/busybox.h b/include/busybox.h index da17b8a..84d0dda 100644 --- a/include/busybox.h +++ b/include/busybox.h @@ -117,6 +117,7 @@ extern int chmod_chown_chgrp_main(int argc, char** argv); extern int chroot_main(int argc, char** argv); extern int chvt_main(int argc, char** argv); extern int clear_main(int argc, char** argv); +extern int cmp_main(int argc, char** argv); extern int cp_mv_main(int argc, char** argv); extern int cut_main(int argc, char** argv); extern int date_main(int argc, char** argv); @@ -181,6 +182,7 @@ extern int printf_main(int argc, char** argv); extern int ps_main(int argc, char** argv); extern int pwd_main(int argc, char** argv); extern int rdate_main(int argc, char** argv); +extern int readlink_main(int argc, char** argv); extern int reboot_main(int argc, char** argv); extern int renice_main(int argc, char** argv); extern int reset_main(int argc, char** argv); @@ -233,6 +235,7 @@ extern const char chown_usage[]; extern const char chroot_usage[]; extern const char chvt_usage[]; extern const char clear_usage[]; +extern const char cmp_usage[]; extern const char cp_usage[]; extern const char cut_usage[]; extern const char date_usage[]; @@ -294,6 +297,7 @@ extern const char printf_usage[]; extern const char ps_usage[]; extern const char pwd_usage[]; extern const char rdate_usage[]; +extern const char readlink_usage[]; extern const char reboot_usage[]; extern const char renice_usage[]; extern const char reset_usage[]; diff --git a/miscutils/readlink.c b/miscutils/readlink.c new file mode 100644 index 0000000..5a798c0 --- /dev/null +++ b/miscutils/readlink.c @@ -0,0 +1,49 @@ +/* vi: set sw=4 ts=4: */ +/* + * Mini readlink implementation for busybox + * + * + * Copyright (C) 2000 by Lineo, inc. + * Written 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 "busybox.h" +#include <errno.h> +#include <unistd.h> + +int readlink_main(int argc, char **argv) +{ + char *buf = NULL; + int bufsize = 128, size = 128; + + if (argc != 2) + usage(readlink_usage); + + while (bufsize < size + 1) { + bufsize *= 2; + buf = xrealloc(buf, bufsize); + size = readlink(argv[1], buf, bufsize); + if (size == -1) + fatalError("%s: %s\n", argv[1], strerror(errno)); + } + + buf[size] = '\0'; + puts(buf); + + return EXIT_SUCCESS; +} diff --git a/readlink.c b/readlink.c new file mode 100644 index 0000000..5a798c0 --- /dev/null +++ b/readlink.c @@ -0,0 +1,49 @@ +/* vi: set sw=4 ts=4: */ +/* + * Mini readlink implementation for busybox + * + * + * Copyright (C) 2000 by Lineo, inc. + * Written 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 "busybox.h" +#include <errno.h> +#include <unistd.h> + +int readlink_main(int argc, char **argv) +{ + char *buf = NULL; + int bufsize = 128, size = 128; + + if (argc != 2) + usage(readlink_usage); + + while (bufsize < size + 1) { + bufsize *= 2; + buf = xrealloc(buf, bufsize); + size = readlink(argv[1], buf, bufsize); + if (size == -1) + fatalError("%s: %s\n", argv[1], strerror(errno)); + } + + buf[size] = '\0'; + puts(buf); + + return EXIT_SUCCESS; +} @@ -93,6 +93,15 @@ const char clear_usage[] = ; #endif +#if defined BB_CMP +const char cmp_usage[] = + "cmp FILE1 [FILE2]\n" +#ifndef BB_FEATURE_TRIVIAL_HELP + "\nCompare files.\n" +#endif + ; +#endif + #if defined BB_CP_MV const char cp_usage[] = "cp [OPTION]... SOURCE DEST\n" @@ -959,6 +968,15 @@ const char rdate_usage[] = ; #endif +#if defined BB_READLINK +const char readlink_usage[] = + "readlink\n" +#ifndef BB_FEATURE_TRIVIAL_HELP + "\nRead a symbolic link.\n" +#endif + ; +#endif + #if defined BB_REBOOT const char reboot_usage[] = "reboot\n" @@ -967,7 +985,6 @@ const char reboot_usage[] = #endif ; #endif - #if defined BB_RENICE const char renice_usage[] = |