libc: update stream getoffset to handle write case

MIRTOS-242

Change-Id: I80b01b446446d5a631d40822f220a0177a95e7e6
Signed-off-by: liuhaitao <liuhaitao@xiaomi.com>
This commit is contained in:
liuhaitao
2021-03-19 12:12:32 +08:00
committed by 刘海涛
parent 293c7e6b6f
commit 563c2c15cf
+11 -7
View File
@@ -65,25 +65,29 @@
****************************************************************************/
#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 != NULL && stream->fs_bufread != stream->fs_bufstart)
{
#if CONFIG_NUNGET_CHARS > 0
rdoffset = stream->fs_bufread - stream->fs_bufpos + stream->fs_nungotten;
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
/****************************************************************************
@@ -121,7 +125,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
{