x11gfx.hidd: support 32 bit modes
[AROS.git] / compiler / stdc / fseek.c
blob7357e1616c97b7c5e655f612bdd47100a5dc42ba
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function fseek()
6 */
7 #include <dos/dos.h>
8 #include <proto/dos.h>
9 #include <errno.h>
11 #include "__stdio.h"
13 #define DEBUG 0
14 #include <aros/debug.h>
16 /*****************************************************************************
18 NAME */
19 #include <stdio.h>
21 int fseek (
23 /* SYNOPSIS */
24 FILE * stream,
25 long offset,
26 int whence)
28 /* FUNCTION
29 Change the current position in a stream.
31 INPUTS
32 stream - Modify this stream
33 offset, whence - How to modify the current position. whence
34 can be SEEK_SET, then offset is the absolute position
35 in the file (0 is the first byte), SEEK_CUR then the
36 position will change by offset (ie. -5 means to move
37 5 bytes to the beginning of the file) or SEEK_END.
38 SEEK_END means that the offset is relative to the
39 end of the file (-1 is the last byte and 0 is
40 the EOF).
42 RESULT
43 0 on success and -1 on error. If an error occurred, the global
44 variable errno is set.
46 NOTES
47 The seek is handled by the files system so effects of what happens
48 when seeking after end of file may differ between file systems.
50 EXAMPLE
52 BUGS
53 Not fully compatible with iso fseek, especially in 'ab' and 'a+b'
54 modes
56 SEE ALSO
57 fopen(), fwrite()
59 INTERNALS
61 ******************************************************************************/
63 LONG mode;
64 BPTR fh = stream->fh;
66 D(bug("[stdcio/fseek()] Entering stream=0x%x, offset=%d, whence=%d\n",
67 stream, offset, whence
68 ));
70 switch (whence)
72 case SEEK_SET:
73 mode = OFFSET_BEGINNING;
74 break;
76 case SEEK_CUR:
77 mode = OFFSET_CURRENT;
78 break;
80 case SEEK_END:
81 mode = OFFSET_END;
82 break;
84 default:
85 errno = EINVAL;
86 return -1;
89 if (Seek(fh, offset, mode) < 0)
91 D(bug("[stdcio/fseek()] Failed (IoErr()=%d)\n", IoErr()));
92 if (IoErr() == ERROR_UNKNOWN)
93 errno = EINVAL;
94 else
95 errno = __stdc_ioerr2errno(IoErr());
96 return -1;
98 else
100 D(bug("[stdcio/fseek()] Done\n"));
101 return 0;
103 } /* fseek */