| 1178 | /*-----------------------------------------------------------*/ |
| 1179 | |
| 1180 | static size_t prvReadBytesFromBuffer( StreamBuffer_t * pxStreamBuffer, |
| 1181 | uint8_t * pucData, |
| 1182 | size_t xMaxCount, |
| 1183 | size_t xBytesAvailable ) |
| 1184 | { |
| 1185 | size_t xCount, xFirstLength, xNextTail; |
| 1186 | |
| 1187 | /* Use the minimum of the wanted bytes and the available bytes. */ |
| 1188 | xCount = configMIN( xBytesAvailable, xMaxCount ); |
| 1189 | |
| 1190 | if( xCount > ( size_t ) 0 ) |
| 1191 | { |
| 1192 | xNextTail = pxStreamBuffer->xTail; |
| 1193 | |
| 1194 | /* Calculate the number of bytes that can be read - which may be |
| 1195 | * less than the number wanted if the data wraps around to the start of |
| 1196 | * the buffer. */ |
| 1197 | xFirstLength = configMIN( pxStreamBuffer->xLength - xNextTail, xCount ); |
| 1198 | |
| 1199 | /* Obtain the number of bytes it is possible to obtain in the first |
| 1200 | * read. Asserts check bounds of read and write. */ |
| 1201 | configASSERT( xFirstLength <= xMaxCount ); |
| 1202 | configASSERT( ( xNextTail + xFirstLength ) <= pxStreamBuffer->xLength ); |
| 1203 | ( void ) memcpy( ( void * ) pucData, ( const void * ) &( pxStreamBuffer->pucBuffer[ xNextTail ] ), xFirstLength ); /*lint !e9087 memcpy() requires void *. */ |
| 1204 | |
| 1205 | /* If the total number of wanted bytes is greater than the number |
| 1206 | * that could be read in the first read... */ |
| 1207 | if( xCount > xFirstLength ) |
| 1208 | { |
| 1209 | /*...then read the remaining bytes from the start of the buffer. */ |
| 1210 | configASSERT( xCount <= xMaxCount ); |
| 1211 | ( void ) memcpy( ( void * ) &( pucData[ xFirstLength ] ), ( void * ) ( pxStreamBuffer->pucBuffer ), xCount - xFirstLength ); /*lint !e9087 memcpy() requires void *. */ |
| 1212 | } |
| 1213 | else |
| 1214 | { |
| 1215 | mtCOVERAGE_TEST_MARKER(); |
| 1216 | } |
| 1217 | |
| 1218 | /* Move the tail pointer to effectively remove the data read from |
| 1219 | * the buffer. */ |
| 1220 | xNextTail += xCount; |
| 1221 | |
| 1222 | if( xNextTail >= pxStreamBuffer->xLength ) |
| 1223 | { |
| 1224 | xNextTail -= pxStreamBuffer->xLength; |
| 1225 | } |
| 1226 | |
| 1227 | pxStreamBuffer->xTail = xNextTail; |
| 1228 | } |
| 1229 | else |
| 1230 | { |
| 1231 | mtCOVERAGE_TEST_MARKER(); |
| 1232 | } |
| 1233 | |
| 1234 | return xCount; |
| 1235 | } |
| 1236 | /*-----------------------------------------------------------*/ |
| 1237 |
no outgoing calls
no test coverage detected