Skip to content

Commit c99e9ff

Browse files
committed
Improve style of sh_close()
Looking into issue #1438 caused me to notice the style of `sh_close()` would benefit from some tweaking.
1 parent d72c3a6 commit c99e9ff

File tree

1 file changed

+4
-5
lines changed
  • src/cmd/ksh93/sh

1 file changed

+4
-5
lines changed

src/cmd/ksh93/sh/io.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -455,21 +455,20 @@ int sh_iorenumber(Shell_t *shp, int f1, int f2) {
455455
//
456456
int sh_close(int fd) {
457457
Shell_t *shp = sh_getinterp();
458-
Sfio_t *sp;
459-
int r = 0;
460458

461459
if (!sh_iovalidfd(shp, fd)) {
462460
errno = EBADF;
463461
return -1;
464462
}
465463

466-
if (!(sp = shp->sftable[fd]) || (sffileno(sp) != fd) || (sfclose(sp) < 0)) {
464+
Sfio_t *sp = shp->sftable[fd];
465+
if (!sp || sffileno(sp) != fd || sfclose(sp) < 0) {
467466
if (fdnotify) (*fdnotify)(fd, SH_FDCLOSE);
468467
close(fd);
469468
}
470469

471-
if (fd > 2) shp->sftable[fd] = 0;
472-
r = (shp->fdstatus[fd] >> 8);
470+
if (fd > STDERR_FILENO) shp->sftable[fd] = 0;
471+
int r = (shp->fdstatus[fd] >> 8);
473472
if (r) close(r);
474473
shp->fdstatus[fd] = IOCLOSE;
475474
if (shp->fdptrs[fd]) *shp->fdptrs[fd] = -1;

0 commit comments

Comments
 (0)