diff --git a/libc/Makefile b/libc/Makefile
index 2444627c..549f58a8 100644
--- a/libc/Makefile
+++ b/libc/Makefile
@@ -311,6 +311,7 @@ tfork.o \
time.o \
truncateat.o \
truncate.o \
+ttyname.o \
umask.o \
unlinkat.o \
unlink.o \
diff --git a/libc/include/unistd.h b/libc/include/unistd.h
index 7e4e6bd8..5e1444e5 100644
--- a/libc/include/unistd.h
+++ b/libc/include/unistd.h
@@ -136,7 +136,6 @@ void sync(void);
long sysconf(int);
pid_t tcgetpgrp(int);
int tcsetpgrp(int, pid_t);
-char* ttyname(int);
int ttyname_r(int, char*, size_t);
#if __POSIX_OBSOLETE <= 200801
@@ -195,6 +194,7 @@ int setuid(uid_t);
unsigned sleep(unsigned);
int truncate(const char*, off_t);
int truncateat(int dirfd, const char*, off_t);
+char* ttyname(int);
int usleep(useconds_t useconds);
int unlinkat(int, const char*, int);
int unlink(const char*);
diff --git a/libc/ttyname.cpp b/libc/ttyname.cpp
new file mode 100644
index 00000000..6b76603e
--- /dev/null
+++ b/libc/ttyname.cpp
@@ -0,0 +1,30 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2013.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ ttyname.cpp
+ Returns the name of a terminal.
+
+*******************************************************************************/
+
+#include
+
+extern "C" char* ttyname(int fd)
+{
+ return isatty(fd) ? (char*) "/dev/tty" : NULL;
+}