]>
Commit | Line | Data |
---|---|---|
d04baaba JV |
1 | /* |
2 | * conf.c | |
23229097 | 3 | * |
96de3501 | 4 | * Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org> |
23229097 | 5 | * |
d04baaba JV |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
23229097 | 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
d04baaba JV |
19 | * USA. |
20 | */ | |
21 | ||
869e81e1 DM |
22 | #include "config.h" |
23 | ||
d04baaba JV |
24 | #include <stdlib.h> |
25 | #include <stdio.h> | |
c22e381a | 26 | #include <string.h> /* strdup */ |
d04baaba | 27 | |
d04baaba | 28 | /* pacman */ |
869e81e1 | 29 | #include "conf.h" |
d04baaba | 30 | |
86ca39d1 DM |
31 | /* global config variable */ |
32 | config_t *config = NULL; | |
33 | ||
14606c30 | 34 | config_t *config_new(void) |
98df67cd | 35 | { |
2f0de317 DM |
36 | config_t *newconfig = calloc(1, sizeof(config_t)); |
37 | if(!newconfig) { | |
6aeda5fb | 38 | fprintf(stderr, "malloc failure: could not allocate %zd bytes\n", |
97313ba3 | 39 | sizeof(config_t)); |
6aeda5fb | 40 | return(NULL); |
97313ba3 | 41 | } |
c22e381a | 42 | /* defaults which may get overridden later */ |
2f0de317 DM |
43 | newconfig->op = PM_OP_MAIN; |
44 | newconfig->logmask = PM_LOG_ERROR | PM_LOG_WARNING; | |
c22e381a | 45 | /* CONFFILE is defined at compile-time */ |
2f0de317 | 46 | newconfig->configfile = strdup(CONFFILE); |
4845207f DM |
47 | newconfig->rootdir = NULL; |
48 | newconfig->dbpath = NULL; | |
49 | newconfig->logfile = NULL; | |
98df67cd | 50 | |
2f0de317 | 51 | return(newconfig); |
98df67cd AF |
52 | } |
53 | ||
2f0de317 | 54 | int config_free(config_t *oldconfig) |
98df67cd | 55 | { |
2f0de317 | 56 | if(oldconfig == NULL) { |
98df67cd AF |
57 | return(-1); |
58 | } | |
59 | ||
2f0de317 | 60 | free(oldconfig->configfile); |
4845207f DM |
61 | free(oldconfig->rootdir); |
62 | free(oldconfig->dbpath); | |
63 | free(oldconfig->logfile); | |
2f0de317 DM |
64 | free(oldconfig); |
65 | oldconfig = NULL; | |
98df67cd AF |
66 | |
67 | return(0); | |
68 | } | |
69 | ||
d04baaba | 70 | /* vim: set ts=2 sw=2 noet: */ |