Path: blob/master/waterbox/libc/functions/stdio/fgetpos.c
2 views
/* fgetpos( FILE * , fpos_t * )12This file is part of the Public Domain C Library (PDCLib).3Permission is granted to use, modify, and / or redistribute at will.4*/56#include <stdio.h>78#ifndef REGTEST9#include "_PDCLIB_io.h"1011int _PDCLIB_fgetpos_unlocked( FILE * _PDCLIB_restrict stream, _PDCLIB_fpos_t * _PDCLIB_restrict pos )12{13pos->offset = stream->pos.offset + stream->bufidx - stream->ungetidx;14pos->mbs = stream->pos.mbs;15/* TODO: Add mbstate. */16return 0;17}1819int fgetpos( FILE * _PDCLIB_restrict stream, _PDCLIB_fpos_t * _PDCLIB_restrict pos )20{21_PDCLIB_flockfile( stream );22int res = _PDCLIB_fgetpos_unlocked( stream, pos );23_PDCLIB_funlockfile( stream );24return res;25}2627#endif2829#ifdef TEST30#include "_PDCLIB_test.h"31#include <string.h>3233int main( void )34{35FILE * fh;36fpos_t pos1, pos2;37TESTCASE( ( fh = tmpfile() ) != NULL );38TESTCASE( fgetpos( fh, &pos1 ) == 0 );39TESTCASE( fwrite( teststring, 1, strlen( teststring ), fh ) == strlen( teststring ) );40TESTCASE( (size_t)ftell( fh ) == strlen( teststring ) );41TESTCASE( fgetpos( fh, &pos2 ) == 0 );42TESTCASE( fsetpos( fh, &pos1 ) == 0 );43TESTCASE( ftell( fh ) == 0 );44TESTCASE( fsetpos( fh, &pos2 ) == 0 );45TESTCASE( (size_t)ftell( fh ) == strlen( teststring ) );46TESTCASE( fclose( fh ) == 0 );47return TEST_RESULTS;48}4950#endif515253