Make setting NNN_TMPFILE explicit

This commit is contained in:
Arun Prakash Jana 2018-09-02 19:04:45 +05:30
parent 2beea9bce8
commit 7d065ff22d
No known key found for this signature in database
GPG Key ID: A75979F35C080412
1 changed files with 10 additions and 14 deletions

24
nnn.c
View File

@ -2408,7 +2408,7 @@ browse(char *ipath, char *ifilter)
static char oldname[NAME_MAX + 1] __attribute__ ((aligned)); static char oldname[NAME_MAX + 1] __attribute__ ((aligned));
char *dir, *tmp, *run = NULL, *env = NULL; char *dir, *tmp, *run = NULL, *env = NULL;
struct stat sb; struct stat sb;
int r, fd, presel, ncp = 0, copystartid = 0, copyendid = 0; int r, fd, truecd, presel, ncp = 0, copystartid = 0, copyendid = 0;
enum action sel = SEL_RUNARG + 1; enum action sel = SEL_RUNARG + 1;
bool dir_changed = FALSE; bool dir_changed = FALSE;
@ -2609,18 +2609,17 @@ nochange:
break; break;
case SEL_CD: case SEL_CD:
{ {
int truecd = 0; truecd = 0;
tmp = xreadline(NULL, "cd: "); tmp = xreadline(NULL, "cd: ");
if (tmp == NULL || tmp[0] == '\0') if (tmp == NULL || tmp[0] == '\0')
break; break;
if (tmp[0] == '~') { if (tmp[0] == '~') {
/* Expand ~ to HOME absolute path */ /* Expand ~ to HOME absolute path */
char *home = getenv("HOME"); char *dir = getenv("HOME");
if (home) if (dir)
snprintf(newpath, PATH_MAX, "%s%s", home, tmp + 1); snprintf(newpath, PATH_MAX, "%s%s", dir, tmp + 1);
else { else {
printmsg(messages[STR_NOHOME_ID]); printmsg(messages[STR_NOHOME_ID]);
goto nochange; goto nochange;
@ -3242,13 +3241,13 @@ nochange:
#endif #endif
case SEL_CDQUIT: case SEL_CDQUIT:
{ {
char *tmpfile = "/tmp/nnn";
tmp = getenv("NNN_TMPFILE"); tmp = getenv("NNN_TMPFILE");
if (tmp) if (!tmp) {
tmpfile = tmp; printmsg("set NNN_TMPFILE");
goto nochange;
}
FILE *fp = fopen(tmpfile, "w"); FILE *fp = fopen(tmp, "w");
if (fp) { if (fp) {
fprintf(fp, "cd \"%s\"", path); fprintf(fp, "cd \"%s\"", path);
@ -3386,9 +3385,6 @@ main(int argc, char *argv[])
fprintf(stderr, "kqueue init! %s\n", strerror(errno)); fprintf(stderr, "kqueue init! %s\n", strerror(errno));
exit(1); exit(1);
} }
gtimeout.tv_sec = 0;
gtimeout.tv_nsec = 0;
#endif #endif
/* Edit text in EDITOR, if opted */ /* Edit text in EDITOR, if opted */