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