]> pd.if.org Git - pdclib.old/blob - platform/posix/functions/_PDCLIB/seek.c
win32: mutex rewrite. new form is much simpler
[pdclib.old] / platform / posix / 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 _PDCLIB_int64_t lseek64( int fd, _PDCLIB_int64_t 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             /* See comments on implementation-defined errno values in
31                <_PDCLIB_config.h>.
32             */
33             _PDCLIB_errno = _PDCLIB_ERROR;
34             return EOF;
35             break;
36     }
37     _PDCLIB_int64_t rc = lseek64( stream->handle, offset, whence );
38     if ( rc != EOF )
39     {
40         stream->ungetidx = 0;
41         stream->bufidx = 0;
42         stream->bufend = 0;
43         stream->pos.offset = rc;
44         return rc;
45     }
46     switch ( errno )
47     {
48         case EBADF:
49         case EFAULT:
50             /* See comments on implementation-defined errno values in
51                <_PDCLIB_config.h>.
52             */
53             _PDCLIB_errno = _PDCLIB_ERROR;
54             break;
55         default:
56             /* This should be something like EUNKNOWN. */
57             _PDCLIB_errno = _PDCLIB_ERROR;
58             break;
59     }
60     return EOF;
61 }
62
63 #ifdef TEST
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
73