Line | |
---|
1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup LibIOFSOps File System Operations |
---|
5 | * |
---|
6 | * @brief RTEMS Default File System reposits the offset of the open file fd |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2012 embedded brains GmbH. All rights reserved. |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #ifdef HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/libio_.h> |
---|
22 | |
---|
23 | off_t rtems_filesystem_default_lseek_file( |
---|
24 | rtems_libio_t *iop, |
---|
25 | off_t offset, |
---|
26 | int whence |
---|
27 | ) |
---|
28 | { |
---|
29 | off_t rv = 0; |
---|
30 | off_t reference_offset; |
---|
31 | struct stat st; |
---|
32 | |
---|
33 | switch ( whence ) { |
---|
34 | case SEEK_SET: |
---|
35 | reference_offset = 0; |
---|
36 | break; |
---|
37 | case SEEK_CUR: |
---|
38 | reference_offset = iop->offset; |
---|
39 | break; |
---|
40 | case SEEK_END: |
---|
41 | st.st_size = 0; |
---|
42 | rv = (*iop->pathinfo.handlers->fstat_h)( &iop->pathinfo, &st ); |
---|
43 | reference_offset = st.st_size; |
---|
44 | break; |
---|
45 | default: |
---|
46 | errno = EINVAL; |
---|
47 | rv = -1; |
---|
48 | break; |
---|
49 | } |
---|
50 | |
---|
51 | if ( rv == 0 ) { |
---|
52 | off_t new_offset = reference_offset + offset; |
---|
53 | |
---|
54 | if ( |
---|
55 | (offset >= 0 && new_offset >= reference_offset) |
---|
56 | || (offset < 0 && new_offset < reference_offset) |
---|
57 | ) { |
---|
58 | if ( new_offset >= 0 ) { |
---|
59 | iop->offset = new_offset; |
---|
60 | rv = new_offset; |
---|
61 | } else { |
---|
62 | errno = EINVAL; |
---|
63 | rv = -1; |
---|
64 | } |
---|
65 | } else { |
---|
66 | errno = EOVERFLOW; |
---|
67 | rv = -1; |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | return rv; |
---|
72 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.