* Added the first simple wallpaper.
[Silver.git] / libsilverconf / libsilverconf.c
blob49e0f19a612928d622074e4ca75c2a8c5277a841
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <sys/stat.h>
6 #include "libsilverconf.h"
8 int load_config(struct Silver_Conf *conf, const char *appname)
10 struct stat st;
11 int result = 0;
13 conf->appname = appname;
15 char *path = malloc(300);
16 strcpy(path, getenv("HOME"));
17 if (stat(path, &st) != 0)
18 result = 1;
20 strcat(path, "/.config");
21 if (stat(path, &st) != 0)
23 int res = mkdir(path, 0755);
24 if (result == 0)
25 return res;
26 if (res != 0)
27 printf("%s: Error creating directory %s. Error code: %i", appname, path, res);
30 strcat(path, "/silver/");
31 if (stat(path, &st) != 0)
33 int res = mkdir(path, 0755);
34 if (result == 0)
35 return res;
36 if (res != 0)
37 printf("%s: Error creating directory %s. Error code: %i", appname, path, res);
40 strcat(path, appname);
41 if (stat(path, &st) != 0)
43 int res = mkdir(path, 0755);
44 if (result == 0)
45 return res;
46 if (res != 0)
47 printf("%s: Error creating directory %s. Error code: %i", appname, path, res);
50 conf->path = path;
52 return result;
55 const char *get_config(struct Silver_Conf *conf, const char *section, const char *key, const char *default_value)
57 const char *value = default_value;
59 return value;
62 void delete_config(struct Silver_Conf *conf)
64 free(conf->path);
65 conf->path = NULL;