From 5822f437a1b826a30899036aa981c063ab274446 Mon Sep 17 00:00:00 2001 From: Jennifer Averett Date: Thu, 3 Dec 1998 22:17:26 +0000 Subject: Added source for F_DUPFD. --- c/src/exec/libcsupport/src/fcntl.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'c/src/exec/libcsupport') diff --git a/c/src/exec/libcsupport/src/fcntl.c b/c/src/exec/libcsupport/src/fcntl.c index f6f33534ab..a538ec1cf9 100644 --- a/c/src/exec/libcsupport/src/fcntl.c +++ b/c/src/exec/libcsupport/src/fcntl.c @@ -27,6 +27,8 @@ int fcntl( { va_list ap; rtems_libio_t *iop; + rtems_libio_t *diop; + int fd2; va_start( ap, cmd ); @@ -50,18 +52,22 @@ int fcntl( switch ( cmd ) { case F_DUPFD: /* dup */ - /* - * This is how it appears that this case should work: - * - * filedes2 = va_arg( ap, int ) - * if filedes2 is 0 - * duplicate fd into a new descriptor - * else - * duplicate fd into specified descriptor after error checking it - * - * See dup2() in case we can eliminate stuff in there. - */ - return -1; + fd2 = va_arg( ap, int ); + if ( fd2 ) + diop = rtems_libio_iop( fd2 ); + else { + /* allocate a file control block */ + diop = rtems_libio_allocate(); + if ( diop == 0 ) + return -1; + } + + diop->handlers = iop->handlers; + diop->file_info = iop->file_info; + diop->flags = iop->flags; + diop->pathinfo = iop->pathinfo; + + return 0; case F_GETFD: /* get f_flags */ if ( iop->flags & LIBIO_FLAGS_CLOSE_ON_EXEC ) -- cgit v1.2.3