From patchwork Sun Dec 27 19:00:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= X-Patchwork-Id: 41562 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 C65C0386F478; Sun, 27 Dec 2020 19:02:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C65C0386F478 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1609095745; bh=XMNZYz/KBvG4ZOPWAykwU5+BFdpt/NT85TPNNDSXQiU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=DHARhXpvv8QzQk7Vnk34ngIFAXsPCpc+c2uSvxOawmLR9a3EfjiQGfXCSarjTHzB5 MGuwNSWtxzPKB78lJxb/mmDtflt0wS3YwwKJ3PbFsDh+s3uxy2J1rrxHz8GUJqfoqi 1KFBm1+bz7Z550y2u68F6e1SlwmuEgli9SDo/niU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by sourceware.org (Postfix) with UTF8SMTPS id 5D1C13846079 for ; Sun, 27 Dec 2020 19:02:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5D1C13846079 Received: by mail-ej1-x62d.google.com with SMTP id w1so11746959ejf.11 for ; Sun, 27 Dec 2020 11:02:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XMNZYz/KBvG4ZOPWAykwU5+BFdpt/NT85TPNNDSXQiU=; b=HElMhZV3FMkxjkaI3/opZ+zloNO2BLXqfqn6D2LSvTiRkYglB5Ke7kBow2q+Ke98cm Cxc6uh4N4bHNygmCW0tOBFtOwuqnSSik3yQcZOSTqdiaH9iUYgFhy4VUpUtkvEkGA/K4 qwyCEITc50SGPVkR/jGRyFsZqqdWwT6/YI5pB4R9UPDybFD4TNWyyLqry7Fb0lTNpktC Ld0VQ/R8rVq2FGR6YoV4hHw24qrVt0xMPjWMWnhqDnLd1z8C3pEprzJQ5QnIBFI4EfgU 9iqar4/pBQZIxznTzAFTb08Kbe+qegLFSfPP9lY9RRye5EolZzojNpP4qPbCU4TQG5vs n2kw== X-Gm-Message-State: AOAM532Ph8EJfQ61uv2NCRRF9epRrbTWJv5XUuXvjGl3T8etX4E2lT2a lsyMj/mVUnUjlqkID3XTkDmp+LmDruc= X-Google-Smtp-Source: ABdhPJzm43Ko5xCrpltgu2dEhovIf1I/kYrOjMSxjHkvM/3kDToVj3S4syx53Vm/TBJpJw6ExLQZUQ== X-Received: by 2002:a17:907:2111:: with SMTP id qn17mr37786513ejb.525.1609095741493; Sun, 27 Dec 2020 11:02:21 -0800 (PST) Received: from localhost.localdomain ([213.226.244.183]) by smtp.gmail.com with ESMTPSA id r24sm35566719edc.21.2020.12.27.11.02.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Dec 2020 11:02:20 -0800 (PST) X-Google-Original-From: =?unknown-8bit?q?Alexandra_H=C3=A1jkov=C3=A1_ahajkov?= =?unknown-8bit?q?a=40redhat=2Ecom?= To: libc-alpha@sourceware.org Subject: [PATCH] Add xchdir to libsupport. Date: Sun, 27 Dec 2020 20:00:25 +0100 Message-Id: <20201227190025.2112061-1-ahajkova@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201226174936.985576-1-ahajkova@redhat.com> References: <20201226174936.985576-1-ahajkova@redhat.com> MIME-Version: 1.0 X-Spam-Status: No, score=-14.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: , X-Patchwork-Original-From: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1_via_Libc-alpha?= From: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= Reply-To: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= Cc: =?utf-8?q?Alexandra_H=C3=A1jkov=C3=A1?= Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" From: Alexandra Hájková Reviewed-by: Adhemerval Zanella --- support/Makefile | 1 + support/xchdir.c | 28 ++++++++++++++++++++++++++++ support/xunistd.h | 1 + 3 files changed, 30 insertions(+) create mode 100644 support/xchdir.c diff --git a/support/Makefile b/support/Makefile index 3198eb5022..26e4ab1c4c 100644 --- a/support/Makefile +++ b/support/Makefile @@ -87,6 +87,7 @@ libsupport-routines = \ xasprintf \ xbind \ xcalloc \ + xchdir \ xchroot \ xclock_gettime \ xclose \ diff --git a/support/xchdir.c b/support/xchdir.c new file mode 100644 index 0000000000..17e3d0bdbb --- /dev/null +++ b/support/xchdir.c @@ -0,0 +1,28 @@ +/* chdir with error checking. + Copyright (C) 2020 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 + 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 +#include + +void +xchdir(const char *path) +{ + if (chdir(path) != 0) + FAIL_EXIT1 ("chdir (\"%s\"): %m", path); +} diff --git a/support/xunistd.h b/support/xunistd.h index b299db77ba..a84501e389 100644 --- a/support/xunistd.h +++ b/support/xunistd.h @@ -45,6 +45,7 @@ long xsysconf (int name); long long xlseek (int fd, long long offset, int whence); void xftruncate (int fd, long long length); void xsymlink (const char *target, const char *linkpath); +void xchdir(const char *path); /* Equivalent of "mkdir -p". */ void xmkdirp (const char *, mode_t);