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