| 22 | #include "301/CO_ODinterface.h" |
| 23 | |
| 24 | ODR_t |
| 25 | OD_readOriginal(OD_stream_t* stream, void* buf, OD_size_t count, OD_size_t* countRead) { |
| 26 | if ((stream == NULL) || (buf == NULL) || (countRead == NULL)) { |
| 27 | return ODR_DEV_INCOMPAT; |
| 28 | } |
| 29 | |
| 30 | OD_size_t dataLenToCopy = stream->dataLength; /* length of OD variable */ |
| 31 | const uint8_t* dataOrig = stream->dataOrig; |
| 32 | |
| 33 | if (dataOrig == NULL) { |
| 34 | return ODR_SUB_NOT_EXIST; |
| 35 | } |
| 36 | |
| 37 | ODR_t returnCode = ODR_OK; |
| 38 | |
| 39 | /* If previous read was partial or OD variable length is larger than |
| 40 | * current buffer size, then data was (will be) read in several segments */ |
| 41 | if ((stream->dataOffset > 0U) || (dataLenToCopy > count)) { |
| 42 | if (stream->dataOffset >= dataLenToCopy) { |
| 43 | return ODR_DEV_INCOMPAT; |
| 44 | } |
| 45 | /* Reduce for already copied data */ |
| 46 | dataLenToCopy -= stream->dataOffset; |
| 47 | dataOrig += stream->dataOffset; |
| 48 | |
| 49 | if (dataLenToCopy > count) { |
| 50 | /* Not enough space in destination buffer */ |
| 51 | dataLenToCopy = count; |
| 52 | stream->dataOffset += dataLenToCopy; |
| 53 | returnCode = ODR_PARTIAL; |
| 54 | } else { |
| 55 | stream->dataOffset = 0; /* copy finished, reset offset */ |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | (void)memcpy((void*)buf, (const void*)dataOrig, dataLenToCopy); |
| 60 | |
| 61 | *countRead = dataLenToCopy; |
| 62 | return returnCode; |
| 63 | } |
| 64 | |
| 65 | ODR_t |
| 66 | OD_writeOriginal(OD_stream_t* stream, const void* buf, OD_size_t count, OD_size_t* countWritten) { |
no outgoing calls
no test coverage detected