Copy up to INL bytes from the char_buffer BUFFER into IN. Note * that due to the strange way this API is designed/used, the * char_buffer object is used to cache a segment of inctx->buffer, and * then this function called to copy (part of) that segment to the * beginning of inctx->buffer. So the segments to copy cannot be * presumed to be non-overlapping, and memmove must be used. */
| 346 | * beginning of inctx->buffer. So the segments to copy cannot be |
| 347 | * presumed to be non-overlapping, and memmove must be used. */ |
| 348 | static int char_buffer_read(char_buffer_t *buffer, char *in, int inl) |
| 349 | { |
| 350 | if (!buffer->length) { |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | if (buffer->length > inl) { |
| 355 | /* we have enough to fill the caller's buffer */ |
| 356 | memmove(in, buffer->value, inl); |
| 357 | buffer->value += inl; |
| 358 | buffer->length -= inl; |
| 359 | } |
| 360 | else { |
| 361 | /* swallow remainder of the buffer */ |
| 362 | memmove(in, buffer->value, buffer->length); |
| 363 | inl = buffer->length; |
| 364 | buffer->value = NULL; |
| 365 | buffer->length = 0; |
| 366 | } |
| 367 | |
| 368 | return inl; |
| 369 | } |
| 370 | |
| 371 | static int char_buffer_write(char_buffer_t *buffer, char *in, int inl) |
| 372 | { |