Closed yindian closed 1 year ago
Unfortunately the suggested patch breaks diff
without --binary
for files with LF line endings:
~ $ diff abcd.lf abde.lf
--- abcd.lf
+++ abde.lf
@@ -1,4 +1,4 @@
a
b
-c
-d
+b
d
+e
Keeping track of the position in the file for both text mode and binary mode looks hard. I've gone back to using the default binary mode along with skipping the CR of CRLF line endings. It's not perfect but it's simple.
Try the most recent prerelease binary.
Thanks for your update. I have tried the latest prerelease binary and it works for both CRLF and LF input now.
It is true that my original patch does not work with LF line ending correctly, and I did not perform enough test before posting. It seems that ftello() would return unexpected result for LF-only text files, e.g. return -1 after 'a' and '\n' are read. Your solution is much better and could get around the crappy MS CRT issue with less footprint.
It seems that since the introduction of --binary flag to diff applet, the diff output has been incorrect for files with CRLF line endings, unless --binary is specified. For example, say there are two files abcd and abde with 4 lines of single character, the current output of
busybox diff abcd abde
is:while the supposed correct output is:
It seems to be related to improper
ft_pos
value in text mode. I have drafted a patch which seems to work, listed below for your reference.