From patchwork Tue May 26 20:43:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 39363 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CA700383E82F; Tue, 26 May 2020 20:43:09 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from hera.aquilenet.fr (hera.aquilenet.fr [IPv6:2a0c:e300::1]) by sourceware.org (Postfix) with ESMTPS id EC6D8383E80D for ; Tue, 26 May 2020 20:43:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EC6D8383E80D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=samuel.thibault@ens-lyon.org Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 0930C1CB9; Tue, 26 May 2020 22:43:05 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at aquilenet.fr Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SG7iaGIctAfl; Tue, 26 May 2020 22:43:03 +0200 (CEST) Received: from function (lputeaux-656-1-124-130.w92-154.abo.wanadoo.fr [92.154.99.130]) by hera.aquilenet.fr (Postfix) with ESMTPSA id B03B91B00; Tue, 26 May 2020 22:43:03 +0200 (CEST) Received: from samy by function with local (Exim 4.93) (envelope-from ) id 1jdgPd-0002hS-Ev; Tue, 26 May 2020 22:43:01 +0200 From: Samuel Thibault To: libc-alpha@sourceware.org Subject: [PATCH] Rearrange bsd_getpt vs bsd_openpt and implement posix_openbt on BSD Date: Tue, 26 May 2020 22:43:00 +0200 Message-Id: <20200526204300.10337-1-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: commit-hurd@gnu.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" * sysdeps/unix/sysv/linux/getpt.c (__getpt): Add oflag parameter, pass it to the _open call and rename to... (__bsd_openpt): ... new function. [!HAVE_GETPT] (__getpt): Reimplement on top of __bsd_openpt. (__posix_openpt): Replace stub with implementation on top of __bsd_openpt. (posix_openpt): Remove stub warning. * sysdeps/unix/bsd/getpt.c (__bsd_getpt): Replace prototype with __bsd_openpt prototype. (__getpt): Use __bsd_openpt instead of __bsd_getpt (as fallback when _posix_openpt fails). (getpt): Add alias (__getpt): Do not define. (HAVE_GETPT): Define. --- sysdeps/unix/bsd/getpt.c | 18 ++++++++++-------- sysdeps/unix/sysv/linux/getpt.c | 7 ++++--- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/sysdeps/unix/bsd/getpt.c b/sysdeps/unix/bsd/getpt.c index 75489aef28..45c91005af 100644 --- a/sysdeps/unix/bsd/getpt.c +++ b/sysdeps/unix/bsd/getpt.c @@ -41,7 +41,7 @@ const char __libc_ptyname2[] attribute_hidden = PTYNAME2; /* Open a master pseudo terminal and return its file descriptor. */ int -__getpt (void) +__bsd_openpt (int oflag) { char buf[sizeof (_PATH_PTY) + 2]; const char *p, *q; @@ -61,7 +61,7 @@ __getpt (void) s[1] = *q; - fd = __open (buf, O_RDWR); + fd = __open (buf, oflag); if (fd != -1) return fd; @@ -74,18 +74,20 @@ __getpt (void) return -1; } -#undef __getpt +#ifndef HAVE_GETPT +int +__getpt (void) +{ + return __bsd_openpt (O_RDWR); +} weak_alias (__getpt, getpt) +#endif #ifndef HAVE_POSIX_OPENPT -/* We cannot define posix_openpt in general for BSD systems. */ int __posix_openpt (int oflag) { - __set_errno (ENOSYS); - return -1; + return __bsd_openpt (oflag); } weak_alias (__posix_openpt, posix_openpt) - -stub_warning (posix_openpt) #endif diff --git a/sysdeps/unix/sysv/linux/getpt.c b/sysdeps/unix/sysv/linux/getpt.c index 1803b232c9..3785f90db0 100644 --- a/sysdeps/unix/sysv/linux/getpt.c +++ b/sysdeps/unix/sysv/linux/getpt.c @@ -31,7 +31,7 @@ #define _PATH_DEVPTS _PATH_DEV "pts" /* Prototype for function that opens BSD-style master pseudo-terminals. */ -extern int __bsd_getpt (void) attribute_hidden; +extern int __bsd_openpt (int oflag) attribute_hidden; /* Open a master pseudo terminal and return its file descriptor. */ int @@ -88,14 +88,15 @@ __getpt (void) { int fd = __posix_openpt (O_RDWR); if (fd == -1) - fd = __bsd_getpt (); + fd = __bsd_openpt (O_RDWR); return fd; } +weak_alias (__getpt, getpt) #define PTYNAME1 "pqrstuvwxyzabcde"; #define PTYNAME2 "0123456789abcdef"; -#define __getpt __bsd_getpt +#define HAVE_GETPT #define HAVE_POSIX_OPENPT #include