Lines Matching refs:buffer
34 ESR_ReturnCode CircularBufferCreate(size_t capacity, const LCHAR* mtag, CircularBuffer** buffer)
37 if (buffer == NULL || capacity <= 0)
45 *buffer = Interface;
50 int CircularBufferRead(CircularBuffer* buffer, void* data, size_t bufSize)
55 if (buffer == NULL || (data == NULL && bufSize > 0))
58 if (buffer->size < bufSize)
59 bufSize = buffer->size;
64 bufferData = ((unsigned char *) buffer) + sizeof(CircularBuffer);
66 if (buffer->readIdx >= buffer->writeIdx)
68 nbRead = buffer->capacity - buffer-> readIdx;
71 memcpy(data, bufferData + buffer->readIdx, nbRead);
72 buffer->size -= nbRead;
73 buffer->readIdx += nbRead;
74 if (buffer->readIdx == buffer->capacity)
75 buffer->readIdx = 0;
81 memcpy(((unsigned char *) data) + nbRead, bufferData + buffer->readIdx, toRead);
82 buffer->size -= toRead;
83 buffer->readIdx += toRead;
89 int CircularBufferSkip(CircularBuffer* buffer, size_t bufSize)
91 if ( buffer == NULL )
94 if (buffer->size < bufSize)
95 bufSize = buffer->size;
100 buffer->readIdx += bufSize;
101 if (buffer->readIdx >= buffer->capacity)
102 buffer->readIdx -= buffer->capacity;
104 buffer->size -= bufSize;
109 int CircularBufferWrite(CircularBuffer* buffer, const void *data, size_t bufSize)
113 size_t available = buffer->capacity - buffer->size;
125 bufferData = ((unsigned char*) buffer) + sizeof(CircularBuffer);
127 if (buffer->writeIdx >= buffer->readIdx)
129 nbWritten = buffer->capacity - buffer->writeIdx;
131 memcpy(bufferData + buffer->writeIdx, data, nbWritten);
132 buffer->size += nbWritten;
133 buffer->writeIdx += nbWritten;
134 if (buffer->writeIdx == buffer->capacity)
135 buffer->writeIdx = 0;
141 memcpy(bufferData + buffer->writeIdx, ((unsigned char*) data) + nbWritten, toWrite);
142 buffer->size += toWrite;
143 buffer->writeIdx += toWrite;
149 int CircularBufferUnwrite(CircularBuffer* buffer, size_t amount)
151 size_t available = buffer->capacity - buffer->size;
155 buffer->size -= amount;