mlib update: new isnan()/isnanf() implementation
[tangerine.git] / compiler / clib / fseek.c
blob72e445c9af5e82687334680b9c46ae13c158ec32
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 Change the position in a stream.
6 */
8 #include <errno.h>
9 #include <dos/dos.h>
10 #include <proto/dos.h>
11 #include "__errno.h"
12 #include "__stdio.h"
13 #include "__open.h"
15 /*****************************************************************************
17 NAME */
18 #include <stdio.h>
20 int fseek (
22 /* SYNOPSIS */
23 FILE * stream,
24 long offset,
25 int whence)
27 /* FUNCTION
28 Change the current position in a stream.
30 INPUTS
31 stream - Modify this stream
32 offset, whence - How to modify the current position. whence
33 can be SEEK_SET, then offset is the absolute position
34 in the file (0 is the first byte), SEEK_CUR then the
35 position will change by offset (ie. -5 means to move
36 5 bytes to the beginning of the file) or SEEK_END.
37 SEEK_END means that the offset is relative to the
38 end of the file (-1 is the last byte and 0 is
39 the EOF).
41 RESULT
42 0 on success and -1 on error. If an error occurred, the global
43 variable errno is set.
45 NOTES
47 EXAMPLE
49 BUGS
51 SEE ALSO
52 fopen(), fwrite()
54 INTERNALS
56 ******************************************************************************/
58 int cnt;
59 BPTR fh;
60 fdesc *fdesc = __getfdesc(stream->fd);
62 if (!fdesc)
64 errno = EBADF;
65 return -1;
68 switch (whence)
70 case SEEK_SET: whence = OFFSET_BEGINNING; break;
71 case SEEK_CUR: whence = OFFSET_CURRENT; break;
72 case SEEK_END: whence = OFFSET_END; break;
74 default:
75 errno = EINVAL;
76 return -1;
79 fh = (BPTR)(fdesc->fh);
81 /* This is buffered IO, flush the buffer before any Seek */
82 Flush (fh);
83 cnt = Seek (fh, offset, whence);
85 if (cnt == -1)
86 errno = IoErr2errno (IoErr ());
87 else
88 cnt = 0;
90 return cnt;
91 } /* fseek */