From 20788aec002ab3f6dea4e01665a439933161d11c Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Thu, 9 Jun 2016 15:16:32 -0700 Subject: [PATCH] Add ctermid. Change-Id: I7c7c815c2725df222932db923632c8b6419741ab --- libc/include/stdio.h | 1 + libc/libc.arm.brillo.map | 1 + libc/libc.arm.map | 1 + libc/libc.arm64.map | 1 + libc/libc.map.txt | 1 + libc/libc.mips.brillo.map | 1 + libc/libc.mips.map | 1 + libc/libc.mips64.map | 1 + libc/libc.x86.brillo.map | 1 + libc/libc.x86.map | 1 + libc/libc.x86_64.map | 1 + libc/stdio/stdio.cpp | 5 +++++ tests/stdio_test.cpp | 8 ++++++++ 13 files changed, 24 insertions(+) diff --git a/libc/include/stdio.h b/libc/include/stdio.h index 83ffc20ec..b92f5d5b3 100644 --- a/libc/include/stdio.h +++ b/libc/include/stdio.h @@ -226,6 +226,7 @@ int vsscanf(const char * __restrict, const char * __restrict, __va_list) */ #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 3928cae69..9ea1d8b41 100644 --- a/libc/libc.arm.brillo.map +++ b/libc/libc.arm.brillo.map @@ -1271,6 +1271,7 @@ LIBC_O { catclose; catgets; catopen; + ctermid; endgrent; endpwent; futimes; diff --git a/libc/libc.arm.map b/libc/libc.arm.map index f6520b59a..0097c25c8 100644 --- a/libc/libc.arm.map +++ b/libc/libc.arm.map @@ -1271,6 +1271,7 @@ LIBC_O { catclose; catgets; catopen; + ctermid; endgrent; endpwent; futimes; diff --git a/libc/libc.arm64.map b/libc/libc.arm64.map index 603ac8651..cfa183810 100644 --- a/libc/libc.arm64.map +++ b/libc/libc.arm64.map @@ -1194,6 +1194,7 @@ LIBC_O { catclose; catgets; catopen; + ctermid; endgrent; endpwent; futimes; diff --git a/libc/libc.map.txt b/libc/libc.map.txt index d2ad2498e..aeb39d329 100644 --- a/libc/libc.map.txt +++ b/libc/libc.map.txt @@ -1296,6 +1296,7 @@ LIBC_O { catclose; catgets; catopen; + ctermid; endgrent; endpwent; futimes; diff --git a/libc/libc.mips.brillo.map b/libc/libc.mips.brillo.map index 2cf5df0a4..ce4d4ad75 100644 --- a/libc/libc.mips.brillo.map +++ b/libc/libc.mips.brillo.map @@ -1255,6 +1255,7 @@ LIBC_O { catclose; catgets; catopen; + ctermid; endgrent; endpwent; futimes; diff --git a/libc/libc.mips.map b/libc/libc.mips.map index 6c5ba9cb1..172a2aec0 100644 --- a/libc/libc.mips.map +++ b/libc/libc.mips.map @@ -1255,6 +1255,7 @@ LIBC_O { catclose; catgets; catopen; + ctermid; endgrent; endpwent; futimes; diff --git a/libc/libc.mips64.map b/libc/libc.mips64.map index 603ac8651..cfa183810 100644 --- a/libc/libc.mips64.map +++ b/libc/libc.mips64.map @@ -1194,6 +1194,7 @@ LIBC_O { catclose; catgets; catopen; + ctermid; endgrent; endpwent; futimes; diff --git a/libc/libc.x86.brillo.map b/libc/libc.x86.brillo.map index 1a254ae9e..81b13d096 100644 --- a/libc/libc.x86.brillo.map +++ b/libc/libc.x86.brillo.map @@ -1253,6 +1253,7 @@ LIBC_O { catclose; catgets; catopen; + ctermid; endgrent; endpwent; futimes; diff --git a/libc/libc.x86.map b/libc/libc.x86.map index ca97c0389..3611e148c 100644 --- a/libc/libc.x86.map +++ b/libc/libc.x86.map @@ -1253,6 +1253,7 @@ LIBC_O { catclose; catgets; catopen; + ctermid; endgrent; endpwent; futimes; diff --git a/libc/libc.x86_64.map b/libc/libc.x86_64.map index 603ac8651..cfa183810 100644 --- a/libc/libc.x86_64.map +++ b/libc/libc.x86_64.map @@ -1194,6 +1194,7 @@ LIBC_O { catclose; catgets; catopen; + ctermid; endgrent; endpwent; futimes; diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp index 5df1bb95d..3aabbe23c 100644 --- a/libc/stdio/stdio.cpp +++ b/libc/stdio/stdio.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -598,3 +599,7 @@ FILE* funopen64(const void* cookie, } return fp; } + +char* ctermid(char* s) { + return s ? strcpy(s, _PATH_TTY) : const_cast(_PATH_TTY); +} diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp index 7e826124f..4db1f72dd 100644 --- a/tests/stdio_test.cpp +++ b/tests/stdio_test.cpp @@ -1297,3 +1297,11 @@ TEST(STDIO_TEST, fseek_fseeko_EINVAL) { 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); +}