# HG changeset patch # User Mike Becker # Date 1349854326 -7200 # Node ID 733f22fca61a7878ae9cb9025af57591220a2c52 # Parent e18157c5298505a3a89a2426634fa1a9d9e45e5b discarded memprintf / memscanf Reason: memscanf has no chance to get the amount of bytes read diff -r e18157c52985 -r 733f22fca61a test/main.c --- a/test/main.c Tue Oct 09 16:46:29 2012 +0200 +++ b/test/main.c Wed Oct 10 09:32:06 2012 +0200 @@ -169,8 +169,6 @@ ucx_test_register(suite, test_ucx_memgetc); ucx_test_register(suite, test_ucx_memwrite); ucx_test_register(suite, test_ucx_memread); - ucx_test_register(suite, test_ucx_memprintf); - ucx_test_register(suite, test_ucx_memscanf); ucx_test_run(suite, stdout); fflush(stdout); diff -r e18157c52985 -r 733f22fca61a test/memstream_tests.c --- a/test/memstream_tests.c Tue Oct 09 16:46:29 2012 +0200 +++ b/test/memstream_tests.c Wed Oct 10 09:32:06 2012 +0200 @@ -62,7 +62,6 @@ ucx_memputc(m, 48); ucx_memputc(m, 48); ucx_memputc(m, 48); UCX_TEST_ASSERT(ucx_memtell(m) == 16, "pos wrong after last 3 puts"); UCX_TEST_ASSERT(ucx_memeof(m), "eof not set"); - UCX_TEST_ASSERT(!ucx_memoverflow(m), "overflow shall not be set"); UCX_TEST_ASSERT(ucx_memputc(m, 48) == EOF, "put shall return EOF on memof"); UCX_TEST_ASSERT(memcmp(buffer, "000 000", 16) == 0, "buffer contains incorrect content"); @@ -121,7 +120,6 @@ UCX_TEST_ASSERT(memcmp(buffer, teststring, 16) == 0, "buffer data incorrect"); UCX_TEST_ASSERT(ucx_memeof(m), "eof shall be set"); - UCX_TEST_ASSERT(!ucx_memoverflow(m), "no overflow shall be caused"); ucx_memseek(m, 8, SEEK_SET); r = ucx_memwrite("not", 1, 3, m); @@ -186,46 +184,3 @@ ucx_memclose(m); free(buffer); } - -UCX_TEST_IMPLEMENT(test_ucx_memprintf) { - char *buffer = malloc(32); - UcxMemstream *m = ucx_memopen(buffer, 16); - - UCX_TEST_BEGIN - int r = ucx_memprintf(m, "number: %d char: %c", 15, '6'); - UCX_TEST_ASSERT(r == 18, "incorrect number of bytes written"); - UCX_TEST_ASSERT(ucx_memoverflow(m), "overflow shall be detected"); - UCX_TEST_ASSERT(memcmp(buffer, "number: 15 char:", 16) == 0, - "incorrect buffer content"); - - ucx_memseek(m, 0, SEEK_SET); - ucx_memprintf(m, "a: %d - b: %d", 1, 2); - UCX_TEST_ASSERT(!ucx_memoverflow(m), "no overflow shall be deteceted"); - UCX_TEST_ASSERT(memcmp(buffer, "a: 1 - b: 2char:", 16), - "incorrect modified buffer content"); - UCX_TEST_ASSERT(ucx_memtell(m) == 11, "incorrect position"); - - UCX_TEST_END - - ucx_memclose(m); - free(buffer); -} - -UCX_TEST_IMPLEMENT(test_ucx_memscanf) { - char *buffer = "string 3.5 1 stuff"; - UcxMemstream *m = ucx_memopen(buffer, 16); - - char s[6]; - float f; - int d; - UCX_TEST_BEGIN - int r = ucx_memscanf(m, "%s %f %d", s, &f, &d); - UCX_TEST_ASSERT(r == 3, "3 arguments shall be read"); - UCX_TEST_ASSERT(strncmp(s, "string", 6) == 0, "incorrect string"); - UCX_TEST_ASSERT(f == 3.5, "incorrect float"); - UCX_TEST_ASSERT(d == 1, "incorrect integer"); - UCX_TEST_ASSERT(ucx_memtell(m) == 12, "incorrect position"); - UCX_TEST_END - - ucx_memclose(m); -} diff -r e18157c52985 -r 733f22fca61a test/memstream_tests.h --- a/test/memstream_tests.h Tue Oct 09 16:46:29 2012 +0200 +++ b/test/memstream_tests.h Wed Oct 10 09:32:06 2012 +0200 @@ -19,8 +19,6 @@ UCX_TEST_DECLARE(test_ucx_memgetc) UCX_TEST_DECLARE(test_ucx_memwrite) UCX_TEST_DECLARE(test_ucx_memread) -UCX_TEST_DECLARE(test_ucx_memprintf) -UCX_TEST_DECLARE(test_ucx_memscanf) #ifdef __cplusplus } diff -r e18157c52985 -r 733f22fca61a ucx/memstream.c --- a/ucx/memstream.c Tue Oct 09 16:46:29 2012 +0200 +++ b/ucx/memstream.c Wed Oct 10 09:32:06 2012 +0200 @@ -69,10 +69,6 @@ return stream->pos >= stream->length; } -int ucx_memoverflow(UcxMemstream *stream) { - return stream->pos > stream->length; -} - size_t ucx_memtell(UcxMemstream *stream) { return stream->pos; } @@ -80,12 +76,8 @@ size_t ucx_memio(void* d, size_t s, size_t n, UcxMemstream *m, _Bool read) { size_t len; if (m->pos + s*n > m->length) { - if (ucx_memoverflow(m)) { - len = 0; - } else { - len = m->length - m->pos; - if (s > 1) len -= len%s; - } + len = m->length - m->pos; + if (s > 1) len -= len%s; } else { len = s*n; } @@ -124,29 +116,3 @@ return c; } } - -int ucx_memprintf(UcxMemstream *stream, const char* format, ...) { - va_list v; - va_start(v, format); - int r = vsprintf((char*)stream->space+stream->pos, format, v); - va_end(v); - - stream->pos += r; - - return r; -} - -int ucx_memscanf(UcxMemstream *stream, const char* format, ...) { - - /* TODO: vsscanf returns the number of fields read, - * we need the number of bytes */ - - va_list v; - va_start(v, format); - int r = vsscanf((char*)stream->space+stream->pos, format, v); - va_end(v); - - stream->pos += r; - - return r; -} diff -r e18157c52985 -r 733f22fca61a ucx/memstream.h --- a/ucx/memstream.h Tue Oct 09 16:46:29 2012 +0200 +++ b/ucx/memstream.h Wed Oct 10 09:32:06 2012 +0200 @@ -37,16 +37,6 @@ * */ int ucx_memeof(UcxMemstream *stream); -/* - * returns non-zero, iff the current stream position has exceeded the length - * of the underlying buffer - * - * in contrast to ucx_memeof this function will return zero, if the current - * position exactly matches the buffer length - * - * this function should be called after any ucx_memprintf/ucx_memscanf call - */ -int ucx_memoverflow(UcxMemstream *stream); /* memwrite, memread, memputc and memreadc shall not generate overflows */ size_t ucx_memio(void *d, size_t s, size_t n, UcxMemstream* m, _Bool read); @@ -57,10 +47,6 @@ int ucx_memputc(UcxMemstream *stream, int c); int ucx_memgetc(UcxMemstream *stream); -/* printf / scanf may generate overflows */ -int ucx_memprintf(UcxMemstream *stream, const char* format, ...); -int ucx_memscanf(UcxMemstream *stream, const char* format, ...); - #ifdef __cplusplus } #endif