Reworked scanf() testing. General cleanups.
[fw/pdclib] / functions / stdio / fgetpos.c
1 /* $Id$ */
2
3 /* fgetpos( FILE * , fpos_t * )
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 #include <stdio.h>
10
11 #ifndef REGTEST
12
13 int fgetpos( struct _PDCLIB_file_t * _PDCLIB_restrict stream, struct _PDCLIB_fpos_t * _PDCLIB_restrict pos )
14 {
15     pos->offset = stream->pos.offset + stream->bufidx - stream->ungetidx;
16     pos->status = stream->pos.status;
17     /* TODO: Add mbstate. */
18     return 0;
19 }
20
21 #endif
22
23 #ifdef TEST
24 #include <_PDCLIB_test.h>
25 #include <string.h>
26
27 int main( void )
28 {
29     FILE * fh;
30     fpos_t pos1, pos2;
31     TESTCASE( ( fh = tmpfile() ) != NULL );
32     TESTCASE( fgetpos( fh, &pos1 ) == 0 );
33     TESTCASE( fwrite( teststring, 1, strlen( teststring ), fh ) == strlen( teststring ) );
34     TESTCASE( fgetpos( fh, &pos2 ) == 0 );
35     TESTCASE( fsetpos( fh, &pos1 ) == 0 );
36     TESTCASE( ftell( fh ) == 0 );
37     TESTCASE( fsetpos( fh, &pos2 ) == 0 );
38     TESTCASE( (size_t)ftell( fh ) == strlen( teststring ) );
39     TESTCASE( fclose( fh ) == 0 );
40     return TEST_RESULTS;
41 }
42
43 #endif