77684050e6f935c40d0b1937aa126b0aa5cb2930
[musl] / src / unistd / ctermid.c
1 #include <stdio.h>
2 #include <fcntl.h>
3 #include <unistd.h>
4 #include <limits.h>
5 #include "syscall.h"
6
7 char *ctermid(char *s)
8 {
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);
17         }
18         return s;
19 }