From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org
Subject: ptsname_r: Add support for DragonFly BSD 6.0
Date: Tue, 08 Jun 2021 01:28:01 +0200 [thread overview]
Message-ID: <1972946.3KXDKOScUx@omega> (raw)
On DragonFly BSD 6.0, which does not have ptsname_r(), the Gnulib replacement
always fails because
1. the fd does not satisfy isatty(),
2. ttyname_r returns just a number, e.g. "25", which is pointless.
On this system, a different approach is needed: fdevname_r(). This is also
what ptsname() uses.
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.
diff --git a/lib/ptsname_r.c b/lib/ptsname_r.c
index fc93912..4043916 100644
--- a/lib/ptsname_r.c
+++ b/lib/ptsname_r.c
@@ -70,6 +70,10 @@
# 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;
diff --git a/tests/test-ptsname_r.c b/tests/test-ptsname_r.c
index 21551d2..73d8c41 100644
--- a/tests/test-ptsname_r.c
+++ b/tests/test-ptsname_r.c
@@ -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];
reply other threads:[~2021-06-07 23:28 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1972946.3KXDKOScUx@omega \
--to=bruno@clisp.org \
--cc=bug-gnulib@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).