summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2013-09-21 23:02:31 -0700
committerKristian Høgsberg <krh@bitplanet.net>2013-09-21 23:05:45 -0700
commit1abe0486bbb51c9c8517f8d5a347c6f46830de89 (patch)
tree5cfe226c1e702b70f83029467a4c3e10faf244c1 /shared
parent81c2c2eb5ec17d2749164ff970a85638e3d0caa8 (diff)
downloadweston-1abe0486bbb51c9c8517f8d5a347c6f46830de89.tar.gz
config-parser: Make weston_config_parse() tkae a file name
Take a basename of the config file to parse instead of an fd.
Diffstat (limited to 'shared')
-rw-r--r--shared/config-parser.c19
-rw-r--r--shared/config-parser.h5
2 files changed, 14 insertions, 10 deletions
diff --git a/shared/config-parser.c b/shared/config-parser.c
index d5491c27..1cee946b 100644
--- a/shared/config-parser.c
+++ b/shared/config-parser.c
@@ -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]) {
diff --git a/shared/config-parser.h b/shared/config-parser.h
index fc6195b0..56e390f6 100644
--- a/shared/config-parser.h
+++ b/shared/config-parser.h
@@ -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);