aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/xwrap.c2
-rw-r--r--toys/other/hwclock.c2
-rw-r--r--toys/other/losetup.c6
-rw-r--r--toys/posix/split.c4
4 files changed, 7 insertions, 7 deletions
diff --git a/lib/xwrap.c b/lib/xwrap.c
index 22f00f2b..607f3c61 100644
--- a/lib/xwrap.c
+++ b/lib/xwrap.c
@@ -416,7 +416,7 @@ void xpipe(int *pp)
void xclose(int fd)
{
- if (close(fd)) perror_exit("xclose");
+ if (fd != -1 && close(fd)) perror_exit("xclose");
}
int xdup(int fd)
diff --git a/toys/other/hwclock.c b/toys/other/hwclock.c
index a6db923a..541c70a3 100644
--- a/toys/other/hwclock.c
+++ b/toys/other/hwclock.c
@@ -84,5 +84,5 @@ void hwclock_main()
if (settimeofday(&timeval, &tzone)) perror_exit("settimeofday failed");
}
- if (fd != -1) close(fd);
+ xclose(fd);
}
diff --git a/toys/other/losetup.c b/toys/other/losetup.c
index 27d25a18..7b8aed4f 100644
--- a/toys/other/losetup.c
+++ b/toys/other/losetup.c
@@ -52,7 +52,7 @@ GLOBALS(
static int loopback_setup(char *device, char *file)
{
struct loop_info64 *loop = (void *)(toybuf+32);
- int lfd = -1, ffd = ffd;
+ int lfd = -1, ffd = -1;
int racy = !device;
// Open file (ffd) and loop device (lfd)
@@ -129,8 +129,8 @@ static int loopback_setup(char *device, char *file)
}
done:
- if (file) close(ffd);
- if (lfd != -1) close(lfd);
+ xclose(ffd);
+ xclose(lfd);
return 0;
}
diff --git a/toys/posix/split.c b/toys/posix/split.c
index 0da8da6a..daf6422e 100644
--- a/toys/posix/split.c
+++ b/toys/posix/split.c
@@ -65,7 +65,7 @@ static void do_split(int infd, char *in)
if (j) error_exit("bad suffix");
bytesleft = TT.b;
linesleft = TT.l;
- if (outfd != -1) close(outfd);
+ xclose(outfd);
outfd = xcreate(TT.outfile, O_RDWR|O_CREAT|O_TRUNC, st.st_mode & 0777);
}
@@ -86,7 +86,7 @@ static void do_split(int infd, char *in)
}
if (CFG_TOYBOX_FREE) {
- if (outfd != -1) close(outfd);
+ xclose(outfd);
if (infd) close(infd);
free(TT.outfile);
}