summaryrefslogtreecommitdiff
path: root/libutil
diff options
context:
space:
mode:
Diffstat (limited to 'libutil')
-rw-r--r--libutil/forkpty.c3
-rw-r--r--libutil/openpty.c80
2 files changed, 4 insertions, 79 deletions
diff --git a/libutil/forkpty.c b/libutil/forkpty.c
index 24643330c..7e42d1a33 100644
--- a/libutil/forkpty.c
+++ b/libutil/forkpty.c
@@ -23,7 +23,8 @@
#include <pty.h>
int
-forkpty (int *amaster, char *name, struct termios *termp, struct winsize *winp)
+forkpty (int *amaster, char *name, const struct termios *termp,
+ const struct winsize *winp)
{
int master, slave, pid;
diff --git a/libutil/openpty.c b/libutil/openpty.c
index 848dc8d38..74d86506b 100644
--- a/libutil/openpty.c
+++ b/libutil/openpty.c
@@ -26,82 +26,18 @@
#include <unistd.h>
#include <sys/types.h>
-/* BCS: the following function is, IMO, overkill */
-#if 0
-/* Return the result of ptsname_r in the buffer pointed to by PTS,
- which should be of length BUF_LEN. If it is too long to fit in
- this buffer, a sufficiently long buffer is allocated using malloc,
- and returned in PTS. 0 is returned upon success, -1 otherwise. */
-static int
-pts_name (int fd, char **pts, size_t buf_len)
-{
- int rv;
- char *buf = *pts;
-
- for (;;)
- {
- char *new_buf;
-
- if (buf_len)
- {
- rv = ptsname_r (fd, buf, buf_len);
-
- if (rv != 0 || memchr (buf, '\0', buf_len))
- /* We either got an error, or we succeeded and the
- returned name fit in the buffer. */
- break;
-
- /* Try again with a longer buffer. */
- buf_len += buf_len; /* Double it */
- }
- else
- /* No initial buffer; start out by mallocing one. */
- buf_len = 128; /* First time guess. */
-
- if (buf != *pts)
- /* We've already malloced another buffer at least once. */
- new_buf = realloc (buf, buf_len);
- else
- new_buf = malloc (buf_len);
- if (! new_buf)
- {
- rv = -1;
- __set_errno (ENOMEM);
- break;
- }
- buf = new_buf;
- }
-
- if (rv == 0)
- *pts = buf; /* Return buffer to the user. */
- else if (buf != *pts)
- free (buf); /* Free what we malloced when returning an error. */
-
- return rv;
-}
-#endif
-
/* Create pseudo tty master slave pair and set terminal attributes
according to TERMP and WINP. Return handles for both ends in
AMASTER and ASLAVE, and return the name of the slave end in NAME. */
int
-openpty (int *amaster, int *aslave, char *name, struct termios *termp,
- struct winsize *winp)
+openpty (int *amaster, int *aslave, char *name, const struct termios *termp,
+ const struct winsize *winp)
{
-#if 0
-#ifdef PATH_MAX
- char _buf[PATH_MAX];
-#else
- char _buf[512];
-#endif
- char *buf = _buf;
-#else
#ifdef PATH_MAX
char buf[PATH_MAX];
#else
char buf[512];
#endif
-#endif
int master, slave;
master = posix_openpt (O_RDWR);
@@ -114,20 +50,12 @@ openpty (int *amaster, int *aslave, char *name, struct termios *termp,
if (unlockpt (master))
goto fail;
-#if 0
- if (pts_name (master, &buf, sizeof (_buf)))
-#else
if (ptsname_r (master, buf, sizeof buf))
-#endif
goto fail;
slave = open (buf, O_RDWR | O_NOCTTY);
if (slave == -1)
{
-#if 0
- if (buf != _buf)
- free (buf);
-#endif
goto fail;
}
@@ -142,10 +70,6 @@ openpty (int *amaster, int *aslave, char *name, struct termios *termp,
if (name != NULL)
strcpy (name, buf);
-#if 0
- if (buf != _buf)
- free (buf);
-#endif
return 0;
fail: