Skip to content

Commit 56f992f

Browse files
committed
Create basic config file if missing
1 parent 379e931 commit 56f992f

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

main.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,35 @@ free_theme_vector(struct themes *themes)
249249
free(themes->data);
250250
}
251251

252+
static const char rcxml_template[] =
253+
"<?xml version=\"1.0\"?>\n"
254+
"<labwc_config>\n"
255+
" <core>\n"
256+
" </core>\n"
257+
"</labwc_config>\n";
258+
259+
static void
260+
create_basic_rcxml(const char *filename)
261+
{
262+
FILE *file = fopen(filename, "w");
263+
if (!file) {
264+
fprintf(stderr, "warn: fopen(%s) failed\n", filename);
265+
return;
266+
}
267+
if (!fwrite(rcxml_template, sizeof(rcxml_template), 1, file)) {
268+
fprintf(stderr, "warn: error writing to %s", filename);
269+
}
270+
fclose(file);
271+
}
252272
int
253273
main(int argc, char **argv)
254274
{
255-
/* read config file */
275+
/* read/create config file */
256276
char filename[4096];
257277
char *home = getenv("HOME");
258278
snprintf(filename, sizeof(filename), "%s/%s", home, ".config/labwc/rc.xml");
259-
260-
struct stat st;
261-
if (stat(filename, &st)) {
262-
printf("error: need ~/.config/labwc/rc.xml to run\n");
263-
exit(EXIT_FAILURE);
279+
if (access(filename, F_OK)) {
280+
create_basic_rcxml(filename);
264281
}
265282
xml_init(filename);
266283

0 commit comments

Comments
 (0)