4.104.114.84.95
Last change
on this file since dfd218d5 was
dfd218d5,
checked in by Joel Sherrill <joel.sherrill@…>, on 08/16/01 at 22:20:06
|
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.
|
-
Property mode set to
100644
|
File size:
1.8 KB
|
Rev | Line | |
---|
[07a3253d] | 1 | /* |
---|
| 2 | * lseek() - POSIX 1003.1b 6.5.3 - Reposition Read/Write File Offset |
---|
| 3 | * |
---|
[08311cc3] | 4 | * COPYRIGHT (c) 1989-1999. |
---|
[07a3253d] | 5 | * On-Line Applications Research Corporation (OAR). |
---|
| 6 | * |
---|
| 7 | * The license and distribution terms for this file may be |
---|
| 8 | * found in the file LICENSE in this distribution or at |
---|
| 9 | * http://www.OARcorp.com/rtems/license.html. |
---|
| 10 | * |
---|
| 11 | * $Id$ |
---|
| 12 | */ |
---|
| 13 | |
---|
[9c49db4] | 14 | #if HAVE_CONFIG_H |
---|
| 15 | #include "config.h" |
---|
| 16 | #endif |
---|
| 17 | |
---|
[07a3253d] | 18 | #include <stdio.h> |
---|
| 19 | |
---|
[3ba74c73] | 20 | #include <rtems/libio_.h> |
---|
[07a3253d] | 21 | |
---|
| 22 | off_t lseek( |
---|
| 23 | int fd, |
---|
| 24 | off_t offset, |
---|
| 25 | int whence |
---|
| 26 | ) |
---|
| 27 | { |
---|
| 28 | rtems_libio_t *iop; |
---|
[dfd218d5] | 29 | off_t old_offset; |
---|
| 30 | off_t status; |
---|
[07a3253d] | 31 | |
---|
[cca4400] | 32 | rtems_libio_check_fd( fd ); |
---|
| 33 | iop = rtems_libio_iop( fd ); |
---|
[2d733c42] | 34 | rtems_libio_check_is_open(iop); |
---|
[cca4400] | 35 | |
---|
[dfd218d5] | 36 | /* |
---|
| 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 | |
---|
[07a3253d] | 43 | /* |
---|
| 44 | * Now process the lseek(). |
---|
| 45 | */ |
---|
| 46 | |
---|
[dfd218d5] | 47 | old_offset = iop->offset; |
---|
[07a3253d] | 48 | switch ( whence ) { |
---|
| 49 | case SEEK_SET: |
---|
| 50 | iop->offset = offset; |
---|
| 51 | break; |
---|
| 52 | |
---|
| 53 | case SEEK_CUR: |
---|
| 54 | iop->offset += offset; |
---|
| 55 | break; |
---|
| 56 | |
---|
| 57 | case SEEK_END: |
---|
[dfd218d5] | 58 | iop->offset = iop->size + offset; |
---|
[07a3253d] | 59 | break; |
---|
| 60 | |
---|
| 61 | default: |
---|
[dfd218d5] | 62 | set_errno_and_return_minus_one( EINVAL ); |
---|
[07a3253d] | 63 | } |
---|
| 64 | |
---|
[dfd218d5] | 65 | /* |
---|
| 66 | * At this time, handlers assume iop->offset has the desired |
---|
| 67 | * new offset. |
---|
| 68 | */ |
---|
| 69 | |
---|
| 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 | */ |
---|
[07a3253d] | 77 | |
---|
[dfd218d5] | 78 | iop->offset = old_offset; |
---|
| 79 | return status; |
---|
[07a3253d] | 80 | } |
---|
| 81 | |
---|
| 82 | /* |
---|
| 83 | * _lseek_r |
---|
| 84 | * |
---|
| 85 | * This is the Newlib dependent reentrant version of lseek(). |
---|
| 86 | */ |
---|
| 87 | |
---|
| 88 | #if defined(RTEMS_NEWLIB) |
---|
| 89 | |
---|
| 90 | #include <reent.h> |
---|
| 91 | |
---|
| 92 | off_t _lseek_r( |
---|
| 93 | struct _reent *ptr, |
---|
| 94 | int fd, |
---|
| 95 | off_t offset, |
---|
| 96 | int whence |
---|
| 97 | ) |
---|
| 98 | { |
---|
| 99 | return lseek( fd, offset, whence ); |
---|
| 100 | } |
---|
| 101 | #endif |
---|
| 102 | |
---|
Note: See
TracBrowser
for help on using the repository browser.