diff options
author | jkh <jkh@FreeBSD.org> | 1993-06-18 05:46:17 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1993-06-18 05:46:17 +0000 |
commit | 77629e160d558a58cca8b90f395ec5eba88b6bf0 (patch) | |
tree | 3595c61e4f85a1d3c1fb6ea6c1ede9ea8397ced7 /gnu/usr.bin/cvs/lib/dup2.c | |
download | FreeBSD-src-77629e160d558a58cca8b90f395ec5eba88b6bf0.zip FreeBSD-src-77629e160d558a58cca8b90f395ec5eba88b6bf0.tar.gz |
Updated CVS
Diffstat (limited to 'gnu/usr.bin/cvs/lib/dup2.c')
-rw-r--r-- | gnu/usr.bin/cvs/lib/dup2.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/gnu/usr.bin/cvs/lib/dup2.c b/gnu/usr.bin/cvs/lib/dup2.c new file mode 100644 index 0000000..0bd3aca --- /dev/null +++ b/gnu/usr.bin/cvs/lib/dup2.c @@ -0,0 +1,36 @@ +/* + dup2 -- 7th Edition UNIX system call emulation for UNIX System V + + last edit: 11-Feb-1987 D A Gwyn +*/ + +#include <errno.h> +#include <fcntl.h> + +extern int close(), fcntl(); + +int +dup2( oldfd, newfd ) + int oldfd; /* already-open file descriptor */ + int newfd; /* desired duplicate descriptor */ +{ + register int ret; /* for fcntl() return value */ + register int save; /* for saving entry errno */ + + if ( oldfd == newfd ) + return oldfd; /* be careful not to close() */ + + save = errno; /* save entry errno */ + (void) close( newfd ); /* in case newfd is open */ + /* (may have just clobbered the original errno value) */ + + ret = fcntl( oldfd, F_DUPFD, newfd ); /* dupe it */ + + if ( ret >= 0 ) + errno = save; /* restore entry errno */ + else /* fcntl() returned error */ + if ( errno == EINVAL ) + errno = EBADF; /* we think of everything */ + + return ret; /* return file descriptor */ +} |