The use of ptsname_r instead of the custom pts_name seems to have proven in the field.
Signed-off-by: Marcus Haehnel marcus.haehnel@kernkonzept.com --- libutil/openpty.c | 76 ----------------------------------------------- 1 file changed, 76 deletions(-)
diff --git a/libutil/openpty.c b/libutil/openpty.c index e14cbc57d..74d86506b 100644 --- a/libutil/openpty.c +++ b/libutil/openpty.c @@ -26,61 +26,6 @@ #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. */ @@ -88,19 +33,10 @@ int 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;
@@ -114,20 +50,12 @@ openpty (int *amaster, int *aslave, char *name, const 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, const struct termios *termp, if (name != NULL) strcpy (name, buf);
-#if 0 - if (buf != _buf) - free (buf); -#endif return 0;
fail: