aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editors/diff.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/editors/diff.c b/editors/diff.c
index 17d41af8d..d91ecea51 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
161 FLAG_binary,
162#endif
157}; 163};
158#define FLAG(x) (1 << FLAG_##x) 164#define FLAG(x) (1 << FLAG_##x)
159 165
@@ -720,7 +726,12 @@ static int diffreg(char *file[2])
720 int fd = STDIN_FILENO; 726 int fd = STDIN_FILENO;
721 if (!LONE_DASH(file[i])) { 727 if (!LONE_DASH(file[i])) {
722 if (!(option_mask32 & FLAG(N))) { 728 if (!(option_mask32 & FLAG(N))) {
729#if ENABLE_PLATFORM_MINGW32
730 int flag = (option_mask32 & FLAG(binary)) ? 0 : _O_TEXT;
731 fd = open_or_warn(file[i], O_RDONLY | flag);
732#else
723 fd = open_or_warn(file[i], O_RDONLY); 733 fd = open_or_warn(file[i], O_RDONLY);
734#endif
724 if (fd == -1) 735 if (fd == -1)
725 goto out; 736 goto out;
726 } else { 737 } else {
@@ -751,10 +762,21 @@ static int diffreg(char *file[2])
751 xfunc_die(); 762 xfunc_die();
752 if (fd != STDIN_FILENO) 763 if (fd != STDIN_FILENO)
753 close(fd); 764 close(fd);
765#if ENABLE_PLATFORM_MINGW32
766 if (!(option_mask32 & FLAG(binary))) {
767 /* Close and reopen tmpfile to get text mode */
768 close(fd_tmp);
769 fd_tmp = xopen(tmpfile[i], O_RDONLY | _O_TEXT);
770 }
771#endif
754 fd = fd_tmp; 772 fd = fd_tmp;
755 xlseek(fd, 0, SEEK_SET); 773 xlseek(fd, 0, SEEK_SET);
756 } 774 }
775#if ENABLE_PLATFORM_MINGW32
776 fp[i] = fdopen(fd, (option_mask32 & FLAG(binary)) ? "r" : "rt");
777#else
757 fp[i] = fdopen(fd, "r"); 778 fp[i] = fdopen(fd, "r");
779#endif
758 } 780 }
759 781
760 setup_common_bufsiz(); 782 setup_common_bufsiz();
@@ -985,6 +1007,9 @@ static const char diff_longopts[] ALIGN1 =
985 "report-identical-files\0" No_argument "s" 1007 "report-identical-files\0" No_argument "s"
986 "starting-file\0" Required_argument "S" 1008 "starting-file\0" Required_argument "S"
987 "minimal\0" No_argument "d" 1009 "minimal\0" No_argument "d"
1010#if ENABLE_PLATFORM_MINGW32
1011 "binary\0" No_argument "\xff"
1012#endif
988 ; 1013 ;
989# define GETOPT32 getopt32long 1014# define GETOPT32 getopt32long
990# define LONGOPTS ,diff_longopts 1015# define LONGOPTS ,diff_longopts