X-Git-Url: https://pd.if.org/git/?p=pdclib;a=blobdiff_plain;f=functions%2Fstdio%2F_PDCLIB_ftell64.c;h=ea93fc69f467a481304181e65f73fb84e430fd9f;hp=77ab8723921e6f9513e7b3bba03bd4f36adb7163;hb=abc15df6b9fae3374d24c7cf5c3ab94c605b2a6d;hpb=8894c921674bb116d0a7b8f23a55311e7a768019 diff --git a/functions/stdio/_PDCLIB_ftell64.c b/functions/stdio/_PDCLIB_ftell64.c index 77ab872..ea93fc6 100644 --- a/functions/stdio/_PDCLIB_ftell64.c +++ b/functions/stdio/_PDCLIB_ftell64.c @@ -1,62 +1,62 @@ -/* _PDCLIB_ftell64( FILE * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include - -#ifndef REGTEST -#include "_PDCLIB_io.h" - -uint_fast64_t _PDCLIB_ftell64_unlocked( FILE * stream ) -{ - /* ftell() must take into account: - - the actual *physical* offset of the file, i.e. the offset as recognized - by the operating system (and stored in stream->pos.offset); and - - any buffers held by PDCLib, which - - in case of unwritten buffers, count in *addition* to the offset; or - - in case of unprocessed pre-read buffers, count in *substraction* to - the offset. (Remember to count ungetidx into this number.) - Conveniently, the calculation ( ( bufend - bufidx ) + ungetidx ) results - in just the right number in both cases: - - in case of unwritten buffers, ( ( 0 - unwritten ) + 0 ) - i.e. unwritten bytes as negative number - - in case of unprocessed pre-read, ( ( preread - processed ) + unget ) - i.e. unprocessed bytes as positive number. - That is how the somewhat obscure return-value calculation works. - */ - - /* ungetc on a stream at offset==0 will cause an overflow to UINT64_MAX. - * C99/C11 says that the return value of ftell in this case is - * "indeterminate" - */ - - return ( stream->pos.offset - ( ( (int)stream->bufend - (int)stream->bufidx ) + (int)stream->ungetidx ) ); -} - -uint_fast64_t _PDCLIB_ftell64( FILE * stream ) -{ - _PDCLIB_flockfile( stream ); - uint_fast64_t pos = _PDCLIB_ftell64_unlocked( stream ); - _PDCLIB_funlockfile( stream ); - return pos; -} - -#endif - -#ifdef TEST -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - /* Tested by ftell */ - return TEST_RESULTS; -} - -#endif - +/* _PDCLIB_ftell64( FILE * ) + + This file is part of the Public Domain C Library (PDCLib). + Permission is granted to use, modify, and / or redistribute at will. +*/ + +#include +#include +#include + +#ifndef REGTEST +#include "_PDCLIB_io.h" + +uint_fast64_t _PDCLIB_ftell64_unlocked( FILE * stream ) +{ + /* ftell() must take into account: + - the actual *physical* offset of the file, i.e. the offset as recognized + by the operating system (and stored in stream->pos.offset); and + - any buffers held by PDCLib, which + - in case of unwritten buffers, count in *addition* to the offset; or + - in case of unprocessed pre-read buffers, count in *substraction* to + the offset. (Remember to count ungetidx into this number.) + Conveniently, the calculation ( ( bufend - bufidx ) + ungetidx ) results + in just the right number in both cases: + - in case of unwritten buffers, ( ( 0 - unwritten ) + 0 ) + i.e. unwritten bytes as negative number + - in case of unprocessed pre-read, ( ( preread - processed ) + unget ) + i.e. unprocessed bytes as positive number. + That is how the somewhat obscure return-value calculation works. + */ + + /* ungetc on a stream at offset==0 will cause an overflow to UINT64_MAX. + * C99/C11 says that the return value of ftell in this case is + * "indeterminate" + */ + + return ( stream->pos.offset - ( ( (int)stream->bufend - (int)stream->bufidx ) + (int)stream->ungetidx ) ); +} + +uint_fast64_t _PDCLIB_ftell64( FILE * stream ) +{ + _PDCLIB_flockfile( stream ); + uint_fast64_t pos = _PDCLIB_ftell64_unlocked( stream ); + _PDCLIB_funlockfile( stream ); + return pos; +} + +#endif + +#ifdef TEST +#include "_PDCLIB_test.h" + +#include + +int main( void ) +{ + /* Tested by ftell */ + return TEST_RESULTS; +} + +#endif +