From c99e9ff13e8fc1bf46127e6f28d0f0bde16ffda0 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Thu, 14 Nov 2019 20:31:18 -0800 Subject: [PATCH] Improve style of sh_close() Looking into issue #1438 caused me to notice the style of `sh_close()` would benefit from some tweaking. --- src/cmd/ksh93/sh/io.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/cmd/ksh93/sh/io.c b/src/cmd/ksh93/sh/io.c index 75a59e2d0185..49a687fe4182 100644 --- a/src/cmd/ksh93/sh/io.c +++ b/src/cmd/ksh93/sh/io.c @@ -455,21 +455,20 @@ int sh_iorenumber(Shell_t *shp, int f1, int f2) { // int sh_close(int fd) { Shell_t *shp = sh_getinterp(); - Sfio_t *sp; - int r = 0; if (!sh_iovalidfd(shp, fd)) { errno = EBADF; return -1; } - if (!(sp = shp->sftable[fd]) || (sffileno(sp) != fd) || (sfclose(sp) < 0)) { + Sfio_t *sp = shp->sftable[fd]; + if (!sp || sffileno(sp) != fd || sfclose(sp) < 0) { if (fdnotify) (*fdnotify)(fd, SH_FDCLOSE); close(fd); } - if (fd > 2) shp->sftable[fd] = 0; - r = (shp->fdstatus[fd] >> 8); + if (fd > STDERR_FILENO) shp->sftable[fd] = 0; + int r = (shp->fdstatus[fd] >> 8); if (r) close(r); shp->fdstatus[fd] = IOCLOSE; if (shp->fdptrs[fd]) *shp->fdptrs[fd] = -1;