summaryrefslogtreecommitdiff
path: root/usr.bin/split
diff options
context:
space:
mode:
authorbjh21 <bjh21@NetBSD.org>2003-06-29 22:57:23 +0000
committerbjh21 <bjh21@NetBSD.org>2003-06-29 22:57:23 +0000
commit548e2c20bb19b824976aec84d8a7d2c5fb74b7b1 (patch)
tree3dd6631966693080587d9fec89bd5eb4e11e1b51 /usr.bin/split
parent4fdb86c883878928e0bb6519b92d74bc42c01caa (diff)
Clean up the mechanism used for opening output files. Rather than freopening
stdout onto each file in turn, then writing through fileno(stdout), use open() and close() like any sensible program. This saves a lot of system calls, removes a dependency on the particular behaviour of BSD freopen(), and allows us to detect and report errors from close().
Diffstat (limited to 'usr.bin/split')
-rw-r--r--usr.bin/split/split.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/usr.bin/split/split.c b/usr.bin/split/split.c
index ec9d6bc3465..ed1f5ed5a3a 100644
--- a/usr.bin/split/split.c
+++ b/usr.bin/split/split.c
@@ -1,4 +1,4 @@
-/* $NetBSD: split.c,v 1.16 2003/06/26 23:19:15 bjh21 Exp $ */
+/* $NetBSD: split.c,v 1.17 2003/06/29 22:57:23 bjh21 Exp $ */
/*
* Copyright (c) 1987, 1993, 1994
@@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1987, 1993, 1994\n\
#if 0
static char sccsid[] = "@(#)split.c 8.3 (Berkeley) 4/25/94";
#endif
-__RCSID("$NetBSD: split.c,v 1.16 2003/06/26 23:19:15 bjh21 Exp $");
+__RCSID("$NetBSD: split.c,v 1.17 2003/06/29 22:57:23 bjh21 Exp $");
#endif /* not lint */
#include <sys/param.h>
@@ -296,7 +296,9 @@ newfile(void)
fpnt = fname + strlen(fname);
defname = 0;
}
- ofd = fileno(stdout);
+ } else {
+ if (close(ofd) != 0)
+ err(1, "%s", fname);
}
/*
* Hack to increase max files; original code wandered through
@@ -315,7 +317,7 @@ newfile(void)
fnum = 0;
}
++fnum;
- if (!freopen(fname, "w", stdout))
+ if ((ofd = open(fname, O_WRONLY | O_CREAT | O_TRUNC, DEFFILEMODE)) < 0)
err(1, "%s", fname);
}