/* * Make a database-root if it doesn't exist. */ static int make_db_root(const char *path) { int rc; char fullpath[PATH_MAX]; if ((rc = make_db_path(fullpath, path, sizeof(fullpath))) == 0) { #if USE_HASHED_DB DB *capdbp; if ((capdbp = _nc_db_open(fullpath, TRUE)) == NULL) rc = -1; else if (_nc_db_close(capdbp) < 0) rc = -1; #else struct stat statbuf; if ((rc = stat(path, &statbuf)) < 0) { rc = mkdir(path, 0777); } else if (_nc_access(path, R_OK | W_OK | X_OK) < 0) { rc = -1; /* permission denied */ } else if (!(S_ISDIR(statbuf.st_mode))) { rc = -1; /* not a directory */ } #endif } return rc; }
_nc_set_writedir(char *dir) { const char *destination; char actual[PATH_MAX]; if (dir == 0 #ifndef USE_ROOT_ENVIRON && use_terminfo_vars() #endif ) dir = getenv("TERMINFO"); if (dir != 0) (void) _nc_tic_dir(dir); destination = _nc_tic_dir(0); if (make_db_root(destination) < 0) { char *home = _nc_home_terminfo(); if (home != 0) { destination = home; if (make_db_root(destination) < 0) _nc_err_abort("%s: permission denied (errno %d)", destination, errno); } } /* * Note: because of this code, this logic should be exercised * *once only* per run. */ #if USE_HASHED_DB make_db_path(actual, destination, sizeof(actual)); #else if (chdir(_nc_tic_dir(destination)) < 0 || getcwd(actual, sizeof(actual)) == 0) _nc_err_abort("%s: not a directory", destination); #endif _nc_keep_tic_dir(strdup(actual)); }