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

Function sys_openat

components/lwp/lwp_syscall.c:700–737  ·  view source on GitHub ↗

* @brief Opens or creates a file relative to a directory file descriptor. * * This system call opens the file specified by `name`, relative to the directory * indicated by `dirfd`, with the specified flags and mode. It provides more * flexibility than `sys_open` for handling files in specific directory contexts. * * @param dirfd The file descriptor of the directory relative to which the file

Source from the content-addressed store, hash-verified

698 * @see sys_open(), sys_read(), sys_write(), sys_close()
699 */
700sysret_t sys_openat(int dirfd, const char *name, int flag, mode_t mode)
701{
702#ifdef ARCH_MM_MMU
703 int ret = -1;
704 rt_size_t len = 0;
705 char *kname = RT_NULL;
706
707 len = lwp_user_strlen(name);
708 if (len <= 0)
709 {
710 return -EINVAL;
711 }
712
713 kname = (char *)kmem_get(len + 1);
714 if (!kname)
715 {
716 return -ENOMEM;
717 }
718
719 lwp_get_from_user(kname, (void *)name, len + 1);
720 ret = openat(dirfd, kname, flag, mode);
721 if (ret < 0)
722 {
723 ret = GET_ERRNO();
724 }
725
726 kmem_put(kname);
727
728 return ret;
729#else
730 if (!lwp_user_accessable((void *)name, 1))
731 {
732 return -EFAULT;
733 }
734 int ret = openat(dirfd, name, flag, mode);
735 return (ret < 0 ? GET_ERRNO() : ret);
736#endif
737}
738
739/**
740 * @brief Closes a file descriptor.

Callers

nothing calls this directly

Calls 6

lwp_user_strlenFunction · 0.85
kmem_getFunction · 0.85
lwp_get_from_userFunction · 0.85
kmem_putFunction · 0.85
lwp_user_accessableFunction · 0.85
openatFunction · 0.50

Tested by

no test coverage detected