summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/truncate/truncate.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/usr.bin/truncate/truncate.c b/usr.bin/truncate/truncate.c
index 469dbcb53083..98f72898c048 100644
--- a/usr.bin/truncate/truncate.c
+++ b/usr.bin/truncate/truncate.c
@@ -40,7 +40,7 @@ static const char rcsid[] =
#include <stdlib.h>
#include <unistd.h>
-static off_t parselength(char *, off_t *);
+static int parselength(char *, off_t *);
static void usage(void);
static int no_create;
@@ -108,6 +108,8 @@ main(int argc, char **argv)
omode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
while ((fname = *argv++) != NULL) {
+ if (fd != -1)
+ close(fd);
if ((fd = open(fname, oflags, omode)) == -1) {
if (errno != ENOENT) {
warn("%s", fname);
@@ -138,9 +140,9 @@ main(int argc, char **argv)
error++;
continue;
}
-
- close(fd);
}
+ if (fd != -1)
+ close(fd);
return error ? EXIT_FAILURE : EXIT_SUCCESS;
}
@@ -149,7 +151,7 @@ main(int argc, char **argv)
* Return the numeric value of a string given in the form [+-][0-9]+[GMKT]
* or -1 on format error or overflow.
*/
-static off_t
+static int
parselength(char *ls, off_t *sz)
{
off_t length, oflow;