Rev 4874 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4874 | Rev 4921 | ||
---|---|---|---|
1 | /* Reentrant versions of lseek system call. */ |
1 | /* Reentrant versions of lseek system call. */ |
2 | 2 | ||
3 | #include |
3 | #include |
4 | #include |
4 | #include |
5 | #include <_syslist.h> |
5 | #include <_syslist.h> |
6 | #include |
- | |
7 | 6 | ||
8 | /* Some targets provides their own versions of this functions. Those |
7 | /* Some targets provides their own versions of this functions. Those |
9 | targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ |
8 | targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS. */ |
10 | 9 | ||
11 | #ifdef _REENT_ONLY |
10 | #ifdef _REENT_ONLY |
12 | #ifndef REENTRANT_SYSCALLS_PROVIDED |
11 | #ifndef REENTRANT_SYSCALLS_PROVIDED |
13 | #define REENTRANT_SYSCALLS_PROVIDED |
12 | #define REENTRANT_SYSCALLS_PROVIDED |
14 | #endif |
13 | #endif |
15 | #endif |
14 | #endif |
16 | 15 | ||
17 | #ifndef REENTRANT_SYSCALLS_PROVIDED |
16 | #ifndef REENTRANT_SYSCALLS_PROVIDED |
18 | 17 | ||
19 | #pragma pack(push, 1) |
18 | /* We use the errno variable used by the system dependent layer. */ |
20 | typedef struct |
- | |
21 | { |
- | |
22 | char sec; |
- | |
23 | char min; |
- | |
24 | char hour; |
- | |
25 | char rsv; |
- | |
26 | }detime_t; |
- | |
27 | - | ||
28 | typedef struct |
- | |
29 | { |
- | |
30 | char day; |
- | |
31 | char month; |
- | |
32 | short year; |
- | |
33 | }dedate_t; |
- | |
34 | - | ||
35 | typedef struct |
- | |
36 | { |
- | |
37 | unsigned attr; |
- | |
38 | unsigned flags; |
- | |
39 | union |
- | |
40 | { |
- | |
41 | detime_t ctime; |
- | |
42 | unsigned cr_time; |
- | |
43 | }; |
- | |
44 | union |
- | |
45 | { |
- | |
46 | dedate_t cdate; |
- | |
47 | unsigned cr_date; |
- | |
48 | }; |
- | |
49 | union |
- | |
50 | { |
- | |
51 | detime_t atime; |
- | |
52 | unsigned acc_time; |
- | |
53 | }; |
- | |
54 | union |
- | |
55 | { |
- | |
56 | dedate_t adate; |
- | |
57 | unsigned acc_date; |
- | |
58 | }; |
- | |
59 | union |
- | |
60 | { |
- | |
61 | detime_t mtime; |
- | |
62 | unsigned mod_time; |
- | |
63 | }; |
- | |
64 | union |
- | |
65 | { |
- | |
66 | dedate_t mdate; |
- | |
67 | unsigned mod_date; |
- | |
68 | }; |
- | |
69 | unsigned size; |
- | |
70 | unsigned size_high; |
- | |
71 | } FILEINFO; |
- | |
72 | - | ||
73 | #pragma pack(pop) |
- | |
74 | - | ||
75 | 19 | #undef errno |
|
76 | extern unsigned __NFiles; |
- | |
77 | - | ||
78 | #define __handle_check( __h, __r ) \ |
- | |
79 | if( (__h) < 0 || (__h) > __NFiles ) { \ |
- | |
80 | ptr->_errno = EBADF ; \ |
- | |
81 | return( __r ); \ |
- | |
82 | } |
- | |
83 | 20 | extern int errno; |
|
84 | 21 | ||
85 | /* |
22 | /* |
86 | FUNCTION |
23 | FUNCTION |
87 | <<_lseek_r>>---Reentrant version of lseek |
24 | <<_lseek_r>>---Reentrant version of lseek |
88 | 25 | ||
89 | INDEX |
26 | INDEX |
90 | _lseek_r |
27 | _lseek_r |
91 | 28 | ||
92 | ANSI_SYNOPSIS |
29 | ANSI_SYNOPSIS |
93 | #include |
30 | #include |
94 | off_t _lseek_r(struct _reent *<[ptr]>, |
31 | off_t _lseek_r(struct _reent *<[ptr]>, |
95 | int <[fd]>, off_t <[pos]>, int <[whence]>); |
32 | int <[fd]>, off_t <[pos]>, int <[whence]>); |
96 | 33 | ||
97 | TRAD_SYNOPSIS |
34 | TRAD_SYNOPSIS |
98 | #include |
35 | #include |
99 | off_t _lseek_r(<[ptr]>, <[fd]>, <[pos]>, <[whence]>) |
36 | off_t _lseek_r(<[ptr]>, <[fd]>, <[pos]>, <[whence]>) |
100 | struct _reent *<[ptr]>; |
37 | struct _reent *<[ptr]>; |
101 | int <[fd]>; |
38 | int <[fd]>; |
102 | off_t <[pos]>; |
39 | off_t <[pos]>; |
103 | int <[whence]>; |
40 | int <[whence]>; |
104 | 41 | ||
105 | DESCRIPTION |
42 | DESCRIPTION |
106 | This is a reentrant version of < |
43 | This is a reentrant version of < |
107 | takes a pointer to the global data block, which holds |
44 | takes a pointer to the global data block, which holds |
108 | < |
45 | < |
109 | */ |
46 | */ |
110 | 47 | ||
111 | _off_t |
48 | _off_t |
112 | _DEFUN (_lseek_r, (ptr, fd, pos, whence), |
49 | _DEFUN (_lseek_r, (ptr, fd, pos, whence), |
113 | struct _reent *ptr _AND |
50 | struct _reent *ptr _AND |
114 | int fd _AND |
51 | int fd _AND |
115 | _off_t pos _AND |
52 | _off_t pos _AND |
116 | int whence) |
53 | int whence) |
117 | { |
54 | { |
118 | _off_t ret; |
55 | _off_t ret; |
119 | __file_handle *fh; |
- | |
120 | - | ||
121 | __handle_check( fd, -1 ); |
- | |
122 | fh = (__file_handle*) __getOSHandle( fd ); |
- | |
123 | - | ||
124 | switch(whence) |
- | |
125 | { |
- | |
126 | case SEEK_SET: |
- | |
127 | ret = pos; |
- | |
128 | break; |
- | |
129 | case SEEK_CUR: |
- | |
130 | ret = fh->offset + pos; |
- | |
131 | break; |
- | |
132 | case SEEK_END: |
56 | |
133 | { |
- | |
134 | FILEINFO info; |
57 | errno = 0; |
135 | get_fileinfo(fh->name, &info); |
58 | if ((ret = _lseek (fd, pos, whence)) == (_off_t) -1 && errno != 0) |
136 | ret = pos + info.size; |
59 | ptr->_errno = errno; |
137 | break; |
60 | return ret; |
138 | } |
- | |
139 | default: |
- | |
140 | ptr->_errno = EINVAL; |
- | |
141 | return -1; |
- | |
142 | }; |
- | |
143 | - | ||
144 | fh->offset = ret; |
- | |
145 | - | ||
146 | return( ret ); |
- | |
147 | } |
- | |
148 | - | ||
149 | _off_t |
- | |
150 | _DEFUN (lseek, (fd, pos, whence), |
- | |
151 | int fd _AND |
- | |
152 | _off_t pos _AND |
- | |
153 | int whence) |
- | |
154 | - | ||
155 | { |
- | |
156 | return _lseek_r(_REENT, fd, pos, whence); |
- | |
157 | }; |
61 | } |
158 | 62 | ||
159 | #endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ |
63 | #endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */ |