From 8bbccfe43a27ce0f8d46b8262201c3e611bedf46 Mon Sep 17 00:00:00 2001 From: batt Date: Mon, 8 Jun 2009 13:00:31 +0000 Subject: [PATCH] Fix seek return value; Clear structure on init; add DB to _type. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2707 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/emul/kfile_posix.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bertos/emul/kfile_posix.c b/bertos/emul/kfile_posix.c index 593571d4..1f09aaff 100644 --- a/bertos/emul/kfile_posix.c +++ b/bertos/emul/kfile_posix.c @@ -37,6 +37,7 @@ */ #include +#include static size_t kfile_posix_read(struct KFile *_fd, void *buf, size_t size) { @@ -67,9 +68,13 @@ static kfile_off_t kfile_posix_seek(struct KFile *_fd, kfile_off_t offset, KSeek break; default: ASSERT(0); + return EOF; } + int err = fseek(fd->fp, offset, std_whence); + if (err) + return err; - return fseek(fd->fp, offset, std_whence); + return ftell(fd->fp); } static int kfile_posix_close(struct KFile *_fd) @@ -86,7 +91,8 @@ static int kfile_posix_flush(struct KFile *_fd) FILE *kfile_posix_init(KFilePosix *file, const char *filename, const char *mode) { - file->fd._type = KFT_KFILEPOSIX; + memset(file, 0, sizeof(*file)); + DB(file->fd._type = KFT_KFILEPOSIX); file->fd.read = kfile_posix_read; file->fd.write = kfile_posix_write; file->fd.close = kfile_posix_close; -- 2.25.1