* @brief Read data from an ELF file at a specific offset. * * @param fd File descriptor of the ELF file. * @param buffer Pointer to the buffer where the read data will be stored. * @param size Number of bytes to read. * @param offset File offset where reading should begin. * @return RT_EOK on success, -RT_ERROR if seek or read operations fail. */
| 235 | * @return RT_EOK on success, -RT_ERROR if seek or read operations fail. |
| 236 | */ |
| 237 | static int elf_file_read(rt_int32_t fd, rt_uint8_t *buffer, size_t size, off_t offset) |
| 238 | { |
| 239 | ssize_t read_len; |
| 240 | off_t pos; |
| 241 | |
| 242 | if (size > 0) |
| 243 | { |
| 244 | pos = lseek(fd, offset, SEEK_SET); |
| 245 | if (pos != offset) |
| 246 | { |
| 247 | LOG_E("%s : seek file offset: 0x%x failed", __func__, offset); |
| 248 | return -RT_ERROR; |
| 249 | } |
| 250 | |
| 251 | read_len = read(fd, buffer, size); |
| 252 | if (read_len != size) |
| 253 | { |
| 254 | LOG_E("%s : read from offset: 0x%x error", __func__, offset); |
| 255 | return -RT_ERROR; |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | return RT_EOK; |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * @brief Validate an ELF header. |
no test coverage detected