-config_t *parse_config_line(char *line, const char *fname, int lineno) {
- config_t *cfg;
- int len;
- char *variable, *value, *eol;
- variable = value = line;
-
- eol = line + strlen(line);
- while(strchr("\t ", *--eol))
- *eol = '\0';
-
- len = strcspn(value, "\t =");
- value += len;
- value += strspn(value, "\t ");
- if(*value == '=') {
- value++;
- value += strspn(value, "\t ");
- }
- variable[len] = '\0';
-
- if(!*value) {
- const char err[] = "No value for variable";
- if (fname)
- logger(DEBUG_ALWAYS, LOG_ERR, "%s `%s' on line %d while reading config file %s",
- err, variable, lineno, fname);
- else
- logger(DEBUG_ALWAYS, LOG_ERR, "%s `%s' in command line option %d",
- err, variable, lineno);
- return NULL;
- }
-
- cfg = new_config();
- cfg->variable = xstrdup(variable);
- cfg->value = xstrdup(value);
- cfg->file = fname ? xstrdup(fname) : NULL;
- cfg->line = lineno;
-
- return cfg;
+/// Write a host configuration file.
+bool config_write(meshlink_handle_t *mesh, const char *name, const config_t *config) {
+ if(!mesh->confbase) {
+ return true;
+ }
+
+ char path[PATH_MAX];
+ make_host_path(mesh, name, path, sizeof(path));
+
+ FILE *f = fopen(path, "w");
+
+ if(!f) {
+ logger(mesh, MESHLINK_ERROR, "Failed to open `%s': %s", path, strerror(errno));
+ return false;
+ }
+
+ if(!config_write_file(mesh, f, config)) {
+ logger(mesh, MESHLINK_ERROR, "Failed to write `%s': %s", path, strerror(errno));
+ fclose(f);
+ return false;
+ }
+
+ fclose(f);
+ return true;