]> pd.if.org Git - pdclib/blob - functions/stdio/fgetpos.c
Comment cleanups.
[pdclib] / functions / stdio / fgetpos.c
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
11 int fgetpos( struct _PDCLIB_file_t * _PDCLIB_restrict stream, struct _PDCLIB_fpos_t * _PDCLIB_restrict pos )
12 {
13     pos->offset = stream->pos.offset + stream->bufidx - stream->ungetidx;
14     pos->status = stream->pos.status;
15     /* TODO: Add mbstate. */
16     return 0;
17 }
18
19 #endif
20
21 #ifdef TEST
22 #include <_PDCLIB_test.h>
23 #include <string.h>
24
25 int main( void )
26 {
27     FILE * fh;
28     fpos_t pos1, pos2;
29     TESTCASE( ( fh = tmpfile() ) != NULL );
30     TESTCASE( fgetpos( fh, &pos1 ) == 0 );
31     TESTCASE( fwrite( teststring, 1, strlen( teststring ), fh ) == strlen( teststring ) );
32     TESTCASE( fgetpos( fh, &pos2 ) == 0 );
33     TESTCASE( fsetpos( fh, &pos1 ) == 0 );
34     TESTCASE( ftell( fh ) == 0 );
35     TESTCASE( fsetpos( fh, &pos2 ) == 0 );
36     TESTCASE( (size_t)ftell( fh ) == strlen( teststring ) );
37     TESTCASE( fclose( fh ) == 0 );
38     return TEST_RESULTS;
39 }
40
41 #endif