X-Git-Url: https://pd.if.org/git/?a=blobdiff_plain;f=platform%2Fexample_cygwin%2Ffunctions%2F_PDCLIB%2Fseek.c;fp=platform%2Fexample_cygwin%2Ffunctions%2F_PDCLIB%2Fseek.c;h=ee21f5695d6b82ec9cb8c8dbfb8ac197500dd8fc;hb=0c316ee3b4dc0712797877f5dc0f4a789646154d;hp=0000000000000000000000000000000000000000;hpb=ffa73a4a2673fece7cd63c471476db6bc4aef9e6;p=pdclib diff --git a/platform/example_cygwin/functions/_PDCLIB/seek.c b/platform/example_cygwin/functions/_PDCLIB/seek.c new file mode 100644 index 0000000..ee21f56 --- /dev/null +++ b/platform/example_cygwin/functions/_PDCLIB/seek.c @@ -0,0 +1,66 @@ +/* $Id$ */ + +/* int64_t _PDCLIB_seek( FILE *, int64_t, int ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include + +#ifndef _PDCLIB_GLUE_H +#define _PDCLIB_GLUE_H +#include <_PDCLIB_glue.h> +#endif + +#include "/usr/include/errno.h" + +extern int lseek( int fd, int offset, int whence ); + +_PDCLIB_int64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int64_t offset, int whence ) +{ + switch ( whence ) + { + case SEEK_SET: + case SEEK_CUR: + case SEEK_END: + /* EMPTY - OK */ + break; + default: + _PDCLIB_errno = _PDCLIB_EINVAL; + return EOF; + break; + } + _PDCLIB_int64_t rc = lseek( stream->handle, offset, whence ); + if ( rc != EOF ) + { + stream->ungetidx = 0; + stream->bufidx = 0; + stream->bufend = 0; + stream->pos.offset = rc; + return rc; + } + switch ( errno ) + { + case EBADF: + case EFAULT: + _PDCLIB_errno = _PDCLIB_EIO; + break; + default: + _PDCLIB_errno = _PDCLIB_EUNKNOWN; + break; + } + return EOF; +} + +#ifdef TEST +#include <_PDCLIB_test.h> + +int main() +{ + /* Testing covered by ftell.c */ + return TEST_RESULTS; +} + +#endif +