changes ucx_stream_Xcopy API

Wed, 07 Sep 2016 12:26:01 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 07 Sep 2016 12:26:01 +0200
changeset 222
e0f850709a5c
parent 221
ebfc6a2902f7
child 223
e18884bbad48

changes ucx_stream_Xcopy API

test/utils_tests.c file | annotate | diff | comparison | revisions
ucx/ucx.h file | annotate | diff | comparison | revisions
ucx/utils.c file | annotate | diff | comparison | revisions
ucx/utils.h file | annotate | diff | comparison | revisions
     1.1 --- a/test/utils_tests.c	Wed Sep 07 11:32:22 2016 +0200
     1.2 +++ b/test/utils_tests.c	Wed Sep 07 12:26:01 2016 +0200
     1.3 @@ -102,7 +102,9 @@
     1.4      UCX_TEST_ASSERT(b1->size == 16, "failed to fill buffer b1");
     1.5      ucx_buffer_seek(b1, 0, SEEK_SET);
     1.6      
     1.7 -    size_t ncp = ucx_stream_hcopy(b1, b2, ucx_buffer_read, ucx_buffer_write);
     1.8 +    char copybuf[256];
     1.9 +    size_t ncp = ucx_stream_bcopy(b1, b2, ucx_buffer_read, ucx_buffer_write,
    1.10 +            copybuf, sizeof(copybuf));
    1.11      UCX_TEST_ASSERT(ncp == 16, "wrong number of copied bytes");
    1.12      UCX_TEST_ASSERT(b2->size == 16, "b2 has wrong size");
    1.13      UCX_TEST_ASSERT(memcmp(b1->space, b2->space, 16) == 0,
    1.14 @@ -116,12 +118,12 @@
    1.15      FILE *file = tmpfile();
    1.16      UCX_TEST_ASSERT(file, "test file cannot be opened, test aborted");
    1.17      
    1.18 -    ncp = ucx_stream_hcopy(b1, file, ucx_buffer_read, fwrite);
    1.19 +    ncp = ucx_stream_copy(b1, file, ucx_buffer_read, fwrite);
    1.20      UCX_TEST_ASSERT(ncp == 16, "copied wrong number of bytes to file");
    1.21      
    1.22      fseek(file, 0, SEEK_SET);
    1.23      
    1.24 -    ncp = ucx_stream_hcopy(file, b2, fread, ucx_buffer_write);
    1.25 +    ncp = ucx_stream_copy(file, b2, fread, ucx_buffer_write);
    1.26      UCX_TEST_ASSERT(ncp == 16, "copied wrong number of bytes from file");
    1.27      
    1.28      UCX_TEST_ASSERT(memcmp(b1->space, b2->space, 16) == 0,
     2.1 --- a/ucx/ucx.h	Wed Sep 07 11:32:22 2016 +0200
     2.2 +++ b/ucx/ucx.h	Wed Sep 07 12:26:01 2016 +0200
     2.3 @@ -40,7 +40,7 @@
     2.4  #define UCX_VERSION_MAJOR   0
     2.5  
     2.6  /** Minor UCX version as integer constant. */
     2.7 -#define UCX_VERSION_MINOR   9
     2.8 +#define UCX_VERSION_MINOR   10
     2.9  
    2.10  #include <stdlib.h>
    2.11  
     3.1 --- a/ucx/utils.c	Wed Sep 07 11:32:22 2016 +0200
     3.2 +++ b/ucx/utils.c	Wed Sep 07 12:26:01 2016 +0200
     3.3 @@ -48,7 +48,7 @@
     3.4      return cpy;
     3.5  }
     3.6  
     3.7 -size_t ucx_stream_copy(void *src, void *dest, read_func readfnc,
     3.8 +size_t ucx_stream_bncopy(void *src, void *dest, read_func readfnc,
     3.9          write_func writefnc, char* buf, size_t bufsize, size_t n) {
    3.10      if(n == 0 || bufsize == 0) {
    3.11          return 0;
     4.1 --- a/ucx/utils.h	Wed Sep 07 11:32:22 2016 +0200
     4.2 +++ b/ucx/utils.h	Wed Sep 07 12:26:01 2016 +0200
     4.3 @@ -48,6 +48,8 @@
     4.4  #include <inttypes.h>
     4.5  #include <string.h>
     4.6  #include <stdarg.h>
     4.7 +    
     4.8 +#define UCX_STREAM_COPY_BUFSIZE 4096
     4.9  
    4.10  /**
    4.11   * Copies a string.
    4.12 @@ -82,23 +84,26 @@
    4.13   * @param n the maximum number of bytes that shall be copied
    4.14   * @return the total number of bytes copied
    4.15    */
    4.16 -size_t ucx_stream_copy(void *src, void *dest, read_func rfnc, write_func wfnc,
    4.17 +size_t ucx_stream_bncopy(void *src, void *dest, read_func rfnc, write_func wfnc,
    4.18          char* buf, size_t bufsize, size_t n);
    4.19  
    4.20  /**
    4.21 - * Shorthand for ucx_stream_copy using the default copy buffer.
    4.22 + * Shorthand for an unbounded ucx_stream_bncopy call using a default buffer.
    4.23   * 
    4.24   * @param src the source stream
    4.25   * @param dest the destination stream
    4.26   * @param rfnc the read function
    4.27   * @param wfnc the write function
    4.28   * @return total number of bytes copied
    4.29 + * 
    4.30 + * @see #UCX_STREAM_COPY_BUFSIZE
    4.31   */
    4.32 -#define ucx_stream_hcopy(src,dest,rfnc,wfnc) ucx_stream_copy(\
    4.33 -        src, dest, (read_func)rfnc, (write_func)wfnc, NULL, 0x100, (size_t)-1)
    4.34 +#define ucx_stream_copy(src,dest,rfnc,wfnc) ucx_stream_bncopy(\
    4.35 +        src, dest, (read_func)rfnc, (write_func)wfnc, \
    4.36 +        NULL, UCX_STREAM_COPY_BUFSIZE, (size_t)-1)
    4.37  
    4.38  /**
    4.39 - * Shorthand for ucx_stream_copy using the default copy buffer and a copy limit.
    4.40 + * Shorthand for ucx_stream_bncopy using a default copy buffer.
    4.41   * 
    4.42   * @param src the source stream
    4.43   * @param dest the destination stream
    4.44 @@ -107,8 +112,27 @@
    4.45   * @param n maximum number of bytes that shall be copied
    4.46   * @return total number of bytes copied
    4.47   */
    4.48 -#define ucx_stream_ncopy(src,dest,rfnc,wfnc, n) ucx_stream_copy(\
    4.49 -        src, dest, (read_func)rfnc, (write_func)wfnc, NULL, 0x100, n)
    4.50 +#define ucx_stream_ncopy(src,dest,rfnc,wfnc, n) ucx_stream_bncopy(\
    4.51 +        src, dest, (read_func)rfnc, (write_func)wfnc, \
    4.52 +        NULL, UCX_STREAM_COPY_BUFSIZE, n)
    4.53 +
    4.54 +/**
    4.55 + * Shorthand for an unbounded ucx_stream_bncopy call using the specified buffer.
    4.56 + * 
    4.57 + * @param src the source stream
    4.58 + * @param dest the destination stream
    4.59 + * @param rfnc the read function
    4.60 + * @param wfnc the write function
    4.61 + * @param buf a pointer to the copy buffer or <code>NULL</code> if a buffer
    4.62 + * shall be implicitly created on the heap
    4.63 + * @param bufsize the size of the copy buffer - if <code>NULL</code> was
    4.64 + * provided for <code>buf</code>, this is the size of the buffer that shall be
    4.65 + * implicitly created
    4.66 + * @return total number of bytes copied
    4.67 + */
    4.68 +#define ucx_stream_bcopy(src,dest,rfnc,wfnc, buf, bufsize) ucx_stream_bncopy(\
    4.69 +        src, dest, (read_func)rfnc, (write_func)wfnc, \
    4.70 +        buf, bufsize, (size_t)-1)
    4.71  
    4.72  /**
    4.73   * Wraps the strcmp function.

mercurial