From patchwork Wed Oct 19 22:14:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 59099 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 03DEF3851AB4 for ; Wed, 19 Oct 2022 22:17:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 03DEF3851AB4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666217853; bh=KvOipvlLrphK69tokPqPXzWVR0GEbyNQ+b+Kr8m7wgk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=SfvKcSns5n5dLIKCCoY08p7W0stGEaaJgMGWGl+JiGbL5RadwKD6ejlorl2GYse2y rvMruDiwhTELAIuXENFtHJybp6tVMgCJked5IoH7qwczYzkQnwYxg8JsbZqk7PtivX 225a4k+AN3i0afJl520uOVarSrjtBbt6m65i1r+o= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by sourceware.org (Postfix) with ESMTPS id 73FE03858291 for ; Wed, 19 Oct 2022 22:14:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 73FE03858291 Received: by mail-oi1-x22c.google.com with SMTP id g10so20856293oif.10 for ; Wed, 19 Oct 2022 15:14:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KvOipvlLrphK69tokPqPXzWVR0GEbyNQ+b+Kr8m7wgk=; b=WjoeDo4JRlvY2AJPjVXbszyjO9YuiLJzD7Hyq3FAmZ9DUjKfPQWoZyqVHSLoxDzvTS UvW5aoWuWgiDjE6X3p5xTPJmvHsr2B1iP0WbGDm53E1CCaCv73Hl0TXLgaluvtK6h4yk i1/FMcAJyTAvP29jMYPPsMOd+Uqph1CBUlvOEEo+Q6RjUtRNolR78SvzR8QCe/K+LnNK jswvGsA709epRZuFEatU7PTdMSD09/o0rUYeJNwjH4hz+VSbVGiwGAn1/BuNMQWo2ZQA ECLI4qcP0UD6P4IRvinZACladTBrgMKlpZL4rXSvUTmw0f/lgrGimyF0UP7tUfY+6LuZ TX3A== X-Gm-Message-State: ACrzQf1Im0tt45SWpSZ8Lfjd4ASQzysNpFfRKXxYU3GYD8jK02wLfk7x 5WnN4iNydb77NJVpzUKndCsM9iQvN5wZtfHl X-Google-Smtp-Source: AMsMyM6tEZnN+tnd19FV4uBmU0DMAIRoqmSyJ0qVLos8wb43sDDyE+D4BSiWTGI3gmLSC+fQ9zSkoA== X-Received: by 2002:a05:6808:3b8:b0:354:7f5a:de31 with SMTP id n24-20020a05680803b800b003547f5ade31mr5678044oie.135.1666217684362; Wed, 19 Oct 2022 15:14:44 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c3:7d19:f1c1:9fb4:472a:ab68]) by smtp.gmail.com with ESMTPSA id m9-20020aca5809000000b00353fe4fb4casm7137927oib.48.2022.10.19.15.14.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 15:14:44 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 05/30] Linux: consolidate dup2 implementation Date: Wed, 19 Oct 2022 19:14:08 -0300 Message-Id: <20221019221433.1082017-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221019221433.1082017-1-adhemerval.zanella@linaro.org> References: <20221019221433.1082017-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Use dup2 syscall if defined, otherwise use dup3. Checked on x86_64-linux-gnu. Reviewed-by: Carlos O'Donell Tested-by: Carlos O'Donell --- sysdeps/unix/sysv/linux/{generic => }/dup2.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) rename sysdeps/unix/sysv/linux/{generic => }/dup2.c (83%) diff --git a/sysdeps/unix/sysv/linux/generic/dup2.c b/sysdeps/unix/sysv/linux/dup2.c similarity index 83% rename from sysdeps/unix/sysv/linux/generic/dup2.c rename to sysdeps/unix/sysv/linux/dup2.c index 0dc45e9b17..1182780e15 100644 --- a/sysdeps/unix/sysv/linux/generic/dup2.c +++ b/sysdeps/unix/sysv/linux/dup2.c @@ -1,4 +1,5 @@ -/* Copyright (C) 2011-2022 Free Software Foundation, Inc. +/* Duplicate a file descriptor. Linux version. + Copyright (C) 2011-2022 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -24,12 +25,16 @@ int __dup2 (int fd, int fd2) { +#ifdef __NR_dup2 + return INLINE_SYSCALL_CALL (dup2, fd, fd2); +#else /* For the degenerate case, check if the fd is valid (by trying to get the file status flags) and return it, or else return EBADF. */ if (fd == fd2) return __libc_fcntl (fd, F_GETFL, 0) < 0 ? -1 : fd; - return INLINE_SYSCALL (dup3, 3, fd, fd2, 0); + return INLINE_SYSCALL_CALL (dup3, fd, fd2, 0); +#endif } libc_hidden_def (__dup2) weak_alias (__dup2, dup2)