diff --git a/fs/tmpfs/fs_tmpfs.c b/fs/tmpfs/fs_tmpfs.c index e4f5e6b2579..34f22336301 100644 --- a/fs/tmpfs/fs_tmpfs.c +++ b/fs/tmpfs/fs_tmpfs.c @@ -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 */ - startpos = filep->f_pos; + if ((filep->f_oflags & O_APPEND) != 0) + { + startpos = tfo->tfo_size; + } + else + { + startpos = filep->f_pos; + } + nwritten = 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) { memcpy(&tfo->tfo_data[startpos], buffer, nwritten); - filep->f_pos += nwritten; } else { DEBUGASSERT(tfo->tfo_size == 0 && nwritten == 0); } + filep->f_pos = endpos; + /* Release the lock on the file */ tmpfs_unlock_file(tfo);