82 void *dest, |
82 void *dest, |
83 cx_read_func rfnc, |
83 cx_read_func rfnc, |
84 cx_write_func wfnc, |
84 cx_write_func wfnc, |
85 size_t n |
85 size_t n |
86 ) { |
86 ) { |
87 if (n == 0) { |
87 char buf[CX_STREAM_COPY_BUF_SIZE]; |
88 return 0; |
88 return cx_stream_bncopy(src, dest, rfnc, wfnc, |
89 } |
89 buf, CX_STREAM_COPY_BUF_SIZE, n); |
90 |
|
91 const size_t bufsize = CX_STREAM_COPY_BUF_SIZE; |
|
92 char lbuf[bufsize]; |
|
93 size_t ncp = 0; |
|
94 |
|
95 size_t r; |
|
96 size_t rn = bufsize > n ? n : bufsize; |
|
97 while ((r = rfnc(lbuf, 1, rn, src)) != 0) { |
|
98 r = wfnc(lbuf, 1, r, dest); |
|
99 ncp += r; |
|
100 n -= r; |
|
101 rn = bufsize > n ? n : bufsize; |
|
102 if (r == 0 || n == 0) { |
|
103 break; |
|
104 } |
|
105 } |
|
106 |
|
107 return ncp; |
|
108 } |
90 } |
109 |
91 |
110 #ifndef CX_SZMUL_BUILTIN |
92 #ifndef CX_SZMUL_BUILTIN |
111 #include "szmul.c" |
93 #include "szmul.c" |
112 #endif |
94 #endif |