diff --git a/src/common/cfgfiles.c b/src/common/cfgfiles.c index af674111..f3271ef1 100644 --- a/src/common/cfgfiles.c +++ b/src/common/cfgfiles.c @@ -1361,3 +1361,25 @@ stream_writef (GOutputStream *ostream, const char *fmt, ...) return ret; } + +GDataInputStream * +file_get_datainputstream (GFile *file) +{ + GInputStream *stream; + GDataInputStream *datastream; + + stream = G_INPUT_STREAM(g_file_read (file, NULL, NULL)); + if (!stream) + return NULL; + + datastream = g_data_input_stream_new (stream); + /* + * This is to avoid any issues moving between windows/unix + * but the docs mention an invalid \r without a following \n + * can lock up the program + */ + g_data_input_stream_set_newline_type (datastream, G_DATA_STREAM_NEWLINE_TYPE_ANY); + g_object_unref (stream); + + return datastream; +} diff --git a/src/common/cfgfiles.h b/src/common/cfgfiles.h index 689b48c8..e4927cdb 100644 --- a/src/common/cfgfiles.h +++ b/src/common/cfgfiles.h @@ -53,6 +53,7 @@ int hexchat_open_file (const char *file, int flags, int mode, int xof_flags); FILE *hexchat_fopen_file (const char *file, const char *mode, int xof_flags); GFile *hexchat_open_gfile (const char *filename); gsize stream_writef (GOutputStream *ostream, const char *fmt, ...) G_GNUC_PRINTF (2, 3); +GDataInputStream *file_get_datainputstream (GFile *file); #define XOF_DOMODE 1 #define XOF_FULLPATH 2 diff --git a/src/common/servlist.c b/src/common/servlist.c index 6e8d6694..a7955eae 100644 --- a/src/common/servlist.c +++ b/src/common/servlist.c @@ -999,7 +999,6 @@ static int servlist_load (void) { GFile *file; - GInputStream *stream; GDataInputStream *istream; gchar *buf; ircnet *net = NULL; @@ -1019,13 +1018,10 @@ servlist_load (void) file = hexchat_open_gfile ("servlist.conf"); - stream = G_INPUT_STREAM(g_file_read (file, NULL, NULL)); - if (!stream) + istream = file_get_datainputstream (file); + if (!istream) return FALSE; - istream = g_data_input_stream_new (stream); - g_data_input_stream_set_newline_type (istream, G_DATA_STREAM_NEWLINE_TYPE_ANY); - g_object_unref (stream); while ((buf = g_data_input_stream_read_line_utf8 (istream, NULL, NULL, NULL))) { diff --git a/src/common/text.c b/src/common/text.c index c2db9254..9822c507 100644 --- a/src/common/text.c +++ b/src/common/text.c @@ -218,7 +218,6 @@ scrollback_save (session *sess, char *text, time_t stamp) void scrollback_load (session *sess) { - GInputStream *stream; GDataInputStream *istream; gchar *buf, *text; gint lines = 0; @@ -244,19 +243,10 @@ scrollback_load (session *sess) g_free (buf); } - stream = G_INPUT_STREAM(g_file_read (sess->scrollfile, NULL, NULL)); - if (!stream) + istream = file_get_datainputstream (sess->scrollfile); + if (!istream) return; - istream = g_data_input_stream_new (stream); - /* - * This is to avoid any issues moving between windows/unix - * but the docs mention an invalid \r without a following \n - * can lock up the program... (Our write() always adds \n) - */ - g_data_input_stream_set_newline_type (istream, G_DATA_STREAM_NEWLINE_TYPE_ANY); - g_object_unref (stream); - while (1) { GError *err = NULL;