Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/dd Optimise previous change, using fcntl(F_DUPFD) to loc...



details:   https://anonhg.NetBSD.org/src/rev/b419263be298
branches:  trunk
changeset: 555356:b419263be298
user:      dsainty <dsainty%NetBSD.org@localhost>
date:      Sat Nov 15 14:55:32 2003 +0000

description:
Optimise previous change, using fcntl(F_DUPFD) to locate a free descriptor
for us, rather than iterating until satisfied.

Suggested by David Laight.

diffstat:

 bin/dd/dd.c |  18 ++++++++----------
 1 files changed, 8 insertions(+), 10 deletions(-)

diffs (43 lines):

diff -r bc66cc6a0bae -r b419263be298 bin/dd/dd.c
--- a/bin/dd/dd.c       Sat Nov 15 12:53:34 2003 +0000
+++ b/bin/dd/dd.c       Sat Nov 15 14:55:32 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: dd.c,v 1.34 2003/11/15 12:44:54 dsainty Exp $  */
+/*     $NetBSD: dd.c,v 1.35 2003/11/15 14:55:32 dsainty Exp $  */
 
 /*-
  * Copyright (c) 1991, 1993, 1994
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "@(#)dd.c       8.5 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: dd.c,v 1.34 2003/11/15 12:44:54 dsainty Exp $");
+__RCSID("$NetBSD: dd.c,v 1.35 2003/11/15 14:55:32 dsainty Exp $");
 #endif
 #endif /* not lint */
 
@@ -272,18 +272,16 @@
                /* File descriptor is ok, return immediately. */
                return fd;
 
-       newfd = dup(fd);
+       /*
+        * 3 is the first descriptor greater than STD*_FILENO.  Any
+        * free descriptor valued 3 or above is acceptable...
+        */
+       newfd = fcntl(fd, F_DUPFD, 3);
        if (newfd < 0) {
-               err(EXIT_FAILURE, "dup IO");
+               err(EXIT_FAILURE, "dupfd IO");
                /* NOTREACHED */
        }
 
-       /*
-        * Recurse, to ensure that the new descriptor is clean.  Don't
-        * free the old descriptor(s) until we've allocated a clean
-        * one.
-        */
-       newfd = redup_clean_fd(newfd);
        close(fd);
 
        return newfd;



Home | Main Index | Thread Index | Old Index