aboutsummaryrefslogtreecommitdiff
path: root/editors/diff.c
diff options
context:
space:
mode:
Diffstat (limited to 'editors/diff.c')
-rw-r--r--editors/diff.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/editors/diff.c b/editors/diff.c
index 1adc4cbc7..b324feaa5 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -119,6 +119,9 @@
119//usage: "\n -t Expand tabs to spaces in output" 119//usage: "\n -t Expand tabs to spaces in output"
120//usage: "\n -U Output LINES lines of context" 120//usage: "\n -U Output LINES lines of context"
121//usage: "\n -w Ignore all whitespace" 121//usage: "\n -w Ignore all whitespace"
122//usage: IF_PLATFORM_MINGW32(IF_FEATURE_DIFF_LONG_OPTIONS(
123//usage: "\n --binary Treat input as binary, not text"
124//usage: ))
122 125
123#include "libbb.h" 126#include "libbb.h"
124#include "common_bufsiz.h" 127#include "common_bufsiz.h"
@@ -154,6 +157,9 @@ enum { /* Commandline flags */
154 FLAG_p, /* not implemented */ 157 FLAG_p, /* not implemented */
155 FLAG_B, 158 FLAG_B,
156 FLAG_E, /* not implemented */ 159 FLAG_E, /* not implemented */
160#if ENABLE_PLATFORM_MINGW32 && ENABLE_FEATURE_DIFF_LONG_OPTIONS
161 FLAG_binary,
162#endif
157}; 163};
158#define FLAG(x) (1 << FLAG_##x) 164#define FLAG(x) (1 << FLAG_##x)
159 165
@@ -217,6 +223,9 @@ static int read_token(FILE_and_pos_t *ft, token_t tok)
217 int t; 223 int t;
218 224
219 t = fgetc(ft->ft_fp); 225 t = fgetc(ft->ft_fp);
226#if ENABLE_PLATFORM_MINGW32 && ENABLE_FEATURE_DIFF_LONG_OPTIONS
227 newline:
228#endif
220 if (t != EOF) 229 if (t != EOF)
221 ft->ft_pos++; 230 ft->ft_pos++;
222 is_space = (t == EOF || isspace(t)); 231 is_space = (t == EOF || isspace(t));
@@ -232,6 +241,16 @@ static int read_token(FILE_and_pos_t *ft, token_t tok)
232 241
233 if ((option_mask32 & FLAG(w)) && is_space) 242 if ((option_mask32 & FLAG(w)) && is_space)
234 continue; 243 continue;
244#if ENABLE_PLATFORM_MINGW32 && ENABLE_FEATURE_DIFF_LONG_OPTIONS
245 if (!(option_mask32 & FLAG(binary)) && t == '\r') {
246 int t2 = fgetc(ft->ft_fp);
247 if (t2 == '\n') {
248 t = t2;
249 goto newline;
250 }
251 ungetc(t2, ft->ft_fp);
252 }
253#endif
235 254
236 /* Trim char value to low 9 bits */ 255 /* Trim char value to low 9 bits */
237 t &= CHAR_MASK; 256 t &= CHAR_MASK;
@@ -709,6 +728,10 @@ static int diffreg(char *file[2])
709 FILE *fp[2]; 728 FILE *fp[2];
710 bool binary = false, differ = false; 729 bool binary = false, differ = false;
711 int status = STATUS_SAME, i; 730 int status = STATUS_SAME, i;
731#if ENABLE_PLATFORM_MINGW32
732 char *tmpfile[2] = { NULL, NULL };
733 char *tmpdir;
734#endif
712 735
713 fp[0] = stdin; 736 fp[0] = stdin;
714 fp[1] = stdin; 737 fp[1] = stdin;
@@ -730,10 +753,19 @@ static int diffreg(char *file[2])
730 * When we meet non-seekable file, we must make a temp copy. 753 * When we meet non-seekable file, we must make a temp copy.
731 */ 754 */
732 if (lseek(fd, 0, SEEK_SET) == -1 && errno == ESPIPE) { 755 if (lseek(fd, 0, SEEK_SET) == -1 && errno == ESPIPE) {
756#if !ENABLE_PLATFORM_MINGW32
733 char name[] = "/tmp/difXXXXXX"; 757 char name[] = "/tmp/difXXXXXX";
734 int fd_tmp = xmkstemp(name); 758 int fd_tmp = xmkstemp(name);
735 759
736 unlink(name); 760 unlink(name);
761#else
762 int fd_tmp;
763
764 if (!(tmpdir=getenv("TMPDIR")))
765 goto out;
766 tmpfile[i] = xasprintf("%s/difXXXXXX", tmpdir);
767 fd_tmp = xmkstemp(tmpfile[i]);
768#endif
737 if (bb_copyfd_eof(fd, fd_tmp) < 0) 769 if (bb_copyfd_eof(fd, fd_tmp) < 0)
738 xfunc_die(); 770 xfunc_die();
739 if (fd != STDIN_FILENO) 771 if (fd != STDIN_FILENO)
@@ -776,6 +808,14 @@ static int diffreg(char *file[2])
776out: 808out:
777 fclose_if_not_stdin(fp[0]); 809 fclose_if_not_stdin(fp[0]);
778 fclose_if_not_stdin(fp[1]); 810 fclose_if_not_stdin(fp[1]);
811#if ENABLE_PLATFORM_MINGW32
812 for (i = 0; i < 2; i++) {
813 if (tmpfile[i]) {
814 unlink(tmpfile[i]);
815 free(tmpfile[i]);
816 }
817 }
818#endif
779 819
780 return status; 820 return status;
781} 821}
@@ -964,6 +1004,9 @@ static const char diff_longopts[] ALIGN1 =
964 "report-identical-files\0" No_argument "s" 1004 "report-identical-files\0" No_argument "s"
965 "starting-file\0" Required_argument "S" 1005 "starting-file\0" Required_argument "S"
966 "minimal\0" No_argument "d" 1006 "minimal\0" No_argument "d"
1007#if ENABLE_PLATFORM_MINGW32
1008 "binary\0" No_argument "\xff"
1009#endif
967 ; 1010 ;
968# define GETOPT32 getopt32long 1011# define GETOPT32 getopt32long
969# define LONGOPTS ,diff_longopts 1012# define LONGOPTS ,diff_longopts
@@ -1019,6 +1062,11 @@ int diff_main(int argc UNUSED_PARAM, char **argv)
1019 * 255, or if a local inode number (st_ino) exceeds 16777215. 1062 * 255, or if a local inode number (st_ino) exceeds 16777215.
1020 */ 1063 */
1021 if (ENABLE_DESKTOP 1064 if (ENABLE_DESKTOP
1065 && (ENABLE_PLATFORM_POSIX || ENABLE_FEATURE_EXTRA_FILE_DATA)
1066#if ENABLE_FEATURE_EXTRA_FILE_DATA
1067 /* ignore invalid inode numbers */
1068 && stb[0].st_ino != 0
1069#endif
1022 && stb[0].st_ino == stb[1].st_ino 1070 && stb[0].st_ino == stb[1].st_ino
1023 && stb[0].st_dev == stb[1].st_dev 1071 && stb[0].st_dev == stb[1].st_dev
1024 && stb[0].st_size == stb[1].st_size 1072 && stb[0].st_size == stb[1].st_size