From patchwork Fri Nov 8 17:45:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 2008693 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=EWA9abpL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XlRG55p6sz1xxq for ; Sat, 9 Nov 2024 04:46:53 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 699AA3858405 for ; Fri, 8 Nov 2024 17:46:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 699AA3858405 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1731088011; bh=fWV5j6gP5iGnyYL5Wd41/eEsT32R8nQ3oxgDhc6SWV4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=EWA9abpLTjkuMJUq801Blc3x1eykGEFzyYWQ182RybSVoGfjRttwpH8ysm+HGI5uy ouoCWrBBH9MoD4LpmukJ2t4w5xtzWV0SkBk39GVcROKhA+HOD2s7QNM98WoN06jKaO xdTKusW0J1xLIZcbKpsh6ibEU9nUia3p5lS0j+2U= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from seashell.cherry.relay.mailchannels.net (seashell.cherry.relay.mailchannels.net [23.83.223.162]) by sourceware.org (Postfix) with ESMTPS id 1B4853858405 for ; Fri, 8 Nov 2024 17:46:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1B4853858405 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=sourceware.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=sourceware.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1B4853858405 Authentication-Results: server2.sourceware.org; arc=pass smtp.remote-ip=23.83.223.162 ARC-Seal: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1731087982; cv=pass; b=jyLurwEt1383IyI3CiKYWPkMk6d7HcfoNekJFW0kvclLVkMtGGOKsaPUFyLkRyamoNLyYhd0eekr6ARHHFJxbZARvoStuoLUYaFAa4uSQN9fa16v5lU1Vrmq7pnoZhcHAiFjHI8zZ/E/PyQtGVgACQ5Xkx58zJ2GeN2AdqotVjo= ARC-Message-Signature: i=2; a=rsa-sha256; d=sourceware.org; s=key; t=1731087982; c=relaxed/simple; bh=jASCGDNtmZ6VaKT3Vx/sHqNkNf3m2QLQw8dcTHjSbvI=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=LPhIRiZHXxU4TbV4qubITXFS/c+/xMr7NQeJoHfLn1Gq2uQlfe6FL0clT0xD+N921TLw+AhzUxvo9BX8YrmCuYKYmKvpCUtlzY/uRPnna8sNAhAnUomiywN0ghFWLjNegXSSoYdJD7Y1QNzYRGF2yFyyTNsNvrW7L9280jfviUw= ARC-Authentication-Results: i=2; server2.sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 383F5C4BB9; Fri, 8 Nov 2024 17:46:18 +0000 (UTC) Received: from pdx1-sub0-mail-a258.dreamhost.com (100-110-86-37.trex-nlb.outbound.svc.cluster.local [100.110.86.37]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id E16E4C4C89; Fri, 8 Nov 2024 17:46:17 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1731087977; a=rsa-sha256; cv=none; b=jnsKZ9+C/p9C4uhvuKSgbvKNUshwwq853Eqs6/f50yWDclZ3Y2R/AtIvIbyPM458Pi6qlK 9+Ca6py0BxkdCdyWRqEKzMExQu99dLfHJ8O1QPPB8XBeOddhEWaTW0/PVieNkeLY+Zu7qa d8tLD7YXCW7FhUBnKkKvotluyVvcPmDAH5BtgWZ6oP6rsErNlVZcL674ZOgTPMZZIfDsKP qf2qNlI1+IXd6wWYrNfOwN4OPZyIbBAdjc4QftAd21N27CxKHN2UCBNwNFvsy3SplKevCY +qpaWYC0FP6nEw/d4KIZblwGBGaGGST/HFw2h7giQgp1e31QMNXQAKd8x/CKig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1731087977; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fWV5j6gP5iGnyYL5Wd41/eEsT32R8nQ3oxgDhc6SWV4=; b=SgS7oqDfakl6ytQtSsKN0Gs5NDElwViTkaIo8Qn6EWXrZ0tA+c8tuUHGDoEKH4cYU+mmBc zBThHRa7wjNtR/pUbHV7LaoS8+nqExE3RGuGNrmMrcQHwa7pkx3z4k5qIR0dzRng2T9Sf+ umW9smM0XBfcDVh8Lhw5tLSRts5JISwfjEBEIdJsRvofc3fNsLi+4XD7uEQV/vCQMJdJhN vjHkNtvI2UNaSHVZ4We24lqi8pHZtNNoN35bseshKQHA2EEzR5WrUOJ1TMLVCrvf4Z2WOw 2SYwqzB3+b0OGxwM9LDSpB17m8CrYWordyf9Su3hoRaMQRt06SHTyFzOkOpHPA== ARC-Authentication-Results: i=1; rspamd-7ffc46dcc8-kq5vw; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Tart-Squirrel: 21cca5975bb763df_1731087978132_259072726 X-MC-Loop-Signature: 1731087978132:2334644853 X-MC-Ingress-Time: 1731087978132 Received: from pdx1-sub0-mail-a258.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.110.86.37 (trex/7.0.2); Fri, 08 Nov 2024 17:46:18 +0000 Received: from fedora.. (unknown [184.146.156.41]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a258.dreamhost.com (Postfix) with ESMTPSA id 4XlRFP40X9z9C; Fri, 8 Nov 2024 09:46:17 -0800 (PST) From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Cc: adhemerval.zanella@linaro.org Subject: [PATCH v2 1/3] support: Add xdup Date: Fri, 8 Nov 2024 12:45:56 -0500 Message-ID: <20241108174559.470880-2-siddhesh@sourceware.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241016192108.811046-1-siddhesh@sourceware.org> References: <20241016192108.811046-1-siddhesh@sourceware.org> MIME-Version: 1.0 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~incoming=patchwork.ozlabs.org@sourceware.org Add xdup as the error-checking version of dup for test cases. Signed-off-by: Siddhesh Poyarekar --- support/Makefile | 1 + support/xdup.c | 30 ++++++++++++++++++++++++++++++ support/xunistd.h | 1 + 3 files changed, 32 insertions(+) create mode 100644 support/xdup.c diff --git a/support/Makefile b/support/Makefile index 84e2419775..099f5ebb9c 100644 --- a/support/Makefile +++ b/support/Makefile @@ -128,6 +128,7 @@ libsupport-routines = \ xcopy_file_range \ xdlfcn \ xdlmopen \ + xdup \ xdup2 \ xfchmod \ xfclose \ diff --git a/support/xdup.c b/support/xdup.c new file mode 100644 index 0000000000..1eab317354 --- /dev/null +++ b/support/xdup.c @@ -0,0 +1,30 @@ +/* dup with error checking. + Copyright The GNU Toolchain Authors. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include + +int +xdup (int from) +{ + int ret = dup (from); + if (ret < 0) + FAIL_EXIT1 ("dup (%d): %m", from); + + return ret; +} diff --git a/support/xunistd.h b/support/xunistd.h index 204951bce7..0c6d837ac0 100644 --- a/support/xunistd.h +++ b/support/xunistd.h @@ -35,6 +35,7 @@ pid_t xfork (void); pid_t xwaitpid (pid_t, int *status, int flags); void xpipe (int[2]); void xdup2 (int, int); +int xdup (int); int xopen (const char *path, int flags, mode_t); void support_check_stat_fd (const char *name, int fd, int result); void support_check_stat_path (const char *name, const char *path, int result);