+ * Note: there's no reason to return the result of make_db_root(), since
+ * this function is called only in instances where that has to succeed.
+ */
+static void
+check_writeable(int code)
+{
+ static const char dirnames[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ static bool verified[sizeof(dirnames)];
+
+ char dir[sizeof(LEAF_FMT)];
+ char *s = 0;
+
+ if (code == 0 || (s = (strchr) (dirnames, code)) == 0)
+ _nc_err_abort("Illegal terminfo subdirectory \"" LEAF_FMT "\"", code);
+
+ if (verified[s - dirnames])
+ return;
+
+ _nc_SPRINTF(dir, _nc_SLIMIT(sizeof(dir)) LEAF_FMT, code);
+ if (make_db_root(dir) < 0) {
+ _nc_err_abort("%s/%s: permission denied", _nc_tic_dir(0), dir);
+ }
+
+ verified[s - dirnames] = TRUE;
+}
+#endif /* !USE_HASHED_DB */
+
+static int
+make_db_path(char *dst, const char *src, size_t limit)
+{
+ int rc = -1;
+ const char *top = _nc_tic_dir(0);
+
+ if (src == top || _nc_is_abs_path(src)) {
+ if (strlen(src) + 1 <= limit) {
+ _nc_STRCPY(dst, src, limit);
+ rc = 0;
+ }
+ } else {
+ if (strlen(top) + strlen(src) + 2 <= limit) {
+ _nc_SPRINTF(dst, _nc_SLIMIT(limit) "%s/%s", top, src);
+ rc = 0;
+ }
+ }
+#if USE_HASHED_DB
+ if (rc == 0) {
+ static const char suffix[] = DBM_SUFFIX;
+ size_t have = strlen(dst);
+ size_t need = strlen(suffix);
+ if (have > need && strcmp(dst + (int) (have - need), suffix)) {
+ if (have + need <= limit) {
+ _nc_STRCAT(dst, suffix, limit);
+ } else {
+ rc = -1;
+ }
+ } else if (_nc_is_dir_path(dst)) {
+ rc = -1;
+ }
+ }
+#endif
+ return rc;
+}
+
+/*
+ * Make a database-root if it doesn't exist.