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

Function sys_write

components/lwp/lwp_syscall.c:494–533  ·  view source on GitHub ↗

* @brief Writes data from a buffer to a file descriptor. * * This system call writes up to `nbyte` bytes of data from the buffer pointed * to by `buf` to the file descriptor specified by `fd`. * * @param fd The file descriptor to write to. This should be a valid file * descriptor obtained through system calls like `open()` or `socket()`. * @param buf A pointer to the buffer contai

Source from the content-addressed store, hash-verified

492 * @see sys_read(), write()
493 */
494ssize_t sys_write(int fd, const void *buf, size_t nbyte)
495{
496#ifdef ARCH_MM_MMU
497 void *kmem = RT_NULL;
498 ssize_t ret = -1;
499
500 if (nbyte)
501 {
502 if (!lwp_user_accessable((void *)buf, nbyte))
503 {
504 return -EFAULT;
505 }
506
507 kmem = kmem_get(nbyte);
508 if (!kmem)
509 {
510 return -ENOMEM;
511 }
512
513 lwp_get_from_user(kmem, (void *)buf, nbyte);
514 }
515
516 ret = write(fd, kmem, nbyte);
517 if (ret < 0)
518 {
519 ret = GET_ERRNO();
520 }
521
522 kmem_put(kmem);
523
524 return ret;
525#else
526 if (!lwp_user_accessable((void *)buf, nbyte))
527 {
528 return -EFAULT;
529 }
530 ssize_t ret = write(fd, buf, nbyte);
531 return (ret < 0 ? GET_ERRNO() : ret);
532#endif
533}
534
535/**
536 * @brief Repositions the file offset of the open file descriptor.

Callers 1

lwp_tty_ioctl_adapterFunction · 0.85

Calls 5

lwp_user_accessableFunction · 0.85
kmem_getFunction · 0.85
lwp_get_from_userFunction · 0.85
kmem_putFunction · 0.85
writeFunction · 0.50

Tested by

no test coverage detected