projects
/
oweals
/
musl.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
implement hcreate_r, hdestroy_r and hsearch_r
[oweals/musl.git]
/
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
}