TMPFS: In open write/append mode, need to set the file position to the end of the file

This commit is contained in:
Gregory Nutt 2015-10-11 10:29:35 -06:00
parent 2c385b81f8
commit 185b941c27

View File

@ -1346,6 +1346,7 @@ static int tmpfs_open(FAR struct file *filep, FAR const char *relpath,
FAR struct inode *inode; FAR struct inode *inode;
FAR struct tmpfs_s *fs; FAR struct tmpfs_s *fs;
FAR struct tmpfs_file_s *tfo; FAR struct tmpfs_file_s *tfo;
off_t offset;
int ret; int ret;
fvdbg("filep: %p\n", filep); fvdbg("filep: %p\n", filep);
@ -1456,6 +1457,18 @@ static int tmpfs_open(FAR struct file *filep, FAR const char *relpath,
filep->f_priv = tfo; filep->f_priv = tfo;
/* In write/append mode, we need to set the file pointer to the end of the
* file.
*/
offset = 0;
if ((oflags & (O_APPEND | O_WRONLY)) == (O_APPEND | O_WRONLY))
{
offset = tfo->tfo_size;
}
filep->f_pos = offset;
/* Unlock the file file object, but retain the reference count */ /* Unlock the file file object, but retain the reference count */
tmpfs_unlock_file(tfo); tmpfs_unlock_file(tfo);