return r;
}
+int nw_config_writef(struct nw_config* config, FILE* f) {
+ struct nw_config_entry* entry = NULL;
+ int r;
+
+ STAILQ_FOREACH(entry, &config->entries, nodes) {
+ // Skip if value is NULL
+ if (!*entry->value)
+ continue;
+
+ // Write the entry
+ r = fprintf(f, "%s=\"%s\"\n", entry->key, entry->value);
+ if (r < 0) {
+ ERROR("Failed to write configuration: %m\n");
+ return r;
+ }
+ }
+
+ return 0;
+}
+
+int nw_config_write(struct nw_config* config, const char* path) {
+ int r;
+
+ FILE* f = fopen(path, "w");
+ if (!f) {
+ ERROR("Failed to open %s for writing: %m\n", path);
+ r = 1;
+ goto ERROR;
+ }
+
+ // Write configuration
+ r = nw_config_writef(config, f);
+
+ERROR:
+ if (f)
+ fclose(f);
+
+ return r;
+}
+
static struct nw_config_entry* nw_config_find(struct nw_config* config, const char* key) {
struct nw_config_entry* entry = NULL;
int nw_config_readf(struct nw_config** config, FILE* f);
int nw_config_read(struct nw_config** config, const char* path);
+int nw_config_writef(struct nw_config* config, FILE* f);
+int nw_config_write(struct nw_config* config, const char* path);
+
int nw_config_del(struct nw_config* config, const char* key);
int nw_config_set(struct nw_config* config, const char* key, const char* value);