Skip to content

Commit

Permalink
tinystdio: ungetc decrements file position indicator correctly
Browse files Browse the repository at this point in the history
According to the ISO/IEC_9899_1999, section: J.5.16 it is mentioned that there is a file position indicator that is decremented by each call of the ungetc function.

The value of the file position indicator was not directed to the right position, this issue is now handled in the ftell function 
so the file indicator is placed correctly after the function
ungetc is called.
An "if" condition is added which checks on the value of unget and if it is not equal zero then ungetc function is called so the indicator will be decremented.
  • Loading branch information
HanaMAshour authored Apr 23, 2024
1 parent 8e5704c commit a6b446f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions newlib/libc/tinystdio/ftell.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ FSEEK_TYPE
ftell(FILE *stream)
{
struct __file_ext *xf = (struct __file_ext *) stream;
if ((stream->flags & __SEXT) && xf->seek)
return (FSEEK_TYPE) (xf->seek) (stream, 0, SEEK_CUR);
FSEEK_TYPE ret;
if ((stream->flags & __SEXT) && xf->seek) {
ret = (FSEEK_TYPE) (xf->seek) (stream, 0, SEEK_CUR);
if(stream->unget != 0)
return --ret;
else
return ret;
}
errno = ESPIPE;
return -1;
}

0 comments on commit a6b446f

Please sign in to comment.