diff options
author | 2009-10-26 21:25:57 +0000 | |
---|---|---|
committer | 2009-10-26 21:25:57 +0000 | |
commit | b4e6597439364bee0425320a12177e21b7635f19 (patch) | |
tree | 4e7dc598f5ba70734b1e856491990a41df143d19 /usr.bin/tmux/cmd-load-buffer.c | |
parent | Reset the umask right after fopen to avoid leaving it changed on error, noticed (diff) | |
download | wireguard-openbsd-b4e6597439364bee0425320a12177e21b7635f19.tar.xz wireguard-openbsd-b4e6597439364bee0425320a12177e21b7635f19.zip |
Call fstat() after fopen() rather than stat() before.
Diffstat (limited to 'usr.bin/tmux/cmd-load-buffer.c')
-rw-r--r-- | usr.bin/tmux/cmd-load-buffer.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/usr.bin/tmux/cmd-load-buffer.c b/usr.bin/tmux/cmd-load-buffer.c index 470179836fa..1a545259ba2 100644 --- a/usr.bin/tmux/cmd-load-buffer.c +++ b/usr.bin/tmux/cmd-load-buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-load-buffer.c,v 1.6 2009/09/07 18:50:45 nicm Exp $ */ +/* $OpenBSD: cmd-load-buffer.c,v 1.7 2009/10/26 21:25:57 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -56,13 +56,14 @@ cmd_load_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) if ((s = cmd_find_session(ctx, data->target)) == NULL) return (-1); - if (stat(data->arg, &sb) < 0) { + if ((f = fopen(data->arg, "rb")) == NULL) { ctx->error(ctx, "%s: %s", data->arg, strerror(errno)); return (-1); } - if ((f = fopen(data->arg, "rb")) == NULL) { + if (fstat(fileno(f), &sb) < 0) { ctx->error(ctx, "%s: %s", data->arg, strerror(errno)); + fclose(f); return (-1); } |