1.1 --- a/ucx/utils.h Wed Sep 07 11:32:22 2016 +0200 1.2 +++ b/ucx/utils.h Wed Sep 07 12:26:01 2016 +0200 1.3 @@ -48,6 +48,8 @@ 1.4 #include <inttypes.h> 1.5 #include <string.h> 1.6 #include <stdarg.h> 1.7 + 1.8 +#define UCX_STREAM_COPY_BUFSIZE 4096 1.9 1.10 /** 1.11 * Copies a string. 1.12 @@ -82,23 +84,26 @@ 1.13 * @param n the maximum number of bytes that shall be copied 1.14 * @return the total number of bytes copied 1.15 */ 1.16 -size_t ucx_stream_copy(void *src, void *dest, read_func rfnc, write_func wfnc, 1.17 +size_t ucx_stream_bncopy(void *src, void *dest, read_func rfnc, write_func wfnc, 1.18 char* buf, size_t bufsize, size_t n); 1.19 1.20 /** 1.21 - * Shorthand for ucx_stream_copy using the default copy buffer. 1.22 + * Shorthand for an unbounded ucx_stream_bncopy call using a default buffer. 1.23 * 1.24 * @param src the source stream 1.25 * @param dest the destination stream 1.26 * @param rfnc the read function 1.27 * @param wfnc the write function 1.28 * @return total number of bytes copied 1.29 + * 1.30 + * @see #UCX_STREAM_COPY_BUFSIZE 1.31 */ 1.32 -#define ucx_stream_hcopy(src,dest,rfnc,wfnc) ucx_stream_copy(\ 1.33 - src, dest, (read_func)rfnc, (write_func)wfnc, NULL, 0x100, (size_t)-1) 1.34 +#define ucx_stream_copy(src,dest,rfnc,wfnc) ucx_stream_bncopy(\ 1.35 + src, dest, (read_func)rfnc, (write_func)wfnc, \ 1.36 + NULL, UCX_STREAM_COPY_BUFSIZE, (size_t)-1) 1.37 1.38 /** 1.39 - * Shorthand for ucx_stream_copy using the default copy buffer and a copy limit. 1.40 + * Shorthand for ucx_stream_bncopy using a default copy buffer. 1.41 * 1.42 * @param src the source stream 1.43 * @param dest the destination stream 1.44 @@ -107,8 +112,27 @@ 1.45 * @param n maximum number of bytes that shall be copied 1.46 * @return total number of bytes copied 1.47 */ 1.48 -#define ucx_stream_ncopy(src,dest,rfnc,wfnc, n) ucx_stream_copy(\ 1.49 - src, dest, (read_func)rfnc, (write_func)wfnc, NULL, 0x100, n) 1.50 +#define ucx_stream_ncopy(src,dest,rfnc,wfnc, n) ucx_stream_bncopy(\ 1.51 + src, dest, (read_func)rfnc, (write_func)wfnc, \ 1.52 + NULL, UCX_STREAM_COPY_BUFSIZE, n) 1.53 + 1.54 +/** 1.55 + * Shorthand for an unbounded ucx_stream_bncopy call using the specified buffer. 1.56 + * 1.57 + * @param src the source stream 1.58 + * @param dest the destination stream 1.59 + * @param rfnc the read function 1.60 + * @param wfnc the write function 1.61 + * @param buf a pointer to the copy buffer or <code>NULL</code> if a buffer 1.62 + * shall be implicitly created on the heap 1.63 + * @param bufsize the size of the copy buffer - if <code>NULL</code> was 1.64 + * provided for <code>buf</code>, this is the size of the buffer that shall be 1.65 + * implicitly created 1.66 + * @return total number of bytes copied 1.67 + */ 1.68 +#define ucx_stream_bcopy(src,dest,rfnc,wfnc, buf, bufsize) ucx_stream_bncopy(\ 1.69 + src, dest, (read_func)rfnc, (write_func)wfnc, \ 1.70 + buf, bufsize, (size_t)-1) 1.71 1.72 /** 1.73 * Wraps the strcmp function.