source: azure_iot_hub/trunk/musl-1.1.18/src/unistd/ttyname_r.c@ 388

Last change on this file since 388 was 388, checked in by coas-nagasima, 5 years ago

Azure IoT Hub Device C SDK を使ったサンプルの追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 573 bytes
Line 
1#include <unistd.h>
2#include <errno.h>
3#include <sys/stat.h>
4
5void __procfdname(char *, unsigned);
6
7int 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.