summaryrefslogtreecommitdiff
path: root/editors/cmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'editors/cmp.c')
-rw-r--r--editors/cmp.c26
1 files changed, 6 insertions, 20 deletions
diff --git a/editors/cmp.c b/editors/cmp.c
index 0cb80f21e..dbfa4be35 100644
--- a/editors/cmp.c
+++ b/editors/cmp.c
@@ -10,17 +10,6 @@
10/* BB_AUDIT SUSv3 (virtually) compliant -- uses nicer GNU format for -l. */ 10/* BB_AUDIT SUSv3 (virtually) compliant -- uses nicer GNU format for -l. */
11/* http://www.opengroup.org/onlinepubs/007904975/utilities/cmp.html */ 11/* http://www.opengroup.org/onlinepubs/007904975/utilities/cmp.html */
12 12
13/* Mar 16, 2003 Manuel Novoa III (mjn3@codepoet.org)
14 *
15 * Original version majorly reworked for SUSv3 compliance, bug fixes, and
16 * size optimizations. Changes include:
17 * 1) Now correctly distinguishes between errors and actual file differences.
18 * 2) Proper handling of '-' args.
19 * 3) Actual error checking of i/o.
20 * 4) Accept SUSv3 -l option. Note that we use the slightly nicer gnu format
21 * in the '-l' case.
22 */
23
24#include "libbb.h" 13#include "libbb.h"
25 14
26static const char fmt_eof[] ALIGN1 = "cmp: EOF on %s\n"; 15static const char fmt_eof[] ALIGN1 = "cmp: EOF on %s\n";
@@ -37,8 +26,7 @@ int cmp_main(int argc UNUSED_PARAM, char **argv)
37{ 26{
38 FILE *fp1, *fp2, *outfile = stdout; 27 FILE *fp1, *fp2, *outfile = stdout;
39 const char *filename1, *filename2 = "-"; 28 const char *filename1, *filename2 = "-";
40 IF_DESKTOP(off_t skip1 = 0, skip2 = 0;) 29 off_t skip1 = 0, skip2 = 0, char_pos = 0;
41 off_t char_pos = 0;
42 int line_pos = 1; /* Hopefully won't overflow... */ 30 int line_pos = 1; /* Hopefully won't overflow... */
43 const char *fmt; 31 const char *fmt;
44 int c1, c2; 32 int c1, c2;
@@ -59,14 +47,12 @@ int cmp_main(int argc UNUSED_PARAM, char **argv)
59 47
60 if (*++argv) { 48 if (*++argv) {
61 filename2 = *argv; 49 filename2 = *argv;
62#if ENABLE_DESKTOP 50 if (ENABLE_DESKTOP && *++argv) {
63 if (*++argv) {
64 skip1 = XATOOFF(*argv); 51 skip1 = XATOOFF(*argv);
65 if (*++argv) { 52 if (*++argv) {
66 skip2 = XATOOFF(*argv); 53 skip2 = XATOOFF(*argv);
67 } 54 }
68 } 55 }
69#endif
70 } 56 }
71 57
72 fp2 = xfopen_stdin(filename2); 58 fp2 = xfopen_stdin(filename2);
@@ -83,10 +69,10 @@ int cmp_main(int argc UNUSED_PARAM, char **argv)
83 else 69 else
84 fmt = fmt_differ; 70 fmt = fmt_differ;
85 71
86#if ENABLE_DESKTOP 72 if (ENABLE_DESKTOP) {
87 while (skip1) { getc(fp1); skip1--; } 73 while (skip1) { getc(fp1); skip1--; }
88 while (skip2) { getc(fp2); skip2--; } 74 while (skip2) { getc(fp2); skip2--; }
89#endif 75 }
90 do { 76 do {
91 c1 = getc(fp1); 77 c1 = getc(fp1);
92 c2 = getc(fp2); 78 c2 = getc(fp2);