changeset 18256:54251fa6389d

reading only necessary part of log file using g_fopen/fseek/fread
author Michael Shkutkov <mshkutkov@soc.pidgin.im>
date Tue, 26 Jun 2007 19:53:55 +0000
parents 507fb436d8c0
children b246ffeb4756
files libpurple/plugins/log_reader.c
diffstat 1 files changed, 14 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/plugins/log_reader.c	Tue Jun 26 11:11:40 2007 +0000
+++ b/libpurple/plugins/log_reader.c	Tue Jun 26 19:53:55 2007 +0000
@@ -1912,6 +1912,8 @@
 	char *selected;
 	GError *error;
 	char *utf8_string;
+	FILE *file;
+
 
 	g_return_val_if_fail(log != NULL, g_strdup(""));
 
@@ -1921,18 +1923,18 @@
 	g_return_val_if_fail(data->length > 0, g_strdup(""));
 
 	error = NULL;
-	if (!g_file_get_contents(data->path, &contents, NULL, &error)) {
-		purple_debug_error("QIP logger",
-			"Couldn't read file %s: %s \n", data->path, error->message);
-		g_error_free(error);
-		return g_strdup("");
-	}
-
-	selected = g_strndup(contents + data->offset, data->length + 2);
-	selected[data->length] = '\n';
-	selected[data->length + 1] = '\0';
-	g_free(contents);
-	contents = selected;
+	
+	contents = g_malloc(data->length + 2);
+
+	file = g_fopen(data->path, "rb");
+	g_return_val_if_fail(file != NULL, g_strdup(""));
+	
+	fseek(file, data->offset, SEEK_SET);
+	fread(contents, data->length, 1, file);
+	fclose(file);
+
+	contents[data->length] = '\n';
+	contents[data->length + 1] = '\0';
 
 	/* Convert file contents from Cp1251 to UTF-8 codeset */
 	error = NULL;