Ignore trailing newline from standard in
authorJoachim Breitner <mail@joachim-breitner.de>
Tue, 12 Aug 2008 04:32:23 +0000 (04:32 +0000)
committerJoachim Breitner <mail@joachim-breitner.de>
Tue, 12 Aug 2008 04:32:23 +0000 (04:32 +0000)
Thanks to Chris Lamb <chris@chris-lamb.co.uk> for the patch.

sm.c

diff --git a/sm.c b/sm.c
index e85cf8b..0667965 100644 (file)
--- a/sm.c
+++ b/sm.c
@@ -281,6 +281,11 @@ int main(int argc, char **argv) {
                        while ((num = fread (buf, 1, sizeof(buf), stdin)) > 0) {
                                g_string_append_len(input, buf, num);
                        }
+
+                       // remove trailing newline, if any
+                       if ((input->len > 0) && (input->str[input->len - 1] == '\n')) {
+                               g_string_truncate(input, input->len - 1);
+                       }
                } else {
                        int i;