#include "cfg/cfg_kfile.h"
#include <cfg/debug.h>
+#include <cfg/log.h>
+#include <drv/timer.h>
#include <mware/formatwr.h>
#include <string.h>
break;
}
+ #if LOG_LEVEL >= LOG_LVL_INFO
/* Bound check */
if (seek_pos + offset > fd->size)
LOG_INFO("seek outside EOF\n");
+ #endif
fd->seek_pos = seek_pos + offset;
};
+/**
+ * Discard input to resynchronize with remote end.
+ *
+ * Discard incoming data until the kfile_getc stops receiving
+ * characters for at least \a delay milliseconds.
+ *
+ * \note If the timeout occur, we reset the error before to
+ * quit.
+ */
+void kfile_resync(KFile *fd, mtime_t delay)
+{
+ ticks_t start_time = timer_clock();
+ for(;;)
+ {
+ if(kfile_getc(fd) != EOF)
+ start_time = timer_clock();
+
+ if ((timer_clock() - start_time) > ms_to_ticks(delay))
+ {
+ kfile_clearerr(fd);
+ break;
+ }
+
+ }
+}
+
+/**
+ * Stub function that does nothing.
+ * This is a generic implementation that only return 0.
+ */
+static int kfile_generic(UNUSED_ARG(struct KFile *, fd))
+{
+ return 0;
+};
+
+
+/**
+ * Base class KFile constructor.
+ */
+void kfile_init(struct KFile *fd)
+{
+ ASSERT(fd);
+ memset(fd, 0, sizeof(*fd));
+ fd->clearerr = (ClearErrFunc_t)kfile_generic;
+ fd->close = kfile_genericClose;
+ fd->error = kfile_generic;
+ fd->flush = kfile_generic;
+ fd->read = (ReadFunc_t)kfile_generic;
+ fd->reopen = kfile_genericReopen;
+ fd->seek = kfile_genericSeek;
+ fd->write = (WriteFunc_t)kfile_generic;
+}
+