diff --git a/libs/libc/stdio/lib_ftell.c b/libs/libc/stdio/lib_ftell.c index ff93622fb4..2df6d78b85 100644 --- a/libs/libc/stdio/lib_ftell.c +++ b/libs/libc/stdio/lib_ftell.c @@ -37,7 +37,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: lib_getrdoffset + * Name: lib_getoffset * * Description: * It is insufficient to simply use the file offset; we must also account @@ -50,9 +50,9 @@ ****************************************************************************/ #ifndef CONFIG_STDIO_DISABLE_BUFFERING -static off_t lib_getrdoffset(FAR FILE *stream) +static off_t lib_getoffset(FAR FILE *stream) { - off_t rdoffset = 0; + off_t offset = 0; lib_take_semaphore(stream); if (stream->fs_bufstart != @@ -60,18 +60,22 @@ static off_t lib_getrdoffset(FAR FILE *stream) stream->fs_bufstart) { #if CONFIG_NUNGET_CHARS > 0 - rdoffset = stream->fs_bufread - stream->fs_bufpos + + offset = stream->fs_bufread - stream->fs_bufpos + stream->fs_nungotten; #else - rdoffset = stream->fs_bufread - stream->fs_bufpos; + offset = stream->fs_bufread - stream->fs_bufpos; #endif } + else + { + offset = -(stream->fs_bufpos - stream->fs_bufstart); + } lib_give_semaphore(stream); - return rdoffset; + return offset; } #else -# define lib_getrdoffset(stream) (0) +# define lib_getoffset(stream) (0) #endif /**************************************************************************** @@ -109,7 +113,7 @@ long ftell(FAR FILE *stream) position = lseek(stream->fs_fd, 0, SEEK_CUR); if (position != (off_t)-1) { - return (long)(position - lib_getrdoffset(stream)); + return (long)(position - lib_getoffset(stream)); } else {