]> pd.if.org Git - pdclib.old/blob - platform/example/functions/_PDCLIB/seek.c
Type error resulting in improper handling of values > 127 and EOF.
[pdclib.old] / 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 #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             _PDCLIB_errno = _PDCLIB_EINVAL;
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             _PDCLIB_errno = _PDCLIB_EIO;
48             break;
49         default:
50             _PDCLIB_errno = _PDCLIB_EUNKNOWN;
51             break;
52     }
53     return EOF;
54 }
55
56 #ifdef TEST
57 #include <_PDCLIB_test.h>
58
59 int main()
60 {
61     /* Testing covered by ftell.c */
62     return TEST_RESULTS;
63 }
64
65 #endif
66