]> git.draconx.ca Git - cdecl99.git/blobdiff - t/normalize.c
Avoid gnulib getline module.
[cdecl99.git] / t / normalize.c
index e11e6484f94ba0ca6479678b8a02dd3249d488ec..e309d70ec08b9be3be1cb3c8dc423ba1a51ca336 100644 (file)
@@ -27,6 +27,7 @@
 
 #define PROGNAME "normalize"
 #include "test.h"
+#include "getline.h"
 
 static const char sopts[] = "f:VH";
 static const struct option lopts[] = {
@@ -191,17 +192,12 @@ int main(int argc, char **argv)
                }
        }
 
-       if (filename) {
-               infile = fopen(filename, "r");
-               if (!infile) {
-                       perror(filename);
-                       return EXIT_FAILURE;
-               }
+       if (filename && !freopen(filename, "r", stdin)) {
+               print_error("%s: %s", filename, strerror(errno));
+               return EXIT_FAILURE;
        }
 
-       while ((rc = getline(&line, &n, infile)) >= 0) {
-               if (rc > 0 && line[rc-1] == '\n')
-                       line[rc-1] = 0;
+       while (do_getline(&line, &n)) {
                if (do_normalize(line, n) < 0)
                        ret = EXIT_FAILURE;
        }