Handle empty current directory more gracefully.

This commit is contained in:
nicm 2013-11-22 20:58:36 +00:00
parent 72a4602b88
commit 7aeb4473ad
3 changed files with 30 additions and 21 deletions

View File

@ -107,6 +107,7 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
cp = format_expand(ft, args_get(args, 'c'));
format_free(ft);
if (cp != NULL && *cp != '\0') {
fd = open(cp, O_RDONLY|O_DIRECTORY);
free(cp);
if (fd == -1) {
@ -114,6 +115,8 @@ cmd_new_session_exec(struct cmd *self, struct cmd_q *cmdq)
strerror(errno));
return (CMD_RETURN_ERROR);
}
} else if (cp != NULL)
free(cp);
cwd = fd;
} else if (c != NULL && c->session == NULL)
cwd = c->cwd;

View File

@ -117,6 +117,7 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
cp = format_expand(ft, args_get(args, 'c'));
format_free(ft);
if (cp != NULL && *cp != '\0') {
fd = open(cp, O_RDONLY|O_DIRECTORY);
free(cp);
if (fd == -1) {
@ -124,6 +125,8 @@ cmd_new_window_exec(struct cmd *self, struct cmd_q *cmdq)
strerror(errno));
return (CMD_RETURN_ERROR);
}
} else if (cp != NULL)
free(cp);
cwd = fd;
} else if (cmdq->client != NULL && cmdq->client->session == NULL)
cwd = cmdq->client->cwd;

View File

@ -95,6 +95,7 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
cp = format_expand(ft, args_get(args, 'c'));
format_free(ft);
if (cp != NULL && *cp != '\0') {
fd = open(cp, O_RDONLY|O_DIRECTORY);
free(cp);
if (fd == -1) {
@ -102,6 +103,8 @@ cmd_split_window_exec(struct cmd *self, struct cmd_q *cmdq)
strerror(errno));
return (CMD_RETURN_ERROR);
}
} else if (cp != NULL)
free(cp);
cwd = fd;
} else if (cmdq->client != NULL && cmdq->client->session == NULL)
cwd = cmdq->client->cwd;