# HG changeset patch # User Mike Becker # Date 1473243961 -7200 # Node ID e0f850709a5cc9b799ac080ae07f3f8fe13f98aa # Parent ebfc6a2902f7c389ef947406fb54cd34b22c3675 changes ucx_stream_Xcopy API diff -r ebfc6a2902f7 -r e0f850709a5c test/utils_tests.c --- a/test/utils_tests.c Wed Sep 07 11:32:22 2016 +0200 +++ b/test/utils_tests.c Wed Sep 07 12:26:01 2016 +0200 @@ -102,7 +102,9 @@ UCX_TEST_ASSERT(b1->size == 16, "failed to fill buffer b1"); ucx_buffer_seek(b1, 0, SEEK_SET); - size_t ncp = ucx_stream_hcopy(b1, b2, ucx_buffer_read, ucx_buffer_write); + char copybuf[256]; + size_t ncp = ucx_stream_bcopy(b1, b2, ucx_buffer_read, ucx_buffer_write, + copybuf, sizeof(copybuf)); UCX_TEST_ASSERT(ncp == 16, "wrong number of copied bytes"); UCX_TEST_ASSERT(b2->size == 16, "b2 has wrong size"); UCX_TEST_ASSERT(memcmp(b1->space, b2->space, 16) == 0, @@ -116,12 +118,12 @@ FILE *file = tmpfile(); UCX_TEST_ASSERT(file, "test file cannot be opened, test aborted"); - ncp = ucx_stream_hcopy(b1, file, ucx_buffer_read, fwrite); + ncp = ucx_stream_copy(b1, file, ucx_buffer_read, fwrite); UCX_TEST_ASSERT(ncp == 16, "copied wrong number of bytes to file"); fseek(file, 0, SEEK_SET); - ncp = ucx_stream_hcopy(file, b2, fread, ucx_buffer_write); + ncp = ucx_stream_copy(file, b2, fread, ucx_buffer_write); UCX_TEST_ASSERT(ncp == 16, "copied wrong number of bytes from file"); UCX_TEST_ASSERT(memcmp(b1->space, b2->space, 16) == 0, diff -r ebfc6a2902f7 -r e0f850709a5c ucx/ucx.h --- a/ucx/ucx.h Wed Sep 07 11:32:22 2016 +0200 +++ b/ucx/ucx.h Wed Sep 07 12:26:01 2016 +0200 @@ -40,7 +40,7 @@ #define UCX_VERSION_MAJOR 0 /** Minor UCX version as integer constant. */ -#define UCX_VERSION_MINOR 9 +#define UCX_VERSION_MINOR 10 #include diff -r ebfc6a2902f7 -r e0f850709a5c ucx/utils.c --- a/ucx/utils.c Wed Sep 07 11:32:22 2016 +0200 +++ b/ucx/utils.c Wed Sep 07 12:26:01 2016 +0200 @@ -48,7 +48,7 @@ return cpy; } -size_t ucx_stream_copy(void *src, void *dest, read_func readfnc, +size_t ucx_stream_bncopy(void *src, void *dest, read_func readfnc, write_func writefnc, char* buf, size_t bufsize, size_t n) { if(n == 0 || bufsize == 0) { return 0; diff -r ebfc6a2902f7 -r e0f850709a5c ucx/utils.h --- a/ucx/utils.h Wed Sep 07 11:32:22 2016 +0200 +++ b/ucx/utils.h Wed Sep 07 12:26:01 2016 +0200 @@ -48,6 +48,8 @@ #include #include #include + +#define UCX_STREAM_COPY_BUFSIZE 4096 /** * Copies a string. @@ -82,23 +84,26 @@ * @param n the maximum number of bytes that shall be copied * @return the total number of bytes copied */ -size_t ucx_stream_copy(void *src, void *dest, read_func rfnc, write_func wfnc, +size_t ucx_stream_bncopy(void *src, void *dest, read_func rfnc, write_func wfnc, char* buf, size_t bufsize, size_t n); /** - * Shorthand for ucx_stream_copy using the default copy buffer. + * Shorthand for an unbounded ucx_stream_bncopy call using a default buffer. * * @param src the source stream * @param dest the destination stream * @param rfnc the read function * @param wfnc the write function * @return total number of bytes copied + * + * @see #UCX_STREAM_COPY_BUFSIZE */ -#define ucx_stream_hcopy(src,dest,rfnc,wfnc) ucx_stream_copy(\ - src, dest, (read_func)rfnc, (write_func)wfnc, NULL, 0x100, (size_t)-1) +#define ucx_stream_copy(src,dest,rfnc,wfnc) ucx_stream_bncopy(\ + src, dest, (read_func)rfnc, (write_func)wfnc, \ + NULL, UCX_STREAM_COPY_BUFSIZE, (size_t)-1) /** - * Shorthand for ucx_stream_copy using the default copy buffer and a copy limit. + * Shorthand for ucx_stream_bncopy using a default copy buffer. * * @param src the source stream * @param dest the destination stream @@ -107,8 +112,27 @@ * @param n maximum number of bytes that shall be copied * @return total number of bytes copied */ -#define ucx_stream_ncopy(src,dest,rfnc,wfnc, n) ucx_stream_copy(\ - src, dest, (read_func)rfnc, (write_func)wfnc, NULL, 0x100, n) +#define ucx_stream_ncopy(src,dest,rfnc,wfnc, n) ucx_stream_bncopy(\ + src, dest, (read_func)rfnc, (write_func)wfnc, \ + NULL, UCX_STREAM_COPY_BUFSIZE, n) + +/** + * Shorthand for an unbounded ucx_stream_bncopy call using the specified buffer. + * + * @param src the source stream + * @param dest the destination stream + * @param rfnc the read function + * @param wfnc the write function + * @param buf a pointer to the copy buffer or NULL if a buffer + * shall be implicitly created on the heap + * @param bufsize the size of the copy buffer - if NULL was + * provided for buf, this is the size of the buffer that shall be + * implicitly created + * @return total number of bytes copied + */ +#define ucx_stream_bcopy(src,dest,rfnc,wfnc, buf, bufsize) ucx_stream_bncopy(\ + src, dest, (read_func)rfnc, (write_func)wfnc, \ + buf, bufsize, (size_t)-1) /** * Wraps the strcmp function.