]> pd.if.org Git - pdclib/blob - platform/win32/functions/_PDCLIB/_PDCLIB_seek.c
e23cd3cbaf5af4ac71910663085487ca0f9d0fa7
[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 _Static_assert(SEEK_SET == FILE_BEGIN, "SEEK_SET is incorrect");
16 _Static_assert(SEEK_CUR == FILE_CURRENT, "SEEK_CUR is incorrect");
17 _Static_assert(SEEK_END == FILE_END, "SEEK_END is incorrect");
18
19 extern void _PDCLIB_w32errno( void );
20 _PDCLIB_int64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int64_t offset, int whence )
21 {
22     LARGE_INTEGER liOffset;
23     liOffset.QuadPart = offset;
24     BOOL rv = SetFilePointerEx( stream->handle, liOffset, &liOffset, whence );
25     if(!rv) {
26         _PDCLIB_w32errno();
27         return EOF;
28     }
29
30     stream->ungetidx = 0;
31     stream->bufidx = 0;
32     stream->bufend = 0;
33     stream->pos.offset = liOffset.QuadPart;
34     return liOffset.QuadPart;
35 }
36
37 #endif
38
39 #ifdef TEST
40 #include <_PDCLIB_test.h>
41
42 int main( void )
43 {
44     /* Testing covered by ftell.c */
45     return TEST_RESULTS;
46 }
47
48 #endif
49