3 /* fgetpos( FILE * , fpos_t * )
5 This file is part of the Public Domain C Library (PDCLib).
6 Permission is granted to use, modify, and / or redistribute at will.
12 #include <_PDCLIB_io.h>
14 int fgetpos_unlocked( FILE * _PDCLIB_restrict stream, _PDCLIB_fpos_t * _PDCLIB_restrict pos )
16 pos->offset = stream->pos.offset + stream->bufidx - stream->ungetidx;
17 pos->mbs = stream->pos.mbs;
18 /* TODO: Add mbstate. */
22 int fgetpos( FILE * _PDCLIB_restrict stream, _PDCLIB_fpos_t * _PDCLIB_restrict pos )
25 int res = fgetpos_unlocked( stream, pos );
26 funlockfile( stream );
33 #include <_PDCLIB_test.h>
40 TESTCASE( ( fh = tmpfile() ) != NULL );
41 TESTCASE( fgetpos( fh, &pos1 ) == 0 );
42 TESTCASE( fwrite( teststring, 1, strlen( teststring ), fh ) == strlen( teststring ) );
43 TESTCASE( (size_t)ftell( fh ) == strlen( teststring ) );
44 TESTCASE( fgetpos( fh, &pos2 ) == 0 );
45 TESTCASE( fsetpos( fh, &pos1 ) == 0 );
46 TESTCASE( ftell( fh ) == 0 );
47 TESTCASE( fsetpos( fh, &pos2 ) == 0 );
48 TESTCASE( (size_t)ftell( fh ) == strlen( teststring ) );
49 TESTCASE( fclose( fh ) == 0 );