From: <ro...@us...> - 2006-08-02 02:42:19
|
Revision: 16612 Author: roast Date: 2006-08-01 19:42:14 -0700 (Tue, 01 Aug 2006) ViewCVS: http://svn.sourceforge.net/gaim/?rev=16612&view=rev Log Message: ----------- log_reader: trillian_logger_read() now uses giochannels Modified Paths: -------------- branches/soc-2006-file-loggers/plugins/log_reader.c Modified: branches/soc-2006-file-loggers/plugins/log_reader.c =================================================================== --- branches/soc-2006-file-loggers/plugins/log_reader.c 2006-08-02 02:23:04 UTC (rev 16611) +++ branches/soc-2006-file-loggers/plugins/log_reader.c 2006-08-02 02:42:14 UTC (rev 16612) @@ -1279,7 +1279,9 @@ { struct trillian_logger_data *data; char *read; - FILE *file; + int filedes = 0; + GIOChannel *channel; + GIOStatus iostat; GaimBuddy *buddy; char *escaped; GString *formatted; @@ -1299,10 +1301,33 @@ read = g_malloc(data->length + 2); - file = g_fopen(data->path, "rb"); - fseek(file, data->offset, SEEK_SET); - fread(read, data->length, 1, file); - fclose(file); + // try to open the file + if (!(filedes = open(data->path, O_RDONLY))) { + return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); + } + // create the giochannel + channel = g_io_channel_unix_new(filedes); + // read from it + if (g_io_channel_read_to_end(channel, &read, NULL, NULL) != G_IO_STATUS_NORMAL) { + // if reading the file wasn't successful... + close(filedes); + return g_strdup("Trillian Log Failed to read the file"); + } + // seek to the right position + iostat = g_io_channel_seek_position(channel, data->offset, G_SEEK_SET, NULL); + if (iostat == G_IO_STATUS_ERROR) { + gaim_debug_info("log_reader", "trillian_logger_read could not seek to the right place to read data from\n"); + return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); + } + // read data->length long + iostat = g_io_channel_read_chars(channel, read, data->length, NULL, NULL); + if (iostat == G_IO_STATUS_ERROR) { + gaim_debug_info("log_reader", "trillian_logger_read could not read data from the logfile\n"); + return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); + } + // we're done reading + g_io_channel_shutdown(channel, FALSE, NULL); + close(filedes); if (read[data->length-1] == '\n') { read[data->length] = '\0'; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |