Add reopen test.
[bertos.git] / kern / kfile.c
index ab8016c32cda080421fd2ba2bb03103a0a50758c..750836fcd524398a8ced1b3f07bcf098a5285b5b 100644 (file)
@@ -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
 
 /**