Package: xchat / 2.8.8-7.1

59_save_colors.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
Write to temporary file and then rename.
Same approach like I did for bug 463072.
Fixes loss of data when disk is full.

--- ../orig/xchat-2.8.8/./src/fe-gtk/palette.c	2010-05-16 03:16:10.000000000 +0000
+++ ./src/fe-gtk/palette.c	2012-09-30 12:58:02.000000000 +0000
@@ -202,25 +202,45 @@
 palette_save (void)
 {
 	int i, j, fh;
+	ssize_t nb;
 	char prefname[256];
 
-	fh = xchat_open_file ("colors.conf", O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE);
+	fh = xchat_open_file ("colors.conf.bug147832", O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE);
 	if (fh != -1)
 	{
+		nb = 1;
+
 		/* mIRC colors 0-31 are here */
 		for (i = 0; i < 32; i++)
 		{
 			snprintf (prefname, sizeof prefname, "color_%d", i);
-			cfg_put_color (fh, colors[i].red, colors[i].green, colors[i].blue, prefname);
+			if( nb > 0 ) nb = cfg_put_color (fh, colors[i].red, colors[i].green, colors[i].blue, prefname);
 		}
 
 		/* our special colors are mapped at 256+ */
 		for (i = 256, j = 32; j < MAX_COL+1; i++, j++)
 		{
 			snprintf (prefname, sizeof prefname, "color_%d", i);
-			cfg_put_color (fh, colors[j].red, colors[j].green, colors[j].blue, prefname);
+			if( nb > 0 ) nb = cfg_put_color (fh, colors[j].red, colors[j].green, colors[j].blue, prefname);
 		}
 
-		close (fh);
+		if( nb <= 0 )
+		{
+			fprintf( stderr, "palette_save: cfg_put_color failed\n" );
+			close( fh );
+			return;
+		}
+
+		if( close (fh) != 0 )
+		{
+			perror( "palette_save: close() failed\n" );
+			return;
+		}
+
+		if( xchat_rename_file( "colors.conf.bug147832", "colors.conf", XOF_DOMODE ) != 0 )
+		{
+			perror( "palette_save: xchat_rename_file() failed" );
+			return;
+		}
 	}
 }