[fusion-commits] Compiz configuration system library: Changes to 'master' (b001d13616d155977b2b5f74c1a6ca1373b3840c)
maniac at server.beryl-project.org
maniac at server.beryl-project.org
Tue Jul 3 16:46:58 CEST 2007
New commits:
commit b001d13616d155977b2b5f74c1a6ca1373b3840c
Author: Danny Baumann <dannybaumann at web.de>
Date: Tue Jul 3 16:46:54 2007 +0200
Use safer methods for open ini files for writing. Files are no longer deleted on opening, but on saving.
src/iniparser.c | 26 ++++++++++++++++++++------
1 files changed, 20 insertions(+), 6 deletions(-)
Modified: fusion/compizconfig/libcompizconfig/src/iniparser.c
===================================================================
--- fusion/compizconfig/libcompizconfig/src/iniparser.c
+++ fusion/compizconfig/libcompizconfig/src/iniparser.c
@@ -33,6 +33,10 @@
#include <string.h>
#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
#include "iniparser.h"
#ifdef __cplusplus
@@ -520,6 +524,7 @@ char * iniparser_getsecname(dictionary * d, int n)
void iniparser_dump_ini(dictionary * d, const char * file_name)
{
int i, j ;
+ int fd;
char keym[ASCIILINESZ+1];
int nsec ;
char * secname ;
@@ -528,8 +533,12 @@ void iniparser_dump_ini(dictionary * d, const char * file_name)
if (d==NULL) return;
- f = fopen (file_name, "w");
- if (f==NULL)
+ fd = open (file_name, O_WRONLY | O_CREAT);
+ if (fd < 0)
+ return;
+
+ f = fdopen (fd, "w");
+ if (f == NULL)
return;
nsec = iniparser_getnsec(d);
@@ -680,10 +689,15 @@ dictionary * iniparser_new(char *ininame)
char * where ;
FILE * ini ;
int lineno ;
+ int fd;
- if ((ini=fopen(ininame, "r"))==NULL) {
- return NULL ;
- }
+ fd = open (ininame, O_RDONLY);
+ if (fd < 0)
+ return NULL;
+
+ ini = fdopen (fd, "r");
+ if (ini == NULL)
+ return NULL;
sec[0]=0;
@@ -720,7 +734,7 @@ dictionary * iniparser_new(char *ininame)
}
}
}
- fclose(ini);
+ fclose(ini);
return d ;
}
More information about the commits
mailing list