]> Savannah Git Hosting - gnulib.git/commitdiff
ptsname_r: Add support for DragonFly BSD 6.0.
authorBruno Haible <bruno@clisp.org>
Mon, 7 Jun 2021 23:27:08 +0000 (01:27 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 7 Jun 2021 23:27:08 +0000 (01:27 +0200)
* lib/ptsname_r.c (__ptsname_r): Add implementation for DragonFly BSD.
* tests/test-ptsname_r.c (main): Treat Dragonfly BSD like Solaris.

ChangeLog
lib/ptsname_r.c
tests/test-ptsname_r.c

index f1eaf5bd390ad41c648ee1598301c4d79e7c449c..6ca3a6c1ae57fbbcaf17412eda4853f39d1b915b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2021-06-07  Bruno Haible  <bruno@clisp.org>
+
+       ptsname_r: Add support for DragonFly BSD 6.0.
+       * lib/ptsname_r.c (__ptsname_r): Add implementation for DragonFly BSD.
+       * tests/test-ptsname_r.c (main): Treat Dragonfly BSD like Solaris.
+
 2021-06-07  Bruno Haible  <bruno@clisp.org>
 
        Avoid some test failures on DragonFly BSD 6.0.
index fc93912426864f2b0627c8c22458d9f7c73922b9..4043916374846fa9c5f00f5cb06595aff5765668 100644 (file)
 # include <stdio.h>
 #endif
 
+#if defined __DragonFly__
+/* Get fdevname_r().  */
+# include <stdlib.h>
+#endif
 
 /* Store at most BUFLEN characters of the pathname of the slave pseudo
    terminal associated with the master FD is open on in BUF.
@@ -84,6 +88,36 @@ __ptsname_r (int fd, char *buf, size_t buflen)
     return 0;
   else
     return errno;
+#elif defined __DragonFly__
+  int save_errno = errno;
+  char tmpbuf[5 + 4 + 10 + 1];
+  int ret;
+  int n;
+  if (buf == NULL)
+    {
+      errno = EINVAL;
+      return errno;
+    }
+  /* The result of fdevname_r is typically of the form ptm/N.  */
+  ret = fdevname_r (fd, tmpbuf + 5, sizeof (tmpbuf) - 5);
+  if (ret < 0 || strncmp (tmpbuf + 5, "ptm/", 4) != 0)
+    {
+      errno = ENOTTY;
+      return errno;
+    }
+  /* Turn it into /dev/pts/N.  */
+  memcpy (tmpbuf, "/dev/pts/", 5 + 4);
+  n = strlen (tmpbuf);
+  if (n >= buflen)
+    {
+      errno = ERANGE;
+      return errno;
+    }
+  memcpy (buf, tmpbuf, n + 1);
+  /* Don't do a final stat(), since the file name /dev/pts/N does not actually
+     exist.  */
+  errno = save_errno;
+  return 0;
 #else
   int save_errno = errno;
   struct stat st;
index 21551d2e9942004a932acbeb9b771bc7d7489485..73d8c41cec2774efc527afa89c2bf9543b807702 100644 (file)
@@ -151,9 +151,10 @@ main (void)
     close (fd);
   }
 
-#if defined __sun
+#if defined __sun || defined __DragonFly__
   /* Solaris has BSD-style /dev/pty[p-r][0-9a-f] files, but the function
-     ptsname() does not work on them.  */
+     ptsname() does not work on them.
+     DragonFly BSD has only /dev/ptmx.  */
   {
     int fd;
     char buffer[256];