Explorar o código

LibC: Add `ctermid`

We simply return "/dev/tty", since it always refers to the controlling
terminal of the calling process.
SeekingBlues %!s(int64=3) %!d(string=hai) anos
pai
achega
f34e69a52b
Modificáronse 2 ficheiros con 11 adicións e 0 borrados
  1. 9 0
      Userland/Libraries/LibC/stdio.cpp
  2. 2 0
      Userland/Libraries/LibC/stdio.h

+ 9 - 0
Userland/Libraries/LibC/stdio.cpp

@@ -1299,6 +1299,15 @@ FILE* tmpfile()
     return fdopen(fd, "rw");
     return fdopen(fd, "rw");
 }
 }
 
 
+// https://pubs.opengroup.org/onlinepubs/9699919799/functions/ctermid.html
+char* ctermid(char* s)
+{
+    static char tty_path[L_ctermid] = "/dev/tty";
+    if (s)
+        return strcpy(s, tty_path);
+    return tty_path;
+}
+
 size_t __fpending(FILE* stream)
 size_t __fpending(FILE* stream)
 {
 {
     ScopedFileLock lock(stream);
     ScopedFileLock lock(stream);

+ 2 - 0
Userland/Libraries/LibC/stdio.h

@@ -27,6 +27,7 @@ __BEGIN_DECLS
 #define _IOLBF 1
 #define _IOLBF 1
 #define _IONBF 2
 #define _IONBF 2
 
 
+#define L_ctermid 9
 #define L_tmpnam 256
 #define L_tmpnam 256
 #define P_tmpdir "/tmp"
 #define P_tmpdir "/tmp"
 
 
@@ -99,5 +100,6 @@ FILE* tmpfile(void);
 char* tmpnam(char*);
 char* tmpnam(char*);
 FILE* popen(char const* command, char const* type);
 FILE* popen(char const* command, char const* type);
 int pclose(FILE*);
 int pclose(FILE*);
+char* ctermid(char* s);
 
 
 __END_DECLS
 __END_DECLS