X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Femul%2Fkfile_posix.c;h=1f09aaff7062dd461856aee0ecaa6a7e21ed70cf;hb=8bbccfe43a27ce0f8d46b8262201c3e611bedf46;hp=3fce00bcf2b46b54bde179d7c4f18b8ce6fd6d25;hpb=b1c122a36a111f4bb088a8f000a7fc8f8975734e;p=bertos.git diff --git a/bertos/emul/kfile_posix.c b/bertos/emul/kfile_posix.c index 3fce00bc..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) { @@ -63,12 +64,17 @@ static kfile_off_t kfile_posix_seek(struct KFile *_fd, kfile_off_t offset, KSeek std_whence = SEEK_END; break; case KSM_SEEK_SET: - /* fall */ - default: std_whence = SEEK_SET; + 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) @@ -83,9 +89,10 @@ static int kfile_posix_flush(struct KFile *_fd) return fflush(fd->fp); } -FILE* kfile_posix_init(KFilePosix *file, const char *filename, const char *mode) +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;