include cleanups: remove unused headers and add feature test macros
[musl.git] / src / unistd / ctermid.c
blob77684050e6f935c40d0b1937aa126b0aa5cb2930
1 #include <stdio.h>
2 #include <fcntl.h>
3 #include <unistd.h>
4 #include <limits.h>
5 #include "syscall.h"
7 char *ctermid(char *s)
9 static char s2[L_ctermid];
10 int fd;
11 if (!s) s = s2;
12 *s = 0;
13 fd = open("/dev/tty", O_WRONLY | O_NOCTTY | O_CLOEXEC);
14 if (fd >= 0) {
15 ttyname_r(fd, s, L_ctermid);
16 __syscall(SYS_close, fd);
18 return s;