]> diplodocus.org Git - nmh/blobdiff - sbr/read_line.c
new.c: Order two return statements to match comment.
[nmh] / sbr / read_line.c
index 35d71a7a23b43dab5ad90b09cab22adc3c0019d5..a6367de4112c3f08b41f377bc341c35d2fde371a 100644 (file)
@@ -1,16 +1,28 @@
+/* read_line.c -- read a possibly incomplete line from stdin.
+ *
+ * This code is Copyright (c) 2017, by the authors of nmh.  See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
+ */
+
 #include <h/mh.h>
 #include <h/mh.h>
+#include <h/utils.h>
+#include "read_line.h"
 
 
+/*
+ * Flush standard output, read a line from standard input into a static buffer,
+ * zero out the newline, and return a pointer to the buffer.
+ * On error, return NULL.
+ */
 const char *
 read_line(void)
 {
 const char *
 read_line(void)
 {
-    char *cp;
     static char line[BUFSIZ];
 
     fflush(stdout);
     if (fgets(line, sizeof(line), stdin) == NULL)
             return NULL;
     static char line[BUFSIZ];
 
     fflush(stdout);
     if (fgets(line, sizeof(line), stdin) == NULL)
             return NULL;
-    if ((cp = strchr(line, '\n')))
-       *cp = 0;
-    return line;
-}
+    trim_suffix_c(line, '\n');
 
 
+    return line; /* May not be a complete line. */
+}