aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Whitley <markw@lineo.com>2000-10-09 18:56:47 +0000
committerMark Whitley <markw@lineo.com>2000-10-09 18:56:47 +0000
commit872138de50b1c5bbf105b0243f5778fcb02b310b (patch)
treebae88fc4587a4d0aa9ec228c1006f4b364d0633e
parent7a86e61a54f75c6c457be177fb20f6dde27c06d3 (diff)
downloadbusybox-w32-872138de50b1c5bbf105b0243f5778fcb02b310b.tar.gz
busybox-w32-872138de50b1c5bbf105b0243f5778fcb02b310b.tar.bz2
busybox-w32-872138de50b1c5bbf105b0243f5778fcb02b310b.zip
Added cmp and readlink applets from Matt Kraai.
-rw-r--r--Config.h2
-rw-r--r--applets/busybox.c6
-rw-r--r--applets/usage.c19
-rw-r--r--busybox.c6
-rw-r--r--busybox.h4
-rw-r--r--cmp.c65
-rw-r--r--coreutils/cmp.c65
-rw-r--r--include/busybox.h4
-rw-r--r--miscutils/readlink.c49
-rw-r--r--readlink.c49
-rw-r--r--usage.c19
11 files changed, 286 insertions, 2 deletions
diff --git a/Config.h b/Config.h
index 961497a77..a111feeda 100644
--- a/Config.h
+++ b/Config.h
@@ -14,6 +14,7 @@
14#define BB_CHROOT 14#define BB_CHROOT
15#define BB_CHVT 15#define BB_CHVT
16#define BB_CLEAR 16#define BB_CLEAR
17#define BB_CMP
17#define BB_CP_MV 18#define BB_CP_MV
18#define BB_CUT 19#define BB_CUT
19#define BB_DATE 20#define BB_DATE
@@ -76,6 +77,7 @@
76#define BB_PS 77#define BB_PS
77#define BB_PWD 78#define BB_PWD
78#define BB_RDATE 79#define BB_RDATE
80#define BB_READLINK
79#define BB_REBOOT 81#define BB_REBOOT
80#define BB_RENICE 82#define BB_RENICE
81#define BB_RESET 83#define BB_RESET
diff --git a/applets/busybox.c b/applets/busybox.c
index 825f40e7c..d25ddc185 100644
--- a/applets/busybox.c
+++ b/applets/busybox.c
@@ -40,6 +40,9 @@ const struct BB_applet applets[] = {
40#ifdef BB_CHVT 40#ifdef BB_CHVT
41 {"chvt", chvt_main, _BB_DIR_USR_BIN, chvt_usage}, 41 {"chvt", chvt_main, _BB_DIR_USR_BIN, chvt_usage},
42#endif 42#endif
43#ifdef BB_CMP
44 {"cmp", cmp_main, _BB_DIR_USR_BIN, cmp_usage},
45#endif
43#ifdef BB_CP_MV 46#ifdef BB_CP_MV
44 {"cp", cp_mv_main, _BB_DIR_BIN, cp_usage}, 47 {"cp", cp_mv_main, _BB_DIR_BIN, cp_usage},
45#endif 48#endif
@@ -235,6 +238,9 @@ const struct BB_applet applets[] = {
235#ifdef BB_RDATE 238#ifdef BB_RDATE
236 {"rdate", rdate_main, _BB_DIR_USR_BIN, rdate_usage}, 239 {"rdate", rdate_main, _BB_DIR_USR_BIN, rdate_usage},
237#endif 240#endif
241#ifdef BB_READLINK
242 {"readlink", readlink_main, _BB_DIR_USR_BIN, readlink_usage},
243#endif
238#ifdef BB_REBOOT 244#ifdef BB_REBOOT
239 {"reboot", reboot_main, _BB_DIR_SBIN, reboot_usage}, 245 {"reboot", reboot_main, _BB_DIR_SBIN, reboot_usage},
240#endif 246#endif
diff --git a/applets/usage.c b/applets/usage.c
index ae6cbaa7c..81f4cfc0e 100644
--- a/applets/usage.c
+++ b/applets/usage.c
@@ -93,6 +93,15 @@ const char clear_usage[] =
93 ; 93 ;
94#endif 94#endif
95 95
96#if defined BB_CMP
97const char cmp_usage[] =
98 "cmp FILE1 [FILE2]\n"
99#ifndef BB_FEATURE_TRIVIAL_HELP
100 "\nCompare files.\n"
101#endif
102 ;
103#endif
104
96#if defined BB_CP_MV 105#if defined BB_CP_MV
97const char cp_usage[] = 106const char cp_usage[] =
98 "cp [OPTION]... SOURCE DEST\n" 107 "cp [OPTION]... SOURCE DEST\n"
@@ -959,6 +968,15 @@ const char rdate_usage[] =
959 ; 968 ;
960#endif 969#endif
961 970
971#if defined BB_READLINK
972const char readlink_usage[] =
973 "readlink\n"
974#ifndef BB_FEATURE_TRIVIAL_HELP
975 "\nRead a symbolic link.\n"
976#endif
977 ;
978#endif
979
962#if defined BB_REBOOT 980#if defined BB_REBOOT
963const char reboot_usage[] = 981const char reboot_usage[] =
964 "reboot\n" 982 "reboot\n"
@@ -967,7 +985,6 @@ const char reboot_usage[] =
967#endif 985#endif
968 ; 986 ;
969#endif 987#endif
970
971 988
972#if defined BB_RENICE 989#if defined BB_RENICE
973const char renice_usage[] = 990const char renice_usage[] =
diff --git a/busybox.c b/busybox.c
index 825f40e7c..d25ddc185 100644
--- a/busybox.c
+++ b/busybox.c
@@ -40,6 +40,9 @@ const struct BB_applet applets[] = {
40#ifdef BB_CHVT 40#ifdef BB_CHVT
41 {"chvt", chvt_main, _BB_DIR_USR_BIN, chvt_usage}, 41 {"chvt", chvt_main, _BB_DIR_USR_BIN, chvt_usage},
42#endif 42#endif
43#ifdef BB_CMP
44 {"cmp", cmp_main, _BB_DIR_USR_BIN, cmp_usage},
45#endif
43#ifdef BB_CP_MV 46#ifdef BB_CP_MV
44 {"cp", cp_mv_main, _BB_DIR_BIN, cp_usage}, 47 {"cp", cp_mv_main, _BB_DIR_BIN, cp_usage},
45#endif 48#endif
@@ -235,6 +238,9 @@ const struct BB_applet applets[] = {
235#ifdef BB_RDATE 238#ifdef BB_RDATE
236 {"rdate", rdate_main, _BB_DIR_USR_BIN, rdate_usage}, 239 {"rdate", rdate_main, _BB_DIR_USR_BIN, rdate_usage},
237#endif 240#endif
241#ifdef BB_READLINK
242 {"readlink", readlink_main, _BB_DIR_USR_BIN, readlink_usage},
243#endif
238#ifdef BB_REBOOT 244#ifdef BB_REBOOT
239 {"reboot", reboot_main, _BB_DIR_SBIN, reboot_usage}, 245 {"reboot", reboot_main, _BB_DIR_SBIN, reboot_usage},
240#endif 246#endif
diff --git a/busybox.h b/busybox.h
index da17b8ab3..84d0ddad8 100644
--- a/busybox.h
+++ b/busybox.h
@@ -117,6 +117,7 @@ extern int chmod_chown_chgrp_main(int argc, char** argv);
117extern int chroot_main(int argc, char** argv); 117extern int chroot_main(int argc, char** argv);
118extern int chvt_main(int argc, char** argv); 118extern int chvt_main(int argc, char** argv);
119extern int clear_main(int argc, char** argv); 119extern int clear_main(int argc, char** argv);
120extern int cmp_main(int argc, char** argv);
120extern int cp_mv_main(int argc, char** argv); 121extern int cp_mv_main(int argc, char** argv);
121extern int cut_main(int argc, char** argv); 122extern int cut_main(int argc, char** argv);
122extern int date_main(int argc, char** argv); 123extern int date_main(int argc, char** argv);
@@ -181,6 +182,7 @@ extern int printf_main(int argc, char** argv);
181extern int ps_main(int argc, char** argv); 182extern int ps_main(int argc, char** argv);
182extern int pwd_main(int argc, char** argv); 183extern int pwd_main(int argc, char** argv);
183extern int rdate_main(int argc, char** argv); 184extern int rdate_main(int argc, char** argv);
185extern int readlink_main(int argc, char** argv);
184extern int reboot_main(int argc, char** argv); 186extern int reboot_main(int argc, char** argv);
185extern int renice_main(int argc, char** argv); 187extern int renice_main(int argc, char** argv);
186extern int reset_main(int argc, char** argv); 188extern int reset_main(int argc, char** argv);
@@ -233,6 +235,7 @@ extern const char chown_usage[];
233extern const char chroot_usage[]; 235extern const char chroot_usage[];
234extern const char chvt_usage[]; 236extern const char chvt_usage[];
235extern const char clear_usage[]; 237extern const char clear_usage[];
238extern const char cmp_usage[];
236extern const char cp_usage[]; 239extern const char cp_usage[];
237extern const char cut_usage[]; 240extern const char cut_usage[];
238extern const char date_usage[]; 241extern const char date_usage[];
@@ -294,6 +297,7 @@ extern const char printf_usage[];
294extern const char ps_usage[]; 297extern const char ps_usage[];
295extern const char pwd_usage[]; 298extern const char pwd_usage[];
296extern const char rdate_usage[]; 299extern const char rdate_usage[];
300extern const char readlink_usage[];
297extern const char reboot_usage[]; 301extern const char reboot_usage[];
298extern const char renice_usage[]; 302extern const char renice_usage[];
299extern const char reset_usage[]; 303extern const char reset_usage[];
diff --git a/cmp.c b/cmp.c
new file mode 100644
index 000000000..98b747eed
--- /dev/null
+++ b/cmp.c
@@ -0,0 +1,65 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini cmp implementation for busybox
4 *
5 *
6 * Copyright (C) 2000 by Lineo, inc.
7 * Written by Matt Kraai <kraai@alumni.carnegiemellon.edu>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include "busybox.h"
26#include <stdio.h>
27#include <string.h>
28#include <errno.h>
29
30int cmp_main(int argc, char **argv)
31{
32 FILE *fp1 = NULL, *fp2 = stdin;
33 char *filename1 = argv[1], *filename2 = "-";
34 int c1, c2, char_pos = 1, line_pos = 1;
35
36 /* parse argv[] */
37 if (argc < 2 || 3 < argc)
38 usage(cmp_usage);
39
40 fp1 = xfopen(argv[1], "r");
41 if (argv[2] != NULL) {
42 fp2 = xfopen(argv[2], "r");
43 filename2 = argv[2];
44 }
45
46 do {
47 c1 = fgetc(fp1);
48 c2 = fgetc(fp2);
49 if (c1 != c2) {
50 if (c1 == EOF)
51 printf("EOF on %s\n", filename1);
52 else if (c2 == EOF)
53 printf("EOF on %s\n", filename2);
54 else
55 printf("%s %s differ: char %d, line %d\n", filename1, filename2,
56 char_pos, line_pos);
57 return 1;
58 }
59 char_pos++;
60 if (c1 == '\n')
61 line_pos++;
62 } while (c1 != EOF);
63
64 return EXIT_SUCCESS;
65}
diff --git a/coreutils/cmp.c b/coreutils/cmp.c
new file mode 100644
index 000000000..98b747eed
--- /dev/null
+++ b/coreutils/cmp.c
@@ -0,0 +1,65 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini cmp implementation for busybox
4 *
5 *
6 * Copyright (C) 2000 by Lineo, inc.
7 * Written by Matt Kraai <kraai@alumni.carnegiemellon.edu>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include "busybox.h"
26#include <stdio.h>
27#include <string.h>
28#include <errno.h>
29
30int cmp_main(int argc, char **argv)
31{
32 FILE *fp1 = NULL, *fp2 = stdin;
33 char *filename1 = argv[1], *filename2 = "-";
34 int c1, c2, char_pos = 1, line_pos = 1;
35
36 /* parse argv[] */
37 if (argc < 2 || 3 < argc)
38 usage(cmp_usage);
39
40 fp1 = xfopen(argv[1], "r");
41 if (argv[2] != NULL) {
42 fp2 = xfopen(argv[2], "r");
43 filename2 = argv[2];
44 }
45
46 do {
47 c1 = fgetc(fp1);
48 c2 = fgetc(fp2);
49 if (c1 != c2) {
50 if (c1 == EOF)
51 printf("EOF on %s\n", filename1);
52 else if (c2 == EOF)
53 printf("EOF on %s\n", filename2);
54 else
55 printf("%s %s differ: char %d, line %d\n", filename1, filename2,
56 char_pos, line_pos);
57 return 1;
58 }
59 char_pos++;
60 if (c1 == '\n')
61 line_pos++;
62 } while (c1 != EOF);
63
64 return EXIT_SUCCESS;
65}
diff --git a/include/busybox.h b/include/busybox.h
index da17b8ab3..84d0ddad8 100644
--- a/include/busybox.h
+++ b/include/busybox.h
@@ -117,6 +117,7 @@ extern int chmod_chown_chgrp_main(int argc, char** argv);
117extern int chroot_main(int argc, char** argv); 117extern int chroot_main(int argc, char** argv);
118extern int chvt_main(int argc, char** argv); 118extern int chvt_main(int argc, char** argv);
119extern int clear_main(int argc, char** argv); 119extern int clear_main(int argc, char** argv);
120extern int cmp_main(int argc, char** argv);
120extern int cp_mv_main(int argc, char** argv); 121extern int cp_mv_main(int argc, char** argv);
121extern int cut_main(int argc, char** argv); 122extern int cut_main(int argc, char** argv);
122extern int date_main(int argc, char** argv); 123extern int date_main(int argc, char** argv);
@@ -181,6 +182,7 @@ extern int printf_main(int argc, char** argv);
181extern int ps_main(int argc, char** argv); 182extern int ps_main(int argc, char** argv);
182extern int pwd_main(int argc, char** argv); 183extern int pwd_main(int argc, char** argv);
183extern int rdate_main(int argc, char** argv); 184extern int rdate_main(int argc, char** argv);
185extern int readlink_main(int argc, char** argv);
184extern int reboot_main(int argc, char** argv); 186extern int reboot_main(int argc, char** argv);
185extern int renice_main(int argc, char** argv); 187extern int renice_main(int argc, char** argv);
186extern int reset_main(int argc, char** argv); 188extern int reset_main(int argc, char** argv);
@@ -233,6 +235,7 @@ extern const char chown_usage[];
233extern const char chroot_usage[]; 235extern const char chroot_usage[];
234extern const char chvt_usage[]; 236extern const char chvt_usage[];
235extern const char clear_usage[]; 237extern const char clear_usage[];
238extern const char cmp_usage[];
236extern const char cp_usage[]; 239extern const char cp_usage[];
237extern const char cut_usage[]; 240extern const char cut_usage[];
238extern const char date_usage[]; 241extern const char date_usage[];
@@ -294,6 +297,7 @@ extern const char printf_usage[];
294extern const char ps_usage[]; 297extern const char ps_usage[];
295extern const char pwd_usage[]; 298extern const char pwd_usage[];
296extern const char rdate_usage[]; 299extern const char rdate_usage[];
300extern const char readlink_usage[];
297extern const char reboot_usage[]; 301extern const char reboot_usage[];
298extern const char renice_usage[]; 302extern const char renice_usage[];
299extern const char reset_usage[]; 303extern const char reset_usage[];
diff --git a/miscutils/readlink.c b/miscutils/readlink.c
new file mode 100644
index 000000000..5a798c0ea
--- /dev/null
+++ b/miscutils/readlink.c
@@ -0,0 +1,49 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini readlink implementation for busybox
4 *
5 *
6 * Copyright (C) 2000 by Lineo, inc.
7 * Written by Matt Kraai <kraai@alumni.carnegiemellon.edu>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include "busybox.h"
26#include <errno.h>
27#include <unistd.h>
28
29int readlink_main(int argc, char **argv)
30{
31 char *buf = NULL;
32 int bufsize = 128, size = 128;
33
34 if (argc != 2)
35 usage(readlink_usage);
36
37 while (bufsize < size + 1) {
38 bufsize *= 2;
39 buf = xrealloc(buf, bufsize);
40 size = readlink(argv[1], buf, bufsize);
41 if (size == -1)
42 fatalError("%s: %s\n", argv[1], strerror(errno));
43 }
44
45 buf[size] = '\0';
46 puts(buf);
47
48 return EXIT_SUCCESS;
49}
diff --git a/readlink.c b/readlink.c
new file mode 100644
index 000000000..5a798c0ea
--- /dev/null
+++ b/readlink.c
@@ -0,0 +1,49 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * Mini readlink implementation for busybox
4 *
5 *
6 * Copyright (C) 2000 by Lineo, inc.
7 * Written by Matt Kraai <kraai@alumni.carnegiemellon.edu>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 *
23 */
24
25#include "busybox.h"
26#include <errno.h>
27#include <unistd.h>
28
29int readlink_main(int argc, char **argv)
30{
31 char *buf = NULL;
32 int bufsize = 128, size = 128;
33
34 if (argc != 2)
35 usage(readlink_usage);
36
37 while (bufsize < size + 1) {
38 bufsize *= 2;
39 buf = xrealloc(buf, bufsize);
40 size = readlink(argv[1], buf, bufsize);
41 if (size == -1)
42 fatalError("%s: %s\n", argv[1], strerror(errno));
43 }
44
45 buf[size] = '\0';
46 puts(buf);
47
48 return EXIT_SUCCESS;
49}
diff --git a/usage.c b/usage.c
index ae6cbaa7c..81f4cfc0e 100644
--- a/usage.c
+++ b/usage.c
@@ -93,6 +93,15 @@ const char clear_usage[] =
93 ; 93 ;
94#endif 94#endif
95 95
96#if defined BB_CMP
97const char cmp_usage[] =
98 "cmp FILE1 [FILE2]\n"
99#ifndef BB_FEATURE_TRIVIAL_HELP
100 "\nCompare files.\n"
101#endif
102 ;
103#endif
104
96#if defined BB_CP_MV 105#if defined BB_CP_MV
97const char cp_usage[] = 106const char cp_usage[] =
98 "cp [OPTION]... SOURCE DEST\n" 107 "cp [OPTION]... SOURCE DEST\n"
@@ -959,6 +968,15 @@ const char rdate_usage[] =
959 ; 968 ;
960#endif 969#endif
961 970
971#if defined BB_READLINK
972const char readlink_usage[] =
973 "readlink\n"
974#ifndef BB_FEATURE_TRIVIAL_HELP
975 "\nRead a symbolic link.\n"
976#endif
977 ;
978#endif
979
962#if defined BB_REBOOT 980#if defined BB_REBOOT
963const char reboot_usage[] = 981const char reboot_usage[] =
964 "reboot\n" 982 "reboot\n"
@@ -967,7 +985,6 @@ const char reboot_usage[] =
967#endif 985#endif
968 ; 986 ;
969#endif 987#endif
970
971 988
972#if defined BB_RENICE 989#if defined BB_RENICE
973const char renice_usage[] = 990const char renice_usage[] =