Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/gen Use ioctl to find the pty name directly instead...
details: https://anonhg.NetBSD.org/src/rev/886d47e704bf
branches: trunk
changeset: 571091:886d47e704bf
user: christos <christos%NetBSD.org@localhost>
date: Thu Nov 11 00:00:15 2004 +0000
description:
Use ioctl to find the pty name directly instead of looking it up in
the database; it is much faster, and the common case these days.
diffstat:
lib/libc/gen/ttyname.c | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
diffs (44 lines):
diff -r 43984fe123f8 -r 886d47e704bf lib/libc/gen/ttyname.c
--- a/lib/libc/gen/ttyname.c Wed Nov 10 23:59:06 2004 +0000
+++ b/lib/libc/gen/ttyname.c Thu Nov 11 00:00:15 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ttyname.c,v 1.19 2003/08/07 16:42:58 agc Exp $ */
+/* $NetBSD: ttyname.c,v 1.20 2004/11/11 00:00:15 christos Exp $ */
/*
* Copyright (c) 1988, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)ttyname.c 8.2 (Berkeley) 1/27/94";
#else
-__RCSID("$NetBSD: ttyname.c,v 1.19 2003/08/07 16:42:58 agc Exp $");
+__RCSID("$NetBSD: ttyname.c,v 1.20 2004/11/11 00:00:15 christos Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -51,12 +51,14 @@
#include <string.h>
#include <termios.h>
#include <unistd.h>
+#include <sys/ioctl.h>
#ifdef __weak_alias
__weak_alias(ttyname,_ttyname)
#endif
static char buf[sizeof(_PATH_DEV) + MAXNAMLEN] = _PATH_DEV;
+static struct ptmget ptm;
static char *oldttyname __P((struct stat *));
char *
@@ -74,6 +76,10 @@
_DIAGASSERT(fd != -1);
+ /* If it is a pty, deal with it quickly */
+ if (ioctl(fd, TIOCPTSNAME, &ptm) != -1)
+ return ptm.sn;
+
/* Must be a terminal. */
if (tcgetattr(fd, &ttyb) < 0)
return (NULL);
Home |
Main Index |
Thread Index |
Old Index