Split test suite in new file.
[bertos.git] / kern / kfile.c
index ab8016c32cda080421fd2ba2bb03103a0a50758c..7607ba793af069278fe8bebb2ca7bdaace3af76a 100644 (file)
@@ -59,7 +59,7 @@
 
 
 /**
- * Generic putc implementation using \a fd->write.
+ * Generic putc() implementation using \a fd->write.
  */
 int kfile_putc(int _c, struct KFile *fd)
 {
@@ -72,7 +72,7 @@ int kfile_putc(int _c, struct KFile *fd)
 }
 
 /**
- * Generic getc implementation using \a fd->read.
+ * Generic getc() implementation using \a fd->read.
  */
 int kfile_getc(struct KFile *fd)
 {
@@ -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,7 +206,19 @@ kfile_off_t kfile_genericSeek(struct KFile *fd, kfile_off_t offset, KSeekMode wh
        return fd->seek_pos;
 }
 
-#if CONFIG_TEST
+/**
+ * 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_KFILE
 
 /**
  * KFile read/write subtest.