MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / elf_file_read

Function elf_file_read

components/lwp/lwp_elf.c:237–260  ·  view source on GitHub ↗

* @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. */

Source from the content-addressed store, hash-verified

235 * @return RT_EOK on success, -RT_ERROR if seek or read operations fail.
236 */
237static 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.

Callers 3

elf_load_ehdrFunction · 0.85
elf_load_phdrFunction · 0.85
elf_load_interpFunction · 0.85

Calls 2

lseekFunction · 0.50
readFunction · 0.50

Tested by

no test coverage detected