]> pd.if.org Git - pdclib/blob - platform/example/functions/_PDCLIB/seek.c
Removed the header include guard 'optimization'.
[pdclib] / platform / example / 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 _PDCLIB_int64_t lseek64( int fd, _PDCLIB_int64_t 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             /* See comments on implementation-defined errno values in
28                <_PDCLIB_config.h>.
29             */
30             _PDCLIB_errno = _PDCLIB_ERROR;
31             return EOF;
32             break;
33     }
34     _PDCLIB_int64_t rc = lseek64( stream->handle, offset, whence );
35     if ( rc != EOF )
36     {
37         stream->ungetidx = 0;
38         stream->bufidx = 0;
39         stream->bufend = 0;
40         stream->pos.offset = rc;
41         return rc;
42     }
43     switch ( errno )
44     {
45         case EBADF:
46         case EFAULT:
47             /* See comments on implementation-defined errno values in
48                <_PDCLIB_config.h>.
49             */
50             _PDCLIB_errno = _PDCLIB_ERROR;
51             break;
52         default:
53             /* This should be something like EUNKNOWN. */
54             _PDCLIB_errno = _PDCLIB_ERROR;
55             break;
56     }
57     return EOF;
58 }
59
60 #ifdef TEST
61 #include <_PDCLIB_test.h>
62
63 int main( void )
64 {
65     /* Testing covered by ftell.c */
66     return TEST_RESULTS;
67 }
68
69 #endif
70