X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=kern%2Fkfile.c;h=750836fcd524398a8ced1b3f07bcf098a5285b5b;hb=99fafc49f3b2d50abb2d7b8b4cbbd3be8e107bef;hp=ab8016c32cda080421fd2ba2bb03103a0a50758c;hpb=a8bcb07b39220b51a08114d74eed103ebe08ee5f;p=bertos.git diff --git a/kern/kfile.c b/kern/kfile.c index ab8016c3..750836fc 100644 --- a/kern/kfile.c +++ b/kern/kfile.c @@ -170,7 +170,7 @@ int kfile_gets_echo(struct KFile *fd, char *buf, int size, bool echo) * Move \a fd file seek position of \a offset bytes from \a whence. * * This is a generic implementation of seek function, you can redefine - * it in your local module is needed. + * it in your local module if needed. */ kfile_off_t kfile_genericSeek(struct KFile *fd, kfile_off_t offset, KSeekMode whence) { @@ -183,7 +183,7 @@ kfile_off_t kfile_genericSeek(struct KFile *fd, kfile_off_t offset, KSeekMode wh seek_pos = 0; break; case KSM_SEEK_END: - seek_pos = fd->size - 1; + seek_pos = fd->size; break; case KSM_SEEK_CUR: seek_pos = fd->seek_pos; @@ -206,6 +206,18 @@ kfile_off_t kfile_genericSeek(struct KFile *fd, kfile_off_t offset, KSeekMode wh return fd->seek_pos; } +/** + * Reopen file \a fd. + * This is a generic implementation that only flush file + * and reset seek_pos to 0. + */ +struct KFile * kfile_genericReopen(struct KFile *fd) +{ + kfile_flush(fd); + kfile_seek(fd, 0, KSM_SEEK_SET); + return fd; +} + #if CONFIG_TEST /**