149 return 0; |
149 return 0; |
150 } |
150 } |
151 |
151 |
152 size_t ucx_buffer_write(const void *ptr, size_t size, size_t nitems, |
152 size_t ucx_buffer_write(const void *ptr, size_t size, size_t nitems, |
153 UcxBuffer *buffer) { |
153 UcxBuffer *buffer) { |
154 size_t len = size * nitems; |
154 size_t len; |
|
155 if(ucx_szmul(size, nitems, &len)) { |
|
156 return 0; |
|
157 } |
155 size_t required = buffer->pos + len; |
158 size_t required = buffer->pos + len; |
156 if (buffer->pos > required) { |
159 if (buffer->pos > required) { |
157 return 0; |
160 return 0; |
158 } |
161 } |
159 |
162 |
183 return len / size; |
186 return len / size; |
184 } |
187 } |
185 |
188 |
186 size_t ucx_buffer_read(void *ptr, size_t size, size_t nitems, |
189 size_t ucx_buffer_read(void *ptr, size_t size, size_t nitems, |
187 UcxBuffer *buffer) { |
190 UcxBuffer *buffer) { |
188 size_t len = size * nitems; |
191 size_t len; |
|
192 if(ucx_szmul(size, nitems, &len)) { |
|
193 return 0; |
|
194 } |
189 if (buffer->pos + len > buffer->size) { |
195 if (buffer->pos + len > buffer->size) { |
190 len = buffer->size - buffer->pos; |
196 len = buffer->size - buffer->pos; |
191 if (size > 1) len -= len%size; |
197 if (size > 1) len -= len%size; |
192 } |
198 } |
193 |
199 |