]> pd.if.org Git - pdclib/blob - platform/example/functions/_PDCLIB/seek.c
Removed Cygwin platform.
[pdclib] / platform / example / functions / _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 #include <_PDCLIB_glue.h>
10
11 #include "/usr/include/errno.h"
12
13 extern _PDCLIB_int64_t lseek64( int fd, _PDCLIB_int64_t offset, int whence );
14
15 _PDCLIB_int64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int64_t offset, int whence )
16 {
17     switch ( whence )
18     {
19         case SEEK_SET:
20         case SEEK_CUR:
21         case SEEK_END:
22             /* EMPTY - OK */
23             break;
24         default:
25             /* See comments on implementation-defined errno values in
26                <_PDCLIB_config.h>.
27             */
28             _PDCLIB_errno = _PDCLIB_ERROR;
29             return EOF;
30             break;
31     }
32     _PDCLIB_int64_t rc = lseek64( stream->handle, offset, whence );
33     if ( rc != EOF )
34     {
35         stream->ungetidx = 0;
36         stream->bufidx = 0;
37         stream->bufend = 0;
38         stream->pos.offset = rc;
39         return rc;
40     }
41     switch ( errno )
42     {
43         case EBADF:
44         case EFAULT:
45             /* See comments on implementation-defined errno values in
46                <_PDCLIB_config.h>.
47             */
48             _PDCLIB_errno = _PDCLIB_ERROR;
49             break;
50         default:
51             /* This should be something like EUNKNOWN. */
52             _PDCLIB_errno = _PDCLIB_ERROR;
53             break;
54     }
55     return EOF;
56 }
57
58 #ifdef TEST
59 #include <_PDCLIB_test.h>
60
61 int main( void )
62 {
63     /* Testing covered by ftell.c */
64     return TEST_RESULTS;
65 }
66
67 #endif
68