summaryrefslogtreecommitdiffstats
path: root/cmd-save-buffer.c
diff options
context:
space:
mode:
authornicm <nicm>2015-11-10 22:29:33 +0000
committernicm <nicm>2015-11-10 22:29:33 +0000
commit005e462e01b58015f3e1d841b185186e6b5d4e14 (patch)
tree04f7d6b9887f73b143333083452e510aab09d448 /cmd-save-buffer.c
parentdcdccf83338654e41281b3b4a8f1c8d2e0621a13 (diff)
Handle absolute paths properly, and don't use resolved path in
realpath() fails.
Diffstat (limited to 'cmd-save-buffer.c')
-rw-r--r--cmd-save-buffer.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/cmd-save-buffer.c b/cmd-save-buffer.c
index dca2c8ef..8de99075 100644
--- a/cmd-save-buffer.c
+++ b/cmd-save-buffer.c
@@ -103,11 +103,15 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_q *cmdq)
if (args_has(self->args, 'a'))
flags = "ab";
- xasprintf(&file, "%s/%s", cwd, path);
- if (realpath(file, resolved) == NULL)
- f = NULL;
+ if (*path == '/')
+ file = xstrdup(path);
else
- f = fopen(resolved, flags);
+ xasprintf(&file, "%s/%s", cwd, path);
+ if (realpath(file, resolved) == NULL) {
+ cmdq_error(cmdq, "%s: %s", file, strerror(errno));
+ return (CMD_RETURN_ERROR);
+ }
+ f = fopen(resolved, flags);
free(file);
if (f == NULL) {
cmdq_error(cmdq, "%s: %s", resolved, strerror(errno));