Changeset dfd218d5 in rtems


Ignore:
Timestamp:
Aug 16, 2001, 10:20:06 PM (20 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
aeb51220
Parents:
3a5fec8
Message:

2001-08-16 Joel Sherrill <joel@…>

  • libc/lseek.c: Modified after discussion with Eugeny S. Mints <jack@…> to correct the behavior. There were two mistakes. First, iop->offset was incorrectly set for SEEK_END. Second, iop->offset should be left unmodified if there are errors. This modification attempts to fix both situations.
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/libcsupport/src/lseek.c

    r3a5fec8 rdfd218d5  
    2727{
    2828  rtems_libio_t *iop;
     29  off_t          old_offset;
     30  off_t          status;
    2931
    3032  rtems_libio_check_fd( fd );
     
    3335
    3436  /*
     37   *  Check as many errors as possible before touching iop->offset.
     38   */
     39
     40  if ( !iop->handlers->lseek_h )
     41    set_errno_and_return_minus_one( ENOTSUP );
     42
     43  /*
    3544   *  Now process the lseek().
    3645   */
    3746
     47  old_offset = iop->offset;
    3848  switch ( whence ) {
    3949    case SEEK_SET:
     
    4656
    4757    case SEEK_END:
    48       iop->offset = iop->size - offset;
     58      iop->offset = iop->size + offset;
    4959      break;
    5060
    5161    default:
    52       errno = EINVAL;
    53       return -1;
     62      set_errno_and_return_minus_one( EINVAL );
    5463  }
    5564
    56   if ( !iop->handlers->lseek_h )
    57     set_errno_and_return_minus_one( ENOTSUP );
     65  /*
     66   *  At this time, handlers assume iop->offset has the desired
     67   *  new offset.
     68   */
    5869
    59   return (*iop->handlers->lseek_h)( iop, offset, whence );
     70  status = (*iop->handlers->lseek_h)( iop, offset, whence );
     71  if ( !status )
     72    return 0;
     73
     74  /*
     75   *  So if the operation failed, we have to restore iop->offset.
     76   */
     77
     78  iop->offset = old_offset;
     79  return status;
    6080}
    6181
  • c/src/lib/ChangeLog

    r3a5fec8 rdfd218d5  
     12001-08-16      Joel Sherrill <joel@OARcorp.com>
     2
     3        * libc/lseek.c: Modified after discussion with Eugeny S. Mints
     4        <jack@oktet.ru> to correct the behavior.  There were two mistakes.
     5        First, iop->offset was incorrectly set for SEEK_END.  Second,
     6        iop->offset should be left unmodified if there are errors.
     7        This modification attempts to fix both situations.
     8
    192001-08-16      Mike Siers <mikes@poliac.com>
    210
  • c/src/lib/libc/lseek.c

    r3a5fec8 rdfd218d5  
    2727{
    2828  rtems_libio_t *iop;
     29  off_t          old_offset;
     30  off_t          status;
    2931
    3032  rtems_libio_check_fd( fd );
     
    3335
    3436  /*
     37   *  Check as many errors as possible before touching iop->offset.
     38   */
     39
     40  if ( !iop->handlers->lseek_h )
     41    set_errno_and_return_minus_one( ENOTSUP );
     42
     43  /*
    3544   *  Now process the lseek().
    3645   */
    3746
     47  old_offset = iop->offset;
    3848  switch ( whence ) {
    3949    case SEEK_SET:
     
    4656
    4757    case SEEK_END:
    48       iop->offset = iop->size - offset;
     58      iop->offset = iop->size + offset;
    4959      break;
    5060
    5161    default:
    52       errno = EINVAL;
    53       return -1;
     62      set_errno_and_return_minus_one( EINVAL );
    5463  }
    5564
    56   if ( !iop->handlers->lseek_h )
    57     set_errno_and_return_minus_one( ENOTSUP );
     65  /*
     66   *  At this time, handlers assume iop->offset has the desired
     67   *  new offset.
     68   */
    5869
    59   return (*iop->handlers->lseek_h)( iop, offset, whence );
     70  status = (*iop->handlers->lseek_h)( iop, offset, whence );
     71  if ( !status )
     72    return 0;
     73
     74  /*
     75   *  So if the operation failed, we have to restore iop->offset.
     76   */
     77
     78  iop->offset = old_offset;
     79  return status;
    6080}
    6181
  • cpukit/libcsupport/src/lseek.c

    r3a5fec8 rdfd218d5  
    2727{
    2828  rtems_libio_t *iop;
     29  off_t          old_offset;
     30  off_t          status;
    2931
    3032  rtems_libio_check_fd( fd );
     
    3335
    3436  /*
     37   *  Check as many errors as possible before touching iop->offset.
     38   */
     39
     40  if ( !iop->handlers->lseek_h )
     41    set_errno_and_return_minus_one( ENOTSUP );
     42
     43  /*
    3544   *  Now process the lseek().
    3645   */
    3746
     47  old_offset = iop->offset;
    3848  switch ( whence ) {
    3949    case SEEK_SET:
     
    4656
    4757    case SEEK_END:
    48       iop->offset = iop->size - offset;
     58      iop->offset = iop->size + offset;
    4959      break;
    5060
    5161    default:
    52       errno = EINVAL;
    53       return -1;
     62      set_errno_and_return_minus_one( EINVAL );
    5463  }
    5564
    56   if ( !iop->handlers->lseek_h )
    57     set_errno_and_return_minus_one( ENOTSUP );
     65  /*
     66   *  At this time, handlers assume iop->offset has the desired
     67   *  new offset.
     68   */
    5869
    59   return (*iop->handlers->lseek_h)( iop, offset, whence );
     70  status = (*iop->handlers->lseek_h)( iop, offset, whence );
     71  if ( !status )
     72    return 0;
     73
     74  /*
     75   *  So if the operation failed, we have to restore iop->offset.
     76   */
     77
     78  iop->offset = old_offset;
     79  return status;
    6080}
    6181
Note: See TracChangeset for help on using the changeset viewer.