Changeset 2725 in MondoRescue for branches/2.2.9/mindi-busybox/editors/cmp.c
- Timestamp:
- Feb 25, 2011, 9:26:54 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mindi-busybox/editors/cmp.c
r1765 r2725 5 5 * Copyright (C) 2000,2001 by Matt Kraai <kraai@alumni.carnegiemellon.edu> 6 6 * 7 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.7 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 8 8 */ 9 9 … … 11 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, and16 * 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 format21 * in the '-l' case.22 */23 24 13 #include "libbb.h" 25 14 26 static FILE *cmp_xfopen_input(const char *filename)27 {28 FILE *fp;29 30 fp = fopen_or_warn_stdin(filename);31 if (fp)32 return fp;33 xfunc_die(); /* We already output an error message. */34 }35 36 15 static const char fmt_eof[] ALIGN1 = "cmp: EOF on %s\n"; 37 static const char fmt_differ[] ALIGN1 = "%s %s differ: char %"OFF_FMT" d, line %d\n";38 // This fmt_l_opt uses gnu-isms. SUSv3 would be "%.0s%.0s%"OFF_FMT" d%o %o\n"39 static const char fmt_l_opt[] ALIGN1 = "%.0s%.0s%"OFF_FMT" d%3o %3o\n";16 static const char fmt_differ[] ALIGN1 = "%s %s differ: char %"OFF_FMT"u, line %u\n"; 17 // This fmt_l_opt uses gnu-isms. SUSv3 would be "%.0s%.0s%"OFF_FMT"u %o %o\n" 18 static const char fmt_l_opt[] ALIGN1 = "%.0s%.0s%"OFF_FMT"u %3o %3o\n"; 40 19 41 20 static const char opt_chars[] ALIGN1 = "sl"; … … 43 22 #define CMP_OPT_l (1<<1) 44 23 45 int cmp_main(int argc, char **argv) ;46 int cmp_main(int argc , char **argv)24 int cmp_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 25 int cmp_main(int argc UNUSED_PARAM, char **argv) 47 26 { 48 27 FILE *fp1, *fp2, *outfile = stdout; 49 28 const char *filename1, *filename2 = "-"; 50 USE_DESKTOP(off_t skip1 = 0, skip2 = 0;) 51 off_t char_pos = 0; 29 off_t skip1 = 0, skip2 = 0, char_pos = 0; 52 30 int line_pos = 1; /* Hopefully won't overflow... */ 53 31 const char *fmt; … … 56 34 int retval = 0; 57 35 58 xfunc_error_retval = 2; /* 1 is returned if files are different. */59 60 36 opt_complementary = "-1" 61 USE_DESKTOP(":?4")62 SKIP_DESKTOP(":?2")37 IF_DESKTOP(":?4") 38 IF_NOT_DESKTOP(":?2") 63 39 ":l--s:s--l"; 64 40 opt = getopt32(argv, opt_chars); … … 66 42 67 43 filename1 = *argv; 68 fp1 = cmp_xfopen_input(filename1);69 70 44 if (*++argv) { 71 45 filename2 = *argv; 72 #if ENABLE_DESKTOP 73 if (*++argv) { 46 if (ENABLE_DESKTOP && *++argv) { 74 47 skip1 = XATOOFF(*argv); 75 48 if (*++argv) { … … 77 50 } 78 51 } 79 #endif80 52 } 81 53 82 fp2 = cmp_xfopen_input(filename2); 54 xfunc_error_retval = 2; /* missing file results in exitcode 2 */ 55 if (opt & CMP_OPT_s) 56 logmode = 0; /* -s suppresses open error messages */ 57 fp1 = xfopen_stdin(filename1); 58 fp2 = xfopen_stdin(filename2); 83 59 if (fp1 == fp2) { /* Paranoia check... stdin == stdin? */ 84 60 /* Note that we don't bother reading stdin. Neither does gnu wc. … … 88 64 return 0; 89 65 } 66 logmode = LOGMODE_STDIO; 90 67 91 68 if (opt & CMP_OPT_l) … … 94 71 fmt = fmt_differ; 95 72 96 #if ENABLE_DESKTOP 97 while (skip1) { getc(fp1); skip1--; }98 while (skip2) { getc(fp2); skip2--; }99 #endif 73 if (ENABLE_DESKTOP) { 74 while (skip1) { getc(fp1); skip1--; } 75 while (skip2) { getc(fp2); skip2--; } 76 } 100 77 do { 101 78 c1 = getc(fp1); … … 119 96 /* There may have been output to stdout (option -l), so 120 97 * make sure we fflush before writing to stderr. */ 121 xfflush_stdout();98 fflush_all(); 122 99 } 123 100 if (!(opt & CMP_OPT_s)) {
Note:
See TracChangeset
for help on using the changeset viewer.