X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fio%2Fkfile.h;h=9a750feb29a2dfe6135f8c1a4f13647de0b4db9c;hb=82f41e5602dce5e8b7a3a8c2872c2091c79eefe2;hp=eefbd41281e2aefeff533e5b07574354d30a2548;hpb=358092ef8d8feeedaf5c1af8eeff954e10fe2172;p=bertos.git diff --git a/bertos/io/kfile.h b/bertos/io/kfile.h index eefbd412..9a750feb 100644 --- a/bertos/io/kfile.h +++ b/bertos/io/kfile.h @@ -31,6 +31,10 @@ * * --> * + * \defgroup io_kfile KFile interface + * \ingroup core + * \{ + * * \brief Virtual KFile I/O interface. * * KFile is a simple, generic interface for file I/O. It uses an @@ -215,18 +219,16 @@ int kfile_genericClose(struct KFile *fd); * Interface functions for KFile access. * @{ */ -int kfile_putc(int c, struct KFile *fd); ///< Generic putc implementation using kfile_write. -int kfile_getc(struct KFile *fd); ///< Generic getc implementation using kfile_read. -int kfile_printf(struct KFile *fd, const char *format, ...); -int kfile_print(struct KFile *fd, const char *s); -int kfile_gets(struct KFile *fd, char *buf, int size); -int kfile_gets_echo(struct KFile *fd, char *buf, int size, bool echo); -void kfile_resync(KFile *fd, mtime_t delay); -void kfile_init(struct KFile *fd); /** * Read \a size bytes from file \a fd into \a buf. * + * This function reads at most the number of requested bytes into the + * provided buffer. + * The value returned may be less than the requested bytes in case EOF is + * reached OR an error occurred. You need to check the error conditions + * using kfile_error() to understand which case happened. + * * \note This function will block if there are less than \a size bytes * to read. * @@ -240,6 +242,18 @@ INLINE size_t kfile_read(struct KFile *fd, void *buf, size_t size) ASSERT(fd->read); return fd->read(fd, buf, 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. @@ -257,17 +271,8 @@ INLINE size_t kfile_write(struct KFile *fd, const void *buf, size_t size) return fd->write(fd, buf, size); } -INLINE KFile * kfile_reopen(struct KFile *fd) -{ - ASSERT(fd->reopen); - return fd->reopen(fd); -} - -INLINE int kfile_close(struct KFile *fd) -{ - ASSERT(fd->close); - return fd->close(fd); -} +int kfile_printf(struct KFile *fd, const char *format, ...); +int kfile_print(struct KFile *fd, const char *s); /** * Seek into file (if seekable). @@ -285,25 +290,63 @@ INLINE kfile_off_t kfile_seek(struct KFile *fd, kfile_off_t offset, KSeekMode wh return fd->seek(fd, offset, whence); } +/** + * Close and reopen file \a fd. + * The reopening is done with the former file parameters and access modes. + */ +INLINE KFile * kfile_reopen(struct KFile *fd) +{ + ASSERT(fd->reopen); + return fd->reopen(fd); +} + +/** + * Close file. + * \return 0 on success, EOF on errors. + */ +INLINE int kfile_close(struct KFile *fd) +{ + ASSERT(fd->close); + return fd->close(fd); +} + +/** + * Flush file I/O. + * \return 0 on success, EOF on errors. + */ INLINE int kfile_flush(struct KFile *fd) { ASSERT(fd->flush); return fd->flush(fd); } +/** + * Get file error mask. + * \return 0 on success or file error code, device specific. + */ INLINE int kfile_error(struct KFile *fd) { ASSERT(fd->error); return fd->error(fd); } +/** + * Clear errors. + */ INLINE void kfile_clearerr(struct KFile *fd) { ASSERT(fd->clearerr); fd->clearerr(fd); } + +int kfile_putc(int c, struct KFile *fd); ///< Generic putc implementation using kfile_write. +int kfile_getc(struct KFile *fd); ///< Generic getc implementation using kfile_read. +void kfile_resync(KFile *fd, mtime_t delay); +void kfile_init(struct KFile *fd); /* @} */ +/** \} */ //Defgroup io_kfile + /* * Kfile test function. */