David Bridson wrote:
Hi!
I just ran into a problem checking an md5 file with \r\n line endings.
md5sum checks for \n line endings but not \r\n so, where an \r\n is
present, tries to fopen the correct filename with a \r appended. Here's
a simple patch to fix the problem.
Cheers,
Dave
--- coreutils-5.3.0/src/md5sum.c 2004-09-20 08:40:39.000000000 +0100
+++ coreutils-updated/src/md5sum.c 2005-03-23 16:48:16.000000000 +0000
@@ -433,7 +433,17 @@
/* Remove any trailing newline. */
if (line[line_length - 1] == '\n')
- line[--line_length] = '\0';
+ {
+ if (line[line_length - 2] == '\r')
+ {
+ line[--line_length] = '\0';
+ line[--line_length] = '\0';
+ }
+ else
+ {
+ line[--line_length] = '\0';
+ }
+ }
if (! (split_3 (line, line_length, &hex_digest, &binary, &filename)
&& hex_digits (hex_digest)))
Yuck! couldn't you just do:
if (line[line_length - 1] == '\n')
line[--line_length] = '\0';
if (line[line_length - 1] == '\r')
line[--line_length] = '\0';
That would handle the mac case also.
I'm not sure this is even required though.
What if you filename did end with '\r' ? unlikely but...
You can always `tr -d '\r'` the file first.
P�draig.
_______________________________________________
Bug-coreutils mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-coreutils