diff src/gaimrc.c @ 4898:bd37db7531e4

[gaim-migrate @ 5230] I Nathan D. Walped the gaimrc file so that it writes a .gaimrc.save file and then renames it to .gaimrc, in the hopes of avoiding the loss of this data in a time that could be crucial to forward progress. Or something. I tested it with and without specifying -f I added a "Status: Not Available" (or whatever) string to ICQ tooltips. This should help at least until we get some new icons. AHEM. And then I dunno, I was planning on taking it out after that, but it could be useful. Also updated some comments and var names in oscar.c to keep things accurate, because I'm one of those people that actually does that. Go ask your Goddess if you've served her well committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Thu, 27 Mar 2003 21:41:21 +0000
parents 78d5be1af6a6
children 5fe846b7603f
line wrap: on
line diff
--- a/src/gaimrc.c	Thu Mar 27 18:32:22 2003 +0000
+++ b/src/gaimrc.c	Thu Mar 27 21:41:21 2003 +0000
@@ -1398,7 +1398,8 @@
 void save_prefs()
 {
 	FILE *f;
-	char buf[BUF_LONG];
+	gchar *filename;
+	gchar *filename_temp;
 
 	debug_printf("enter save_prefs\n");  
 	if (is_loading_prefs) {
@@ -1407,16 +1408,15 @@
 		return;
 	}
 
-	if (opt_rcfile_arg) {
-		g_snprintf(buf, sizeof(buf), "%s", opt_rcfile_arg);
-	}
-	else if (gaim_home_dir()) {
-		g_snprintf(buf, sizeof(buf), "%s" G_DIR_SEPARATOR_S ".gaimrc", gaim_home_dir());
-	}
-	else {
+	if (opt_rcfile_arg)
+		filename = g_build_filename(opt_rcfile_arg, NULL);
+	else if (gaim_home_dir())
+		filename = g_build_filename(gaim_home_dir(), ".gaimrc", NULL);
+	else
 		return;
-	}
-	if ((f = fopen(buf, "w"))) {
+	filename_temp = g_strdup_printf("%s.save", filename);
+
+	if ((f = fopen(filename_temp, "w"))) {
 		is_saving_prefs = 1;
 		fprintf(f, "# .gaimrc v%d\n", 4);
 		gaimrc_write_users(f);
@@ -1429,22 +1429,25 @@
 #endif
 		gaimrc_write_proxy(f);
 		fclose(f);
-
-		chmod(buf, S_IRUSR | S_IWUSR);
+		chmod(filename, S_IRUSR | S_IWUSR);
+		if (rename(filename_temp, filename) < 0)
+			debug_printf("error renaming %s to %s\n", filename_temp, filename);
 		is_saving_prefs = 0;
-	}
-	else
-	  debug_printf("Error opening .gaimrc\n");
+	} else
+		debug_printf("error opening %s\n", filename_temp);
+
 	if (request_load_prefs) {
 		debug_printf("loading prefs on request\n");
 		load_prefs();
 		request_load_prefs = 0;
 	}
+
+	g_free(filename);
+	g_free(filename_temp);
 	debug_printf("exit save_prefs\n");
 }
 
 
-
 /* This function is called by g_slist_insert_sorted to compare the item
  * being compared to the rest of the items on the list.
  */