tmpfs: write end of file if open flag with O_APPEND
Signed-off-by: Shoukui Zhang <zhangshoukui@xiaomi.com>
This commit is contained in:
parent
3f3ad34f42
commit
a3b94383ed
@ -1605,7 +1605,15 @@ static ssize_t tmpfs_write(FAR struct file *filep, FAR const char *buffer,
|
|||||||
|
|
||||||
/* Handle attempts to write beyond the end of the file */
|
/* Handle attempts to write beyond the end of the file */
|
||||||
|
|
||||||
startpos = filep->f_pos;
|
if ((filep->f_oflags & O_APPEND) != 0)
|
||||||
|
{
|
||||||
|
startpos = tfo->tfo_size;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
startpos = filep->f_pos;
|
||||||
|
}
|
||||||
|
|
||||||
nwritten = buflen;
|
nwritten = buflen;
|
||||||
endpos = startpos + buflen;
|
endpos = startpos + buflen;
|
||||||
|
|
||||||
@ -1625,13 +1633,14 @@ static ssize_t tmpfs_write(FAR struct file *filep, FAR const char *buffer,
|
|||||||
if (tfo->tfo_data != NULL)
|
if (tfo->tfo_data != NULL)
|
||||||
{
|
{
|
||||||
memcpy(&tfo->tfo_data[startpos], buffer, nwritten);
|
memcpy(&tfo->tfo_data[startpos], buffer, nwritten);
|
||||||
filep->f_pos += nwritten;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DEBUGASSERT(tfo->tfo_size == 0 && nwritten == 0);
|
DEBUGASSERT(tfo->tfo_size == 0 && nwritten == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
filep->f_pos = endpos;
|
||||||
|
|
||||||
/* Release the lock on the file */
|
/* Release the lock on the file */
|
||||||
|
|
||||||
tmpfs_unlock_file(tfo);
|
tmpfs_unlock_file(tfo);
|
||||||
|
Loading…
Reference in New Issue
Block a user