Mercurial > pidgin.yaz
changeset 19498:7589b218f89a
- Add purple_util_write_data_to_file_absolute; glib's
g_file_set_contents is a post-2.0 addition.
- Change ssl-gnutls plugin to use it
author | William Ehlhardt <williamehlhardt@gmail.com> |
---|---|
date | Sat, 25 Aug 2007 20:32:15 +0000 |
parents | d351a42435a9 |
children | 47a2d00ab060 |
files | libpurple/plugins/ssl/ssl-gnutls.c libpurple/util.c libpurple/util.h |
diffstat | 3 files changed, 60 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/plugins/ssl/ssl-gnutls.c Mon Aug 20 16:25:44 2007 +0000 +++ b/libpurple/plugins/ssl/ssl-gnutls.c Sat Aug 25 20:32:15 2007 +0000 @@ -568,12 +568,8 @@ } /* Write it out to an actual file */ - /* TODO: THIS IS A COMPATIBILITY VIOLATION - Look into util.c write_data_to_file. */ - success = g_file_set_contents(filename, - out_buf, - out_size, - NULL); + success = purple_util_write_data_to_file_absolute(filename, + out_buf, out_size); g_free(out_buf);
--- a/libpurple/util.c Mon Aug 20 16:25:44 2007 +0000 +++ b/libpurple/util.c Sat Aug 25 20:32:15 2007 +0000 @@ -2542,10 +2542,8 @@ purple_util_write_data_to_file(const char *filename, const char *data, size_t size) { const char *user_dir = purple_user_dir(); - gchar *filename_temp, *filename_full; - FILE *file; - size_t real_size, byteswritten; - struct stat st; + gchar *filename_full; + gboolean ret = FALSE; g_return_val_if_fail(user_dir != NULL, FALSE); @@ -2564,6 +2562,25 @@ } filename_full = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", user_dir, filename); + + ret = purple_util_write_data_to_file_absolute(filename_full, + data,size); + + g_free(filename_full); + return ret; +} + +gboolean +purple_util_write_data_to_file_absolute(const char *filename_full, const char *data, size_t size) +{ + gchar *filename_temp; + FILE *file; + size_t real_size, byteswritten; + struct stat st; + + purple_debug_info("util", "Writing file %s\n", + filename_full); + filename_temp = g_strdup_printf("%s.save", filename_full); /* Remove an old temporary file, if one exists */ @@ -2571,8 +2588,9 @@ { if (g_unlink(filename_temp) == -1) { - purple_debug_error("util", "Error removing old file %s: %s\n", - filename_temp, strerror(errno)); + purple_debug_error("util", "Error removing old file " + "%s: %s\n", + filename_temp, strerror(errno)); } } @@ -2580,9 +2598,9 @@ file = g_fopen(filename_temp, "wb"); if (file == NULL) { - purple_debug_error("util", "Error opening file %s for writing: %s\n", - filename_temp, strerror(errno)); - g_free(filename_full); + purple_debug_error("util", "Error opening file %s for " + "writing: %s\n", + filename_temp, strerror(errno)); g_free(filename_temp); return FALSE; } @@ -2595,8 +2613,7 @@ if (fclose(file) != 0) { purple_debug_error("util", "Error closing file %s: %s\n", - filename_temp, strerror(errno)); - g_free(filename_full); + filename_temp, strerror(errno)); g_free(filename_temp); return FALSE; } @@ -2604,10 +2621,11 @@ /* Ensure the file is the correct size */ if (byteswritten != real_size) { - purple_debug_error("util", "Error writing to file %s: Wrote %" G_GSIZE_FORMAT " bytes " - "but should have written %" G_GSIZE_FORMAT "; is your disk full?\n", - filename_temp, byteswritten, real_size); - g_free(filename_full); + purple_debug_error("util", "Error writing to file %s: Wrote %" + G_GSIZE_FORMAT " bytes " + "but should have written %" G_GSIZE_FORMAT + "; is your disk full?\n", + filename_temp, byteswritten, real_size); g_free(filename_temp); return FALSE; } @@ -2615,9 +2633,9 @@ if ((g_stat(filename_temp, &st) == -1) || (st.st_size != real_size)) { purple_debug_error("util", "Error writing data to file %s: " - "Incomplete file written; is your disk full?\n", - filename_temp); - g_free(filename_full); + "Incomplete file written; is your disk " + "full?\n", + filename_temp); g_free(filename_temp); return FALSE; } @@ -2635,10 +2653,10 @@ if (g_rename(filename_temp, filename_full) == -1) { purple_debug_error("util", "Error renaming %s to %s: %s\n", - filename_temp, filename_full, strerror(errno)); + filename_temp, filename_full, + strerror(errno)); } - g_free(filename_full); g_free(filename_temp); return TRUE;
--- a/libpurple/util.h Mon Aug 20 16:25:44 2007 +0000 +++ b/libpurple/util.h Sat Aug 25 20:32:15 2007 +0000 @@ -589,6 +589,26 @@ size_t size); /** + * Write data to a file using the absolute path. + * + * This exists for Glib backwards compatibility reasons. + * + * @param filename_full Filename to write to + * @param data A null-terminated string of data to write. + * @param size The size of the data to save. If data is + * null-terminated you can pass in -1. + * + * @return TRUE if the file was written successfully. FALSE otherwise. + * + * @todo Remove this function (use g_file_set_contents instead) when 3.0.0 + * rolls around. + * @see purple_util_write_data_to_file() + * + */ +gboolean +purple_util_write_data_to_file_absolute(const char *filename_full, const char *data, size_t size); + +/** * Read the contents of a given file and parse the results into an * xmlnode tree structure. This is intended to be used to read * Purple's configuration xml files (prefs.xml, pounces.xml, etc.)