Kernel, libc: Add isatty() and F_ISTTY to fcntl()
This commit is contained in:
parent
93207820b3
commit
bef9158450
@ -24,6 +24,11 @@ struct Descriptor
|
||||
m_is_open = false;
|
||||
}
|
||||
|
||||
VFS::Node* node()
|
||||
{
|
||||
return m_node;
|
||||
}
|
||||
|
||||
ssize_t read(size_t size, char* buffer);
|
||||
ssize_t write(size_t size, const char* buffer);
|
||||
|
||||
|
@ -30,6 +30,7 @@ namespace VFS
|
||||
node_finddir find_func;
|
||||
node_mkdir mkdir_func;
|
||||
node_write write_func;
|
||||
int tty = 0;
|
||||
Node* link;
|
||||
};
|
||||
|
||||
|
@ -13,6 +13,7 @@ VFS::Node* ConsoleDevice::create_new(const char* devname)
|
||||
dev->length = 0;
|
||||
dev->type = VFS_DEVICE;
|
||||
dev->flags = 0;
|
||||
dev->tty = 1;
|
||||
strncpy(dev->name, devname, sizeof(dev->name));
|
||||
return dev;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ VFS::Node* KeyboardDevice::create_new(const char* devname)
|
||||
dev->length = 0;
|
||||
dev->type = VFS_DEVICE;
|
||||
dev->flags = 0;
|
||||
dev->tty = 1;
|
||||
strncpy(dev->name, devname, sizeof(dev->name));
|
||||
return dev;
|
||||
}
|
||||
|
@ -19,7 +19,8 @@
|
||||
#define SEEK_CUR 1
|
||||
#define SEEK_END 2
|
||||
|
||||
#define FNCTL_DUPFD 0
|
||||
#define FCNTL_DUPFD 0
|
||||
#define FCNTL_ISTTY 1
|
||||
|
||||
void sys_fcntl(Context* context, int fd, int command, uintptr_t arg)
|
||||
{
|
||||
@ -35,7 +36,7 @@ void sys_fcntl(Context* context, int fd, int command, uintptr_t arg)
|
||||
return;
|
||||
}
|
||||
Descriptor& file = current_task->files[fd];
|
||||
if (command == FNCTL_DUPFD)
|
||||
if (command == FCNTL_DUPFD)
|
||||
{
|
||||
if ((int)arg < 0 || (int)arg >= TASK_MAX_FDS)
|
||||
{
|
||||
@ -53,6 +54,14 @@ void sys_fcntl(Context* context, int fd, int command, uintptr_t arg)
|
||||
kdbgln("fcntl(F_DUPFD): duplicated fd %d, result is %d", fd, dupfd);
|
||||
return;
|
||||
}
|
||||
else if (command == FCNTL_ISTTY)
|
||||
{
|
||||
VFS::Node* node = file.node();
|
||||
if (node->tty) { context->rax = 1; }
|
||||
else
|
||||
context->rax = -ENOTTY;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
context->rax = -EINVAL;
|
||||
|
@ -10,6 +10,8 @@
|
||||
|
||||
/* Duplicate a file descriptor. */
|
||||
#define F_DUPFD 0
|
||||
/* Is a file descriptor a TTY? */
|
||||
#define F_ISTTY 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
|
@ -66,6 +66,9 @@ extern "C"
|
||||
/* Checks if the current program can access the file or directory at path. */
|
||||
int access(const char* path, int amode);
|
||||
|
||||
/* Checks if the file descriptor fd refers to a terminal. */
|
||||
int isatty(int fd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -74,4 +74,11 @@ extern "C"
|
||||
{
|
||||
return (int)syscall(SYS_access, path, amode);
|
||||
}
|
||||
|
||||
int isatty(int fd)
|
||||
{
|
||||
int result = fcntl(fd, F_ISTTY);
|
||||
if (result < 0) return 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user