From: David van Moolenbroek Date: Sun, 24 Nov 2013 20:50:44 +0000 (+0100) Subject: libc: make ttyname(3) use devname(3) X-Git-Tag: v3.3.0~188 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/nslookup.html?a=commitdiff_plain;h=69cba46141faec19a7832fd10efdce3ec055e2bc;p=minix.git libc: make ttyname(3) use devname(3) There was an off-by-one in the old MINIX-specific implementation, which caused ttyname(3) to fail at random. Since we now have a working devname(3), there is no need for MINIX-specific code anymore here. Change-Id: I27d8b6c4f66c84f383156ed494b740d071af02a7 --- diff --git a/lib/libc/gen/ttyname.c b/lib/libc/gen/ttyname.c index 879c5c9a2..95842c98b 100644 --- a/lib/libc/gen/ttyname.c +++ b/lib/libc/gen/ttyname.c @@ -56,56 +56,6 @@ __weak_alias(ttyname,_ttyname) __weak_alias(ttyname_r,_ttyname_r) #endif -#if defined(__minix) -/* LSC: We do not have devname functionality on Minix, so re-import for now - * old, manual way of doing it.*/ -#include -static int -oldttyname(const struct stat *sb, char *buf, size_t len) -{ - struct dirent *dirp; - DIR *dp; - struct stat dsb; - size_t dlen; - - _DIAGASSERT(sb != NULL); - - if ((dp = opendir(_PATH_DEV)) == NULL) - return -1; - - while ((dirp = readdir(dp)) != NULL) { -#define DEVSZ (sizeof(_PATH_DEV) - 1) - if (dirp->d_fileno != sb->st_ino) - continue; - dlen = strlen(dirp->d_name); - if (len - DEVSZ <= dlen) { - /* - * XXX: we return an error if *any* entry does not - * fit - */ - errno = ERANGE; - (void)closedir(dp); - return -1; - } - (void)memcpy(buf + DEVSZ, dirp->d_name, dlen); - if (stat(buf, &dsb) || sb->st_dev != dsb.st_dev || - sb->st_ino != dsb.st_ino) - continue; - (void)closedir(dp); - return 0; -#undef DEVSZ - } - (void)closedir(dp); - /* - * XXX: Documented by TOG to return EBADF or ENOTTY only; neither are - * applicable here. - */ - errno = ENOENT; - return -1; -} - -#endif /* defined(__minix) */ - int ttyname_r(int fd, char *buf, size_t len) { @@ -136,16 +86,9 @@ ttyname_r(int fd, char *buf, size_t len) if (strlcpy(buf, _PATH_DEV, len) >= len) return ERANGE; - -#if defined(__minix) - if (oldttyname(&sb, buf, len) == -1) - return errno; - return 0; -#else buf += strlen(_PATH_DEV); len -= strlen(_PATH_DEV); return devname_r(sb.st_rdev, sb.st_mode & S_IFMT, buf, len); -#endif /* defined(__minix) */ } char *