From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 0FF641F5AE for ; Mon, 7 Jun 2021 23:28:13 +0000 (UTC) Received: from localhost ([::1]:59714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqOfD-0007N8-Vd for normalperson@yhbt.net; Mon, 07 Jun 2021 19:28:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqOfA-0007Mw-UY for bug-gnulib@gnu.org; Mon, 07 Jun 2021 19:28:08 -0400 Received: from mo4-p00-ob.smtp.rzone.de ([85.215.255.22]:26409) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqOf9-0002EI-9B for bug-gnulib@gnu.org; Mon, 07 Jun 2021 19:28:08 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1623108483; cv=none; d=strato.com; s=strato-dkim-0002; b=GVBQB+Gq8Sm1EgtjbqL1AzEdZTxGgP3O2W6CBB/aLxZuFxmmF6hmRyM7kTABFyw7u0 HdPQFnXctx3A5f1mZKGscTryn1TSjWO1luiOlZQ4poIxaFUkK17s8sm2O3S4CrRCk8uD R5Jbrv16Ul3t2Fnqm0wK4dDEduDx94p6Ivb8IjlnhtO8z3oXDxha/1doiwgPpQcgFE9V oSbzpC40qQNtwd7F6o6lqWpZyX5ez/vrM/nCVUV+K3Z2fFdVUOxA9bQt+rvgtFQ8WOKD L07jfcMVmQ6YK6sEOggwijBo/RDB3I9dYZfyvCP3HNHYNfxs4eyKHCqoPEopO84Rqerv VNEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1623108483; s=strato-dkim-0002; d=strato.com; h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; bh=xWddgfI5Im0HgNFT5x7+6A5mSVQ4i3MoU5kTvN+Iu40=; b=tPZyMNHvP01u+oKueEcpkmkR4TaBfPqf+8Zzz+pGWisy2BXkfSm9VyZjcZarGqZQss KudG4HO2IrEM6b1lOleVY2QFYQrhUgEz9JwpK+mwnY1vBdKjdFNLZNgayfszpPGIXRxY 1DVMXKX/Cw90msQjAlCwVczvInupwB8bRoxe3148fFzI/L6AVjknFDGLW8bW6RHSVCpV v0p/BiZ7uCxwjIJfTE+OHPFiaB/6SQIxNdk6S17UgWZZPBK+NYbBAJVOAeCHiftRbxoN BMsC0yZl5YRjMr2u8AWisZO4cN2eRExkdkNJ0aJwUJKVmtsk+Lodj7ryvjp6PgJA+P7H VkHg== ARC-Authentication-Results: i=1; strato.com; dkim=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1623108483; s=strato-dkim-0002; d=clisp.org; h=Message-ID:Date:Subject:To:From:Cc:Date:From:Subject:Sender; bh=xWddgfI5Im0HgNFT5x7+6A5mSVQ4i3MoU5kTvN+Iu40=; b=cdGqjJlUP3KI+D8kT6Rwo5QzxkfzMe9/2BznT2B0RqhG9ctTu2GhlrjIVUslWUbki+ Ck4jV47gjQtH22bYHxGHE6FMN6fdrDgOuEos2rlyyP7C1AuWwKuMsBK4vWQedzw8EJ6E hjfrkCFn8H7gSDyxoPygpt/YCkwqOWfUoFqx0bcVE88zkad/X0c0P6YCOW6Hgj1+xk3a DBR6gH3XEweqIsbqoA91JaXcJzPs8r5Ol8xzqlYYAChvzptuqhzBGYiCdldOVaesmw6E ALijsY84dSyksLusvU+oFYhykjpDA1lH/BS0JWJzx13dKPg2cYZ4D8z+J3PxO/Qo+nH0 lLYQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOHqf3z5NW" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 47.27.2 DYNA|AUTH) with ESMTPSA id q0869dx57NS1QSc (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve X9_62_prime256v1 with 256 ECDH bits, eq. 3072 bits RSA)) (Client did not present a certificate); Tue, 8 Jun 2021 01:28:01 +0200 (CEST) From: Bruno Haible To: bug-gnulib@gnu.org Subject: ptsname_r: Add support for DragonFly BSD 6.0 Date: Tue, 08 Jun 2021 01:28:01 +0200 Message-ID: <1972946.3KXDKOScUx@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-210-generic; KDE/5.18.0; x86_64; ; ) MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Received-SPF: none client-ip=85.215.255.22; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" 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 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 #endif +#if defined __DragonFly__ +/* Get fdevname_r(). */ +# include +#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];