aboutsummaryrefslogtreecommitdiff
path: root/cmd-save-buffer.c
diff options
context:
space:
mode:
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));