From: arjen Date: Sat, 23 Nov 2002 12:48:18 +0000 (+0000) Subject: Check if a configuration file exists before feeding it to the XML parser. X-Git-Tag: V0_3~1 X-Git-Url: http://www.andromeda.nl/gitweb/?p=AXE.git;a=commitdiff_plain;h=bf81bfab66dbb01e105ee339429053f3285efca5 Check if a configuration file exists before feeding it to the XML parser. --- diff --git a/src/configuration.cpp b/src/configuration.cpp index c4cce46..76e0338 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -6,7 +6,7 @@ *********************** ** FILE NAME : configuration.cpp ** SYSTEM NAME : AXE - Andromeda X-windows Encapsulation -** VERSION NUMBER : $Revision: 1.3 $ +** VERSION NUMBER : $Revision: 1.4 $ ** ** DESCRIPTION : Implementation of configuration class ** @@ -18,13 +18,16 @@ ******************************** ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl ** CREATION DATE : Jul 23, 2002 -** LAST UPDATE : Nov 02, 2002 +** LAST UPDATE : Nov 22, 2002 ** MODIFICATIONS : **************************************************************************/ /***************************** $Log: configuration.cpp,v $ - Revision 1.3 2002-11-02 14:35:15 arjen + Revision 1.4 2002-11-23 12:48:18 arjen + Check if a configuration file exists before feeding it to the XML parser. + + Revision 1.3 2002/11/02 14:35:15 arjen Uses the XML2 library BugFix: segfault when finding a parameters that is not in the user-sepcific config tree. @@ -38,8 +41,10 @@ *****************************/ -static const char *RCSID = "$Id: configuration.cpp,v 1.3 2002-11-02 14:35:15 arjen Exp $"; +static const char *RCSID = "$Id: configuration.cpp,v 1.4 2002-11-23 12:48:18 arjen Exp $"; +#include +#include #include "configuration.h" /*========================================================================= @@ -54,7 +59,7 @@ static const char *RCSID = "$Id: configuration.cpp,v 1.3 2002-11-02 14:35:15 arj ** VARS CHANGED : ** FUNCTIONS USED : ** SEE ALSO : -** LAST MODIFIED : Jul 24, 2002 +** LAST MODIFIED : Nov 22, 2002 **========================================================================= */ @@ -67,18 +72,30 @@ bool configuration::read(const String name) // Try to read the config files. filename = "/etc/" + name + ".conf"; - system = xmlParseFile(filename); + // Check if we can read the file. - if (system == NULL) + int fd = open(filename, O_RDONLY); + if (fd < 0) { filename = "/usr/local/etc/" + name + ".conf"; + fd = open(filename, O_RDONLY); + } + + if (fd > 0) + { + close(fd); system = xmlParseFile(filename); } filename = getenv("HOME"); filename += "/."; filename += name + ".conf"; - user = xmlParseFile(filename); + fd = open(filename, O_RDONLY); + if (fd > 0) + { + close(fd); + user = xmlParseFile(filename); + } // Check the root element, which must be the application name