summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Haehnel <marcus.haehnel@kernkonzept.com>2025-06-26 17:25:08 +0200
committerWaldemar Brodkorb <wbx@openadk.org>2025-06-30 10:35:38 +0200
commite1a6b2b60d1cd86fc918b84eecca1f9ba76cb158 (patch)
tree4a14b07600a54a1509107ff500f475c4d7b39f5c
parentc0a9f8cf8e81516f07cac6abc78a70b07e79e148 (diff)
openpty: Remove code that has been disabled for more than 20 years
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>
-rw-r--r--libutil/openpty.c76
1 files changed, 0 insertions, 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,20 +33,11 @@ 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;
master = posix_openpt (O_RDWR);
@@ -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: