mirror of
https://github.com/apache/nuttx.git
synced 2026-06-04 14:53:47 +08:00
fcntl: add O_CLOEXEC/FD_CLOEXEC support
This commit is contained in:
+28
-6
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user