From 548e2c20bb19b824976aec84d8a7d2c5fb74b7b1 Mon Sep 17 00:00:00 2001 From: bjh21 Date: Sun, 29 Jun 2003 22:57:23 +0000 Subject: 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(). --- usr.bin/split/split.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'usr.bin/split/split.c') 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 @@ -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); } -- cgit