diff options
author | Jim Meyering <jim@meyering.net> | 1995-07-30 23:57:03 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1995-07-30 23:57:03 +0000 |
commit | fc88df745835bb27d23df5099ca5f2b612b2a2d9 (patch) | |
tree | 2f0010c5eb72fb5b9ecfbf6965c4b808572af60b | |
parent | 11ec25d3cefc3f8cac9f44f5237d52e1ccdfdb9a (diff) | |
download | coreutils-fc88df745835bb27d23df5099ca5f2b612b2a2d9.tar.xz |
(md5_check): Use getline instead of fgets.
-rw-r--r-- | src/md5sum.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/md5sum.c b/src/md5sum.c index 7968bb124..408662952 100644 --- a/src/md5sum.c +++ b/src/md5sum.c @@ -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); |