bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PATCH to enable reading of \r\n Newlines in md5sum


From: Padraig Brady
Subject: Re: PATCH to enable reading of \r\n Newlines in md5sum
Date: Wed, 23 Mar 2005 17:51:28 +0000
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040124

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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]