]> pd.if.org Git - pdclib/blob - platform/win32/functions/_PDCLIB/_PDCLIB_seek.c
Enable building PDCLib with Watcom. This was surprisingly painless: their C99 mode...
[pdclib] / platform / win32 / functions / _PDCLIB / _PDCLIB_seek.c
1 /* $Id$ */
2
3 /* int64_t _PDCLIB_seek( FILE *, int64_t, int )
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 #include <stdio.h>
10 #include <errno.h>
11 #ifndef REGTEST
12 #include <_PDCLIB_glue.h>
13 #include <windows.h>
14
15 #if _PDCLIB_C_MIN(2011)
16 _Static_assert(SEEK_SET == FILE_BEGIN, "SEEK_SET is incorrect");
17 _Static_assert(SEEK_CUR == FILE_CURRENT, "SEEK_CUR is incorrect");
18 _Static_assert(SEEK_END == FILE_END, "SEEK_END is incorrect");
19 #endif
20
21 extern void _PDCLIB_w32errno( void );
22 _PDCLIB_int64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int64_t offset, int whence )
23 {
24     LARGE_INTEGER liOffset;
25     liOffset.QuadPart = offset;
26     BOOL rv = SetFilePointerEx( stream->handle, liOffset, &liOffset, whence );
27     if(!rv) {
28         _PDCLIB_w32errno();
29         return EOF;
30     }
31
32     stream->ungetidx = 0;
33     stream->bufidx = 0;
34     stream->bufend = 0;
35     stream->pos.offset = liOffset.QuadPart;
36     return liOffset.QuadPart;
37 }
38
39 #endif
40
41 #ifdef TEST
42 #include <_PDCLIB_test.h>
43
44 int main( void )
45 {
46     /* Testing covered by ftell.c */
47     return TEST_RESULTS;
48 }
49
50 #endif
51