Quellcode durchsuchen

feat(gblibc): isatty()

greatbridf vor 2 Jahren
Ursprung
Commit
69803ca140
3 geänderte Dateien mit 11 neuen und 1 gelöschten Zeilen
  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);
 void* sbrk(ssize_t increment);
 
+int isatty(int fd);
+
 #ifdef __cplusplus
 }
 #endif

+ 5 - 0
gblibc/src/unistd.c

@@ -245,3 +245,8 @@ void* sbrk(ssize_t increment)
         return curr_brk += increment;
     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
     //       either a tty or a pipe.
     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;
 
     switch (request) {