Add F_DUPFD, F_DUPFD_CLOEXEC, F_DUPFD_CLOFORK.

This commit is contained in:
Jonas 'Sortie' Termansen 2013-09-24 13:35:05 +02:00
parent 42f00f5d79
commit defa74d7ec
2 changed files with 11 additions and 0 deletions

View File

@ -88,6 +88,12 @@ __BEGIN_DECLS
#define F_GETFL_NUM 3
#define F_GETFL F_ENCODE_CMD(F_GETFL_NUM, F_TYPE_VOID)
/* Duplicates the file descriptor with at least the given index. */
#define F_DUPFD_NUM 4
#define F_DUPFD F_ENCODE_CMD(F_ENCODE(F_DUPFD_NUM, 0), F_TYPE_INT)
#define F_DUPFD_CLOEXEC F_ENCODE_CMD(F_ENCODE(F_DUPFD_NUM, FD_CLOEXEC), F_TYPE_INT)
#define F_DUPFD_CLOFORK F_ENCODE_CMD(F_ENCODE(F_DUPFD_NUM, FD_CLOFORK), F_TYPE_INT)
#define AT_FDCWD (-100)
#define AT_REMOVEDIR (1<<0)
#define AT_EACCESS (1<<1)

View File

@ -328,6 +328,11 @@ static int sys_fcntl(int fd, int cmd, uintptr_t arg)
return dtable->GetFlags(fd);
// Operations on the file description.
if ( F_DECODE_CMD(F_DECODE_CMD_RAW(cmd)) == F_DUPFD_NUM )
{
int fd_flags = F_DECODE_FLAGS(F_DECODE_CMD_RAW(cmd));
return dtable->Allocate(fd, fd_flags, (int) arg);
}
Ref<Descriptor> desc = dtable->Get(fd);
if ( !desc )
return -1;