fcntl: add O_CLOEXEC/FD_CLOEXEC support

This commit is contained in:
chao.an
2020-02-03 22:21:54 +08:00
committed by Gregory Nutt
parent c015e42602
commit d07afc934e
6 changed files with 71 additions and 18 deletions
+28 -6
View File
@@ -113,15 +113,37 @@ int file_vfcntl(FAR struct file *filep, int cmd, va_list ap)
* that refer to the same file.
*/
{
ret = filep->f_oflags & O_CLOEXEC ? FD_CLOEXEC : 0;
}
break;
case F_SETFD:
/* Set the file descriptor flags defined in <fcntl.h>, that are associated
* with fd, to the third argument, arg, taken as type int. If the
* FD_CLOEXEC flag in the third argument is 0, the file shall remain open
* across the exec functions; otherwise, the file shall be closed upon
* successful execution of one of the exec functions.
/* Set the file descriptor flags defined in <fcntl.h>, that are
* associated with fd, to the third argument, arg, taken as type int.
* If the FD_CLOEXEC flag in the third argument is 0, the file shall
* remain open across the exec functions; otherwise, the file shall
* be closed upon successful execution of one of the exec functions.
*/
ret = -ENOSYS;
{
int oflags = va_arg(ap, int);
if (oflags & ~FD_CLOEXEC)
{
ret = -ENOSYS;
break;
}
if (oflags & FD_CLOEXEC)
{
filep->f_oflags |= O_CLOEXEC;
}
else
{
filep->f_oflags &= ~O_CLOEXEC;
}
}
break;
case F_GETFL: