Added SDL_PeekIntoDataQueue().
authorRyan C. Gordon <icculus@icculus.org>
Tue, 10 Oct 2017 11:56:54 -0400
changeset 11582cc0b1273a381
parent 11581 49393a9dffe4
child 11583 c48ab2c208a2
Added SDL_PeekIntoDataQueue().
src/SDL_dataqueue.c
src/SDL_dataqueue.h
     1.1 --- a/src/SDL_dataqueue.c	Tue Oct 10 11:10:15 2017 -0700
     1.2 +++ b/src/SDL_dataqueue.c	Tue Oct 10 11:56:54 2017 -0400
     1.3 @@ -226,6 +226,31 @@
     1.4  }
     1.5  
     1.6  size_t
     1.7 +SDL_PeekIntoDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
     1.8 +{
     1.9 +    size_t len = _len;
    1.10 +    Uint8 *buf = (Uint8 *) _buf;
    1.11 +    Uint8 *ptr = buf;
    1.12 +    SDL_DataQueuePacket *packet;
    1.13 +
    1.14 +    if (!queue) {
    1.15 +        return 0;
    1.16 +    }
    1.17 +
    1.18 +    for (packet = queue->head; len && packet; packet = packet->next) {
    1.19 +        const size_t avail = packet->datalen - packet->startpos;
    1.20 +        const size_t cpy = SDL_min(len, avail);
    1.21 +        SDL_assert(queue->queued_bytes >= avail);
    1.22 +
    1.23 +        SDL_memcpy(ptr, packet->data + packet->startpos, cpy);
    1.24 +        ptr += cpy;
    1.25 +        len -= cpy;
    1.26 +    }
    1.27 +
    1.28 +    return (size_t) (ptr - buf);
    1.29 +}
    1.30 +
    1.31 +size_t
    1.32  SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *_buf, const size_t _len)
    1.33  {
    1.34      size_t len = _len;
     2.1 --- a/src/SDL_dataqueue.h	Tue Oct 10 11:10:15 2017 -0700
     2.2 +++ b/src/SDL_dataqueue.h	Tue Oct 10 11:56:54 2017 -0400
     2.3 @@ -31,6 +31,7 @@
     2.4  void SDL_ClearDataQueue(SDL_DataQueue *queue, const size_t slack);
     2.5  int SDL_WriteToDataQueue(SDL_DataQueue *queue, const void *data, const size_t len);
     2.6  size_t SDL_ReadFromDataQueue(SDL_DataQueue *queue, void *buf, const size_t len);
     2.7 +size_t SDL_PeekIntoDataQueue(SDL_DataQueue *queue, void *buf, const size_t len);
     2.8  size_t SDL_CountDataQueue(SDL_DataQueue *queue);
     2.9  
    2.10  /* this sets a section of the data queue aside (possibly allocating memory for it)