This commit is contained in:
Kartik K. Agaram 2022-01-04 22:09:23 -08:00
parent 4798d97a15
commit 64f8a1e15d
1 changed files with 17 additions and 17 deletions

View File

@ -1187,6 +1187,23 @@ void initialize_trustedL() {
lua_gc(trustedL, LUA_GCRESTART, 0);
}
static const char* user_configuration_filename() {
const char* home = getenv("HOME");
if (home == NULL) {
endwin();
fprintf(stderr, "$HOME is not set; unclear where to save permissions.\n");
abort();
}
static char config_filename[1024] = {0};
memset(config_filename, '\0', 1024);
const char* config_home = getenv("XDG_CONFIG_HOME");
if (config_home == NULL)
snprintf(config_filename, 1024, "%s/.teliva", home);
else
snprintf(config_filename, 1024, "%s/.teliva", config_home);
return config_filename;
}
int file_operation_permitted(const char* filename, const char* mode) {
int oldtop = lua_gettop(trustedL);
lua_getglobal(trustedL, "file_operation_permitted");
@ -1354,23 +1371,6 @@ static void permissions_view() {
}
}
static const char* user_configuration_filename() {
const char* home = getenv("HOME");
if (home == NULL) {
endwin();
fprintf(stderr, "$HOME is not set; unclear where to save permissions.\n");
abort();
}
static char config_filename[1024] = {0};
memset(config_filename, '\0', 1024);
const char* config_home = getenv("XDG_CONFIG_HOME");
if (config_home == NULL)
snprintf(config_filename, 1024, "%s/.teliva", home);
else
snprintf(config_filename, 1024, "%s/.teliva", config_home);
return config_filename;
}
static void save_permissions_to_user_configuration(lua_State* L) {
const char* rcfilename = user_configuration_filename();
FILE* in = fopen(rcfilename, "r"); /* can be NULL when rcfile doesn't exist */