Commit e08cc508 authored by Chris Friedt's avatar Chris Friedt Committed by Henrik Brix Andersen
Browse files

os: fdtable: set offset to zero with newly reserved fd's

Previously, if a file object is was re-used, it could
inherit the offset field of the previously closed file object,
making reading from the beginning of the file impossible
until the offset was manually zero'ed.

The offset should *always* be zero when a file is ready to be
used.

The issue really only presents itself when implementing a
vtable backend.

Signed-off-by: default avatarChris Friedt <cfriedt@tenstorrent.com>
parent 2a2806bb
Loading
Loading
Loading
Loading
+1 −0
Changes for lib/os/fdtable.c: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -249,6 +249,7 @@ int zvfs_reserve_fd(void)
		(void)z_fd_ref(fd);
		fdtable[fd].obj = NULL;
		fdtable[fd].vtable = NULL;
		fdtable[fd].offset = 0;
		k_mutex_init(&fdtable[fd].lock);
		k_condvar_init(&fdtable[fd].cond);
	}