]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(md5_check): Use getline instead of fgets.
authorJim Meyering <jim@meyering.net>
Sun, 30 Jul 1995 23:57:03 +0000 (23:57 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 30 Jul 1995 23:57:03 +0000 (23:57 +0000)
src/md5sum.c

index 7968bb1242d1e3beddba5350761b2bb4e23283d9..408662952feaa45451569aeca95fc09d124ca40a 100644 (file)
@@ -27,6 +27,7 @@
 #include <sys/types.h>
 
 #include "md5.h"
+#include "getline.h"
 #include "system.h"
 #include "error.h"
 #include "version.h"
@@ -247,6 +248,8 @@ md5_check (checkfile_name, binary)
   int n_tests_failed = 0;
   unsigned char md5buffer[16];
   size_t line_number;
+  char *line;
+  size_t line_chars_allocated;
 
   if (strcmp (checkfile_name, "-") == 0)
     {
@@ -265,18 +268,20 @@ md5_check (checkfile_name, binary)
     }
 
   line_number = 0;
+  line = NULL;
+  line_chars_allocated = 0;
   do
     {
-      char line[1024];
       char *filename;
       int type_flag;
       char *md5num;
       int err;
+      int line_length;
 
       ++line_number;
 
-      /* FIXME: Use getline, not fgets.  */
-      if (fgets (line, 1024, checkfile_stream) == NULL)
+      line_length = getline (&line, &line_chars_allocated, checkfile_stream);
+      if (line_length <= 0)
        break;
 
       /* Ignore comment lines, which begin with a '#' character.  */
@@ -284,15 +289,14 @@ md5_check (checkfile_name, binary)
        continue;
 
       /* Remove any trailing newline.  */
-      if (line[strlen (line) - 1] == '\n')
-       line[strlen (line) - 1] = '\0';
+      if (line[line_length - 1] == '\n')
+       line[--line_length] = '\0';
 
       err = split_3 (line, &md5num, &type_flag, &filename);
       if (err || !hex_digits (md5num))
        {
          if (verbose)
            {
-             /* FIXME: use fprintf rather than error?  */
              error (0, 0, _("%s: %lu: invalid MD5 checksum line"),
                     checkfile_name, (unsigned long) line_number);
            }
@@ -337,6 +341,10 @@ md5_check (checkfile_name, binary)
     }
   while (!feof (checkfile_stream) && !ferror (checkfile_stream));
 
+  /* FIXME: check ferror!!  */
+  if (line)
+    free (line);
+
   if (checkfile_stream != stdin && fclose (checkfile_stream) == EOF)
     {
       error (0, errno, "%s", checkfile_name);