From 4c8d2e18a125eff3a5d36c7ec6fac486c8be21d5 Mon Sep 17 00:00:00 2001 From: batt Date: Wed, 2 Feb 2011 16:12:16 +0000 Subject: [PATCH] Add new function: kfile_copy(). git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4672 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/io/kfile.c | 23 +++++++++++++++++++++++ bertos/io/kfile.h | 10 ++++++++++ 2 files changed, 33 insertions(+) diff --git a/bertos/io/kfile.c b/bertos/io/kfile.c index f8981180..ca7e1fc3 100644 --- a/bertos/io/kfile.c +++ b/bertos/io/kfile.c @@ -167,6 +167,29 @@ int kfile_gets_echo(struct KFile *fd, char *buf, int size, bool echo) #endif /* !CONFIG_KFILE_GETS */ +kfile_off_t kfile_copy(KFile *src, KFile *dst, kfile_off_t size) +{ + char buf[32]; + kfile_off_t cp_len = 0; + + while (size) + { + size_t len = MIN(sizeof(buf), (size_t)size); + if (kfile_read(src, buf, len) != len) + break; + + size_t wr_len = kfile_write(dst, buf, len); + cp_len += wr_len; + size -= len; + + if (wr_len != len) + break; + } + + return cp_len; +} + + /** * Move \a fd file seek position of \a offset bytes from \a whence. * diff --git a/bertos/io/kfile.h b/bertos/io/kfile.h index 9b0b07d0..56f7d57a 100644 --- a/bertos/io/kfile.h +++ b/bertos/io/kfile.h @@ -245,6 +245,16 @@ INLINE size_t kfile_read(struct KFile *fd, void *buf, size_t size) int kfile_gets(struct KFile *fd, char *buf, int size); int kfile_gets_echo(struct KFile *fd, char *buf, int size, bool echo); +/** + * Copy \a size bytes from file \a src to \a dst. + * + * \param src Source KFile. + * \param dst Destionation KFile. + * \param size number of bytes to copy. + * \return the number of bytes copied. + */ +kfile_off_t kfile_copy(KFile *src, KFile *dst, kfile_off_t size); + /** * Write \a size bytes from buffer \a buf into KFile \a fd. * -- 2.25.1