Add fcntl(F_PREVFD) and fcntl(F_NEXTFD).
This commit is contained in:
parent
8643c37102
commit
536d7a06f5
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
|
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014.
|
||||||
|
|
||||||
This file is part of Sortix.
|
This file is part of Sortix.
|
||||||
|
|
||||||
|
@ -219,4 +219,39 @@ int DescriptorTable::GetFlags(int index)
|
||||||
return entries[index].flags;
|
return entries[index].flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int DescriptorTable::Previous(int index)
|
||||||
|
{
|
||||||
|
ScopedLock lock(&dtablelock);
|
||||||
|
|
||||||
|
if ( index < 0 )
|
||||||
|
index = numentries;
|
||||||
|
|
||||||
|
do index--;
|
||||||
|
while ( 0 <= index && !IsGoodEntry(index) );
|
||||||
|
|
||||||
|
if ( index < 0 )
|
||||||
|
return errno = EBADF, -1;
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
int DescriptorTable::Next(int index)
|
||||||
|
{
|
||||||
|
ScopedLock lock(&dtablelock);
|
||||||
|
|
||||||
|
if ( index < 0 )
|
||||||
|
index = -1;
|
||||||
|
|
||||||
|
if ( numentries <= index )
|
||||||
|
return errno = EBADF, -1;
|
||||||
|
|
||||||
|
do index++;
|
||||||
|
while ( index < numentries && !IsGoodEntry(index) );
|
||||||
|
|
||||||
|
if ( numentries <= index )
|
||||||
|
return errno = EBADF, -1;
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Sortix
|
} // namespace Sortix
|
||||||
|
|
|
@ -99,6 +99,14 @@ __BEGIN_DECLS
|
||||||
#define F_DUPFD_CLOEXEC F_ENCODE_CMD(F_ENCODE(F_DUPFD_NUM, FD_CLOEXEC), 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 F_DUPFD_CLOFORK F_ENCODE_CMD(F_ENCODE(F_DUPFD_NUM, FD_CLOFORK), F_TYPE_INT)
|
||||||
|
|
||||||
|
/* Find the previous file descriptor. */
|
||||||
|
#define F_PREVFD_NUM 5
|
||||||
|
#define F_PREVFD F_ENCODE_CMD(F_PREVFD_NUM, F_TYPE_VOID)
|
||||||
|
|
||||||
|
/* Find the next file descriptor. */
|
||||||
|
#define F_NEXTFD_NUM 6
|
||||||
|
#define F_NEXTFD F_ENCODE_CMD(F_NEXTFD_NUM, F_TYPE_VOID)
|
||||||
|
|
||||||
#define AT_FDCWD (-100)
|
#define AT_FDCWD (-100)
|
||||||
#define AT_REMOVEDIR (1<<0)
|
#define AT_REMOVEDIR (1<<0)
|
||||||
#define AT_EACCESS (1<<1)
|
#define AT_EACCESS (1<<1)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
|
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014.
|
||||||
|
|
||||||
This file is part of Sortix.
|
This file is part of Sortix.
|
||||||
|
|
||||||
|
@ -52,6 +52,8 @@ public:
|
||||||
void OnExecute();
|
void OnExecute();
|
||||||
bool SetFlags(int index, int flags);
|
bool SetFlags(int index, int flags);
|
||||||
int GetFlags(int index);
|
int GetFlags(int index);
|
||||||
|
int Previous(int index);
|
||||||
|
int Next(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Reset(); // Hey, reference counted. Don't call this.
|
void Reset(); // Hey, reference counted. Don't call this.
|
||||||
|
|
|
@ -316,6 +316,10 @@ static int sys_fcntl(int fd, int cmd, uintptr_t arg)
|
||||||
{
|
{
|
||||||
// Operations on the descriptor table.
|
// Operations on the descriptor table.
|
||||||
Ref<DescriptorTable> dtable = CurrentProcess()->GetDTable();
|
Ref<DescriptorTable> dtable = CurrentProcess()->GetDTable();
|
||||||
|
if ( cmd == F_PREVFD )
|
||||||
|
return dtable->Previous(fd);
|
||||||
|
if ( cmd == F_NEXTFD )
|
||||||
|
return dtable->Next(fd);
|
||||||
|
|
||||||
// Operations on the file descriptior.
|
// Operations on the file descriptior.
|
||||||
if ( cmd == F_SETFD )
|
if ( cmd == F_SETFD )
|
||||||
|
|
Loading…
Reference in New Issue