diff --git a/sortix/fcntl.h b/sortix/fcntl.h index fab9e3a0..3e7ffb64 100644 --- a/sortix/fcntl.h +++ b/sortix/fcntl.h @@ -48,6 +48,8 @@ __BEGIN_DECLS #define F_SETFD 0 #define F_GETFD 1 +#define F_SETFL 2 +#define F_GETFL 3 __END_DECLS diff --git a/sortix/filesystem.cpp b/sortix/filesystem.cpp index 93da49a6..cd4838e0 100644 --- a/sortix/filesystem.cpp +++ b/sortix/filesystem.cpp @@ -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;