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

Function sys_pwrite64

components/lwp/lwp_syscall.c:10563–10606  ·  view source on GitHub ↗

* @brief Write data to a file descriptor at a specific offset. * * This function writes data from the buffer `buf` to the file descriptor `fd`, starting at the * specified byte `offset`. Unlike a regular `write` call, `sys_pwrite64` allows the file pointer to * remain unchanged after the write, as the operation directly writes the data to the file at the * provided offset. * * @param[in] fd

Source from the content-addressed store, hash-verified

10561 * writes to arbitrary positions without affecting the current file pointer.
10562 */
10563ssize_t sys_pwrite64(int fd, void *buf, int size, size_t offset)
10564#ifdef RT_USING_DFS_V2
10565{
10566 ssize_t pwrite(int fd, const void *buf, size_t len, size_t offset);
10567#ifdef ARCH_MM_MMU
10568 ssize_t ret = -1;
10569 void *kmem = RT_NULL;
10570
10571 if (!size)
10572 {
10573 return -EINVAL;
10574 }
10575
10576 if (!lwp_user_accessable((void *)buf, size))
10577 {
10578 return -EFAULT;
10579 }
10580 kmem = kmem_get(size);
10581 if (!kmem)
10582 {
10583 return -ENOMEM;
10584 }
10585
10586 lwp_get_from_user(kmem, (void *)buf, size);
10587
10588 ret = pwrite(fd, kmem, size, offset);
10589 if (ret < 0)
10590 {
10591 ret = GET_ERRNO();
10592 }
10593
10594 kmem_put(kmem);
10595
10596 return ret;
10597#else
10598 if (!lwp_user_accessable((void *)buf, size))
10599 {
10600 return -EFAULT;
10601 }
10602
10603 ssize_t ret = pwrite(fd, kmem, size, offset);
10604 return (ret < 0 ? GET_ERRNO() : ret);
10605#endif
10606}
10607#else
10608{
10609 ssize_t ret = -ENOSYS;

Callers

nothing calls this directly

Calls 5

lwp_user_accessableFunction · 0.85
kmem_getFunction · 0.85
lwp_get_from_userFunction · 0.85
pwriteFunction · 0.85
kmem_putFunction · 0.85

Tested by

no test coverage detected