Changeset cbdb144 in rtems


Ignore:
Timestamp:
Aug 16, 2001, 10:15:35 PM (20 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Children:
45e1417
Parents:
b3a6713
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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libc/lseek.c

    rb3a6713 rcbdb144  
    2323{
    2424  rtems_libio_t *iop;
     25  off_t          old_offset;
     26  off_t          status;
    2527
    2628  rtems_libio_check_fd( fd );
     
    2931
    3032  /*
     33   *  Check as many errors as possible before touching iop->offset.
     34   */
     35
     36  if ( !iop->handlers->lseek )
     37    set_errno_and_return_minus_one( ENOTSUP );
     38
     39  /*
    3140   *  Now process the lseek().
    3241   */
    3342
     43  old_offset = iop->offset;
    3444  switch ( whence ) {
    3545    case SEEK_SET:
     
    4252
    4353    case SEEK_END:
    44       iop->offset = iop->size - offset;
     54      iop->offset = iop->size + offset;
    4555      break;
    4656
    4757    default:
    48       errno = EINVAL;
    49       return -1;
     58      set_errno_and_return_minus_one( EINVAL );
    5059  }
    5160
    52   if ( !iop->handlers->lseek )
    53     set_errno_and_return_minus_one( ENOTSUP );
     61  /*
     62   *  At this time, handlers assume iop->offset has the desired
     63   *  new offset.
     64   */
    5465
    55   return (*iop->handlers->lseek)( iop, offset, whence );
     66  status = (*iop->handlers->lseek)( iop, offset, whence );
     67  if ( !status )
     68    return 0;
     69
     70  /*
     71   *  So if the operation failed, we have to restore iop->offset.
     72   */
     73
     74  iop->offset = old_offset;
     75  return status;
    5676}
    5777
Note: See TracChangeset for help on using the changeset viewer.