From: batt Date: Mon, 2 Aug 2010 12:53:25 +0000 (+0000) Subject: Change clearerr prototype; Automatically flush the device on close. X-Git-Tag: 2.6.0~273 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=064508b5d658cff958bf6a3e5d803c308e4ab9ec;p=bertos.git Change clearerr prototype; Automatically flush the device on close. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4117 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/drv/sd.c b/bertos/drv/sd.c index 091a42bd..c12d7592 100644 --- a/bertos/drv/sd.c +++ b/bertos/drv/sd.c @@ -378,11 +378,10 @@ static int sd_error(KBlock *b) return sd->r1; } -static int sd_clearerr(KBlock *b) +static void sd_clearerr(KBlock *b) { Sd *sd = SD_CAST(b); sd->r1 = 0; - return 0; } static const KBlockVTable sd_unbuffered_vt = diff --git a/bertos/io/kblock.h b/bertos/io/kblock.h index 7775d7b8..8d30ffc3 100644 --- a/bertos/io/kblock.h +++ b/bertos/io/kblock.h @@ -66,7 +66,7 @@ typedef int (* kblock_load_t) (struct KBlock *b, block_idx_t index); typedef int (* kblock_store_t) (struct KBlock *b, block_idx_t index); typedef int (* kblock_error_t) (struct KBlock *b); -typedef int (* kblock_clearerr_t) (struct KBlock *b); +typedef void (* kblock_clearerr_t) (struct KBlock *b); typedef int (* kblock_close_t) (struct KBlock *b); /* \} */ @@ -206,12 +206,24 @@ INLINE int kblock_error(struct KBlock *b) * * \sa kblock_error() */ -INLINE int kblock_clearerr(struct KBlock *b) +INLINE void kblock_clearerr(struct KBlock *b) { KB_ASSERT_METHOD(b, clearerr); - return b->priv.vt->clearerr(b); + b->priv.vt->clearerr(b); } + +/** + * Flush the cache (if any) to the device. + * + * This function will write any pending modifications to the device. + * If the device does not have a cache, this function will do nothing. + * + * \return 0 if all is OK, EOF on errors. + * \sa kblock_read(), kblock_write(), kblock_buffered(). + */ +int kblock_flush(struct KBlock *b); + /** * Close the device. * @@ -222,7 +234,7 @@ INLINE int kblock_clearerr(struct KBlock *b) INLINE int kblock_close(struct KBlock *b) { KB_ASSERT_METHOD(b, close); - return b->priv.vt->close(b); + return kblock_flush(b) | b->priv.vt->close(b); } /** @@ -331,19 +343,6 @@ size_t kblock_read(struct KBlock *b, block_idx_t idx, void *buf, size_t offset, */ size_t kblock_write(struct KBlock *b, block_idx_t idx, const void *buf, size_t offset, size_t size); - -/** - * Flush the cache (if any) to the device. - * - * This function will write any pending modifications to the device. - * If the device does not have a cache, this function will do nothing. - * - * \return 0 if all is OK, EOF on errors. - * \sa kblock_read(), kblock_write(), kblock_buffered(). - */ -int kblock_flush(struct KBlock *b); - - /** * Copy one block to another. * diff --git a/bertos/io/kblock_ram.c b/bertos/io/kblock_ram.c index e3780d7d..70899ce3 100644 --- a/bertos/io/kblock_ram.c +++ b/bertos/io/kblock_ram.c @@ -100,7 +100,7 @@ static const KBlockVTable kblockram_hwbuffered_vt = .store = kblockram_store, .error = kblockram_dummy, - .clearerr = kblockram_dummy, + .clearerr = (kblock_clearerr_t)kblockram_dummy, .close = kblockram_dummy, }; @@ -116,7 +116,7 @@ static const KBlockVTable kblockram_swbuffered_vt = .store = kblock_swStore, .error = kblockram_dummy, - .clearerr = kblockram_dummy, + .clearerr = (kblock_clearerr_t)kblockram_dummy, .close = kblockram_dummy, }; @@ -126,7 +126,7 @@ static const KBlockVTable kblockram_unbuffered_vt = .writeDirect = kblockram_writeDirect, .error = kblockram_dummy, - .clearerr = kblockram_dummy, + .clearerr = (kblock_clearerr_t)kblockram_dummy, .close = kblockram_dummy, };