]> pd.if.org Git - pdclib/blob - platform/example/functions/_PDCLIB/_PDCLIB_seek.c
cafcee8ddc2cfd64db234c335ca00e9754667321
[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
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 #endif
61
62 #ifdef TEST
63
64 #include "_PDCLIB_test.h"
65
66 int main( void )
67 {
68     /* Testing covered by ftell.c */
69     return TEST_RESULTS;
70 }
71
72 #endif