#ifdef TRY_OPEN_PTY_MASTER_BSD
-static const char *
-open_pty_master_bsd (Tchannel * master_fd, const char ** master_fname)
+static int
+open_pty_master_bsd (Tchannel * master_fd, const char ** master_fname,
+ const char * slave_name, size_t namelen)
{
- static char master_name [24];
- static char slave_name [24];
const char * p1;
const char * p2;
int fd;
+ if (namelen < 11)
+ return (1);
+
for (p1 = "pqrstuvwxyzPQRST"; ((*p1) != 0); p1 += 1)
for (p2 = "0123456789abcdef"; ((*p2) != 0); p2 += 1)
{
continue;
}
MAKE_CHANNEL (fd, channel_type_unix_pty_master, (*master_fd) =);
- (*master_fname) = master_name;
- return (slave_name);
+ return (0);
}
- return (0);
+ return (1);
}
#endif /* not TRY_OPEN_PTY_MASTER_BSD */
# undef HAVE_POSIX_OPENPT
#endif
-/* Open an available pty, putting channel in (*master_fd),
- and return the file name of the pty.
- Signal error if none available. */
-
-const char *
-OS_open_pty_master (Tchannel * master_fd, const char ** master_fname)
+int
+OS_open_pty_master (Tchannel * master_fd, char * master_fname,
+ char * slave_name, size_t name_length)
{
#ifdef HAVE_GRANTPT
while (1)
{
- static char slave_name [24];
#ifdef HAVE_POSIX_OPENPT
int fd = (posix_openpt (O_RDWR | O_NOCTTY));
#else
int fd;
{
int slave_fd;
- int rc = (openpty ((&fd), (&slave_fd), slave_name, 0, 0));
+ int rc = (openpty ((&fd), (&slave_fd), 0, 0, 0));
if (rc < 0)
fd = -1;
else
#ifdef TRY_OPEN_PTY_MASTER_BSD
/* Try BSD open. This is needed for Linux which might have
Unix98 support in the library but not the kernel. */
- return (open_pty_master_bsd (master_fd, master_fname));
+ return (open_pty_master_bsd (master_fd, master_fname,
+ slave_name, name_length));
#else
- return (0);
+ return (1);
#endif
}
#ifdef sonyrisc
#endif
grantpt (fd);
unlockpt (fd);
- strcpy (slave_name, (ptsname (fd)));
+#ifdef ENABLE_SMP
+ {
+ int err = ptsname_r (fd, slave_name, name_length);
+ if (err)
+ return (2);
+ }
+#else
+ {
+ char *name = ptsname (fd);
+ int len = strlen (name);
+ if (name_length < len)
+ return (3);
+ strcpy (slave_name, name);
+ }
+#endif
#ifdef sonyrisc
sony_unblock_sigchld ();
#endif
MAKE_CHANNEL (fd, channel_type_unix_pty_master, (*master_fd) =);
- (*master_fname) = "/dev/ptmx";
- return (slave_name);
+ strcpy (master_fname, "/dev/ptmx");
+ return (0);
}
#else /* not HAVE_GRANTPT */
if (!OS_have_ptys_p ())
error_unimplemented_primitive ();
- return (open_pty_master_bsd (master_fd, master_fname));
+ return (open_pty_master_bsd (master_fd, master_fname,
+ slave_name, name_length));
#endif /* not HAVE_GRANTPT */
}