Compare commits

...

7 Commits

Author SHA1 Message Date
TingPing
eafc1e2b70 Use Gio for url logger 2016-01-31 16:20:10 -05:00
TingPing
06d323025d Use Gio for load_perform_file() 2016-01-31 16:20:10 -05:00
TingPing
c0c2668c10 Use Gio for random_line() 2016-01-31 16:20:10 -05:00
TingPing
7cf631f93c Create convenience function to get datastreams 2016-01-31 16:16:18 -05:00
TingPing
f5142c6724 Use Gio for cfgfiles 2016-01-31 16:15:14 -05:00
TingPing
3ba5581c6b Move writeline func to cfgfiles 2016-01-31 15:40:16 -05:00
TingPing
d825b3514b Use Gio for servlist.conf 2016-01-31 15:39:08 -05:00
11 changed files with 282 additions and 224 deletions

View File

@ -77,7 +77,7 @@ list_addentry (GSList ** list, char *cmd, char *name)
/* read it in from a buffer to our linked list */ /* read it in from a buffer to our linked list */
static void static void
list_load_from_data (GSList ** list, char *ibuf, int size) list_load_from_data (GSList ** list, char *ibuf, gsize size)
{ {
char cmd[384]; char cmd[384];
char name[128]; char name[128];
@ -110,36 +110,28 @@ list_load_from_data (GSList ** list, char *ibuf, int size)
} }
void void
list_loadconf (char *file, GSList ** list, char *defaultconf) list_loadconf (char *filename, GSList ** list, char *defaultconf)
{ {
char *filebuf; GFile *file;
char *ibuf; char *data;
int fd; gsize len;
struct stat st;
filebuf = g_build_filename (get_xdir (), file, NULL); file = hexchat_open_gfile (filename);
fd = g_open (filebuf, O_RDONLY | OFLAGS, 0);
g_free (filebuf);
if (fd == -1) if (!g_file_query_exists (file, NULL))
{ {
if (defaultconf) if (defaultconf)
list_load_from_data (list, defaultconf, strlen (defaultconf)); list_load_from_data (list, defaultconf, strlen (defaultconf));
return; return;
} }
if (fstat (fd, &st) != 0)
if (g_file_load_contents (file, NULL, &data, &len, NULL, NULL))
{ {
perror ("fstat"); list_load_from_data (list, data, len);
abort (); g_free (data);
} }
ibuf = g_malloc (st.st_size); g_object_unref (file);
read (fd, ibuf, st.st_size);
close (fd);
list_load_from_data (list, ibuf, st.st_size);
g_free (ibuf);
} }
void void
@ -214,40 +206,25 @@ cfg_get_str (char *cfg, const char *var, char *dest, int dest_len)
} }
} }
static int int
cfg_put_str (int fh, char *var, char *value) cfg_put_str (GOutputStream *ostream, const char *var, const char *value)
{ {
char buf[512]; return (stream_writef (ostream, "%s = %s\n", var, value) != 0);
int len;
g_snprintf (buf, sizeof buf, "%s = %s\n", var, value);
len = strlen (buf);
return (write (fh, buf, len) == len);
} }
int int
cfg_put_color (int fh, guint16 r, guint16 g, guint16 b, char *var) cfg_put_color (GOutputStream *ostream, guint16 r, guint16 g, guint16 b, char *var)
{ {
char buf[400]; return (stream_writef (ostream, "%s = %04x %04x %04x\n", var, r, g, b) != 0);
int len;
g_snprintf (buf, sizeof buf, "%s = %04hx %04hx %04hx\n", var, r, g, b);
len = strlen (buf);
return (write (fh, buf, len) == len);
} }
int int
cfg_put_int (int fh, int value, char *var) cfg_put_int (GOutputStream *ostream, int value, char *var)
{ {
char buf[400];
int len;
if (value == -1) if (value == -1)
value = 1; value = 1;
g_snprintf (buf, sizeof buf, "%s = %d\n", var, value); return (stream_writef (ostream, "%s = %d\n", var, value) != 0);
len = strlen (buf);
return (write (fh, buf, len) == len);
} }
int int
@ -338,18 +315,6 @@ check_config_dir (void)
return g_access (get_xdir (), F_OK); return g_access (get_xdir (), F_OK);
} }
static char *
default_file (void)
{
static char *dfile = NULL;
if (!dfile)
{
dfile = g_build_filename (get_xdir (), "hexchat.conf", NULL);
}
return dfile;
}
/* Keep these sorted!! */ /* Keep these sorted!! */
const struct prefs vars[] = const struct prefs vars[] =
@ -953,13 +918,21 @@ make_dcc_dirs (void)
int int
load_config (void) load_config (void)
{ {
GFile *file;
char *cfg, *sp; char *cfg, *sp;
int res, val, i; int res, val, i;
g_assert(check_config_dir () == 0); g_assert(check_config_dir () == 0);
if (!g_file_get_contents (default_file (), &cfg, NULL, NULL)) file = hexchat_open_gfile ("hexchat.conf");
if (!g_file_load_contents (file, NULL, &cfg, NULL, NULL, NULL))
{
g_object_unref (file);
return -1; return -1;
}
g_object_unref (file);
/* If the config is incomplete we have the default values loaded */ /* If the config is incomplete we have the default values loaded */
load_default_config(); load_default_config();
@ -1001,26 +974,26 @@ load_config (void)
int int
save_config (void) save_config (void)
{ {
int fh, i; GFile *file, *tmpfile;
char *config, *new_config; GOutputStream *ostream;
GFileIOStream *tmpstream;
gboolean ret;
int i;
if (check_config_dir () != 0) if (check_config_dir () != 0)
make_config_dirs (); make_config_dirs ();
config = default_file (); tmpfile = g_file_new_tmp (NULL, &tmpstream, NULL);
new_config = g_strconcat (config, ".new", NULL); if (!tmpfile)
fh = g_open (new_config, OFLAGS | O_TRUNC | O_WRONLY | O_CREAT, 0600);
if (fh == -1)
{ {
g_free (new_config);
return 0; return 0;
} }
if (!cfg_put_str (fh, "version", PACKAGE_VERSION)) ostream = g_io_stream_get_output_stream (G_IO_STREAM(tmpstream));
if (!cfg_put_str (ostream, "version", PACKAGE_VERSION))
{ {
close (fh); g_object_unref (tmpfile);
g_free (new_config);
return 0; return 0;
} }
@ -1030,19 +1003,17 @@ save_config (void)
switch (vars[i].type) switch (vars[i].type)
{ {
case TYPE_STR: case TYPE_STR:
if (!cfg_put_str (fh, vars[i].name, (char *) &prefs + vars[i].offset)) if (!cfg_put_str (ostream, vars[i].name, (char *) &prefs + vars[i].offset))
{ {
close (fh); g_object_unref (tmpfile);
g_free (new_config);
return 0; return 0;
} }
break; break;
case TYPE_INT: case TYPE_INT:
case TYPE_BOOL: case TYPE_BOOL:
if (!cfg_put_int (fh, *((int *) &prefs + vars[i].offset), vars[i].name)) if (!cfg_put_int (ostream, *((int *) &prefs + vars[i].offset), vars[i].name))
{ {
close (fh); g_object_unref (tmpfile);
g_free (new_config);
return 0; return 0;
} }
} }
@ -1050,23 +1021,15 @@ save_config (void)
} }
while (vars[i].name); while (vars[i].name);
if (close (fh) == -1) g_object_unref (ostream);
{
g_free (new_config);
return 0;
}
#ifdef WIN32 file = hexchat_open_gfile ("hexchat.conf");
g_unlink (config); /* win32 can't rename to an existing file */ ret = g_file_move (tmpfile, file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL);
#endif
if (g_rename (new_config, config) == -1)
{
g_free (new_config);
return 0;
}
g_free (new_config);
return 1; g_object_unref (tmpfile);
g_object_unref (file);
return ret;
} }
static void static void
@ -1357,3 +1320,69 @@ hexchat_fopen_file (const char *file, const char *mode, int xof_flags)
return fh; return fh;
} }
/*
* Returns a #GFile* to a file in HexChat's config dir.
* Must be g_object_unref()'d when done.
* @filename must be in utf8 encoding.
*/
GFile *
hexchat_open_gfile (const char *filename)
{
GFile *file;
gchar *full_path, *full_path_fs;
if (g_path_is_absolute (filename))
full_path = g_strdup (filename);
else
full_path = g_build_filename (get_xdir(), filename, NULL);
full_path_fs = g_filename_from_utf8 (full_path, -1, NULL, NULL, NULL);
file = g_file_new_for_path (full_path_fs);
g_free (full_path);
g_free (full_path_fs);
return file;
}
G_GNUC_PRINTF (2, 3)
gsize
stream_writef (GOutputStream *ostream, const char *fmt, ...)
{
char *tmp;
va_list args;
gint len;
gsize ret;
va_start (args, fmt);
len = g_vasprintf (&tmp, fmt, args);
va_end (args);
ret = g_output_stream_write (ostream, tmp, len, NULL, NULL);
g_free (tmp);
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;
}

View File

@ -30,12 +30,13 @@ extern char *xdir;
extern const char * const languages[LANGUAGES_LENGTH]; extern const char * const languages[LANGUAGES_LENGTH];
char *cfg_get_str (char *cfg, const char *var, char *dest, int dest_len); char *cfg_get_str (char *cfg, const char *var, char *dest, int dest_len);
int cfg_put_str (GOutputStream *ostream, const char *var, const char *value);
int cfg_get_bool (char *var); int cfg_get_bool (char *var);
int cfg_get_int_with_result (char *cfg, char *var, int *result); int cfg_get_int_with_result (char *cfg, char *var, int *result);
int cfg_get_int (char *cfg, char *var); int cfg_get_int (char *cfg, char *var);
int cfg_put_int (int fh, int value, char *var); int cfg_put_int (GOutputStream *ostream, int value, char *var);
int cfg_get_color (char *cfg, char *var, guint16 *r, guint16 *g, guint16 *b); int cfg_get_color (char *cfg, char *var, guint16 *r, guint16 *g, guint16 *b);
int cfg_put_color (int fh, guint16 r, guint16 g, guint16 b, char *var); int cfg_put_color (GOutputStream *ostream, guint16 r, guint16 g, guint16 b, char *var);
char *get_xdir (void); char *get_xdir (void);
int check_config_dir (void); int check_config_dir (void);
void load_default_config (void); void load_default_config (void);
@ -44,12 +45,15 @@ int make_dcc_dirs (void);
int load_config (void); int load_config (void);
int save_config (void); int save_config (void);
void list_free (GSList ** list); void list_free (GSList ** list);
void list_loadconf (char *file, GSList ** list, char *defaultconf); void list_loadconf (char *filename, GSList ** list, char *defaultconf);
int list_delentry (GSList ** list, char *name); int list_delentry (GSList ** list, char *name);
void list_addentry (GSList ** list, char *cmd, char *name); void list_addentry (GSList ** list, char *cmd, char *name);
int cmd_set (session *sess, char *tbuf, char *word[], char *word_eol[]); int cmd_set (session *sess, char *tbuf, char *word[], char *word_eol[]);
int hexchat_open_file (const char *file, int flags, int mode, int xof_flags); 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); 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_DOMODE 1
#define XOF_FULLPATH 2 #define XOF_FULLPATH 2

View File

@ -78,40 +78,72 @@ notc_msg (struct session *sess)
static char * static char *
random_line (char *file_name) random_line (char *file_name)
{ {
FILE *fh; GFile *file;
char buf[512]; char *data, *p, *ret = NULL;
int lines, ran; int lines = 0, ran;
gsize len;
if (!file_name[0]) if (!file_name[0])
goto nofile; return g_strdup ("");
fh = hexchat_fopen_file (file_name, "r", 0); file = hexchat_open_gfile (file_name);
if (!fh)
if (!g_file_query_exists (file, NULL))
{ {
nofile:
/* reason is not a file, an actual reason! */ /* reason is not a file, an actual reason! */
return g_strdup (file_name); return g_strdup (file_name);
} }
/* count number of lines in file */ if (!g_file_load_contents (file, NULL, &data, &len, NULL, NULL))
lines = 0;
while (fgets (buf, sizeof (buf), fh))
lines++;
if (lines < 1)
goto nofile;
/* go down a random number */
rewind (fh);
ran = RAND_INT (lines);
do
{ {
fgets (buf, sizeof (buf), fh); g_object_unref (file);
lines--; return g_strdup (file_name);
} }
while (lines > ran);
fclose (fh); g_object_unref (file);
return g_strdup (buf);
/* count number of lines in file */
p = data;
while (p != data + len)
{
if (*p == '\n')
lines++;
p++;
}
if (!lines)
{
g_free (data);
return g_strdup (file_name);
}
/* create random number */
ran = RAND_INT (lines);
/* get that random line */
p = data;
while (p != data + len)
{
if (*p == '\n')
{
if (!--ran)
{
char *end;
end = strchr (++p, '\n');
*end = '\0';
ret = g_strdup (p);
break;
}
}
p++;
}
g_free (data);
if (ret)
return ret;
else
return g_strdup (file_name);
} }
void void
@ -2487,30 +2519,32 @@ cmd_list (struct session *sess, char *tbuf, char *word[], char *word_eol[])
} }
gboolean gboolean
load_perform_file (session *sess, char *file) load_perform_file (session *sess, char *filename)
{ {
char tbuf[1024 + 4]; GFile *file;
char *nl; GDataInputStream *istream;
FILE *fp; gchar *buf;
fp = hexchat_fopen_file (file, "r", 0); /* load files from config dir */ file = hexchat_open_gfile (filename);
if (!fp)
return FALSE;
tbuf[1024] = 0; istream = file_get_datainputstream (file);
while (fgets (tbuf, 1024, fp)) if (!istream)
{ {
nl = strchr (tbuf, '\n'); g_object_unref (file);
if (nl == tbuf) /* skip empty commands */ return FALSE;
continue;
if (nl)
*nl = 0;
if (tbuf[0] == prefs.hex_input_command_char[0])
handle_command (sess, tbuf + 1, TRUE);
else
handle_command (sess, tbuf, TRUE);
} }
fclose (fp);
while ((buf = g_data_input_stream_read_line_utf8 (istream, NULL, NULL, NULL)))
{
if (g_str_has_prefix (buf, prefs.hex_input_command_char))
handle_command (sess, buf + 1, TRUE);
else
handle_command (sess, buf, TRUE);
g_free (buf);
}
g_object_unref (file);
g_object_unref (istream);
return TRUE; return TRUE;
} }

View File

@ -998,9 +998,9 @@ servlist_load_defaults (void)
static int static int
servlist_load (void) servlist_load (void)
{ {
FILE *fp; GFile *file;
char buf[2048]; GDataInputStream *istream;
int len; gchar *buf;
ircnet *net = NULL; ircnet *net = NULL;
/* simple migration we will keep for a short while */ /* simple migration we will keep for a short while */
@ -1015,15 +1015,16 @@ servlist_load (void)
g_free (oldfile); g_free (oldfile);
g_free (newfile); g_free (newfile);
fp = hexchat_fopen_file ("servlist.conf", "r", 0);
if (!fp) file = hexchat_open_gfile ("servlist.conf");
istream = file_get_datainputstream (file);
if (!istream)
return FALSE; return FALSE;
while (fgets (buf, sizeof (buf) - 2, fp))
while ((buf = g_data_input_stream_read_line_utf8 (istream, NULL, NULL, NULL)))
{ {
len = strlen (buf);
buf[len] = 0;
buf[len-1] = 0; /* remove the trailing \n */
if (net) if (net)
{ {
switch (buf[0]) switch (buf[0])
@ -1096,8 +1097,12 @@ servlist_load (void)
} }
if (buf[0] == 'N') if (buf[0] == 'N')
net = servlist_net_add (buf + 2, /* comment */ NULL, FALSE); net = servlist_net_add (buf + 2, /* comment */ NULL, FALSE);
g_free (buf);
} }
fclose (fp);
g_object_unref (file);
g_object_unref (istream);
return TRUE; return TRUE;
} }
@ -1138,8 +1143,9 @@ servlist_check_encoding (char *charset)
int int
servlist_save (void) servlist_save (void)
{ {
FILE *fp; GFile *file;
char *buf; GOutputStream *ostream;
gchar *buf;
ircnet *net; ircnet *net;
ircserver *serv; ircserver *serv;
commandentry *cmd; commandentry *cmd;
@ -1148,52 +1154,37 @@ servlist_save (void)
GSList *netlist; GSList *netlist;
GSList *cmdlist; GSList *cmdlist;
GSList *favlist; GSList *favlist;
#ifndef WIN32
int first = FALSE;
buf = g_build_filename (get_xdir (), "servlist.conf", NULL); file = hexchat_open_gfile ("servlist.conf");
if (g_access (buf, F_OK) != 0)
first = TRUE;
#endif
fp = hexchat_fopen_file ("servlist.conf", "w", 0); ostream = G_OUTPUT_STREAM(g_file_replace (file, NULL, TRUE,
if (!fp) G_FILE_CREATE_PRIVATE, NULL, NULL));
{ if (!ostream)
#ifndef WIN32
g_free (buf);
#endif
return FALSE; return FALSE;
}
#ifndef WIN32 stream_writef (ostream, "v=%s\n\n", PACKAGE_VERSION);
if (first)
g_chmod (buf, 0600);
g_free (buf);
#endif
fprintf (fp, "v=" PACKAGE_VERSION "\n\n");
list = network_list; list = network_list;
while (list) while (list)
{ {
net = list->data; net = list->data;
fprintf (fp, "N=%s\n", net->name); stream_writef (ostream, "N=%s\n", net->name);
if (net->nick) if (net->nick)
fprintf (fp, "I=%s\n", net->nick); stream_writef (ostream, "I=%s\n", net->nick);
if (net->nick2) if (net->nick2)
fprintf (fp, "i=%s\n", net->nick2); stream_writef (ostream, "i=%s\n", net->nick2);
if (net->user) if (net->user)
fprintf (fp, "U=%s\n", net->user); stream_writef (ostream, "U=%s\n", net->user);
if (net->real) if (net->real)
fprintf (fp, "R=%s\n", net->real); stream_writef (ostream, "R=%s\n", net->real);
if (net->pass) if (net->pass)
fprintf (fp, "P=%s\n", net->pass); stream_writef (ostream, "P=%s\n", net->pass);
if (net->logintype) if (net->logintype)
fprintf (fp, "L=%d\n", net->logintype); stream_writef (ostream, "L=%d\n", net->logintype);
if (net->encoding) if (net->encoding)
{ {
fprintf (fp, "E=%s\n", net->encoding); stream_writef (ostream, "E=%s\n", net->encoding);
if (!servlist_check_encoding (net->encoding)) if (!servlist_check_encoding (net->encoding))
{ {
buf = g_strdup_printf (_("Warning: \"%s\" character set is unknown. No conversion will be applied for network %s."), buf = g_strdup_printf (_("Warning: \"%s\" character set is unknown. No conversion will be applied for network %s."),
@ -1203,13 +1194,13 @@ servlist_save (void)
} }
} }
fprintf (fp, "F=%d\nD=%d\n", net->flags, net->selected); stream_writef (ostream, "F=%d\nD=%d\n", net->flags, net->selected);
netlist = net->servlist; netlist = net->servlist;
while (netlist) while (netlist)
{ {
serv = netlist->data; serv = netlist->data;
fprintf (fp, "S=%s\n", serv->hostname); stream_writef (ostream, "S=%s\n", serv->hostname);
netlist = netlist->next; netlist = netlist->next;
} }
@ -1217,7 +1208,7 @@ servlist_save (void)
while (cmdlist) while (cmdlist)
{ {
cmd = cmdlist->data; cmd = cmdlist->data;
fprintf (fp, "C=%s\n", cmd->command); stream_writef (ostream, "C=%s\n", cmd->command);
cmdlist = cmdlist->next; cmdlist = cmdlist->next;
} }
@ -1228,26 +1219,24 @@ servlist_save (void)
if (favchan->key) if (favchan->key)
{ {
fprintf (fp, "J=%s,%s\n", favchan->name, favchan->key); stream_writef (ostream, "J=%s,%s\n", favchan->name, favchan->key);
} }
else else
{ {
fprintf (fp, "J=%s\n", favchan->name); stream_writef (ostream, "J=%s\n", favchan->name);
} }
favlist = favlist->next; favlist = favlist->next;
} }
if (fprintf (fp, "\n") < 1) if (!stream_writef (ostream, "\n"))
{
fclose (fp);
return FALSE; return FALSE;
}
list = list->next; list = list->next;
} }
fclose (fp); g_object_unref (file);
g_object_unref (ostream);
return TRUE; return TRUE;
} }

View File

@ -218,7 +218,6 @@ scrollback_save (session *sess, char *text, time_t stamp)
void void
scrollback_load (session *sess) scrollback_load (session *sess)
{ {
GInputStream *stream;
GDataInputStream *istream; GDataInputStream *istream;
gchar *buf, *text; gchar *buf, *text;
gint lines = 0; gint lines = 0;
@ -244,19 +243,10 @@ scrollback_load (session *sess)
g_free (buf); g_free (buf);
} }
stream = G_INPUT_STREAM(g_file_read (sess->scrollfile, NULL, NULL)); istream = file_get_datainputstream (sess->scrollfile);
if (!stream) if (!istream)
return; 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) while (1)
{ {
GError *err = NULL; GError *err = NULL;

View File

@ -68,42 +68,47 @@ url_clear (void)
} }
static int static int
url_save_cb (char *url, FILE *fd) url_save_cb (char *url, GOutputStream *ostream)
{ {
fprintf (fd, "%s\n", url); stream_writef (ostream, "%s\n", url);
return TRUE; return TRUE;
} }
void void
url_save_tree (const char *fname, const char *mode, gboolean fullpath) url_save_tree (const char *fname)
{ {
FILE *fd; GFile *file;
GOutputStream *ostream;
if (fullpath) file = hexchat_open_gfile (fname);
fd = hexchat_fopen_file (fname, mode, XOF_FULLPATH);
else
fd = hexchat_fopen_file (fname, mode, 0);
if (fd == NULL)
return;
tree_foreach (url_tree, (tree_traverse_func *)url_save_cb, fd); ostream = G_OUTPUT_STREAM(g_file_append_to (file, G_FILE_CREATE_NONE, NULL, NULL));
fclose (fd); if (ostream)
{
tree_foreach (url_tree, (tree_traverse_func *)url_save_cb, ostream);
g_object_unref (ostream);
}
g_object_unref (file);
} }
static void static void
url_save_node (char* url) url_save_node (char* url)
{ {
FILE *fd; GFile *file;
GOutputStream *ostream;
/* open <config>/url.log in append mode */ /* open <config>/url.log in append mode */
fd = hexchat_fopen_file ("url.log", "a", 0); file = hexchat_open_gfile ("url.log");
if (fd == NULL)
ostream = G_OUTPUT_STREAM(g_file_append_to (file, G_FILE_CREATE_NONE, NULL, NULL));
if (ostream)
{ {
return; stream_writef (ostream, "%s\n", url);
g_object_unref (ostream);
} }
fprintf (fd, "%s\n", url); g_object_unref (file);
fclose (fd);
} }
static int static int

View File

@ -33,7 +33,7 @@ extern void *url_tree;
#define WORD_PATH -2 #define WORD_PATH -2
void url_clear (void); void url_clear (void);
void url_save_tree (const char *fname, const char *mode, gboolean fullpath); void url_save_tree (const char *fname);
int url_last (int *, int *); int url_last (int *, int *);
int url_check_word (const char *word); int url_check_word (const char *word);
void url_check_line (char *buf); void url_check_line (char *buf);

View File

@ -530,7 +530,7 @@ get_sys_str (int with_cpu)
#endif #endif
int int
buf_get_line (char *ibuf, char **buf, int *position, int len) buf_get_line (char *ibuf, char **buf, int *position, gsize len)
{ {
int pos = *position, spos = pos; int pos = *position, spos = pos;

View File

@ -44,7 +44,7 @@ char *file_part (char *file);
void for_files (char *dirname, char *mask, void callback (char *file)); void for_files (char *dirname, char *mask, void callback (char *file));
int rfc_casecmp (const char *, const char *); int rfc_casecmp (const char *, const char *);
int rfc_ncasecmp (char *, char *, int); int rfc_ncasecmp (char *, char *, int);
int buf_get_line (char *, char **, int *, int len); int buf_get_line (char *, char **, int *, gsize len);
char *nocasestrstr (const char *text, const char *tofind); char *nocasestrstr (const char *text, const char *tofind);
char *country (char *); char *country (char *);
void country_search (char *pattern, void *ud, void (*print)(void *, char *, ...)); void country_search (char *pattern, void *ud, void (*print)(void *, char *, ...));

View File

@ -146,26 +146,33 @@ palette_load (void)
void void
palette_save (void) palette_save (void)
{ {
int i, j, fh; GFile *file;
GOutputStream *ostream;
int i, j;
char prefname[256]; char prefname[256];
fh = hexchat_open_file ("colors.conf", O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE); file = hexchat_open_gfile ("colors.conf");
if (fh != -1)
ostream = G_OUTPUT_STREAM(g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL));
if (ostream)
{ {
/* mIRC colors 0-31 are here */ /* mIRC colors 0-31 are here */
for (i = 0; i < 32; i++) for (i = 0; i < 32; i++)
{ {
g_snprintf (prefname, sizeof prefname, "color_%d", i); g_snprintf (prefname, sizeof prefname, "color_%d", i);
cfg_put_color (fh, colors[i].red, colors[i].green, colors[i].blue, prefname); cfg_put_color (ostream, colors[i].red, colors[i].green, colors[i].blue, prefname);
} }
/* our special colors are mapped at 256+ */ /* our special colors are mapped at 256+ */
for (i = 256, j = 32; j < MAX_COL+1; i++, j++) for (i = 256, j = 32; j < MAX_COL+1; i++, j++)
{ {
g_snprintf (prefname, sizeof prefname, "color_%d", i); g_snprintf (prefname, sizeof prefname, "color_%d", i);
cfg_put_color (fh, colors[j].red, colors[j].green, colors[j].blue, prefname); cfg_put_color (ostream, colors[j].red, colors[j].green, colors[j].blue, prefname);
} }
close (fh); g_object_unref (ostream);
} }
g_object_unref (file);
} }

View File

@ -138,7 +138,7 @@ url_save_callback (void *arg1, char *file)
{ {
if (file) if (file)
{ {
url_save_tree (file, "w", TRUE); url_save_tree (file);
} }
} }