]> pd.if.org Git - pdclib/blob - functions/stdio/fseek.c
b4e76b9cbab17e4cea0c85372e0816fb16d42c2f
[pdclib] / functions / stdio / fseek.c
1 // ----------------------------------------------------------------------------
2 // $Id$
3 // ----------------------------------------------------------------------------
4 // Public Domain C Library - http://pdclib.sourceforge.net
5 // This code is Public Domain. Use, modify, and redistribute at will.
6 // ----------------------------------------------------------------------------
7
8 int fseek( FILE * stream, long offset, int mode ) { /* TODO */ };
9
10 /* PDPC code - unreviewed
11 Read the note in fopen.c.
12 {
13     long newpos;
14 #ifdef __OS2__
15     ULONG retpos;
16     APIRET rc;
17 #endif
18
19     if (stream->mode == __WRITE_MODE)
20     {
21         fflush(stream);
22     }
23     if (whence == SEEK_SET)
24     {
25         newpos = offset;
26     }
27     else if (whence == SEEK_CUR)
28     {
29         newpos = offset + stream->bufStartR + (stream->upto - stream->fbuf);
30     }
31     if ((newpos > stream->bufStartR)
32         && (newpos < (stream->bufStartR + (stream->endbuf - stream->fbuf)))
33         && stream->update)
34     {
35         stream->upto = stream->fbuf + (size_t)(newpos - stream->bufStartR);
36     }
37     else
38     {
39 #ifdef __OS2__
40         rc = DosSetFilePtr(stream->hfile, newpos, FILE_BEGIN, &retpos);
41         if ((rc != 0) || (retpos != newpos))
42         {
43             errno = rc;
44             return (-1);
45         }
46         else
47         {
48             stream->endbuf = stream->fbuf + stream->szfbuf;
49             stream->upto = stream->endbuf;
50             stream->bufStartR = newpos - stream->szfbuf;
51         }
52 #endif
53 #ifdef __MSDOS
54         __seek(stream->hfile, newpos, whence);
55         stream->endbuf = stream->fbuf + stream->szfbuf;
56         stream->upto = stream->endbuf;
57         stream->bufStartR = newpos - stream->szfbuf;
58 #endif
59     }
60     stream->quickBin = 0;
61     stream->quickText = 0;
62     stream->ungetCh = -1;
63     return (0);
64 }
65 */