diff libfdcore/config.c @ 947:cce5d4bace82

Make config file parameter const and convert another fprintf to TRACE_DEBUG_ERROR.
author Thomas Klausner <tk@giga.or.at>
date Wed, 13 Feb 2013 14:47:47 +0100
parents 5d9229144cac
children 9b37f34c1b1f
line wrap: on
line diff
--- a/libfdcore/config.c	Tue Feb 12 12:38:32 2013 +0100
+++ b/libfdcore/config.c	Wed Feb 13 14:47:47 2013 +0100
@@ -229,7 +229,7 @@
 int fd_conf_parse()
 {
 	extern FILE * fddin;
-	char * orig = NULL;
+	const char * orig = NULL;
 	
 	/* Attempt to find the configuration file */
 	if (!fd_g_config->cnf_file)
@@ -237,23 +237,18 @@
 	
 	fddin = fopen(fd_g_config->cnf_file, "r");
 	if ((fddin == NULL) && (*fd_g_config->cnf_file != '/')) {
+		char * new_cnf = NULL;
 		/* We got a relative path, attempt to add the default directory prefix */
 		orig = fd_g_config->cnf_file;
-		CHECK_MALLOC( fd_g_config->cnf_file = malloc(strlen(orig) + strlen(DEFAULT_CONF_PATH) + 2) ); /* we will not free it, but not important */
-		sprintf( fd_g_config->cnf_file, DEFAULT_CONF_PATH "/%s", orig );
+		CHECK_MALLOC( new_cnf = malloc(strlen(orig) + strlen(DEFAULT_CONF_PATH) + 2) ); /* we will not free it, but not important */
+		sprintf( new_cnf, DEFAULT_CONF_PATH "/%s", orig );
+		fd_g_config->cnf_file = new_cnf;
 		fddin = fopen(fd_g_config->cnf_file, "r");
 	}
 	if (fddin == NULL) {
 		int ret = errno;
-		if (orig) {
-			fprintf(stderr, "Unable to open configuration file for reading\n"
-					"Tried the following locations:\n"
-					" - %s\n"
-					" - %s\n"
-					"Error: %s\n", orig, fd_g_config->cnf_file, strerror(ret));
-		} else {
-			fprintf(stderr, "Unable to open '%s' for reading: %s\n", fd_g_config->cnf_file, strerror(ret));
-		}
+		TRACE_DEBUG_ERROR("Unable to open configuration file for reading; tried the following locations: %s%s%s; Error: %s\n",
+				  orig ?: "", orig? " and " : "", fd_g_config->cnf_file, strerror(ret));
 		return ret;
 	}
 	
"Welcome to our mercurial repository"