This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via e0a04e8ae2d7a772cab0eb49858bb6d3045c025d (commit) via 271d541c7c6b1cf431dec46bf577770ad5a32d30 (commit) via 948e9d7dc2253e7086c2f94792b9a3989a372a80 (commit) from 76277f09b9ea5b7884309cfe4625ed82811cdfb9 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/e0a04e8ae2d7a772cab0eb49858bb6d3045c0...
commit e0a04e8ae2d7a772cab0eb49858bb6d3045c025d Author: Cyril Hrubis metan@ucw.cz Date: Tue Jun 17 00:02:09 2014 +0200
doc: loaders; Update I/O documentation.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/doc/loaders_io.txt b/doc/loaders_io.txt index 2e010bbc..d3d00a7e 100644 --- a/doc/loaders_io.txt +++ b/doc/loaders_io.txt @@ -73,7 +73,21 @@ This is a wrapper to 'io->Read()'. Reads at most 'size' bytes from an 'IO' stream and stores them into the buffer. Returns number of bytes read.
-On failure the return value is negative and errno is set. +On failure negative value is returned and errno is set. + + +[source,c] +------------------------------------------------------------------------------- +#include <loaders/GP_IO.h> +/* or */ +#include <GP.h> + +int GP_IOFill(GP_IO *io, void *buf, size_t size); +------------------------------------------------------------------------------- + +Similar to 'GP_IORead()' but either reads the whole buffer or fails. + +Returns zero on success and non-zero on failure.
[source,c] @@ -90,7 +104,34 @@ This is a wrapper to 'io->Write()'. Writes at most 'size' bytes from an 'IO' stream and stores them into the buffer. Returns number of bytes read.
-On failure the return value is negative and errno is set. +On failure negative value is returned and errno is set. + + +[source,c] +------------------------------------------------------------------------------- +#include <loaders/GP_IO.h> +/* or */ +#include <GP.h> + +int GP_IOFlush(GP_IO *io, void *buf, size_t size); +------------------------------------------------------------------------------- + +Similar to 'GP_IOWrite()' but either writes the whole buffer or fails. + +Returns zero on success and non-zero on failure. + +[source,c] +------------------------------------------------------------------------------- +#include <loaders/GP_IO.h> +/* or */ +#include <GP.h> + +int GP_IOPrintF(GP_IO *io, const char *fmt, ...); +------------------------------------------------------------------------------- + +Printf-like function for an I/O stream. + +Returns zero on success and non-zero on failure.
[source,c] ------------------------------------------------------------------------------- @@ -106,7 +147,7 @@ This is a wrapper to 'io->Close()'. Finalizes reading/writing, closes file descriptors (in case of file IO), frees memory buffers.
-Returns zero on success, non-zero on IO failure and errno is set. +Returns zero on success, non-zero on I/O failure and errno is set.
[source,c] @@ -115,13 +156,30 @@ Returns zero on success, non-zero on IO failure and errno is set. /* or */ #include <GP.h>
+enum GP_IOWhence { + GP_IO_SEEK_SET = 0, + GP_IO_SEEK_CUR = 1, + GP_IO_SEEK_END = 2, +}; + off_t GP_IOSeek(GP_IO *io, off_t off, enum GP_IOWhence whence); -------------------------------------------------------------------------------
This is a wrapper to 'io->Seek()'.
-//TODO
+Returns '(off_t)-1' on failure and errno is set. + +Generally not all read I/O streams are seekable back (zlib/rle decompression +streams, etc.) but all streams should be able to seek to the start of the +stream, to the end and forward. + +.Most common errno values +|============================================================================== +| 'EINVAL' | Invalid 'whence' or 'off' points outside the stream. +| 'ENOSYS' | Operation not supported, combination of 'whence' and 'off' points + inside the stream (is valid) but action cannot be done. +|==============================================================================
[source,c] ------------------------------------------------------------------------------- @@ -132,7 +190,7 @@ This is a wrapper to 'io->Seek()'. off_t GP_IOTell(GP_IO *io); -------------------------------------------------------------------------------
-Wrapper to 'GP_IOSeek()', returns current position in IO stream. +Wrapper to 'GP_IOSeek()', returns current position in I/O stream.
[source,c] @@ -144,7 +202,7 @@ Wrapper to 'GP_IOSeek()', returns current position in IO stream. off_t GP_IORewind(GP_IO *io) -------------------------------------------------------------------------------
-Wrapper to 'GP_IOSeek()', rewinds to the start of the IO stream. +Wrapper to 'GP_IOSeek()', rewinds to the start of the I/O stream.
Returns zero on success, non-zero on failure and errno is set.
@@ -158,16 +216,17 @@ Returns zero on success, non-zero on failure and errno is set. GP_IO *GP_IOMem(void *buf, size_t size, void (*free)(void *)); -------------------------------------------------------------------------------
-Creates an read-only IO from a memory buffer. +Creates an read-only I/O from a memory buffer.
-Returns initialized IO or in case of failure NULL and errno is set. +Returns initialized I/O or in case of failure NULL and errno is set.
The 'buf' is pointer to the start of the buffer, the 'size' is size in bytes.
The 'free()' callback if not NULL is called with the start of the buffer as an argument on 'IOClose()'.
-TIP: See link:example_memory_io.html[memory IO example]. +TIP: See link:example_memory_io.html[memory I/O example]. +
[source,c] ------------------------------------------------------------------------------- @@ -186,5 +245,24 @@ GP_IO *GP_IOFile(const char *path, enum GP_IOFileMode mode);
Creates an IO stream from a file.
-Returns a pointer to initialized IO stream, or in case of failure NULL and +Returns a pointer to initialized I/O stream, or in case of failure NULL and errno is set. + + +[source,c] +------------------------------------------------------------------------------- +#include <loaders/GP_IO.h> +/* or */ +#include <GP.h> + +GP_IO *GP_IOWBuffer(GP_IO *io, size_t bsize); +------------------------------------------------------------------------------- + +Creates write buffered I/O on the top of an existing I/O. + +Generally you should create a buffered I/O if you are about to write data a +few bytes at the time. + +If 'bsize' is zero default size is choosen. + +TIP: See link:example_loader_registration.html[example buffered I/O usage].
http://repo.or.cz/w/gfxprim.git/commit/271d541c7c6b1cf431dec46bf577770ad5a32...
commit 271d541c7c6b1cf431dec46bf577770ad5a32d30 Author: Cyril Hrubis metan@ucw.cz Date: Tue Jun 17 00:01:07 2014 +0200
loaders: IO: Two fixes.
* Fix IOWBuffer close().
* Set errno on invalid whence.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/libs/loaders/GP_IO.c b/libs/loaders/GP_IO.c index 329fdd43..c8dd9038 100644 --- a/libs/loaders/GP_IO.c +++ b/libs/loaders/GP_IO.c @@ -64,6 +64,7 @@ static off_t file_seek(GP_IO *self, off_t off, enum GP_IOWhence whence) break; default: GP_WARN("Invalid whence"); + errno = EINVAL; return (off_t)-1; }
@@ -389,7 +390,7 @@ static int wbuf_close(GP_IO *io) GP_DEBUG(1, "Closing BufferIO (from %p)", buf_io->io);
if (buf_io->bpos) { - if (GP_IOFlush(buf_io->io, buf_io->buf, buf_io->bsize)) + if (GP_IOFlush(buf_io->io, buf_io->buf, buf_io->bpos)) ret = 1; }
http://repo.or.cz/w/gfxprim.git/commit/948e9d7dc2253e7086c2f94792b9a3989a372...
commit 948e9d7dc2253e7086c2f94792b9a3989a372a80 Author: Cyril Hrubis metan@ucw.cz Date: Tue Jun 17 00:00:14 2014 +0200
tests: loaders: Add IOWBuffer test.
Signed-off-by: Cyril Hrubis metan@ucw.cz
diff --git a/tests/loaders/IO.c b/tests/loaders/IO.c index 32cfa2a1..723c17d0 100644 --- a/tests/loaders/IO.c +++ b/tests/loaders/IO.c @@ -255,6 +255,70 @@ static int test_IOFill(void) return TST_SUCCESS; }
+static size_t counter; + +static ssize_t wbuf_write(GP_IO GP_UNUSED(*io), void *buf, size_t size) +{ + unsigned int i; + + for (i = 0; i < size; i++) { + if (((uint8_t*)buf)[i] != 'a') { + tst_msg("Wrong data in buffer"); + return -1; + } + } + + counter += size; + return size; +} + +static int wbuf_close(GP_IO GP_UNUSED(*io)) +{ + return 0; +} + +static int test_IOWBuffer(void) +{ + GP_IO *bio; + size_t cnt = 0; + unsigned int i; + GP_IO io = { + .Write = wbuf_write, + .Close = wbuf_close, + }; + + counter = 0; + + bio = GP_IOWBuffer(&io, 100); + + if (!bio) + return TST_FAILED; + + for (i = 0; i < 100; i++) { + size_t to_write = i % 10 + 1; + if (GP_IOFlush(bio, "aaaaaaaaaaa", to_write)) { + tst_msg("Failed to write data: %s", tst_strerr(errno)); + GP_IOClose(bio); + return TST_FAILED; + } + cnt += to_write; + } + + if (GP_IOClose(bio)) { + tst_msg("Failed to close I/O: %s", tst_strerr(errno)); + return TST_FAILED; + } + + if (counter != cnt) { + tst_msg("Wrong number of bytes written have %zu expected %zu", + counter, cnt); + return TST_FAILED; + } + + return TST_SUCCESS; +} + + const struct tst_suite tst_suite = { .suite_name = "IO", .tests = { @@ -269,6 +333,9 @@ const struct tst_suite tst_suite = { {.name = "IOFill", .tst_fn = test_IOFill},
+ {.name = "IOWBuffer", + .tst_fn = test_IOWBuffer}, + {.name = NULL}, } };
-----------------------------------------------------------------------
Summary of changes: doc/loaders_io.txt | 98 ++++++++++++++++++++++++++++++++++++++++++++----- libs/loaders/GP_IO.c | 3 +- tests/loaders/IO.c | 67 ++++++++++++++++++++++++++++++++++ 3 files changed, 157 insertions(+), 11 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.