2 * configfile.c -- config file functions for browser-switchboard
4 * Copyright (C) 2009 Steven Luo
5 * Derived from a Python implementation by Jason Simpson and Steven Luo
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
27 #include "configfile.h"
29 FILE *open_config_file(void) {
30 char *homedir, *configfile;
34 /* Put together the path to the config file */
35 if (!(homedir = getenv("HOME")))
36 homedir = DEFAULT_HOMEDIR;
37 len = strlen(homedir) + strlen(CONFIGFILE_LOC) + 1;
38 if (!(configfile = calloc(len, sizeof(char))))
40 snprintf(configfile, len, "%s%s", homedir, CONFIGFILE_LOC);
42 /* Try to open the config file */
43 if (!(fp = fopen(configfile, "r"))) {
44 /* Try the legacy config file location before giving up
45 XXX we assume here that CONFIGFILE_LOC_OLD is shorter
46 than CONFIGFILE_LOC! */
47 snprintf(configfile, len, "%s%s", homedir, CONFIGFILE_LOC_OLD);
48 fp = fopen(configfile, "r");