Last change
on this file since 403 was 337, checked in by coas-nagasima, 6 years ago |
ASP3版ECNLを追加
|
-
Property svn:eol-style
set to
native
-
Property svn:mime-type
set to
text/x-csrc;charset=UTF-8
|
File size:
573 bytes
|
Line | |
---|
1 | #include <unistd.h>
|
---|
2 | #include <errno.h>
|
---|
3 | #include <sys/stat.h>
|
---|
4 |
|
---|
5 | void __procfdname(char *, unsigned);
|
---|
6 |
|
---|
7 | int ttyname_r(int fd, char *name, size_t size)
|
---|
8 | {
|
---|
9 | struct stat st1, st2;
|
---|
10 | char procname[sizeof "/proc/self/fd/" + 3*sizeof(int) + 2];
|
---|
11 | ssize_t l;
|
---|
12 |
|
---|
13 | if (!isatty(fd)) return ENOTTY;
|
---|
14 |
|
---|
15 | __procfdname(procname, fd);
|
---|
16 | l = readlink(procname, name, size);
|
---|
17 |
|
---|
18 | if (l < 0) return errno;
|
---|
19 | else if (l == size) return ERANGE;
|
---|
20 |
|
---|
21 | name[l] = 0;
|
---|
22 |
|
---|
23 | if (stat(name, &st1) || fstat(fd, &st2))
|
---|
24 | return errno;
|
---|
25 | if (st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino)
|
---|
26 | return ENODEV;
|
---|
27 |
|
---|
28 | return 0;
|
---|
29 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.