[Pommed-commits] r273 - trunk/gpomme
Julien Blache
jblache at alioth.debian.org
Thu Feb 22 23:58:14 CET 2007
Author: jblache
Date: 2007-02-22 23:58:13 +0100 (Thu, 22 Feb 2007)
New Revision: 273
Modified:
trunk/gpomme/conffile.c
Log:
Build config file path.
Modified: trunk/gpomme/conffile.c
===================================================================
--- trunk/gpomme/conffile.c 2007-02-22 22:31:52 UTC (rev 272)
+++ trunk/gpomme/conffile.c 2007-02-22 22:58:13 UTC (rev 273)
@@ -22,6 +22,10 @@
#include <stdio.h>
#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <pwd.h>
+
#include <confuse.h>
#include "gpomme.h"
@@ -29,11 +33,10 @@
/*
* TODO
- * - print config with cfg_print() (need to create the path if it doesn't exist)
- * - build config file path
+ * - print config with cfg_print()
*/
-#define CONFFILE "/dev/null"
+#define CONFFILE "/.gpommerc"
static cfg_opt_t cfg_opts[] =
{
@@ -43,6 +46,9 @@
};
+static char *conffile;
+
+
static int
config_validate_positive_integer(cfg_t *cfg, cfg_opt_t *opt)
{
@@ -75,10 +81,30 @@
int
config_load(void)
{
+ struct passwd *pw;
cfg_t *cfg;
int ret;
+ pw = getpwuid(getuid());
+ if (pw == NULL)
+ {
+ fprintf(stderr, "Could not get user information\n");
+
+ return -1;
+ }
+
+ conffile = (char *) malloc(strlen(pw->pw_dir) + strlen(CONFFILE) + 1);
+ if (conffile == NULL)
+ {
+ fprintf(stderr, "Could not allocate memory\n");
+
+ return -1;
+ }
+
+ strncpy(conffile, pw->pw_dir, strlen(pw->pw_dir) + 1);
+ strncat(conffile, CONFFILE, strlen(CONFFILE));
+
cfg = cfg_init(cfg_opts, CFGF_NONE);
if (cfg == NULL)
@@ -97,7 +123,7 @@
* If the file does not exist or cannot be opened,
* we'll be using the default values defined in the cfg_opt_t array.
*/
- ret = cfg_parse(cfg, CONFFILE);
+ ret = cfg_parse(cfg, conffile);
if ((ret != CFG_SUCCESS) && (ret != CFG_FILE_ERROR))
{
cfg_free(cfg);
More information about the Pommed-commits
mailing list