evolution r35615 - branches/gnome-2-22/e-util



Author: mcrha
Date: Mon Jun  9 09:40:53 2008
New Revision: 35615
URL: http://svn.gnome.org/viewvc/evolution?rev=35615&view=rev

Log:
2008-06-09  Milan Crha  <mcrha redhat com>

	** Fix for bug #509595

	* e-logger.c: (e_logger_get_logs): Do not crash if file does not
	exists. Also be able to read lines more than 249 characters long.



Modified:
   branches/gnome-2-22/e-util/ChangeLog
   branches/gnome-2-22/e-util/e-logger.c

Modified: branches/gnome-2-22/e-util/e-logger.c
==============================================================================
--- branches/gnome-2-22/e-util/e-logger.c	(original)
+++ branches/gnome-2-22/e-util/e-logger.c	Mon Jun  9 09:40:53 2008
@@ -151,23 +151,46 @@
 {
 	FILE *fp;
 	char buf[250];
-	gboolean error = FALSE;
 
 	/* Flush everything before we get the logs */
 	fflush (el->priv->fp);	
 	fp = g_fopen (el->priv->logfile, "r");
-	while (!error || feof(fp)) {
+
+	if (!fp) {
+		fprintf (stderr, "Cannot open log file '%s' for reading! No flush yet?\n", el->priv->logfile ? el->priv->logfile : "[null]");
+		return;
+	}
+
+	while (!feof (fp)) {
 		char *tmp;
-		tmp = fgets (buf, 250, fp);
+		size_t len;
+
+		tmp = fgets (buf, sizeof (buf), fp);
 		if (!tmp)
 			break;
-#if 0		
-		if (strlen(tmp) == 249) {
-			/* FIXME: There may be more */
-		}
-#endif 		
-		func (tmp, data);
+
+		len = strlen (tmp);
+		if (len > 0 && tmp [len - 1] != '\n' && !feof (fp)) {
+			/* there are more characters on a row than 249, so read them all */
+			GString *str = g_string_sized_new (1024);
+
+			g_string_append (str, tmp);
+
+			while (!feof (fp) && len > 0 && tmp [len - 1] != '\n') {
+				tmp = fgets (buf, sizeof (buf), fp);
+				if (!tmp)
+					break;
+
+				len = strlen (tmp);
+				g_string_append (str, tmp);
+			}
+
+			func (str->str, data);
+
+			g_string_free (str, TRUE);
+		} else
+			func (tmp, data);
 	}
-	fclose(fp);
-}
 
+	fclose (fp);
+}



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