ref: 2a1ad3f2ba59b3a6866338d5015bd94248ca3204
parent: c5f2a8f34cf0c14a905edb5cb3f2a9001c9b752e
author: cancel <cancel@cancel.fm>
date: Mon Jan 27 05:13:47 EST 2020
Cleanup conf naming prefix requirement
--- a/sysmisc.c
+++ b/sysmisc.c
@@ -243,6 +243,21 @@
return Conf_dir_no_home;
}
+static void conf_impl_catconfpath(oso **p, char const *conf_file_name,
+ size_t conflen) {
+ oso *path = *p;
+ size_t n = osolen(path);
+ osoensurecap(&path, n + 1 + conflen);
+ if (!path)
+ goto done;
+ ((char *)path)[n] = '/';
+ memcpy((char *)path + n + 1, conf_file_name, conflen);
+ ((char *)path)[n + 1 + conflen] = '\0';
+ osopokelen(path, n + 1 + conflen);
+done:
+ *p = path;
+}
+
FILE *conf_file_open_for_reading(char const *conf_file_name) {
if (!conf_file_name)
return NULL;
@@ -249,7 +264,10 @@
oso *path = NULL;
if (try_get_conf_dir(&path))
return NULL;
- osocat(&path, conf_file_name);
+ size_t conflen = strlen(conf_file_name);
+ if (conflen == 0)
+ return NULL;
+ conf_impl_catconfpath(&path, conf_file_name, conflen);
if (!path)
return NULL;
FILE *file = fopen(osoc(path), "r");
@@ -275,12 +293,25 @@
goto cleanup;
}
osoputoso(&p->canonpath, dir);
- osocat(&p->canonpath, conf_file_name);
if (!p->canonpath) {
err = Conf_save_start_alloc_failed;
goto cleanup;
}
+ size_t namelen = strlen(conf_file_name);
+ if (namelen == 0) {
+ err = Conf_save_start_bad_conf_name;
+ goto cleanup;
+ }
+ conf_impl_catconfpath(&p->canonpath, conf_file_name, namelen);
+ if (!p->canonpath) {
+ err = Conf_save_start_alloc_failed;
+ goto cleanup;
+ }
osoputoso(&p->temppath, p->canonpath);
+ if (!p->temppath) {
+ err = Conf_save_start_alloc_failed;
+ goto cleanup;
+ }
osocat(&p->temppath, ".tmp");
if (!p->temppath) {
err = Conf_save_start_alloc_failed;
@@ -394,7 +425,7 @@
return "Unknown";
}
-void ezconf_r_start(Ezconf_r *ezcr, char const* conf_file_name) {
+void ezconf_r_start(Ezconf_r *ezcr, char const *conf_file_name) {
ezcr->file = conf_file_open_for_reading(conf_file_name);
ezcr->index = 0;
ezcr->value = NULL;
--- a/thirdparty/oso.c
+++ b/thirdparty/oso.c
@@ -189,6 +189,7 @@
*a = *b;
*b = tmp;
}
+void osopokelen(oso *s, size_t len) { OSO_HDR(s)->len = len; }
size_t osolen(oso const *s) { return s ? OSO_HDR(s)->len : 0; }
size_t osocap(oso const *s) { return s ? OSO_HDR(s)->cap : 0; }
void osolencap(oso const *s, size_t *out_len, size_t *out_cap) {
--- a/tui_main.c
+++ b/tui_main.c
@@ -2490,7 +2490,7 @@
*io_use_gui_clipboard = false;
}
-static char const *const conf_file_name = "/orca.conf";
+static char const *const conf_file_name = "orca.conf";
#define CONFOPT_STRING(x) #x,
#define CONFOPT_ENUM(x) Confopt_##x,
#define CONFOPTS(_) \