1 /* fgetpos( FILE * , fpos_t * )
3 This file is part of the Public Domain C Library (PDCLib).
4 Permission is granted to use, modify, and / or redistribute at will.
10 #include "_PDCLIB_io.h"
12 int _PDCLIB_fgetpos_unlocked( FILE * _PDCLIB_restrict stream, _PDCLIB_fpos_t * _PDCLIB_restrict pos )
14 pos->offset = stream->pos.offset + stream->bufidx - stream->ungetidx;
15 pos->mbs = stream->pos.mbs;
16 /* TODO: Add mbstate. */
20 int fgetpos( FILE * _PDCLIB_restrict stream, _PDCLIB_fpos_t * _PDCLIB_restrict pos )
22 _PDCLIB_flockfile( stream );
23 int res = _PDCLIB_fgetpos_unlocked( stream, pos );
24 _PDCLIB_funlockfile( stream );
31 #include "_PDCLIB_test.h"
38 TESTCASE( ( fh = tmpfile() ) != NULL );
39 TESTCASE( fgetpos( fh, &pos1 ) == 0 );
40 TESTCASE( fwrite( teststring, 1, strlen( teststring ), fh ) == strlen( teststring ) );
41 TESTCASE( (size_t)ftell( fh ) == strlen( teststring ) );
42 TESTCASE( fgetpos( fh, &pos2 ) == 0 );
43 TESTCASE( fsetpos( fh, &pos1 ) == 0 );
44 TESTCASE( ftell( fh ) == 0 );
45 TESTCASE( fsetpos( fh, &pos2 ) == 0 );
46 TESTCASE( (size_t)ftell( fh ) == strlen( teststring ) );
47 TESTCASE( fclose( fh ) == 0 );