浏览代码

feat(gblibc): isatty()

greatbridf 2 年之前
父节点
当前提交
69803ca140
共有 3 个文件被更改,包括 11 次插入1 次删除
  1. 2 0
      gblibc/include/unistd.h
  2. 5 0
      gblibc/src/unistd.c
  3. 4 1
      src/kernel/syscall.cpp

+ 2 - 0
gblibc/include/unistd.h

@@ -47,6 +47,8 @@ int tcsetpgrp(int fd, pid_t pgrp);
 int brk(void* addr);
 int brk(void* addr);
 void* sbrk(ssize_t increment);
 void* sbrk(ssize_t increment);
 
 
+int isatty(int fd);
+
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }
 #endif
 #endif

+ 5 - 0
gblibc/src/unistd.c

@@ -245,3 +245,8 @@ void* sbrk(ssize_t increment)
         return curr_brk += increment;
         return curr_brk += increment;
     return (void*)-1;
     return (void*)-1;
 }
 }
+
+int isatty(int fd)
+{
+    return tcgetpgrp(fd) != -1;
+}

+ 4 - 1
src/kernel/syscall.cpp

@@ -400,7 +400,10 @@ int _syscall_ioctl(interrupt_stack* data)
     //       not. and we suppose that stdin will be
     //       not. and we suppose that stdin will be
     //       either a tty or a pipe.
     //       either a tty or a pipe.
     auto* file = current_process->files[fd];
     auto* file = current_process->files[fd];
-    if (!file || file->type != fs::file::types::ind)
+    if (!file)
+        return -EBADF;
+
+    if (file->type != fs::file::types::ind)
         return -ENOTTY;
         return -ENOTTY;
 
 
     switch (request) {
     switch (request) {