Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Jul 2008 23:11:50 GMT
From:      Ed Schouten <ed@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 145760 for review
Message-ID:  <200807232311.m6NNBoYo034434@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=145760

Change 145760 by ed@ed_dull on 2008/07/23 23:11:45

	Cleanups to grantpt.c:
	
	- Move the pseudo-terminal master device tests to a new
	  __isptmaster() routine.
	- Use __strong_reference() to link them to grantpt() and
	  unlockpt().
	- Use __isptmaster() inside ptsname(), instead of using
	  TIOCPTMASTER directly.

Affected files ...

.. //depot/projects/mpsafetty/lib/libc/stdlib/grantpt.c#2 edit

Differences ...

==== //depot/projects/mpsafetty/lib/libc/stdlib/grantpt.c#2 (text+ko) ====

@@ -41,23 +41,13 @@
 #include "un-namespace.h"
 
 /*
- * grantpt():   grant ownership of a slave pseudo-terminal device to the
- *              current user.
- *
- * unlockpt():  unlock a pseudo-terminal device pair.
+ * __isptmaster():  return whether the file descriptor refers to a
+ *                  pseudo-terminal master device.
  */
+static int
+__isptmaster(int fildes)
+{
 
-int
-grantpt(int fildes)
-{
-	/*
-	 * In our implementation, grantpt() and unlockpt() don't
-	 * actually have any use, because PTY's are created on the fly
-	 * and already have proper permissions.
-	 *
-	 * Just make sure `fildes' actually points to a real PTY master
-	 * device.
-	 */
 	if (_ioctl(fildes, TIOCPTMASTER) == 0)
 		return (0);
 
@@ -67,7 +57,15 @@
 	return (-1);
 }
 
-__weak_reference(grantpt, unlockpt);
+/*
+ * In our implementation, grantpt() and unlockpt() don't actually have
+ * any use, because PTY's are created on the fly and already have proper
+ * permissions upon creation.
+ *
+ * Just make sure `fildes' actually points to a real PTY master device.
+ */
+__strong_reference(__isptmaster, grantpt);
+__strong_reference(__isptmaster, unlockpt);
 
 /*
  * ptsname():  return the pathname of the slave pseudo-terminal device
@@ -82,7 +80,7 @@
 	int sverrno = errno;
 
 	/* Make sure fildes points to a master device. */
-	if (_ioctl(fildes, TIOCPTMASTER) != 0)
+	if (__isptmaster(fildes) != 0)
 		goto done;
 	
 	/* Obtain the device name through FIODGNAME */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200807232311.m6NNBoYo034434>