Add a generic implentation o seek function. Add test prototype.
authorasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 29 Nov 2007 15:22:59 +0000 (15:22 +0000)
committerasterix <asterix@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 29 Nov 2007 15:22:59 +0000 (15:22 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1014 38d2e660-2303-0410-9eaa-f027e97ec537

kern/kfile.c
kern/kfile.h

index b9934e7948bec241625a84a2adec53ca810e53c8..38f438027d3c738a32a42fab054776e5b86a6ef4 100644 (file)
 
 #include <kfile.h>
 
+#inclede <appconfig.h>
+
+
+/**
+ * Move \a fd file seek position of \a offset bytes
+ * from current position.
+ * This is a generic implementation of seek function, you should redefine
+ * it in your local module.
+ */
+int32_t kfile_seek(struct _KFile *fd, kfile_off_t offset, KSeekMode whence)
+{
+       uint32_t seek_pos;
+
+       switch(whence)
+       {
+
+       case KSM_SEEK_SET:
+               seek_pos = 0;
+               break;
+       case KSM_SEEK_END:
+               seek_pos = fd->size - 1;
+               break;
+       case KSM_SEEK_CUR:
+               seek_pos = fd->seek_pos;
+               break;
+       default:
+               ASSERT(0);
+               return -1;
+               break;
+
+       }
+
+       /* Bound check */
+       if (seek_pos + offset > fd->size)
+       {
+               ASSERT(0);
+               return -1;
+       }
+
+       fd->seek_pos = seek_pos + offset;
+       kprintf("Flash seek to [%lu]\n", fd->seek_pos);
+
+       return fd->seek_pos;
+}
 
 #if CONFIG_TEST
 
index e9d4a5c8c43740e352d9e45259a16d67e873f2b5..d59f7fb93f57d090f6ad83507cb602055ddac9e8 100644 (file)
@@ -83,4 +83,15 @@ typedef struct _KFile
        uint32_t                size;
 } KFile;
 
+
+/*
+ * Generic implementation of seek function.
+ */
+int32_t kfile_seek(struct _KFile *fd, kfile_off_t offset, KSeekMode whence);
+
+/*
+ * Kfile test function
+ */
+bool kfile_test(uint8_t *buf, size_t _size , uint8_t *save_buf, size_t * save_buf_size);
+
 #endif /* MWARE_KFILE_H */