Changeset 6122cb6a in rtems


Ignore:
Timestamp:
Dec 10, 2013, 1:35:29 AM (6 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.11, master
Children:
663ffd0e
Parents:
9da8740
Message:

PR2158: Add support for dup2.

Split the dub call into dup and dup2 in fcntl.c. This requires
a private command which is placed in the internal libio header.

Location:
cpukit/libcsupport
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libcsupport/include/rtems/libio_.h

    r9da8740 r6122cb6a  
    4141
    4242#define RTEMS_FILESYSTEM_SYMLOOP_MAX 32
     43
     44/*
     45 * Not defined in newlib so provide here. Users should use dup2 and
     46 * not this non-portable fcntl command. Provided here to allow the
     47 * RTEMS implementation to work.
     48 */
     49#define F_DUP2FD 20
    4350
    4451/*
  • cpukit/libcsupport/src/dup2.c

    r9da8740 r6122cb6a  
    5555   */
    5656
    57   return fcntl( fildes, F_DUPFD, fildes2 );
     57  return fcntl( fildes, F_DUP2FD, fildes2 );
    5858}
  • cpukit/libcsupport/src/fcntl.c

    r9da8740 r6122cb6a  
    2525#include <rtems/libio_.h>
    2626
    27 static int duplicate_iop( rtems_libio_t *iop, int fd2 )
     27static int duplicate_iop( rtems_libio_t *iop )
    2828{
    2929  int rv = 0;
    3030
    31   /*
    32    * FIXME: We ignore the start value fd2 for the file descriptor search.  This
    33    * is not POSIX conform.
    34    */
    3531  rtems_libio_t *diop = rtems_libio_allocate();
    3632
     
    6359}
    6460
     61static int duplicate2_iop( rtems_libio_t *iop, int fd2 )
     62{
     63  rtems_libio_t *iop2;
     64  int            rv = 0;
     65
     66  rtems_libio_check_fd( fd2 );
     67  iop2 = rtems_libio_iop( fd2 );
     68
     69  if (iop != iop2)
     70  {
     71    int oflag;
     72
     73    if ((iop2->flags & LIBIO_FLAGS_OPEN) != 0) {
     74      rv = (*iop2->pathinfo.handlers->close_h)( iop2 );
     75    }
     76
     77    if (rv == 0) {
     78      oflag = rtems_libio_to_fcntl_flags( iop->flags );
     79      oflag &= ~O_CREAT;
     80      iop2->flags |= rtems_libio_fcntl_flags( oflag );
     81
     82      rtems_filesystem_instance_lock( &iop->pathinfo );
     83      rtems_filesystem_location_clone( &iop2->pathinfo, &iop->pathinfo );
     84      rtems_filesystem_instance_unlock( &iop->pathinfo );
     85
     86      /*
     87       * XXX: We call the open handler here to have a proper open and close
     88       *      pair.
     89       *
     90       * FIXME: What to do with the path?
     91       */
     92      rv = (*iop2->pathinfo.handlers->open_h)( iop2, NULL, oflag, 0 );
     93      if ( rv == 0 ) {
     94        rv = fd2;
     95      }
     96    }
     97  }
     98
     99  return rv;
     100}
     101
    65102static int vfcntl(
    66103  int fd,
     
    89126  switch ( cmd ) {
    90127    case F_DUPFD:        /* dup */
     128      ret = duplicate_iop( iop );
     129      break;
     130
     131    case F_DUP2FD:       /* dup2 */
    91132      fd2 = va_arg( ap, int );
    92       ret = duplicate_iop( iop, fd2 );
     133      ret = duplicate2_iop( iop, fd2 );
    93134      break;
    94135
Note: See TracChangeset for help on using the changeset viewer.