Added F_SETFL and F_GETFL to fcntl(2).

This is a bit of a hacky implementation.
This commit is contained in:
Jonas 'Sortie' Termansen 2012-03-11 20:29:00 +01:00
parent beb88d0443
commit 5b916b5f63
2 changed files with 19 additions and 1 deletions

View File

@ -48,6 +48,8 @@ __BEGIN_DECLS
#define F_SETFD 0
#define F_GETFD 1
#define F_SETFL 2
#define F_GETFL 3
__END_DECLS

View File

@ -189,8 +189,24 @@ namespace Sortix
if ( !dev ) { Error::Set(EBADF); return -1; }
switch ( cmd )
{
case F_GETFD: return descs->GetFlags(fd);
case F_SETFD: descs->SetFlags(fd, (int) arg); return 0;
case F_GETFD: return descs->GetFlags(fd);
case F_SETFL: Error::Set(ENOSYS); return -1;
case F_GETFL:
if ( dev->IsType(Device::DIRECTORY) ) { return O_SEARCH; }
if ( !dev->IsType(Device::STREAM) )
{
Error::Set(ENOSYS);
return -1;
}
DevStream* stream = (DevStream*) stream;
bool write = stream->IsWritable();
bool read = stream->IsReadable();
if ( write && read ) { return O_RDWR; }
if ( write && !read ) { return O_WRONLY; }
if ( !write && read ) { return O_RDONLY; }
return O_EXEC;
break;
}
Error::Set(EINVAL);
return 1;