| 63 | } |
| 64 | |
| 65 | ODR_t |
| 66 | OD_writeOriginal(OD_stream_t* stream, const void* buf, OD_size_t count, OD_size_t* countWritten) { |
| 67 | if ((stream == NULL) || (buf == NULL) || (countWritten == NULL)) { |
| 68 | return ODR_DEV_INCOMPAT; |
| 69 | } |
| 70 | |
| 71 | OD_size_t dataLenToCopy = stream->dataLength; /* length of OD variable */ |
| 72 | OD_size_t dataLenRemain = dataLenToCopy; /* remaining length of dataOrig buffer */ |
| 73 | uint8_t* dataOrig = stream->dataOrig; |
| 74 | |
| 75 | if (dataOrig == NULL) { |
| 76 | return ODR_SUB_NOT_EXIST; |
| 77 | } |
| 78 | |
| 79 | ODR_t returnCode = ODR_OK; |
| 80 | |
| 81 | /* If previous write was partial or OD variable length is larger than current buffer size, |
| 82 | * then data was (will be) written in several segments */ |
| 83 | if ((stream->dataOffset > 0U) || (dataLenToCopy > count)) { |
| 84 | if (stream->dataOffset >= dataLenToCopy) { |
| 85 | return ODR_DEV_INCOMPAT; |
| 86 | } |
| 87 | /* reduce for already copied data */ |
| 88 | dataLenToCopy -= stream->dataOffset; |
| 89 | dataLenRemain = dataLenToCopy; |
| 90 | dataOrig += stream->dataOffset; |
| 91 | |
| 92 | if (dataLenToCopy > count) { |
| 93 | /* Remaining data space in OD variable is larger than current count |
| 94 | * of data, so only current count of data will be copied */ |
| 95 | dataLenToCopy = count; |
| 96 | stream->dataOffset += dataLenToCopy; |
| 97 | returnCode = ODR_PARTIAL; |
| 98 | } else { |
| 99 | stream->dataOffset = 0; /* copy finished, reset offset */ |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | if (dataLenToCopy < count) { |
| 104 | /* OD variable is smaller than current amount of data */ |
| 105 | return ODR_DATA_LONG; |
| 106 | } |
| 107 | |
| 108 | /* additional check for Misra c compliance */ |
| 109 | if ((dataLenToCopy <= dataLenRemain) && (dataLenToCopy <= count)) { |
| 110 | (void)memcpy((void*)dataOrig, (const void*)buf, dataLenToCopy); |
| 111 | } else { |
| 112 | return ODR_DEV_INCOMPAT; |
| 113 | } |
| 114 | |
| 115 | *countWritten = dataLenToCopy; |
| 116 | return returnCode; |
| 117 | } |
| 118 | |
| 119 | /* Read value from variable from Object Dictionary disabled, see OD_IO_t */ |
| 120 | static ODR_t |
no outgoing calls
no test coverage detected