1.1 --- a/ucx/utils.c Mon Aug 12 14:43:22 2013 +0200 1.2 +++ b/ucx/utils.c Tue Aug 13 14:20:12 2013 +0200 1.3 @@ -27,7 +27,7 @@ 1.4 */ 1.5 1.6 #include "utils.h" 1.7 -#include "math.h" 1.8 +#include <math.h> 1.9 1.10 /* COPY FUCNTIONS */ 1.11 void* ucx_strcpy(void* s, void* data) { 1.12 @@ -45,6 +45,36 @@ 1.13 return cpy; 1.14 } 1.15 1.16 +size_t ucx_stream_copy(void *src, void *dest, read_func readfnc, 1.17 + write_func writefnc, char* buf, size_t bufsize, size_t n) { 1.18 + if(n == 0 || bufsize == 0) { 1.19 + return 0; 1.20 + } 1.21 + 1.22 + size_t ncp = 0; 1.23 + if (!buf) { 1.24 + buf = (char*)malloc(bufsize); 1.25 + if(buf == NULL) { 1.26 + return 0; 1.27 + } 1.28 + } 1.29 + 1.30 + size_t r; 1.31 + size_t rn = bufsize > n ? n : bufsize; 1.32 + while((r = readfnc(buf, 1, rn, src)) != 0) { 1.33 + r = writefnc(buf, 1, r, dest); 1.34 + ncp += r; 1.35 + n -= r; 1.36 + rn = bufsize > n ? n : bufsize; 1.37 + if(r == 0 || n == 0) { 1.38 + break; 1.39 + } 1.40 + } 1.41 + 1.42 + free(buf); 1.43 + return ncp; 1.44 +} 1.45 + 1.46 /* COMPARE FUNCTION */ 1.47 1.48 int ucx_strcmp(void *s1, void *s2, void *data) {