ucx/utils.h

changeset 140
15f871f50bfd
parent 138
7800811078b8
child 142
ee8cb27d8b8e
     1.1 --- a/ucx/utils.h	Mon Aug 12 14:43:22 2013 +0200
     1.2 +++ b/ucx/utils.h	Tue Aug 13 14:20:12 2013 +0200
     1.3 @@ -43,6 +43,7 @@
     1.4  #endif
     1.5  
     1.6  #include "ucx.h"
     1.7 +#include <stdint.h>
     1.8  #include <string.h>
     1.9  
    1.10  /**
    1.11 @@ -62,6 +63,50 @@
    1.12   */
    1.13  void *ucx_memcpy(void *m, void *n);
    1.14  
    1.15 +
    1.16 +/**
    1.17 + * Reads data from a stream and writes it to another stream.
    1.18 + * 
    1.19 + * @param src the source stream
    1.20 + * @param dest the destination stream
    1.21 + * @param rfnc the read function
    1.22 + * @param wfnc the write function
    1.23 + * @param buf a pointer to the copy buffer or <code>NULL</code> if a buffer
    1.24 + * shall be implicitly created on the heap
    1.25 + * @param bufsize the size of the copy buffer - if <code>NULL</code> was
    1.26 + * provided for <code>buf</code>, this is the size of the buffer that shall be
    1.27 + * implicitly created
    1.28 + * @param n the maximum number of bytes that shall be copied
    1.29 + * @return the total number of bytes copied
    1.30 +  */
    1.31 +size_t ucx_stream_copy(void *src, void *dest, read_func rfnc, write_func wfnc,
    1.32 +        char* buf, size_t bufsize, size_t n);
    1.33 +
    1.34 +/**
    1.35 + * Shorthand for ucx_stream_copy using the default copy buffer.
    1.36 + * 
    1.37 + * @param src the source stream
    1.38 + * @param dest the destination stream
    1.39 + * @param rfnc the read function
    1.40 + * @param wfnc the write function
    1.41 + * @return total number of bytes copied
    1.42 + */
    1.43 +#define ucx_stream_hcopy(src,dest,rfnc,wfnc) ucx_stream_copy(\
    1.44 +        src, dest, (read_func)rfnc, (write_func)wfnc, NULL, 0x100, SIZE_MAX)
    1.45 +
    1.46 +/**
    1.47 + * Shorthand for ucx_stream_copy using the default copy buffer and a copy limit.
    1.48 + * 
    1.49 + * @param src the source stream
    1.50 + * @param dest the destination stream
    1.51 + * @param rfnc the read function
    1.52 + * @param wfnc the write function
    1.53 + * @param n maximum number of bytes that shall be copied
    1.54 + * @return total number of bytes copied
    1.55 + */
    1.56 +#define ucx_stream_ncopy(src,dest,rfnc,wfnc, n) ucx_stream_copy(\
    1.57 +        src, dest, (read_func)rfnc, (write_func)wfnc, NULL, 0x100, n)
    1.58 +
    1.59  /**
    1.60   * Wraps the strcmp function.
    1.61   * @param s1 string one

mercurial