Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/waterbox/libc/functions/stdio/fgetpos.c
2 views
1
/* fgetpos( FILE * , fpos_t * )
2
3
This file is part of the Public Domain C Library (PDCLib).
4
Permission is granted to use, modify, and / or redistribute at will.
5
*/
6
7
#include <stdio.h>
8
9
#ifndef REGTEST
10
#include "_PDCLIB_io.h"
11
12
int _PDCLIB_fgetpos_unlocked( FILE * _PDCLIB_restrict stream, _PDCLIB_fpos_t * _PDCLIB_restrict pos )
13
{
14
pos->offset = stream->pos.offset + stream->bufidx - stream->ungetidx;
15
pos->mbs = stream->pos.mbs;
16
/* TODO: Add mbstate. */
17
return 0;
18
}
19
20
int fgetpos( FILE * _PDCLIB_restrict stream, _PDCLIB_fpos_t * _PDCLIB_restrict pos )
21
{
22
_PDCLIB_flockfile( stream );
23
int res = _PDCLIB_fgetpos_unlocked( stream, pos );
24
_PDCLIB_funlockfile( stream );
25
return res;
26
}
27
28
#endif
29
30
#ifdef TEST
31
#include "_PDCLIB_test.h"
32
#include <string.h>
33
34
int main( void )
35
{
36
FILE * fh;
37
fpos_t pos1, pos2;
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 );
48
return TEST_RESULTS;
49
}
50
51
#endif
52
53