config-parser: Make weston_config_parse() tkae a file name

Take a basename of the config file to parse instead of an fd.
This commit is contained in:
Kristian Høgsberg
2013-09-21 23:02:31 -07:00
parent 81c2c2eb5e
commit 1abe0486bb
8 changed files with 22 additions and 36 deletions
+13 -6
View File
@@ -41,7 +41,7 @@
const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
int
static int
open_config_file(const char *name)
{
const char *config_dir = getenv("XDG_CONFIG_HOME");
@@ -51,6 +51,9 @@ open_config_file(const char *name)
const char *p, *next;
int fd;
if (name[0] == '/')
return open(name, O_RDONLY | O_CLOEXEC);
/* Precedence is given to config files in the home directory,
* and then to directories listed in XDG_CONFIG_DIRS and
* finally to the current working directory. */
@@ -312,13 +315,13 @@ section_add_entry(struct weston_config_section *section,
}
struct weston_config *
weston_config_parse(int fd)
weston_config_parse(const char *name)
{
FILE *fp;
char line[512], *p;
struct weston_config *config;
struct weston_config_section *section = NULL;
int i;
int i, fd;
config = malloc(sizeof *config);
if (config == NULL)
@@ -326,13 +329,17 @@ weston_config_parse(int fd)
wl_list_init(&config->section_list);
fp = fdopen(dup(fd), "r");
if (fp == NULL) {
fd = open_config_file(name);
if (fd == -1) {
free(config);
return NULL;
}
rewind(fp);
fp = fdopen(fd, "r");
if (fp == NULL) {
free(config);
return NULL;
}
while (fgets(line, sizeof line, fp)) {
switch (line[0]) {
+1 -4
View File
@@ -47,9 +47,6 @@ struct config_section {
void (*done)(void *data);
};
int
open_config_file(const char *name);
enum weston_option_type {
WESTON_OPTION_INTEGER,
WESTON_OPTION_UNSIGNED_INTEGER,
@@ -96,7 +93,7 @@ weston_config_section_get_bool(struct weston_config_section *section,
const char *key,
int *value, int default_value);
struct weston_config *
weston_config_parse(int fd);
weston_config_parse(const char *name);
void
weston_config_destroy(struct weston_config *config);