[gedit] Check if stdin is actually something valid to read from



commit 67b56b465d9b14b802939671eea6773e926d2897
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Sun May 16 20:44:16 2010 +0200

    Check if stdin is actually something valid to read from

 gedit/gedit-utils.c |   15 ++++++++++++---
 gedit/gedit.c       |    8 +++++---
 2 files changed, 17 insertions(+), 6 deletions(-)
---
diff --git a/gedit/gedit-utils.c b/gedit/gedit-utils.c
index 9f7c0f3..618491c 100644
--- a/gedit/gedit-utils.c
+++ b/gedit/gedit-utils.c
@@ -60,6 +60,7 @@
 
 #ifdef G_OS_UNIX
 #include <unistd.h>
+#include <sys/stat.h>
 #endif
 
 #include "gseal-gtk-compat.h"
@@ -1533,10 +1534,18 @@ gboolean
 gedit_utils_can_read_from_stdin (void)
 {
 #ifdef G_OS_UNIX
-	return !isatty (STDIN_FILENO);
-#else
-	return FALSE;
+	if (!isatty (STDIN_FILENO))
+	{
+		struct stat sbuffer;
+
+		if (fstat (STDIN_FILENO, &sbuffer) == 0 &&
+		    (S_ISREG (sbuffer.st_mode) || S_ISFIFO (sbuffer.st_mode) || S_ISLNK (sbuffer.st_mode)))
+		{
+			return TRUE;
+		}
+	}
 #endif
+	return FALSE;
 }
 
 GeditDocumentCompressionType
diff --git a/gedit/gedit.c b/gedit/gedit.c
index ba20b11..8b4eb7b 100644
--- a/gedit/gedit.c
+++ b/gedit/gedit.c
@@ -62,7 +62,7 @@
 #include <unistd.h>
 #endif
 
-static void
+static gboolean
 gedit_main_load_from_stdin (GeditWindow *window,
                             gboolean jump_to)
 {
@@ -89,6 +89,9 @@ gedit_main_load_from_stdin (GeditWindow *window,
 	                                     column_position,
 	                                     jump_to);
 	g_object_unref (stream);
+	return TRUE;
+#else
+	return FALSE;
 #endif
 }
 
@@ -134,8 +137,7 @@ gedit_main_window (void)
 
 	if (gedit_utils_can_read_from_stdin ())
 	{
-		gedit_main_load_from_stdin (window, !doc_created);
-		doc_created = TRUE;
+		doc_created = gedit_main_load_from_stdin (window, !doc_created);
 	}
 
 	if (!doc_created || gedit_command_line_get_new_document (command_line))



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]