]> pd.if.org Git - pdclib/blob - platform/example/functions/_PDCLIB/_PDCLIB_seek.c
Inlined some of the Cygwin patches. Not nice, but useful as I keep switching platforms.
[pdclib] / platform / example / functions / _PDCLIB / _PDCLIB_seek.c
1 /* int64_t _PDCLIB_seek( FILE *, int64_t, int )
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #include <stdio.h>
8
9 #ifndef REGTEST
10
11 #include "_PDCLIB_glue.h"
12
13 #include "/usr/include/errno.h"
14
15 extern _PDCLIB_int64_t lseek64( int fd, _PDCLIB_int64_t offset, int whence );
16 extern long lseek( int fd, long offset, int whence );
17
18 _PDCLIB_int64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int64_t offset, int whence )
19 {
20     switch ( whence )
21     {
22         case SEEK_SET:
23         case SEEK_CUR:
24         case SEEK_END:
25             /* EMPTY - OK */
26             break;
27         default:
28             /* See comments on implementation-defined errno values in
29                <_PDCLIB_config.h>.
30             */
31             _PDCLIB_errno = _PDCLIB_ERROR;
32             return EOF;
33             break;
34     }
35 #ifdef __CYGWIN__
36     _PDCLIB_int64_t rc = lseek( stream->handle, offset, whence );
37 #else
38     _PDCLIB_int64_t rc = lseek64( stream->handle, offset, whence );
39 #endif
40     if ( rc != EOF )
41     {
42         stream->ungetidx = 0;
43         stream->bufidx = 0;
44         stream->bufend = 0;
45         stream->pos.offset = rc;
46         return rc;
47     }
48     switch ( errno )
49     {
50         case EBADF:
51         case EFAULT:
52             /* See comments on implementation-defined errno values in
53                <_PDCLIB_config.h>.
54             */
55             _PDCLIB_errno = _PDCLIB_ERROR;
56             break;
57         default:
58             /* This should be something like EUNKNOWN. */
59             _PDCLIB_errno = _PDCLIB_ERROR;
60             break;
61     }
62     return EOF;
63 }
64
65 #endif
66
67 #ifdef TEST
68
69 #include "_PDCLIB_test.h"
70
71 int main( void )
72 {
73     /* Testing covered by ftell.c */
74     return TEST_RESULTS;
75 }
76
77 #endif