conf.c

Go to the documentation of this file.
00001 /*
00002  *  conf.c
00003  *
00004  *  Copyright (c) 2002-2007 by Judd Vinet <jvinet@zeroflux.org>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 
00020 #include "config.h"
00021 
00022 #include <stdlib.h>
00023 #include <stdio.h>
00024 #include <string.h> /* strdup */
00025 
00026 /* pacman */
00027 #include "conf.h"
00028 
00029 /* global config variable */
00030 config_t *config = NULL;
00031 
00032 config_t *config_new(void)
00033 {
00034     config_t *newconfig = calloc(1, sizeof(config_t));
00035     if(!newconfig) {
00036             fprintf(stderr, "malloc failure: could not allocate %zd bytes\n",
00037                     sizeof(config_t));
00038             return(NULL);
00039     }
00040     /* defaults which may get overridden later */
00041     newconfig->op = PM_OP_MAIN;
00042     newconfig->logmask = PM_LOG_ERROR | PM_LOG_WARNING;
00043     /* CONFFILE is defined at compile-time */
00044     newconfig->configfile = strdup(CONFFILE);
00045     newconfig->rootdir = NULL;
00046     newconfig->dbpath = NULL;
00047     newconfig->logfile = NULL;
00048 
00049     return(newconfig);
00050 }
00051 
00052 int config_free(config_t *oldconfig)
00053 {
00054     if(oldconfig == NULL) {
00055         return(-1);
00056     }
00057 
00058     free(oldconfig->configfile);
00059     free(oldconfig->rootdir);
00060     free(oldconfig->dbpath);
00061     free(oldconfig->logfile);
00062     free(oldconfig);
00063     oldconfig = NULL;
00064 
00065     return(0);
00066 }
00067 
00068 /* vim: set ts=2 sw=2 noet: */

Generated on Mon Jan 14 23:53:39 2008 for libalpm by  doxygen 1.5.4