* @brief Read data from a file descriptor at a specific offset. * * This function reads data from a file descriptor `fd` into the buffer `buf`, starting from the * specified byte `offset`. Unlike a regular `read` call, `sys_pread64` allows the file pointer to * remain unchanged after the read, as the operation directly accesses the file at the provided * offset. * * @param[in] fd The f
| 10487 | * reads from arbitrary positions without affecting the current file pointer. |
| 10488 | */ |
| 10489 | ssize_t sys_pread64(int fd, void *buf, int size, size_t offset) |
| 10490 | #ifdef RT_USING_DFS_V2 |
| 10491 | { |
| 10492 | ssize_t pread(int fd, void *buf, size_t len, size_t offset); |
| 10493 | #ifdef ARCH_MM_MMU |
| 10494 | ssize_t ret = -1; |
| 10495 | void *kmem = RT_NULL; |
| 10496 | |
| 10497 | if (!size) |
| 10498 | { |
| 10499 | return -EINVAL; |
| 10500 | } |
| 10501 | |
| 10502 | if (!lwp_user_accessable((void *)buf, size)) |
| 10503 | { |
| 10504 | return -EFAULT; |
| 10505 | } |
| 10506 | kmem = kmem_get(size); |
| 10507 | if (!kmem) |
| 10508 | { |
| 10509 | return -ENOMEM; |
| 10510 | } |
| 10511 | |
| 10512 | ret = pread(fd, kmem, size, offset); |
| 10513 | if (ret > 0) |
| 10514 | { |
| 10515 | lwp_put_to_user(buf, kmem, ret); |
| 10516 | } |
| 10517 | |
| 10518 | if (ret < 0) |
| 10519 | { |
| 10520 | ret = GET_ERRNO(); |
| 10521 | } |
| 10522 | |
| 10523 | kmem_put(kmem); |
| 10524 | |
| 10525 | return ret; |
| 10526 | #else |
| 10527 | if (!lwp_user_accessable((void *)buf, size)) |
| 10528 | { |
| 10529 | return -EFAULT; |
| 10530 | } |
| 10531 | |
| 10532 | ssize_t ret = pread(fd, kmem, size, offset); |
| 10533 | return (ret < 0 ? GET_ERRNO() : ret); |
| 10534 | #endif |
| 10535 | } |
| 10536 | #else |
| 10537 | { |
| 10538 | ssize_t ret = -ENOSYS; |
nothing calls this directly
no test coverage detected