From 185b941c2766b59b9e0e14fc0f0fc273f201b4d4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 11 Oct 2015 10:29:35 -0600 Subject: [PATCH] TMPFS: In open write/append mode, need to set the file position to the end of the file --- fs/tmpfs/fs_tmpfs.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index 947ea028f2..529cdd5ee7 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -1346,6 +1346,7 @@ static int tmpfs_open(FAR struct file *filep, FAR const char *relpath, FAR struct inode *inode; FAR struct tmpfs_s *fs; FAR struct tmpfs_file_s *tfo; + off_t offset; int ret; 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; + /* 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 */ tmpfs_unlock_file(tfo);