Don't call ReadArgs() if started from WB.
[tangerine.git] / compiler / clib / lseek.c
blob1e3238bba292ce2a08c6a507085d72e423fd538c
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 Reposition read/write file offset.
6 */
7 #include <errno.h>
8 #include <dos/dos.h>
9 #include <proto/dos.h>
10 #include "__errno.h"
11 #include "__open.h"
13 /*****************************************************************************
15 NAME */
16 #include <unistd.h>
18 off_t lseek (
20 /* SYNOPSIS */
21 int filedes,
22 off_t offset,
23 int whence)
25 /* FUNCTION
26 Reposition read/write file offset
28 INPUTS
29 filedef - the filedescriptor being modified
30 offset, whence -
31 How to modify the current position. whence
32 can be SEEK_SET, then offset is the absolute position
33 in the file (0 is the first byte), SEEK_CUR then the
34 position will change by offset (ie. -5 means to move
35 5 bytes to the beginning of the file) or SEEK_END.
36 SEEK_END means that the offset is relative to the
37 end of the file (-1 is the last byte and 0 is
38 the EOF).
40 RESULT
41 The new position on success and -1 on error. If an error occurred, the global
42 variable errno is set.
44 NOTES
46 EXAMPLE
48 BUGS
50 SEE ALSO
51 fopen(), fwrite()
53 INTERNALS
55 ******************************************************************************/
57 int cnt;
58 fdesc *fdesc = __getfdesc(filedes);
60 if (!fdesc)
62 errno = EBADF;
63 return -1;
66 switch (whence)
68 case SEEK_SET: whence = OFFSET_BEGINNING; break;
69 case SEEK_CUR: whence = OFFSET_CURRENT; break;
70 case SEEK_END: whence = OFFSET_END; break;
72 default:
73 errno = EINVAL;
74 return -1;
77 cnt = Seek ((BPTR)fdesc->fh, offset, whence);
79 if (cnt == -1)
80 errno = IoErr2errno (IoErr ());
82 return Seek((BPTR)fdesc->fh, 0, OFFSET_CURRENT);
83 } /* lseek */