[gnome-builder/wip/lantw/freebsd-improvement-and-gtk-doc: 2/5] pty: use fdevname_r as a thread-safe alternative of ptsname on FreeBSD



commit 9aef95de4b6bc6061bcc07ebeb19f383d83a4502
Author: Ting-Wei Lan <lantw src gnome org>
Date:   Tue Jan 30 02:21:24 2018 +0800

    pty: use fdevname_r as a thread-safe alternative of ptsname on FreeBSD
    
    fdevname_r is a FreeBSD-specific function which obtains the name of a
    character device from a file descriptor. ptsname is implemented with
    fdevname_r on FreeBSD.

 src/libide/util/ptyintercept.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/util/ptyintercept.c b/src/libide/util/ptyintercept.c
index 69b16c41f..a5ef8025d 100644
--- a/src/libide/util/ptyintercept.c
+++ b/src/libide/util/ptyintercept.c
@@ -96,7 +96,7 @@ pty_intercept_create_slave (pty_fd_t master_fd,
 {
   g_auto(pty_fd_t) ret = PTY_FD_INVALID;
   gint extra = blocking ? 0 : O_NONBLOCK;
-#ifdef HAVE_PTSNAME_R
+#if defined(HAVE_PTSNAME_R) || defined(__FreeBSD__)
   char name[256];
 #else
   const char *name;
@@ -114,6 +114,11 @@ pty_intercept_create_slave (pty_fd_t master_fd,
   if (ptsname_r (master_fd, name, sizeof name - 1) != 0)
     return PTY_FD_INVALID;
   name[sizeof name - 1] = '\0';
+#elif defined(__FreeBSD__)
+  if (fdevname_r (master_fd, name + 5, sizeof name - 6) == NULL)
+    return PTY_FD_INVALID;
+  memcpy (name, "/dev/", 5);
+  name[sizeof name - 1] = '\0';
 #else
   if (NULL == (name = ptsname (master_fd)))
     return PTY_FD_INVALID;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]