[vte] pty: Simplify ptsname call
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vte] pty: Simplify ptsname call
- Date: Sun, 29 Nov 2015 19:58:27 +0000 (UTC)
commit 5a1b8bef8b1416948ce83e12bcd89f2a653a7549
Author: Christian Persch <chpe gnome org>
Date: Sun Nov 29 20:57:54 2015 +0100
pty: Simplify ptsname call
There's no need to use ptsname_r here or offer a fallback to
ioctl(TIOCGPTN), since all supported OSes (linux, BSDs, illumos)
have ptsname(3).
https://bugzilla.gnome.org/show_bug.cgi?id=747046
src/pty.cc | 71 ++++-------------------------------------------------------
1 files changed, 5 insertions(+), 66 deletions(-)
---
diff --git a/src/pty.cc b/src/pty.cc
index 7200f8f..8feef8f 100644
--- a/src/pty.cc
+++ b/src/pty.cc
@@ -211,8 +211,6 @@ struct _VtePtyClass {
GObjectClass parent_class;
};
-static char *_vte_pty_ptsname(int master);
-
/**
* vte_pty_child_setup:
* @pty: a #VtePty
@@ -229,9 +227,11 @@ vte_pty_child_setup (VtePty *pty)
if (masterfd == -1)
_exit(127);
- char *name = _vte_pty_ptsname(masterfd);
- if (name == nullptr)
- _exit(127);
+ char *name = ptsname(masterfd);
+ if (name == nullptr) {
+ _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "ptsname");
+ _exit(127);
+ }
_vte_debug_print (VTE_DEBUG_PTY,
"Setting up child pty: master FD = %d name = %s\n",
@@ -607,67 +607,6 @@ vte_pty_get_size(VtePty *pty,
}
}
-/*
- * _vte_pty_ptsname:
- * @master: file descriptor to the PTY master
- * @error: a location to store a #GError, or %NULL
- *
- * Returns: a newly allocated string containing the file name of the
- * PTY slave device, or %NULL on failure with @error filled in
- */
-static char *
-_vte_pty_ptsname(int master)
-{
-#if defined(HAVE_PTSNAME_R)
- gsize len = 1024;
- char *buf = NULL;
- int i, errsv;
- do {
- buf = (char *) g_malloc0(len);
- i = ptsname_r(master, buf, len - 1);
- switch (i) {
- case 0:
- /* Return the allocated buffer with the name in it. */
- _vte_debug_print(VTE_DEBUG_PTY,
- "PTY slave is `%s'.\n", buf);
- return buf;
- break;
- default:
- errsv = errno;
- _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "ptsname_r");
- g_free(buf);
- errno = errsv;
- buf = NULL;
- break;
- }
- len *= 2;
- } while ((i != 0) && (errno == ERANGE));
-
- return NULL;
-#elif defined(HAVE_PTSNAME)
- char *p;
- if ((p = ptsname(master)) != NULL) {
- _vte_debug_print(VTE_DEBUG_PTY, "PTY slave is `%s'.\n", p);
- return g_strdup(p);
- }
-
- _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "ptsname");
- return NULL;
-#elif defined(TIOCGPTN)
- int pty = 0;
- if (ioctl(master, TIOCGPTN, &pty) == 0) {
- _vte_debug_print(VTE_DEBUG_PTY,
- "PTY slave is `/dev/pts/%d'.\n", pty);
- return g_strdup_printf("/dev/pts/%d", pty);
- }
-
- _vte_debug_print(VTE_DEBUG_PTY, "%s failed: %m\n", "ioctl(TIOCGPTN)");
- return NULL;
-#else
-#error no ptsname implementation for this platform
-#endif
-}
-
#if defined(HAVE_UNIX98_PTY)
/*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]