Skip to content

Commit 89eb6c3

Browse files
committed
tinystdio: ungetc decrements file position indicator correctly
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. Signed-off-by: Hana Ashour <[email protected]>
1 parent 8e5704c commit 89eb6c3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

newlib/libc/tinystdio/ftell.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@ FSEEK_TYPE
4343
ftell(FILE *stream)
4444
{
4545
struct __file_ext *xf = (struct __file_ext *) stream;
46-
if ((stream->flags & __SEXT) && xf->seek)
47-
return (FSEEK_TYPE) (xf->seek) (stream, 0, SEEK_CUR);
46+
FSEEK_TYPE ret;
47+
if ((stream->flags & __SEXT) && xf->seek) {
48+
ret = (FSEEK_TYPE) (xf->seek) (stream, 0, SEEK_CUR);
49+
if(stream->unget != 0)
50+
return --ret;
51+
else
52+
return ret;
53+
}
4854
errno = ESPIPE;
4955
return -1;
5056
}

0 commit comments

Comments
 (0)