Rev 4921 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
9952 | turbocat | 1 | /* |
2 | * Copyright (C) KolibriOS team 2004-2024. All rights reserved. |
||
3 | * Distributed under terms of the GNU General Public License |
||
4 | */ |
||
4921 | Serge | 5 | |
6 | #include |
||
7 | #include |
||
8 | #include |
||
9952 | turbocat | 9 | #include |
4921 | Serge | 10 | #include "glue.h" |
11 | #include "io.h" |
||
12 | |||
13 | _off_t |
||
14 | _DEFUN (lseek, (fd, pos, whence), |
||
15 | int fd _AND |
||
16 | _off_t pos _AND |
||
17 | int whence) |
||
18 | { |
||
9952 | turbocat | 19 | ksys_file_info_t info; |
4921 | Serge | 20 | __io_handle *ioh; |
21 | _off_t ret; |
||
22 | |||
9952 | turbocat | 23 | if ((fd < 0) || (fd >=64)) |
4921 | Serge | 24 | { |
25 | errno = EBADF; |
||
26 | return (-1); |
||
9952 | turbocat | 27 | } |
4921 | Serge | 28 | |
29 | ioh = &__io_tab[fd]; |
||
30 | |||
31 | switch(whence) |
||
32 | { |
||
33 | case SEEK_SET: |
||
34 | ret = pos; |
||
35 | break; |
||
36 | case SEEK_CUR: |
||
37 | ret = ioh->offset + pos; |
||
38 | break; |
||
39 | case SEEK_END: |
||
40 | { |
||
9952 | turbocat | 41 | _ksys_file_info(ioh->name, &info); |
4921 | Serge | 42 | ret = pos + info.size; |
43 | break; |
||
44 | } |
||
45 | default: |
||
46 | errno = EINVAL; |
||
9952 | turbocat | 47 | return -1; |
48 | } |
||
4921 | Serge | 49 | |
50 | ioh->offset = ret; |
||
51 | |||
9952 | turbocat | 52 | return ret; |
53 | }> |