Loading...
--- Libc/Libc-1725.40.4/util/pty.c
+++ Libc/Libc-498/util/pty.c
@@ -64,77 +64,79 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
#include <termios.h>
#include <unistd.h>
#include <util.h>
+#include <syslog.h>
-int openpty(int *aprimary, int *areplica, char *name, struct termios *termp, struct winsize *winp)
+static char ptytemplate[] = "/dev/ptyXX";
+
+int openpty(amaster, aslave, name, termp, winp)
+ int *amaster, *aslave;
+ char *name;
+ struct termios *termp;
+ struct winsize *winp;
{
- int primary, replica;
- char rname[__PTYNAMELEN];
- int errno_saved;
+ int master, slave;
+ char *sname;
- if ((primary = posix_openpt(O_RDWR|O_NOCTTY)) < 0)
+ if ((master = posix_openpt(O_RDWR|O_NOCTTY)) < 0)
return -1;
- if (grantpt(primary) < 0 || unlockpt(primary) < 0
- || ptsname_r(primary, rname, sizeof(rname)) == -1
- || (replica = open(rname, O_RDWR|O_NOCTTY, 0)) < 0) {
- errno_saved = errno;
- (void) close(primary);
- errno = errno_saved;
+ if (grantpt(master) < 0 || unlockpt(master) < 0
+ || (sname = ptsname(master)) == NULL
+ || (slave = open(sname, O_RDWR|O_NOCTTY, 0)) < 0) {
+ (void) close(master);
return -1;
}
- *aprimary = primary;
- *areplica = replica;
+ *amaster = master;
+ *aslave = slave;
if (name)
- strlcpy(name, rname, __PTYNAMELEN);
+ strcpy(name, sname);
if (termp)
- (void) tcsetattr(replica, TCSAFLUSH, termp);
+ (void) tcsetattr(slave, TCSAFLUSH, termp);
if (winp)
- (void) ioctl(replica, TIOCSWINSZ, (char *)winp);
+ (void) ioctl(slave, TIOCSWINSZ, (char *)winp);
return (0);
}
int
-forkpty(int *aprimary, char *name, struct termios *termp, struct winsize *winp)
+forkpty(amaster, name, termp, winp)
+ int *amaster;
+ char *name;
+ struct termios *termp;
+ struct winsize *winp;
{
- int primary, replica, pid;
- int errno_saved;
+ int master, slave, pid;
- if (openpty(&primary, &replica, name, termp, winp) == -1)
+ if (openpty(&master, &slave, name, termp, winp) == -1)
return (-1);
switch (pid = fork()) {
case -1:
- errno_saved = errno;
- (void) close(primary);
- (void) close(replica);
- errno = errno_saved;
return (-1);
case 0:
/*
* child
*/
- (void) close(primary);
+ (void) close(master);
/*
* 4300297: login_tty() may fail to set the controlling tty.
* Since we have already forked, the best we can do is to
- * dup the replica as if login_tty() succeeded.
+ * dup the slave as if login_tty() succeeded.
*/
- if (login_tty(replica) < 0) {
+ if (login_tty(slave) < 0) {
syslog(LOG_ERR, "forkpty: login_tty could't make controlling tty");
- (void) dup2(replica, 0);
- (void) dup2(replica, 1);
- (void) dup2(replica, 2);
- if (replica > 2)
- (void) close(replica);
+ (void) dup2(slave, 0);
+ (void) dup2(slave, 1);
+ (void) dup2(slave, 2);
+ if (slave > 2)
+ (void) close(slave);
}
return (0);
}
/*
* parent
*/
- *aprimary = primary;
- (void) close(replica);
+ *amaster = master;
+ (void) close(slave);
return (pid);
}