src/internal/utils/kitringbuffer.c
int Kit_WriteRingBuffer(Kit_RingBuffer *rb, const char* data, int len) {
    int k;
    len = (len > (rb->size - rb->len)) ? (rb->size - rb->len) : len;
    if(rb->len < rb->size) {
        if(len + rb->wpos > rb->size) {
            k = (len + rb->wpos) % rb->size;
            memcpy((rb->data + rb->wpos), data, len - k);
            memcpy(rb->data, data+(len-k), k);
        } else {
            memcpy((rb->data + rb->wpos), data, len);
        }
        rb->len += len;
        rb->wpos += len;
        if(rb->wpos >= rb->size) {
            rb->wpos = rb->wpos % rb->size;
        }
        return len;
    }
    return 0;
}
/**
  * Writes to the given ringbuffer. If given length is larger than the amount
  * the ringbuffer can fit, only the data that fits will be written.
  * @param rb Ringbuffer to write to.
  * @param data Data to write
  * @param len Data length
  * @return Amount of data that was actually written.
  */
Writes to the given ringbuffer. If given length is larger than the amount
the ringbuffer can fit, only the data that fits will be written.
@param rb Ringbuffer to write to.
@param data Data to write
@param len Data length
@return Amount of data that was actually written.
Writes to the given ringbuffer . If given length is larger than the amount the ringbuffer can fit only the data that fits will be written . @param rb Ringbuffer to write to . @param data Data to write @param len Data length @return Amount of data that was actually written .
int Kit_WriteRingBuffer(Kit_RingBuffer *rb, const char* data, int len) {
    int k;
    len = (len > (rb->size - rb->len)) ? (rb->size - rb->len) : len;
    if(rb->len < rb->size) {
        if(len + rb->wpos > rb->size) {
            k = (len + rb->wpos) % rb->size;
            memcpy((rb->data + rb->wpos), data, len - k);
            memcpy(rb->data, data+(len-k), k);
        } else {
            memcpy((rb->data + rb->wpos), data, len);
        }
        rb->len += len;
        rb->wpos += len;
        if(rb->wpos >= rb->size) {
            rb->wpos = rb->wpos % rb->size;
        }
        return len;
    }
    return 0;
}
int Kit_WriteRingBuffer ( Kit_RingBuffer * rb , const char * data , int len ) { int k ; len = ( len > ( rb -> size - rb -> len ) ) ? ( rb -> size - rb -> len ) : len ; if ( rb -> len < rb -> size ) { if ( len + rb -> wpos > rb -> size ) { k = ( len + rb -> wpos ) % rb -> size ; memcpy ( ( rb -> data + rb -> wpos ) , data , len - k ) ; memcpy ( rb -> data , data + ( len - k ) , k ) ; } else { memcpy ( ( rb -> data + rb -> wpos ) , data , len ) ; } rb -> len += len ; rb -> wpos += len ; if ( rb -> wpos >= rb -> size ) { rb -> wpos = rb -> wpos % rb -> size ; } return len ; } return 0 ; }
Writes to the given ringbuffer.
Writes to the given ringbuffer .