OLD | NEW |
1 #include <unistd.h> | 1 #include <unistd.h> |
2 #include <errno.h> | 2 #include <errno.h> |
3 | 3 |
4 void __procfdname(char *, unsigned); | 4 void __procfdname(char*, unsigned); |
5 | 5 |
6 int ttyname_r(int fd, char *name, size_t size) | 6 int ttyname_r(int fd, char* name, size_t size) { |
7 { | 7 char procname[sizeof "/proc/self/fd/" + 3 * sizeof(int) + 2]; |
8 » char procname[sizeof "/proc/self/fd/" + 3*sizeof(int) + 2]; | 8 ssize_t l; |
9 » ssize_t l; | |
10 | 9 |
11 » if (!isatty(fd)) return ENOTTY; | 10 if (!isatty(fd)) |
| 11 return ENOTTY; |
12 | 12 |
13 » __procfdname(procname, fd); | 13 __procfdname(procname, fd); |
14 » l = readlink(procname, name, size); | 14 l = readlink(procname, name, size); |
15 | 15 |
16 » if (l < 0) return errno; | 16 if (l < 0) |
17 » else if (l == size) return ERANGE; | 17 return errno; |
18 » else { | 18 else if (l == size) |
19 » » name[l] = 0; | 19 return ERANGE; |
20 » » return 0; | 20 else { |
21 » } | 21 name[l] = 0; |
| 22 return 0; |
| 23 } |
22 } | 24 } |
OLD | NEW |