]> pd.if.org Git - pdclib/blob - platform/example_cygwin/functions/_PDCLIB/seek.c
Fixed prototype warnings.
[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 #ifndef _PDCLIB_GLUE_H
12 #define _PDCLIB_GLUE_H
13 #include <_PDCLIB_glue.h>
14 #endif
15
16 #include "/usr/include/errno.h"
17
18 extern int lseek( int fd, int offset, int whence );
19
20 _PDCLIB_int64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int64_t offset, int whence )
21 {
22     switch ( whence )
23     {
24         case SEEK_SET:
25         case SEEK_CUR:
26         case SEEK_END:
27             /* EMPTY - OK */
28             break;
29         default:
30             _PDCLIB_errno = _PDCLIB_ERROR;
31             return EOF;
32             break;
33     }
34     _PDCLIB_int64_t rc = lseek( 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         /* See comments on implementation-defined errno values in
46            <_PDCLIB_config.h>.
47         */
48         case EBADF:
49         case EFAULT:
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