Add ctermid.
Change-Id: I7c7c815c2725df222932db923632c8b6419741ab
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
index 83ffc20..b92f5d5 100644
--- a/libc/include/stdio.h
+++ b/libc/include/stdio.h
@@ -226,6 +226,7 @@
*/
#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE
#define L_ctermid 1024 /* size for ctermid(); PATH_MAX */
+char* ctermid(char*);
FILE *fdopen(int, const char *);
int fileno(FILE *);
diff --git a/libc/libc.arm.brillo.map b/libc/libc.arm.brillo.map
index 3928cae..9ea1d8b 100644
--- a/libc/libc.arm.brillo.map
+++ b/libc/libc.arm.brillo.map
@@ -1271,6 +1271,7 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
futimes;
diff --git a/libc/libc.arm.map b/libc/libc.arm.map
index f6520b5..0097c25 100644
--- a/libc/libc.arm.map
+++ b/libc/libc.arm.map
@@ -1271,6 +1271,7 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
futimes;
diff --git a/libc/libc.arm64.map b/libc/libc.arm64.map
index 603ac86..cfa1838 100644
--- a/libc/libc.arm64.map
+++ b/libc/libc.arm64.map
@@ -1194,6 +1194,7 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
futimes;
diff --git a/libc/libc.map.txt b/libc/libc.map.txt
index d2ad249..aeb39d3 100644
--- a/libc/libc.map.txt
+++ b/libc/libc.map.txt
@@ -1296,6 +1296,7 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
futimes;
diff --git a/libc/libc.mips.brillo.map b/libc/libc.mips.brillo.map
index 2cf5df0..ce4d4ad 100644
--- a/libc/libc.mips.brillo.map
+++ b/libc/libc.mips.brillo.map
@@ -1255,6 +1255,7 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
futimes;
diff --git a/libc/libc.mips.map b/libc/libc.mips.map
index 6c5ba9c..172a2ae 100644
--- a/libc/libc.mips.map
+++ b/libc/libc.mips.map
@@ -1255,6 +1255,7 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
futimes;
diff --git a/libc/libc.mips64.map b/libc/libc.mips64.map
index 603ac86..cfa1838 100644
--- a/libc/libc.mips64.map
+++ b/libc/libc.mips64.map
@@ -1194,6 +1194,7 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
futimes;
diff --git a/libc/libc.x86.brillo.map b/libc/libc.x86.brillo.map
index 1a254ae..81b13d0 100644
--- a/libc/libc.x86.brillo.map
+++ b/libc/libc.x86.brillo.map
@@ -1253,6 +1253,7 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
futimes;
diff --git a/libc/libc.x86.map b/libc/libc.x86.map
index ca97c03..3611e14 100644
--- a/libc/libc.x86.map
+++ b/libc/libc.x86.map
@@ -1253,6 +1253,7 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
futimes;
diff --git a/libc/libc.x86_64.map b/libc/libc.x86_64.map
index 603ac86..cfa1838 100644
--- a/libc/libc.x86_64.map
+++ b/libc/libc.x86_64.map
@@ -1194,6 +1194,7 @@
catclose;
catgets;
catopen;
+ ctermid;
endgrent;
endpwent;
futimes;
diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp
index 5df1bb9..3aabbe2 100644
--- a/libc/stdio/stdio.cpp
+++ b/libc/stdio/stdio.cpp
@@ -36,6 +36,7 @@
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
+#include <paths.h>
#include <stdlib.h>
#include <string.h>
#include <sys/param.h>
@@ -598,3 +599,7 @@
}
return fp;
}
+
+char* ctermid(char* s) {
+ return s ? strcpy(s, _PATH_TTY) : const_cast<char*>(_PATH_TTY);
+}
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index 7e82612..4db1f72 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -1297,3 +1297,11 @@
fclose(fp);
}
+
+TEST(STDIO_TEST, ctermid) {
+ ASSERT_STREQ("/dev/tty", ctermid(nullptr));
+
+ char buf[L_ctermid] = {};
+ ASSERT_EQ(buf, ctermid(buf));
+ ASSERT_STREQ("/dev/tty", buf);
+}