Take a basename of the config file to parse instead of an fd.
int main(int argc, char *argv[])
{
struct desktop desktop = { 0 };
- int config_fd;
struct output *output;
struct weston_config_section *s;
desktop.unlock_task.run = unlock_dialog_finish;
wl_list_init(&desktop.outputs);
- config_fd = open_config_file("weston.ini");
- desktop.config = weston_config_parse(config_fd);
- close(config_fd);
-
+ desktop.config = weston_config_parse("weston.ini");
s = weston_config_get_section(desktop.config, "shell", NULL, NULL);
weston_config_section_get_bool(s, "locking", &desktop.locking, 1);
{
struct tablet tablet = { 0 };
struct display *display;
- int config_fd;
struct output *output;
struct weston_config *config;
struct weston_config_section *s;
wl_list_init(&tablet.homescreen->launcher_list);
- config_fd = open_config_file("weston.ini");
- config = weston_config_parse(config_fd);
- close(config_fd);
-
+ config = weston_config_parse("weston.ini");
s = weston_config_get_section(config, "shell", NULL, NULL);
weston_config_section_get_string(s, "lockscreen-icon",
&key_lockscreen_icon, NULL);
struct terminal *terminal;
struct weston_config *config;
struct weston_config_section *s;
- int config_fd;
/* as wcwidth is locale-dependent,
wcwidth needs setlocale call to function properly. */
if (!option_shell)
option_shell = "/bin/bash";
- config_fd = open_config_file("weston.ini");
- config = weston_config_parse(config_fd);
- close(config_fd);
-
+ config = weston_config_parse("weston.ini");
s = weston_config_get_section(config, "terminal", NULL, NULL);
weston_config_section_get_string(s, "font", &option_font, "mono");
weston_config_section_get_int(s, "font-size", &option_font_size, 14);
{
struct weston_config *config;
struct weston_config_section *s;
- int config_fd, size;
+ int size;
char *theme = NULL;
unsigned int i, j;
struct wl_cursor *cursor;
- config_fd = open_config_file("weston.ini");
- config = weston_config_parse(config_fd);
- close(config_fd);
-
+ config = weston_config_parse("weston.ini");
s = weston_config_get_section(config, "shell", NULL, NULL);
weston_config_section_get_string(s, "cursor-theme", &theme, NULL);
weston_config_section_get_int(s, "cursor-size", &size, 32);
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");
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. */
}
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)
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]) {
void (*done)(void *data);
};
-int
-open_config_file(const char *name);
-
enum weston_option_type {
WESTON_OPTION_INTEGER,
WESTON_OPTION_UNSIGNED_INTEGER,
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);
*(*backend_init)(struct wl_display *display,
int *argc, char *argv[],
struct weston_config *config);
- int i, config_fd;
+ int i;
char *backend = NULL;
char *shell = NULL;
char *modules, *option_modules = NULL;
backend = WESTON_NATIVE_BACKEND;
}
- config_fd = open_config_file("weston.ini");
- config = weston_config_parse(config_fd);
- close(config_fd);
-
+ config = weston_config_parse("weston.ini");
section = weston_config_get_section(config, "core", NULL, NULL);
weston_config_section_get_string(section, "modules", &modules, "");
len = write(fd, text, strlen(text));
assert(len == (int) strlen(text));
- config = weston_config_parse(fd);
+ config = weston_config_parse(file);
close(fd);
unlink(file);