Added fcntl(3) with FD_GET and FD_SET.

This commit is contained in:
Jonas 'Sortie' Termansen 2012-03-04 21:36:40 +01:00
parent 75b14aa821
commit 5e75f5c428
5 changed files with 28 additions and 5 deletions

View File

@ -36,8 +36,6 @@ __BEGIN_DECLS
/* TODO: F_* missing here */
/* TODO: FD_CLOEXEC missing here */
/* TODO: F_RDLCK, F_UNLCK, F_WRLCK missing here */
/* TODO: AT_FDCWD missing here */
@ -61,11 +59,10 @@ struct _flock
typedef struct _flock flock;
/* TODO: These are not implemented in libmaxsi/sortix yet. */
int fcntl(int fd, int cmd, ...);
int open(const char* path, int oflag, ...);
#if defined(__SORTIX_SHOW_UNIMPLEMENTED)
int creat(const char* path, mode_t mode);
int fcntl(int fd, int cmd, ...);
int openat(int fd, const char* path, int oflag, ...);
#endif

View File

@ -57,6 +57,7 @@ namespace Maxsi
DEFN_SYSCALL2(int, SysFTruncate, SYSCALL_FTRUNCATE, int, off_t);
DEFN_SYSCALL2(int, SysStat, SYSCALL_STAT, const char*, struct stat*);
DEFN_SYSCALL2(int, SysFStat, SYSCALL_FSTAT, int, struct stat*);
DEFN_SYSCALL3(int, SysFCntl, SYSCALL_FCNTL, int, int, unsigned long);
size_t Print(const char* string)
{
@ -293,6 +294,11 @@ namespace Maxsi
return SysFStat(fd, st);
}
extern "C" int fcntl(int fd, int cmd, unsigned long arg)
{
return SysFCntl(fd, cmd, arg);
}
// TODO: This is a hacky implementation of a stupid function.
char* mktemp(char* templ)
{

View File

@ -46,6 +46,9 @@ __BEGIN_DECLS
#define FD_CLOEXEC (1<<0)
#define FD_CLOFORK (1<<1)
#define F_SETFD 0
#define F_GETFD 1
__END_DECLS
#endif

View File

@ -130,6 +130,21 @@ namespace Sortix
return -1;
}
int SysFCntl(int fd, int cmd, unsigned long arg)
{
Process* process = CurrentProcess();
DescriptorTable* descs = &(process->descriptors);
Device* dev = descs->Get(fd);
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;
}
Error::Set(EINVAL);
return 1;
}
void Init()
{
Syscall::Register(SYSCALL_OPEN, (void*) SysOpen);
@ -140,6 +155,7 @@ namespace Sortix
Syscall::Register(SYSCALL_FTRUNCATE, (void*) SysFTruncate);
Syscall::Register(SYSCALL_STAT, (void*) SysStat);
Syscall::Register(SYSCALL_FSTAT, (void*) SysFStat);
Syscall::Register(SYSCALL_FCNTL, (void*) SysFCntl);
}
}

View File

@ -70,7 +70,8 @@
#define SYSCALL_GETTERMMODE 43
#define SYSCALL_STAT 44
#define SYSCALL_FSTAT 45
#define SYSCALL_MAX_NUM 46 /* index of highest constant + 1 */
#define SYSCALL_FCNTL 46
#define SYSCALL_MAX_NUM 47 /* index of highest constant + 1 */
#endif