Use GIOChannel to read from stdin
authorJoachim Breitner <mail@joachim-breitner.de>
Sat, 24 Nov 2012 12:12:19 +0000 (12:12 +0000)
committerJoachim Breitner <mail@joachim-breitner.de>
Sat, 24 Nov 2012 12:12:19 +0000 (12:12 +0000)
sm.c

diff --git a/sm.c b/sm.c
index 53098d2..a1452b0 100644 (file)
--- a/sm.c
+++ b/sm.c
@@ -1,6 +1,6 @@
 /*
 #     sm.c
-#     Copyright (C) 2006 - 2010 Joachim Breitner
+#     Copyright (C) 2006 - 2012 Joachim Breitner
 #
 #     The Code for making a window fullscreen was taken from src/fullscreen.c in
 #     the geeqie package:
@@ -317,17 +317,16 @@ int main(int argc, char **argv) {
        if (argc > optind)
                if (!strcmp(argv[optind], "-") ) {
                        // read from stdin
-                       gchar buf[1024];
-                       int num;
+                       GIOChannel *chan = g_io_channel_unix_new(0);
 
-                       input = g_string_new("");
-
-                       while ((num = fread (buf, 1, sizeof(buf), stdin)) > 0) {
-                               g_string_append_len(input, buf, num);
-                       }
+                       gchar *buf;
+                       gsize len;
+                       g_io_channel_read_to_end (chan, &buf, &len, NULL);
+                       input = g_string_new_len(buf, len);
+                       g_free(buf);
 
-                       // remove trailing newline, if any
-                       if ((input->len > 0) && (input->str[input->len - 1] == '\n')) {
+                       // remove trailing newlines, if any
+                       while ((input->len > 0) && (input->str[input->len - 1] == '\n')) {
                                g_string_truncate(input, input->len - 1);
                        }
                        input_provided++;