diff --git a/usr.bin/touch/touch.c b/usr.bin/touch/touch.c --- a/usr.bin/touch/touch.c +++ b/usr.bin/touch/touch.c @@ -163,19 +163,14 @@ /* Create the file. */ fd = open(*argv, O_WRONLY | O_CREAT, DEFFILEMODE); - if (fd == -1) { + if (fd < 0 || fstat(fd, &sb) < 0) { rval = 1; warn("%s", *argv); + if (fd >= 0) + (void)close(fd); continue; } - if (fstat(fd, &sb) < 0) { - warn("%s", *argv); - rval = 1; - } - if (close(fd) < 0) { - warn("%s", *argv); - rval = 1; - } + (void)close(fd); /* If using the current time, we're done. */ if (!timeset)