Annotation of coherent/g/usr/lib/uucp/tay104/unix/dup2.c, revision 1.1

1.1     ! root        1: /* dup2.c
        !             2:    The Unix dup2 function, for systems which only have dup.
        !             3: 
        !             4:    Copyright (C) 1985, 1986, 1987, 1988, 1990 Free Software Foundation, Inc.
        !             5: 
        !             6:    This file is part of the Taylor UUCP package.
        !             7: 
        !             8:    This program is free software; you can redistribute it and/or
        !             9:    modify it under the terms of the GNU General Public License as
        !            10:    published by the Free Software Foundation; either version 2 of the
        !            11:    License, or (at your option) any later version.
        !            12: 
        !            13:    This program is distributed in the hope that it will be useful, but
        !            14:    WITHOUT ANY WARRANTY; without even the implied warranty of
        !            15:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
        !            16:    General Public License for more details.
        !            17: 
        !            18:    You should have received a copy of the GNU General Public License
        !            19:    along with this program; if not, write to the Free Software
        !            20:    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
        !            21: 
        !            22:    The author of the program may be contacted at [email protected] or
        !            23:    c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
        !            24:    */
        !            25: 
        !            26: #include "uucp.h"
        !            27: #include "sysdep.h"
        !            28: 
        !            29: #include <errno.h>
        !            30: 
        !            31: #if HAVE_FCNTL_H
        !            32: #include <fcntl.h>
        !            33: #else
        !            34: #if HAVE_SYS_FILE_H
        !            35: #include <sys/file.h>
        !            36: #endif
        !            37: #endif
        !            38: 
        !            39: /* I basically took this from the emacs 18.57 distribution, although I
        !            40:    cleaned it up a bit and made it POSIX compliant.  */
        !            41: 
        !            42: int
        !            43: dup2 (oold, onew)
        !            44:      int oold;
        !            45:      int onew;
        !            46: {
        !            47:   if (oold == onew)
        !            48:     return onew;
        !            49:   (void) close (onew);
        !            50:   
        !            51: #ifdef F_DUPFD
        !            52:   return fcntl (oold, F_DUPFD, onew);
        !            53: #else
        !            54:   {
        !            55:     int onext, oret, isave;
        !            56: 
        !            57:     onext = dup (oold);
        !            58:     if (onext == onew)
        !            59:       return onext;
        !            60:     if (onext < 0)
        !            61:       return -1;
        !            62:     oret = dup2 (oold, onew);
        !            63:     isave = errno;
        !            64:     (void) close (onext);
        !            65:     errno = isave;
        !            66:     return oret;
        !            67:   }
        !            68: #endif
        !            69: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.