From patchwork Fri Mar 2 18:59:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 130571 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp1600983lja; Fri, 2 Mar 2018 10:59:57 -0800 (PST) X-Google-Smtp-Source: AG47ELvEmoRwV0OUnnJKCFvAXvn9K9FUfQ01AHmP6rOGgfNnaol6Au9nLZvaG4LeqGneeq08CMFM X-Received: by 10.99.123.92 with SMTP id k28mr5319702pgn.167.1520017197549; Fri, 02 Mar 2018 10:59:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520017197; cv=none; d=google.com; s=arc-20160816; b=DMmzVeIx7gsfLUnrK/cK2znmyQOynPJPRtnsHKyGgRe1FjfOFXy2VEB8jMma37QLxp VTJ5ZFA+lTdKe8xAN/+7yWEPaD+USVKqVQkC8kSQJKMsx4uIeKAygMBHGsR7Wj/KeKEB a3I1LstpTnFYmfsag+NKJR8K+pcDYWT/XEYMiVI9QkJcaMDLlh0wV4qcsBLRvfdPKXK1 uYmY0QvuBzOffC+EYQby1SjfroZUB7gLI9RD2oMcqFYZvEoQsJ70FkTNyAi14hpWYN9i j9HdLHniTxQG7aIYuvDVlQCbOy+OHt7a2U2ydL0h310peYmbufWl4KFldvksDTuGu7He jyPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:to:from:delivered-to:sender:list-help :list-post:list-archive:list-subscribe:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=shGmVZV4do+XoPU67dunwiDQHK9G26/QITbRWBA0evE=; b=xpW03wo/h/3M1zZxn5hlyh80r4UQgRzBr6omzrMxvBIy+mVlM0ravAf27tPdGga3Tv 9nGBOTSnOjM+H3s8FX/84evIEFln/aLtjaM8bO0FwH0kQvj0o1aQtT7Ypt0v01s31LGW W3mlxvGDjgLTrGqVpTlo/VbeW4EX7/+JxZwD0hyn9Y5eiymyzjojYcCbvJ6iVNsKM/9F shvpHWwPR23QcDacWN30NyxZE/IRyiuprDn9cWZ+m96AADXpfS35IArofAjE47cyWEKw WNdWn/+98lGaskqcbnAlrBe0LZlR5GWjW4rAXjyiTnxg/0Tu2C8yJpL+lUhRy2j3K8Xx vxtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=egFoCh8x; spf=pass (google.com: domain of libc-alpha-return-90737-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90737-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id o4si4305818pgp.285.2018.03.02.10.59.57 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 10:59:57 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90737-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=egFoCh8x; spf=pass (google.com: domain of libc-alpha-return-90737-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90737-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=fQPSon0cfs9kKxo/5S+R7MO7FBLbSzKqnIOP9rtCW/sgmJJv+3S3U B+oO8fsgXgVyo1HI8t7ARJ1hVijsQJCnQTgRJwlsWwq2dfsmT9K9ksCPw5mf3h3v lx4BqD9ssZA3jUFjse2yu78meIVtb9qreIbv3TfRX1729mxZbS/kJ4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; s=default; bh=Rk1zuBucSKV2I1BXXP58uicESg4=; b=egFoCh8xPqfUo0JFueh+OkjBOyGf STZr8+9CW+sK7Ik4i+GjYVpWfGdy9ODiUaga+Yi2YC9CTrveq0XJUsBPDFAPjRm/ 5EGUGdvqITNa+cW+uyhOgIil5zPCESczvcsQvRNefzUuXFXKeAUv6Zmc08k1wiSm kr7L4+ErxWBert8= Received: (qmail 96959 invoked by alias); 2 Mar 2018 18:59:40 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 96858 invoked by uid 89); 2 Mar 2018 18:59:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt0-f196.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=shGmVZV4do+XoPU67dunwiDQHK9G26/QITbRWBA0evE=; b=eJGJbAeohwK2J1WUyrluHZsZqnxX3NxGc3v4jH8WZQx3LJBr6MwELlX6ZvH3OmvwGW mx3MGsk0/8/fv6hWeNvprB8qZGMNFmQ/QrXxi8BV6JbcP/nT3EOdehHaZhZUgUa4w3aM q+8de36pwp8L8d0Z4CWNOurbOmNbQtDPOoYgvv0SOUz/pYXXkuf1Li4Mm76crqY+b+C6 O+zyZL2IlH8MH1E8RGfc4vkwBb5XZH9wru7B8DRCTYTfPmqdm9IXIb/UTYxMHl+XQSQf YQCClipld9FZCMVj4bAaSP+IsTp7mWRfxOtLSHNk8Dpk+klQFvxfKDBBTPnpn+O12vOm Aj+Q== X-Gm-Message-State: AElRT7Fqe+wEGyOeKKKNMWMMpEyWL9/qmF64jNBx9Pisk9vQrTWTn1nS 71WWv916yUCMAx2jHdofHIUuhpdOudI= X-Received: by 10.200.83.12 with SMTP id t12mr10444992qtn.333.1520017172079; Fri, 02 Mar 2018 10:59:32 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 1/7] Assume O_DIRECTORY for opendir Date: Fri, 2 Mar 2018 15:59:19 -0300 Message-Id: <1520017165-15830-1-git-send-email-adhemerval.zanella@linaro.org> This patch assumes O_DIRECTORY works as defined by POSIX on opendir implementation (aligning with other glibc code, for instance pwd). This allows remove both the fallback code to handle system with missing or broken O_DIRECTORY along with the Linux specific opendir.c which just advertise the working flag. Checked on aarch64-linux-gnu, x86_64-linux-gnu, i686-linux-gnu, sparcv9-linux-gnu, sparc64-linux-gnu, powerpc-linux-gnu, and powerpc64le-linux-gnu. * sysdeps/posix/opendir.c (o_directory_works, tryopen_o_directory): Remove definitions. (opendir_oflags): Use O_DIRECTORY regardless. (__opendir, __opendirat): Remove need_isdir_precheck usage. * sysdeps/unix/sysv/linux/opendir.c: Remove file. --- ChangeLog | 8 +++ sysdeps/posix/opendir.c | 108 ++------------------------------------ sysdeps/unix/sysv/linux/opendir.c | 20 ------- 3 files changed, 13 insertions(+), 123 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/opendir.c -- 2.7.4 diff --git a/sysdeps/posix/opendir.c b/sysdeps/posix/opendir.c index d925804..dea23b2 100644 --- a/sysdeps/posix/opendir.c +++ b/sysdeps/posix/opendir.c @@ -15,24 +15,13 @@ License along with the GNU C Library; if not, see . */ -#include -#include -#include -#include -#include -#include #include #include -#include -#include -#include -#include -#include -#include - -#include +#include +#include /* For BUFSIZ. */ +#include /* For MIN and MAX. */ + #include -#include /* The st_blksize value of the directory is used as a hint for the size of the buffer which receives struct dirent values from the @@ -40,49 +29,8 @@ file system provides a bogus value. */ #define MAX_DIR_BUFFER_SIZE 1048576U -/* opendir() must not accidentally open something other than a directory. - Some OS's have kernel support for that, some don't. In the worst - case we have to stat() before the open() AND fstat() after. - - We have to test at runtime for kernel support since libc may have - been compiled with different headers to the kernel it's running on. - This test can't be done reliably in the general case. We'll use - /dev/null, which if it's not a device lots of stuff will break, as - a guinea pig. It may be missing in chroot environments, so we - make sure to fail safe. */ -#ifdef O_DIRECTORY -# ifdef O_DIRECTORY_WORKS -# define o_directory_works 1 -# define tryopen_o_directory() while (1) /* This must not be called. */ -# else -static int o_directory_works; - -static void -tryopen_o_directory (void) -{ - int serrno = errno; - int x = __open_nocancel ("/dev/null", O_RDONLY|O_NDELAY|O_DIRECTORY); - - if (x >= 0) - { - __close_nocancel_nostatus (x); - o_directory_works = -1; - } - else if (errno != ENOTDIR) - o_directory_works = -1; - else - o_directory_works = 1; - - __set_errno (serrno); -} -# endif -# define EXTRA_FLAGS O_DIRECTORY -#else -# define EXTRA_FLAGS 0 -#endif - enum { - opendir_oflags = O_RDONLY|O_NDELAY|EXTRA_FLAGS|O_LARGEFILE|O_CLOEXEC + opendir_oflags = O_RDONLY|O_NDELAY|O_DIRECTORY|O_LARGEFILE|O_CLOEXEC }; static bool @@ -98,21 +46,6 @@ invalid_name (const char *name) return false; } - -static bool -need_isdir_precheck (void) -{ -#ifdef O_DIRECTORY - /* Test whether O_DIRECTORY works. */ - if (o_directory_works == 0) - tryopen_o_directory (); - - /* We can skip the expensive `stat' call if O_DIRECTORY works. */ - return o_directory_works < 0; -#endif - return true; -} - static DIR * opendir_tail (int fd) { @@ -144,22 +77,6 @@ __opendirat (int dfd, const char *name) if (__glibc_unlikely (invalid_name (name))) return NULL; - if (need_isdir_precheck ()) - { - /* We first have to check whether the name is for a directory. We - cannot do this after the open() call since the open/close operation - performed on, say, a tape device might have undesirable effects. */ - struct stat64 statbuf; - if (__glibc_unlikely (__fxstatat64 (_STAT_VER, dfd, name, - &statbuf, 0) < 0)) - return NULL; - if (__glibc_unlikely (! S_ISDIR (statbuf.st_mode))) - { - __set_errno (ENOTDIR); - return NULL; - } - } - return opendir_tail (__openat_nocancel (dfd, name, opendir_oflags)); } #endif @@ -172,21 +89,6 @@ __opendir (const char *name) if (__glibc_unlikely (invalid_name (name))) return NULL; - if (need_isdir_precheck ()) - { - /* We first have to check whether the name is for a directory. We - cannot do this after the open() call since the open/close operation - performed on, say, a tape device might have undesirable effects. */ - struct stat64 statbuf; - if (__glibc_unlikely (__xstat64 (_STAT_VER, name, &statbuf) < 0)) - return NULL; - if (__glibc_unlikely (! S_ISDIR (statbuf.st_mode))) - { - __set_errno (ENOTDIR); - return NULL; - } - } - return opendir_tail (__open_nocancel (name, opendir_oflags)); } weak_alias (__opendir, opendir) diff --git a/sysdeps/unix/sysv/linux/opendir.c b/sysdeps/unix/sysv/linux/opendir.c deleted file mode 100644 index 2677253..0000000 --- a/sysdeps/unix/sysv/linux/opendir.c +++ /dev/null @@ -1,20 +0,0 @@ -/* Copyright (C) 2000-2018 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 - . */ - -#define O_DIRECTORY_WORKS 1 - -#include From patchwork Fri Mar 2 18:59:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 130570 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp1600838lja; Fri, 2 Mar 2018 10:59:48 -0800 (PST) X-Google-Smtp-Source: AG47ELvEnp1hR7W9OCcfjIQPAw4rivG2Xxa5FwAKiEk3wEoCgqcxi9qmHlf+jshV+v0WiiGpDvyN X-Received: by 10.98.220.207 with SMTP id c76mr6534112pfl.159.1520017188122; Fri, 02 Mar 2018 10:59:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520017188; cv=none; d=google.com; s=arc-20160816; b=HpVQc6AQwZymoQVCk3MsZ8mlHyIOmr56bEZxVxSTj+gfaaPwl0h/n3/KRZmY6Hzvt9 Q52XiuHNGRNs+qjcXNxoeA/Wzl/Fx0kglKsvhtY97CzcY55K2q5XECBt7340Mk+scwmB L1CJHrkH5FAw4HhRqwuNBqX0/kBHLoCwfnre5yKVz27EROBaiCKBsMWT9w9LjkW3Qgpx 9uTFkG4raf/9MBgMeYH8PNdEg0XoiI1htA6wbySPUyPzQEUesEbXzigz335qhcPeOHoJ yBTb4ygiUy28rQ+Wy+teHl50Cko7IQqDq2CLQTI5PqL0hs+kvn+sJxtaWqt3VBX/T4n+ Gi/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from:delivered-to :sender:list-help:list-post:list-archive:list-subscribe :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=lYzYTl5pPXgcQ+gTlVNPBLn6V2RUTgrH54LXtniaASo=; b=T1SCCS5NOy3rRw7Aukqu2pzInprAeH/J4WAXOQ6X3fpvPzaDU7+UheRU9Bg/lOqlfI TFwf7GL5PbFfZfNVjxBDWkPvuMHqdcR/h6u73551G6Vg6AOAdYwYsS1Q/4jiI5syEJk5 O4T8NmDH+Hk8qyEoGin/pfeOb+BhP67yDZVEtD5pKbzxPu+aGO1Iu7M98cKcyA0zscJJ 8fQ6GtQa8+Pjnq32g/PQQ+HptWhLHKvc7DJYH+Tzumyet2Lw8YSByMOhC27q0k2EOsDe O5WkidbbhRQ85JmD8RnTwNvUhooklGIhsZngyu0PsSXhYOSraC5axmn/ICW5QowWrTU2 HPIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=LgIBMO9I; spf=pass (google.com: domain of libc-alpha-return-90736-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90736-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id n4si4341708pgt.712.2018.03.02.10.59.47 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 10:59:48 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90736-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=LgIBMO9I; spf=pass (google.com: domain of libc-alpha-return-90736-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90736-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=vlqdo2Q97B+XLlIoLbdTjP68tLUEc7J 4zNDEhjiKmaK7pXKK71nuDaYc8/7UC+TBMTyuXXe0z1XjV8aZEFGd1i9FSkvXOJt dtLYQzZIBzfXx7KyYJNIJS65D7b3su6RMQgJAv8mWHGsI7jywdwz5YC1qrF0lD8k qnokm0QEwMBM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=ILxqknr4FOf+CJpZu2mQFqvU4yc=; b=LgIBM O9IOGe8Y1Nlhz+CGFzjX2r8XpWM4wjBS/FRpgWxMgZmTU8SIlWqRmai8lVi8EqKs cfQ77rbs3w0k82OysXAiH1Bi74vpoN+vd34J8IFiRsYVgy9r1CbL3SN5BTclKpH1 f2yoydUc9liQMYvbs6xxuJ/dx4wEiQVar0I89s= Received: (qmail 96650 invoked by alias); 2 Mar 2018 18:59:38 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 96639 invoked by uid 89); 2 Mar 2018 18:59:37 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt0-f196.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=lYzYTl5pPXgcQ+gTlVNPBLn6V2RUTgrH54LXtniaASo=; b=REqR46LalaSnDzKhVa/SCgxhSrWfpLdRT8z9xCk2xdJIPjFSP3AXXiflxeU6Dv2fef iDfVtCxdqpagk+ZgYfBK5KheRDup3O20Ruy457V9GNk/QXQxwXy8JvuOtcmMSC3QfaoH Xdh//+HmMazKvCtqzpwDtWBWLBG0HmcXA0RUzl9O98RK6YGVKbWtO1NfG8tRLzlCzDpc LKLO1g753uKUYHC36D7+xlKt3EnJWaWdN2khyi2b175Hyao1Fx3imO565bX2DYl0Ng14 YuG9Y60rRo+3Bwh+A9PpJ/YHbn1wR6tEYryBuwpt0ElvjqMKZNAwTTMk+taWFjS6BAAT HKdg== X-Gm-Message-State: AElRT7Gj4kpjaEx+L35g1Cd9SIXyQyxAI4LTH+oKxmTjBdPAyJehGQty R7BEv796CL+Loe/RoLNi2nNJ7WCEhaU= X-Received: by 10.237.57.106 with SMTP id l97mr10036428qte.198.1520017173281; Fri, 02 Mar 2018 10:59:33 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 2/7] Define _DIRENT_MATCHES_DIRENT64 regardless Date: Fri, 2 Mar 2018 15:59:20 -0300 Message-Id: <1520017165-15830-2-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1520017165-15830-1-git-send-email-adhemerval.zanella@linaro.org> References: <1520017165-15830-1-git-send-email-adhemerval.zanella@linaro.org> This patch defines _DIRENT_MATCHES_DIRENT64 to either 0 or 1 and adjust its usage from checking its definition to its value. Checked on a build for major Linux abis. * bits/dirent.h (__INO_T_MATCHES_INO64_T): Define regardless whether __INO_T_MATCHES_INO64_T is defined. * sysdeps/unix/sysv/linux/bits/dirent.h: Likewise. * dirent/alphasort.c: Check _DIRENT_MATCHES_DIRENT64 value instead of definition. * dirent/alphasort64.c: Likewise. * dirent/scandir.c: Likewise. * dirent/scandir64-tail.c: Likewise. * dirent/scandir64.c: Likewise. * dirent/scandirat.c: Likewise. * dirent/scandirat64.c: Likewise. * dirent/versionsort.c: Likewise. * dirent/versionsort64.c: Likewise. * include/dirent.h: Likewise. --- ChangeLog | 15 +++++++++++++++ bits/dirent.h | 2 ++ dirent/alphasort.c | 2 +- dirent/alphasort64.c | 2 +- dirent/scandir.c | 2 +- dirent/scandir64-tail.c | 2 +- dirent/scandir64.c | 2 +- dirent/scandirat.c | 2 +- dirent/scandirat64.c | 2 +- dirent/versionsort.c | 2 +- dirent/versionsort64.c | 2 +- include/dirent.h | 2 +- sysdeps/unix/sysv/linux/bits/dirent.h | 2 ++ 13 files changed, 29 insertions(+), 10 deletions(-) -- 2.7.4 diff --git a/bits/dirent.h b/bits/dirent.h index 8c38b8c..d775540 100644 --- a/bits/dirent.h +++ b/bits/dirent.h @@ -56,4 +56,6 @@ struct dirent64 #ifdef __INO_T_MATCHES_INO64_T /* Inform libc code that these two types are effectively identical. */ # define _DIRENT_MATCHES_DIRENT64 1 +#else +# define _DIRENT_MATCHES_DIRENT64 0 #endif diff --git a/dirent/alphasort.c b/dirent/alphasort.c index 8d3b939..a6cd151 100644 --- a/dirent/alphasort.c +++ b/dirent/alphasort.c @@ -32,6 +32,6 @@ alphasort (const struct dirent **a, const struct dirent **b) return strcoll ((*a)->d_name, (*b)->d_name); } -#ifdef _DIRENT_MATCHES_DIRENT64 +#if _DIRENT_MATCHES_DIRENT64 weak_alias (alphasort, alphasort64) #endif diff --git a/dirent/alphasort64.c b/dirent/alphasort64.c index deb1921..3a47a97 100644 --- a/dirent/alphasort64.c +++ b/dirent/alphasort64.c @@ -19,7 +19,7 @@ #include /* alphasort.c defines alphasort64 as an alias if _DIRENT_MATCHES_DIRENT64. */ -#ifndef _DIRENT_MATCHES_DIRENT64 +#if !_DIRENT_MATCHES_DIRENT64 int alphasort64 (const struct dirent64 **a, const struct dirent64 **b) diff --git a/dirent/scandir.c b/dirent/scandir.c index 977d645..b24e157 100644 --- a/dirent/scandir.c +++ b/dirent/scandir.c @@ -40,6 +40,6 @@ SCANDIR (const char *dir, return SCANDIR_TAIL (__opendir (dir), namelist, select, cmp); } -#ifdef _DIRENT_MATCHES_DIRENT64 +#if _DIRENT_MATCHES_DIRENT64 weak_alias (scandir, scandir64) #endif diff --git a/dirent/scandir64-tail.c b/dirent/scandir64-tail.c index 684088c..8d5cc07 100644 --- a/dirent/scandir64-tail.c +++ b/dirent/scandir64-tail.c @@ -18,7 +18,7 @@ #include -#ifndef _DIRENT_MATCHES_DIRENT64 +#if !_DIRENT_MATCHES_DIRENT64 # define SCANDIR_TAIL __scandir64_tail # define READDIR __readdir64 # define DIRENT_TYPE struct dirent64 diff --git a/dirent/scandir64.c b/dirent/scandir64.c index 7e666b0..0c63fa9 100644 --- a/dirent/scandir64.c +++ b/dirent/scandir64.c @@ -18,7 +18,7 @@ #include /* scandir.c defines scandir64 as an alias if _DIRENT_MATCHES_DIRENT64. */ -#ifndef _DIRENT_MATCHES_DIRENT64 +#if !_DIRENT_MATCHES_DIRENT64 # define SCANDIR scandir64 # define SCANDIR_TAIL __scandir64_tail diff --git a/dirent/scandirat.c b/dirent/scandirat.c index 3f63f4d..96a1b0e 100644 --- a/dirent/scandirat.c +++ b/dirent/scandirat.c @@ -44,6 +44,6 @@ libc_hidden_def (SCANDIRAT) weak_alias (__scandirat, scandirat) #endif -#ifdef _DIRENT_MATCHES_DIRENT64 +#if _DIRENT_MATCHES_DIRENT64 weak_alias (scandirat, scandirat64) #endif diff --git a/dirent/scandirat64.c b/dirent/scandirat64.c index 6d682ff..520ae7c 100644 --- a/dirent/scandirat64.c +++ b/dirent/scandirat64.c @@ -18,7 +18,7 @@ #include /* scandirat.c defines scandirat64 as an alias if _DIRENT_MATCHES_DIRENT64. */ -#ifndef _DIRENT_MATCHES_DIRENT64 +#if !_DIRENT_MATCHES_DIRENT64 # define SCANDIRAT scandirat64 # define SCANDIR_TAIL __scandir64_tail diff --git a/dirent/versionsort.c b/dirent/versionsort.c index 0130138..5ec15e8 100644 --- a/dirent/versionsort.c +++ b/dirent/versionsort.c @@ -32,6 +32,6 @@ versionsort (const struct dirent **a, const struct dirent **b) return __strverscmp ((*a)->d_name, (*b)->d_name); } -#ifdef _DIRENT_MATCHES_DIRENT64 +#if _DIRENT_MATCHES_DIRENT64 weak_alias (versionsort, versionsort64) #endif diff --git a/dirent/versionsort64.c b/dirent/versionsort64.c index bfb0cbb..7689c26 100644 --- a/dirent/versionsort64.c +++ b/dirent/versionsort64.c @@ -19,7 +19,7 @@ #include /* versionsort.c defines a versionsort64 alias if _DIRENT_MATCHES_DIRENT64. */ -#ifndef _DIRENT_MATCHES_DIRENT64 +#if !_DIRENT_MATCHES_DIRENT64 int versionsort64 (const struct dirent64 **a, const struct dirent64 **b) diff --git a/include/dirent.h b/include/dirent.h index caaeb0b..cc8f189 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -57,7 +57,7 @@ extern int __scandir_tail (DIR *dp, int (*cmp) (const struct dirent **, const struct dirent **)) attribute_hidden; -# ifdef _DIRENT_MATCHES_DIRENT64 +# if _DIRENT_MATCHES_DIRENT64 # define __scandir64_tail (dp, namelist, select, cmp) \ __scandir_tail (dp, (struct dirent ***) (namelist), \ (int (*) (const struct dirent *)) (select), \ diff --git a/sysdeps/unix/sysv/linux/bits/dirent.h b/sysdeps/unix/sysv/linux/bits/dirent.h index 2ed7919..f312720 100644 --- a/sysdeps/unix/sysv/linux/bits/dirent.h +++ b/sysdeps/unix/sysv/linux/bits/dirent.h @@ -54,4 +54,6 @@ struct dirent64 #if defined __OFF_T_MATCHES_OFF64_T && defined __INO_T_MATCHES_INO64_T /* Inform libc code that these two types are effectively identical. */ # define _DIRENT_MATCHES_DIRENT64 1 +#else +# define _DIRENT_MATCHES_DIRENT64 0 #endif From patchwork Fri Mar 2 18:59:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 130572 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp1601097lja; Fri, 2 Mar 2018 11:00:06 -0800 (PST) X-Google-Smtp-Source: AG47ELtMOpbJzq8FeIVBz9hUrGiHU02R0eOW+xqUOBwxtV562qM4L0fPfOpcWqynGZ9trEZ3EClY X-Received: by 10.99.176.15 with SMTP id h15mr5269454pgf.448.1520017206475; Fri, 02 Mar 2018 11:00:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520017206; cv=none; d=google.com; s=arc-20160816; b=pdXjeqspolpEvkaKKTwUdo278Q5wv4FglfsSlENl1uv3JqBb3y60wgmrNxM87plObV SoCMnQswYnRKFg5wlTEZFV9InE4dxbLlagiHWmaS4I1ORkPyV9zWACYb+gbMn/9uJ0na 93Cfqb2T12atdwEA49zQjdSTXMNOekEt7ZYFhODN7KmMDLHVhUT/Aq4A56XFS0FglVI2 9EGuiuBH6rE8/j57TzOFrJuvPcNcLlEh9F5py0pevJpobK6+sxIGYRwZz3hJkuO59Gha /usIA6tOZMuWDBVkHugifWwOos0gV1fCi2Ry+1vVDs7wnDfo9+2z6EPxiLWeunCnCe33 q56A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from:delivered-to :sender:list-help:list-post:list-archive:list-subscribe :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=QlqhES6zlAD/tWiBBm5yvRtAQo1H1CCf7mGDalppfjY=; b=LQQ+C7cwLZrBKi2RJ0+pRrqMlIe11soVEM13HoY2IRBgzYXTuzWGFHHor5hrRQD26P +r5SQzvG5oidAWCQpIB3zVoOUYUK5oy8yT8iHXm8jiodtea6ooTu5Vu3A86kG89R8uOI Z/RJp1YY3tKnIcTR2t9ggUy8ZlcrvjF5z/ElelyMkhSn+G4ASosXQIIAZ1QqkYiC99bh IMJJUysc+CBY2pk8W90RiRl8zfG2K5UrUrHiivv7lik4c07w9oy+DGINrkY84P8iSMC0 tUYlyX/v3MHR7ALClDlsFP4ySvyU1Vzm+dnjPBsM3hAggDKfIy7jN82RvYH4fKy/0VAD NieA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=Wu3tBXSw; spf=pass (google.com: domain of libc-alpha-return-90738-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90738-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id k3si5332492pfj.24.2018.03.02.11.00.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 11:00:06 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90738-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=Wu3tBXSw; spf=pass (google.com: domain of libc-alpha-return-90738-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90738-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=iDgX82f2Nqwi225QHyL5ZSNWGqflMEY tdHdQvUSfHgLLnR0NnaDwXe3DQm1ZqvMQYpmB3pHuJLYr38AulGxRAhBNTC0CiN2 iH+yjOysJBoccsdVtHNQRCcxlJ4usirFUbs7lG8RKOPdy/bCn8bG2LCziATrLHt0 XDcABQrfqJBk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=v4s4Jrc6tVW8oiz3vVsNdUhqixw=; b=Wu3tB XSwFjQ5TijbUVadxEcegTuRRed36Wtg8Zv+zWOg8OrO7KO5p9MfBDwsiQfPXVtyK GEdxfuvr33sQPztmpNk7XeLZ8Yp/MDY2Lj2kYy1+7T4m35qqEdbeMMg4i+smUsNc sJONoi0Ha0hH7gNMDb0Tr6pIUJQLuvt8VFef4U= Received: (qmail 97264 invoked by alias); 2 Mar 2018 18:59:42 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 97127 invoked by uid 89); 2 Mar 2018 18:59:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Consolidate X-HELO: mail-qk0-f193.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=QlqhES6zlAD/tWiBBm5yvRtAQo1H1CCf7mGDalppfjY=; b=OvLaXra0Jnp6TGRdFIcI1lG3ypByToiWRZK2RXzfLFdhi2tBBku8QMB5DpRGIIS/zi vzQkeHXapmz2uEl1YFe0auG9/8SSi26FbZAOdjc5xdmqzlH49ApypV65UhieT+K/E9qy L3XBLM0V8AdrqoGF+zGLUNbuyAuZkSD2luQaB8LID6bdohunHSXClFG7xP+2YAy/b2vD DkmKLQFmqBY2mot25xSC6u+Kv6Xa/JFEtlcd2ROrwZAZHHfSKZx6tNPpMGFreCYuZhcb sWhltV2W4K5yEth6SvmkSokOJR++CJ7k+k9o8UOCsXZTJoKTFI0z80TTHKWnhmlCeKIv V76g== X-Gm-Message-State: APf1xPCka1mjVJmUwRmTM/awThDuhRqDFKozfa82sbkbtr9IsAGtpl96 W2u/A9LuwifQe+4kh9sxhA9fC5ZCV6o= X-Received: by 10.55.123.5 with SMTP id w5mr9668190qkc.261.1520017174651; Fri, 02 Mar 2018 10:59:34 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 3/7] Consolidate Linux readdir{64}{_r} implementation Date: Fri, 2 Mar 2018 15:59:21 -0300 Message-Id: <1520017165-15830-3-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1520017165-15830-1-git-send-email-adhemerval.zanella@linaro.org> References: <1520017165-15830-1-git-send-email-adhemerval.zanella@linaro.org> This patch consolidates Linux readdir{64}{_r} implementation on just the default sysdeps/unix/sysv/linux/readdir{64}{_r}.c ones. The default implementation handle the Linux requirements: * readdir{_r} is only built for _DIRENT_MATCHES_DIRENT64 being 0. * readdir64{_r} is always built and aliased to readdir{_r} for ABI that define _DIRENT_MATCHES_DIRENT64. * A compat symbol is added for readdir64{_r} for ABI that used to export the old non-LFS version. Checked on aarch64-linux-gnu, x86_64-linux-gnu, i686-linux-gnu, sparcv9-linux-gnu, sparc64-linux-gnu, powerpc-linux-gnu, and powerpc64le-linux-gnu. * sysdeps/posix/readdir.c (__READDIR, __GETDENTS, DIRENTY_TYPE, __READDIR_ALIAS): Undefine after usage. * sysdeps/posix/readdir_r.c (__READDIR_R, __GETDENTS, DIRENT_TYPE, __READDIR_R_ALIAS): Likewise. * sysdeps/unix/sysv/linux/arm/readdir64.c: Remove file. * sysdeps/unix/sysv/linux/arm/readdir64_r.c: Likewise. * sysdeps/unix/sysv/linux/m68k/readdir64.c: Likewise. * sysdeps/unix/sysv/linux/m68k/readdir64_r.c: Likewise. * sysdeps/unix/sysv/linux/powerpc/readdir64.c: Likewise. * sysdeps/unix/sysv/linux/powerpc/readdir64_r.c: Likewise. * sysdeps/unix/sysv/linux/i386/readdir64.c: Likewise. * sysdeps/unix/sysv/linux/i386/readdir64_r.c: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/readdir64.c: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/readdir64_r.c: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/readdir64.c: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/readdir64_r.c: Likewise. * sysdeps/unix/sysv/linux/wordsize-64/readdir.c: Likewise. * sysdeps/unix/sysv/linux/wordsize-64/readdir64.c: Likewise. * sysdeps/unix/sysv/linux/wordsize-64/readdir64_r.c: Likewise. * sysdeps/unix/sysv/linux/wordsize-64/readdir_r.c: Likewise. * sysdeps/unix/sysv/linux/readdir.c: New file. * sysdeps/unix/sysv/linux/readdir_r.c: Likewise. * sysdeps/unix/sysv/linux/readdir64.c: Add compat symbol if required. * sysdeps/unix/sysv/linux/readdir64_r.c: Likewise. --- ChangeLog | 25 +++++++++++ sysdeps/posix/readdir.c | 5 +++ sysdeps/posix/readdir_r.c | 5 +++ sysdeps/unix/sysv/linux/arm/readdir64.c | 1 - sysdeps/unix/sysv/linux/arm/readdir64_r.c | 1 - sysdeps/unix/sysv/linux/m68k/readdir64.c | 1 - sysdeps/unix/sysv/linux/m68k/readdir64_r.c | 1 - sysdeps/unix/sysv/linux/powerpc/readdir64.c | 1 - sysdeps/unix/sysv/linux/powerpc/readdir64_r.c | 1 - .../sysv/linux/{i386/readdir64_r.c => readdir.c} | 30 +++---------- sysdeps/unix/sysv/linux/readdir64.c | 51 +++++++++++++++++++++- sysdeps/unix/sysv/linux/readdir64_r.c | 48 +++++++++++++++++++- .../sysv/linux/{i386/readdir64.c => readdir_r.c} | 33 +++----------- sysdeps/unix/sysv/linux/s390/s390-32/readdir64.c | 1 - sysdeps/unix/sysv/linux/s390/s390-32/readdir64_r.c | 1 - sysdeps/unix/sysv/linux/sparc/sparc32/readdir64.c | 1 - .../unix/sysv/linux/sparc/sparc32/readdir64_r.c | 1 - sysdeps/unix/sysv/linux/wordsize-64/readdir.c | 8 ---- sysdeps/unix/sysv/linux/wordsize-64/readdir64.c | 1 - sysdeps/unix/sysv/linux/wordsize-64/readdir64_r.c | 1 - sysdeps/unix/sysv/linux/wordsize-64/readdir_r.c | 4 -- 21 files changed, 141 insertions(+), 80 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/arm/readdir64.c delete mode 100644 sysdeps/unix/sysv/linux/arm/readdir64_r.c delete mode 100644 sysdeps/unix/sysv/linux/m68k/readdir64.c delete mode 100644 sysdeps/unix/sysv/linux/m68k/readdir64_r.c delete mode 100644 sysdeps/unix/sysv/linux/powerpc/readdir64.c delete mode 100644 sysdeps/unix/sysv/linux/powerpc/readdir64_r.c rename sysdeps/unix/sysv/linux/{i386/readdir64_r.c => readdir.c} (52%) rename sysdeps/unix/sysv/linux/{i386/readdir64.c => readdir_r.c} (51%) delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/readdir64.c delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/readdir64_r.c delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/readdir64.c delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/readdir64_r.c delete mode 100644 sysdeps/unix/sysv/linux/wordsize-64/readdir.c delete mode 100644 sysdeps/unix/sysv/linux/wordsize-64/readdir64.c delete mode 100644 sysdeps/unix/sysv/linux/wordsize-64/readdir64_r.c delete mode 100644 sysdeps/unix/sysv/linux/wordsize-64/readdir_r.c -- 2.7.4 diff --git a/sysdeps/posix/readdir.c b/sysdeps/posix/readdir.c index fcd3853..a6ecc0f 100644 --- a/sysdeps/posix/readdir.c +++ b/sysdeps/posix/readdir.c @@ -120,3 +120,8 @@ __READDIR (DIR *dirp) #ifdef __READDIR_ALIAS weak_alias (__readdir, readdir) #endif + +#undef __READDIR +#undef __GETDENTS +#undef DIRENT_TYPE +#undef __READDIR_ALIAS diff --git a/sysdeps/posix/readdir_r.c b/sysdeps/posix/readdir_r.c index 79030ab..2d691e7 100644 --- a/sysdeps/posix/readdir_r.c +++ b/sysdeps/posix/readdir_r.c @@ -152,3 +152,8 @@ __READDIR_R (DIR *dirp, DIRENT_TYPE *entry, DIRENT_TYPE **result) #ifdef __READDIR_R_ALIAS weak_alias (__readdir_r, readdir_r) #endif + +#undef __READDIR_R +#undef __GETDENTS +#undef DIRENT_TYPE +#undef __READDIR_R_ALIAS diff --git a/sysdeps/unix/sysv/linux/arm/readdir64.c b/sysdeps/unix/sysv/linux/arm/readdir64.c deleted file mode 100644 index 2ea26dd..0000000 --- a/sysdeps/unix/sysv/linux/arm/readdir64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/arm/readdir64_r.c b/sysdeps/unix/sysv/linux/arm/readdir64_r.c deleted file mode 100644 index 9f54f89..0000000 --- a/sysdeps/unix/sysv/linux/arm/readdir64_r.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/m68k/readdir64.c b/sysdeps/unix/sysv/linux/m68k/readdir64.c deleted file mode 100644 index 2ea26dd..0000000 --- a/sysdeps/unix/sysv/linux/m68k/readdir64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/m68k/readdir64_r.c b/sysdeps/unix/sysv/linux/m68k/readdir64_r.c deleted file mode 100644 index 9f54f89..0000000 --- a/sysdeps/unix/sysv/linux/m68k/readdir64_r.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/powerpc/readdir64.c b/sysdeps/unix/sysv/linux/powerpc/readdir64.c deleted file mode 100644 index 2ea26dd..0000000 --- a/sysdeps/unix/sysv/linux/powerpc/readdir64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/powerpc/readdir64_r.c b/sysdeps/unix/sysv/linux/powerpc/readdir64_r.c deleted file mode 100644 index 9f54f89..0000000 --- a/sysdeps/unix/sysv/linux/powerpc/readdir64_r.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/i386/readdir64_r.c b/sysdeps/unix/sysv/linux/readdir.c similarity index 52% rename from sysdeps/unix/sysv/linux/i386/readdir64_r.c rename to sysdeps/unix/sysv/linux/readdir.c index 31862a0..b99bc96 100644 --- a/sysdeps/unix/sysv/linux/i386/readdir64_r.c +++ b/sysdeps/unix/sysv/linux/readdir.c @@ -1,4 +1,5 @@ -/* Copyright (C) 2000-2018 Free Software Foundation, Inc. +/* Read a directory. Linux no-LFS version. + Copyright (C) 2018 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 @@ -15,29 +16,8 @@ License along with the GNU C Library; if not, see . */ -#define __READDIR_R __readdir64_r -#define __GETDENTS __getdents64 -#define DIRENT_TYPE struct dirent64 +#include -#include - -#undef __READDIR_R -#undef __GETDENTS -#undef DIRENT_TYPE - -#include - -versioned_symbol (libc, __readdir64_r, readdir64_r, GLIBC_2_2); - -#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) - -#include - -#define __READDIR_R attribute_compat_text_section __old_readdir64_r -#define __GETDENTS __old_getdents64 -#define DIRENT_TYPE struct __old_dirent64 - -#include - -compat_symbol (libc, __old_readdir64_r, readdir64_r, GLIBC_2_1); +#if !_DIRENT_MATCHES_DIRENT64 +# include #endif diff --git a/sysdeps/unix/sysv/linux/readdir64.c b/sysdeps/unix/sysv/linux/readdir64.c index 6d154fe..054e4ff 100644 --- a/sysdeps/unix/sysv/linux/readdir64.c +++ b/sysdeps/unix/sysv/linux/readdir64.c @@ -1,8 +1,55 @@ -#define __READDIR __readdir64 -#define __GETDENTS __getdents64 +/* Read a directory. Linux LFS version. + Copyright (C) 2018 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 + . */ + +/* When _DIRENT_MATCHES_DIRENT64 is defined we can alias 'readdir64' to + 'readdir'. However the function signatures are not equal due + different return types, so we need to suppress {__}readdir so weak + and strong alias do not throw conflicting types errors. */ +#define readdir __no_readdir_decl +#define __readdir __no___readdir_decl +#include + +#define __READDIR __readdir64 +#define __GETDENTS __getdents64 #define DIRENT_TYPE struct dirent64 #include +#undef __readdir +#undef readdir + libc_hidden_def (__readdir64) +#if _DIRENT_MATCHES_DIRENT64 +strong_alias (__readdir64, __readdir) weak_alias (__readdir64, readdir64) +weak_alias (__readdir64, readdir) +#else +/* The compat code expects the 'struct direct' with d_ino being a __ino_t + instead of __ino64_t. */ +# include +versioned_symbol (libc, __readdir64, readdir64, GLIBC_2_2); +# if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) +# include +# define __READDIR attribute_compat_text_section __old_readdir64 +# define __GETDENTS __old_getdents64 +# define DIRENT_TYPE struct __old_dirent64 +# include +libc_hidden_def (__old_readdir64) +compat_symbol (libc, __old_readdir64, readdir64, GLIBC_2_1); +# endif /* SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) */ +#endif /* _DIRENT_MATCHES_DIRENT64 */ diff --git a/sysdeps/unix/sysv/linux/readdir64_r.c b/sysdeps/unix/sysv/linux/readdir64_r.c index 3dfbf4f..22b23d5 100644 --- a/sysdeps/unix/sysv/linux/readdir64_r.c +++ b/sysdeps/unix/sysv/linux/readdir64_r.c @@ -1,7 +1,53 @@ +/* Read a directory in reentrant mode. Linux LFS version. + Copyright (C) 2018 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 + . */ + +/* When _DIRENT_MATCHES_DIRENT64 is defined we can alias 'readdir64' to + 'readdir'. However the function signatures are not equal due + different return types, so we need to suppress {__}readdir so weak + and strong alias do not throw conflicting types errors. */ +#define readdir_r __no_readdir_r_decl +#define __readdir_r __no___readdir_r_decl +#include + #define __READDIR_R __readdir64_r -#define __GETDENTS __getdents64 +#define __GETDENTS __getdents64 #define DIRENT_TYPE struct dirent64 #include +#undef __readdir_r +#undef readdir_r + +#if _DIRENT_MATCHES_DIRENT64 +strong_alias (__readdir64_r, __readdir_r) +weak_alias (__readdir64_r, readdir_r) weak_alias (__readdir64_r, readdir64_r) +#else +/* The compat code expects the 'struct direct' with d_ino being a __ino_t + instead of __ino64_t. */ +# include +versioned_symbol (libc, __readdir64_r, readdir64_r, GLIBC_2_2); +# if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) +# include +# define __READDIR_R attribute_compat_text_section __old_readdir64_r +# define __GETDENTS __old_getdents64 +# define DIRENT_TYPE struct __old_dirent64 +# include +compat_symbol (libc, __old_readdir64_r, readdir64_r, GLIBC_2_1); +# endif /* SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) */ +#endif /* _DIRENT_MATCHES_DIRENT64 */ diff --git a/sysdeps/unix/sysv/linux/i386/readdir64.c b/sysdeps/unix/sysv/linux/readdir_r.c similarity index 51% rename from sysdeps/unix/sysv/linux/i386/readdir64.c rename to sysdeps/unix/sysv/linux/readdir_r.c index 42b7302..7ca9e8e 100644 --- a/sysdeps/unix/sysv/linux/i386/readdir64.c +++ b/sysdeps/unix/sysv/linux/readdir_r.c @@ -1,4 +1,5 @@ -/* Copyright (C) 2000-2018 Free Software Foundation, Inc. +/* Read a directory in reentrant mode. Linux no-LFS version. + Copyright (C) 2018 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 @@ -15,32 +16,8 @@ License along with the GNU C Library; if not, see . */ -#define __READDIR __readdir64 -#define __GETDENTS __getdents64 -#define DIRENT_TYPE struct dirent64 +#include -#include - -#include - -#undef __READDIR -#undef __GETDENTS -#undef DIRENT_TYPE - -libc_hidden_def (__readdir64) -versioned_symbol (libc, __readdir64, readdir64, GLIBC_2_2); - -#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) - -#include - -#define __READDIR attribute_compat_text_section __old_readdir64 -#define __GETDENTS __old_getdents64 -#define DIRENT_TYPE struct __old_dirent64 - -#include - -libc_hidden_def (__old_readdir64) - -compat_symbol (libc, __old_readdir64, readdir64, GLIBC_2_1); +#if !_DIRENT_MATCHES_DIRENT64 +# include #endif diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/readdir64.c b/sysdeps/unix/sysv/linux/s390/s390-32/readdir64.c deleted file mode 100644 index 2ea26dd..0000000 --- a/sysdeps/unix/sysv/linux/s390/s390-32/readdir64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/readdir64_r.c b/sysdeps/unix/sysv/linux/s390/s390-32/readdir64_r.c deleted file mode 100644 index 9f54f89..0000000 --- a/sysdeps/unix/sysv/linux/s390/s390-32/readdir64_r.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64.c b/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64.c deleted file mode 100644 index 2ea26dd..0000000 --- a/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64_r.c b/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64_r.c deleted file mode 100644 index 9f54f89..0000000 --- a/sysdeps/unix/sysv/linux/sparc/sparc32/readdir64_r.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/wordsize-64/readdir.c b/sysdeps/unix/sysv/linux/wordsize-64/readdir.c deleted file mode 100644 index 0d57988..0000000 --- a/sysdeps/unix/sysv/linux/wordsize-64/readdir.c +++ /dev/null @@ -1,8 +0,0 @@ -#define readdir64 __no_readdir64_decl -#define __readdir64 __no___readdir64_decl -#include -#undef __readdir64 -strong_alias (__readdir, __readdir64) -strong_alias (__readdir, __GI___readdir64) -#undef readdir64 -weak_alias (__readdir, readdir64) diff --git a/sysdeps/unix/sysv/linux/wordsize-64/readdir64.c b/sysdeps/unix/sysv/linux/wordsize-64/readdir64.c deleted file mode 100644 index 9796431..0000000 --- a/sysdeps/unix/sysv/linux/wordsize-64/readdir64.c +++ /dev/null @@ -1 +0,0 @@ -/* readdir64 is in readdir.c */ diff --git a/sysdeps/unix/sysv/linux/wordsize-64/readdir64_r.c b/sysdeps/unix/sysv/linux/wordsize-64/readdir64_r.c deleted file mode 100644 index b8fe9a3..0000000 --- a/sysdeps/unix/sysv/linux/wordsize-64/readdir64_r.c +++ /dev/null @@ -1 +0,0 @@ -/* readdir64_r is in readdir_r.c */ diff --git a/sysdeps/unix/sysv/linux/wordsize-64/readdir_r.c b/sysdeps/unix/sysv/linux/wordsize-64/readdir_r.c deleted file mode 100644 index 290f2c8..0000000 --- a/sysdeps/unix/sysv/linux/wordsize-64/readdir_r.c +++ /dev/null @@ -1,4 +0,0 @@ -#define readdir64_r __no_readdir64_r_decl -#include -#undef readdir64_r -weak_alias (__readdir_r, readdir64_r) From patchwork Fri Mar 2 18:59:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 130574 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp1602019lja; Fri, 2 Mar 2018 11:00:45 -0800 (PST) X-Google-Smtp-Source: AG47ELsXC++ceHB0rmscG/ZZoDkJgDUsYPC10j0pqWCrgs5LwbjwvwC1OuUAek03uItWY9EvAmA5 X-Received: by 2002:a17:902:167:: with SMTP id 94-v6mr6168523plb.294.1520017245472; Fri, 02 Mar 2018 11:00:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520017245; cv=none; d=google.com; s=arc-20160816; b=OhXYxtLzg6ahY6NH2YwIC9CtBwqLVwW00vH0yskk4DtYWqQzVUovgfT2WapVQ19GXy Xy7xqIxTHxJOOBkOdAitrXMlBsPQQD+WEchqgP1HjZpyQGToKAv7tK6BzmH38H5V2fth NALm20BXkHboGs513nt10k0Uqxoo4vqR5g8jcQLSAjpb8DL2jdxBFv2WCC/u6ZK1UOVz c35fioXHJ4m4zHRRvlJtWQZgSUzD6f/lWIms89J0LVF0GYGD2+sxSrO5eWuJdFUYx34n Jwt2+2m1vBysWbZf7qdoMHGBpHA8jf39ig3nAp60eYGNFdHvBiJ3sxGjhCIa08FguIck nKFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from:delivered-to :sender:list-help:list-post:list-archive:list-subscribe :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=DutLNfZAuftB5SGbwcsEsCNuiEI2cie4Jd2JI9MoXiw=; b=siVmej+Fz+cJUIovpBwlYvbIvJsxcmll/UoLNguliW1vZ3/4ci2eTad4HXm0XHmxii 9XuEAxI1qXh3Q8zrBheyedjE8MB7soFvAK96EdWYznrXDjfvv/yMHmHNGftYkfKBmiMb DOpCKQAc4v6MmHRlJB78CWDqXqpxU4+S8xk4MWNh5+TdIrugRt/hwGXIe5ll/JZUHjqy 28p5tl6fxygAWC81iPbuoUfKFn1gz70Rih2iL2it4CriViww7G4iBX8BLeKVk6/jzZlB LgfFer4S/qUv3OKUp4MM1IOTCKRJ89APljOdUztUJbK6RUOcIqrsXJPoaYN689zuAB6K icSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=Pp+1juR8; spf=pass (google.com: domain of libc-alpha-return-90740-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90740-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id v7si5240444pfi.403.2018.03.02.11.00.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 11:00:45 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90740-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=Pp+1juR8; spf=pass (google.com: domain of libc-alpha-return-90740-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90740-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=ky0qKJJ1ueVLB75Bb3wdVH30/ILRnv3 jScdQOGGydPBXPGtD+ML6VORrHwqqaLanGJu7IEAC5UjrBZFMpnDtH39CglQNT+M 7+jYP815kO2XN/BQ7rQ8nADpgX+oa8Jg0wAWs7cjDzfZN3H+cNmT9cANybIyEYg2 25S9bnQtVyvs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=OjIsM/t38l6TvzDTZq/p8f45VVc=; b=Pp+1j uR8FYB2Fv1vRmpFMkn5gkV2Tlnifd8FUr2v6nfRX38HC9FlZPLCRD/V/QX1iDQRx dZfvh+zo92H9fIeXyO+nPvc2uFRmO8BFgNHHiiTgOPAxYitP7WcnpOzR7CFV7xtV 5r7nwqtfYQ2/Pp8R147ciAI8hk1V4P+lkkCJSo= Received: (qmail 98725 invoked by alias); 2 Mar 2018 18:59:54 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 97777 invoked by uid 89); 2 Mar 2018 18:59:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt0-f193.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=DutLNfZAuftB5SGbwcsEsCNuiEI2cie4Jd2JI9MoXiw=; b=U53eFbQAYbBKJ9UQ3b+PUxsBsSTqSat1UkWGYbF88vqwlbW7DY+qLSXLqCtc9ivNCe lo5CF0L1Qhc0NZ2B3P/F+193DNzOxQt1iMBSV4MozdjKOtxPG4UxWSJs4pszSPIL1cXW +rjdSBXbwbN7Lgd4sMJYKvbLYeEymrSXXjLqpKh9lZ0sq93zZU+IGNWGqtpo2BEf6Psz YWYk5dotOC4wxNq/PLr6uPAY9te/n3dB0medeDFnxvp7tAqs/9tQfQDJIpkf2LTzM/J4 6gk9EnBi/tL800TJJ1AN7tUPwzkCOzHDZjOuP+4aSebE38I9pehJXTEwl6TAlK79MGk1 iVKQ== X-Gm-Message-State: AElRT7HtMA/QTgdWuu/K9jTJEamdlyGwp2WYwz5KnXmaolP09xq9JzVZ XHOESCdm0IsUHeXC3Y90FI3qp5IpBfo= X-Received: by 10.200.36.37 with SMTP id c34mr9979960qtc.38.1520017176450; Fri, 02 Mar 2018 10:59:36 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 4/7] Consolidate Linux getdents{64} implementation Date: Fri, 2 Mar 2018 15:59:22 -0300 Message-Id: <1520017165-15830-4-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1520017165-15830-1-git-send-email-adhemerval.zanella@linaro.org> References: <1520017165-15830-1-git-send-email-adhemerval.zanella@linaro.org> This patch consolidates Linux getdents{64} implementation on just the default sysdeps/unix/sysv/linux/getdents{64}{_r}.c ones. Although this symbol is used only internally, the non-LFS version still need to be build due the non-LFS getdirentries which requires its semantic. The non-LFS default implementation now uses the wordsize-32 as base which uses getdents64 syscall plus adjustment for overflow (it allows to use the same code for architectures that does not support non-LFS getdents syscall). It has two main differences to wordsize-32 one: - DIRENT_SET_DP_INO is added to handle alpha requirement to zero the padding. - alloca is removed by allocating a bounded temporary buffer (it increases stack usage by roughly 276 bytes). The default implementation handle the Linux requirements: * getdents is only built for _DIRENT_MATCHES_DIRENT64 being 0. * getdents64 is always built and aliased to getdents for ABIs that define _DIRENT_MATCHES_DIRENT64 to 1. * A compat symbol is added for getdents64 for ABI that used to export the old non-LFS version. Checked on aarch64-linux-gnu, x86_64-linux-gnu, i686-linux-gnu, sparcv9-linux-gnu, sparc64-linux-gnu, powerpc-linux-gnu, and powerpc64le-linux-gnu. * sysdeps/unix/sysv/linux/alpha/getdents.c: Add comments with alpha requirements. (_DIRENT_MATCHES_DIRENT64): Undef * sysdeps/unix/sysv/linux/alpha/getdents64.c: Likewise. * sysdeps/unix/sysv/linux/arm/getdents64.c: Remove file. * sysdeps/unix/sysv/linux/generic/getdents.c: Likewise. * sysdeps/unix/sysv/linux/generic/getdents64.c: Likewise. * sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c: Likewise. * sysdeps/unix/sysv/linux/getdents.c: Simplify implementation by use getdents64 syscalls as base. * sysdeps/unix/sysv/linux/getdents64.c: Likewise and add compatibility symbol if required. * sysdeps/unix/sysv/linux/hppa/getdents64.c: Likewise. * sysdeps/unix/sysv/linux/i386/getdents64.c: Likewise. * sysdeps/unix/sysv/linux/m68k/getdents64.c: Likewise. * sysdeps/unix/sysv/linux/powerpc/getdents64.c: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/getdents64.c: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/getdents64.c: Likewise. * sysdeps/unix/sysv/linux/wordsize-64/getdents.c: Likewise. * sysdeps/unix/sysv/linux/wordsize-64/getdents64.c: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/get_clockfreq.c --- ChangeLog | 22 ++ sysdeps/unix/sysv/linux/alpha/getdents.c | 8 + sysdeps/unix/sysv/linux/alpha/getdents64.c | 9 + sysdeps/unix/sysv/linux/arm/getdents64.c | 1 - sysdeps/unix/sysv/linux/generic/getdents.c | 1 - sysdeps/unix/sysv/linux/generic/getdents64.c | 37 --- .../unix/sysv/linux/generic/wordsize-32/getdents.c | 115 -------- sysdeps/unix/sysv/linux/getdents.c | 323 ++++++--------------- sysdeps/unix/sysv/linux/getdents64.c | 80 ++++- sysdeps/unix/sysv/linux/hppa/getdents64.c | 1 - sysdeps/unix/sysv/linux/i386/getdents64.c | 39 --- sysdeps/unix/sysv/linux/m68k/getdents64.c | 1 - sysdeps/unix/sysv/linux/powerpc/getdents64.c | 1 - sysdeps/unix/sysv/linux/s390/s390-32/getdents64.c | 1 - sysdeps/unix/sysv/linux/sparc/sparc32/getdents64.c | 1 - .../unix/sysv/linux/sparc/sparc64/get_clockfreq.c | 8 +- sysdeps/unix/sysv/linux/wordsize-64/getdents.c | 4 - sysdeps/unix/sysv/linux/wordsize-64/getdents64.c | 1 - 18 files changed, 203 insertions(+), 450 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/arm/getdents64.c delete mode 100644 sysdeps/unix/sysv/linux/generic/getdents.c delete mode 100644 sysdeps/unix/sysv/linux/generic/getdents64.c delete mode 100644 sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c delete mode 100644 sysdeps/unix/sysv/linux/hppa/getdents64.c delete mode 100644 sysdeps/unix/sysv/linux/i386/getdents64.c delete mode 100644 sysdeps/unix/sysv/linux/m68k/getdents64.c delete mode 100644 sysdeps/unix/sysv/linux/powerpc/getdents64.c delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/getdents64.c delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/getdents64.c delete mode 100644 sysdeps/unix/sysv/linux/wordsize-64/getdents.c delete mode 100644 sysdeps/unix/sysv/linux/wordsize-64/getdents64.c -- 2.7.4 diff --git a/sysdeps/unix/sysv/linux/alpha/getdents.c b/sysdeps/unix/sysv/linux/alpha/getdents.c index dfecfef..64ccf86 100644 --- a/sysdeps/unix/sysv/linux/alpha/getdents.c +++ b/sysdeps/unix/sysv/linux/alpha/getdents.c @@ -1,3 +1,11 @@ +/* Although Alpha defines _DIRENT_MATCHES_DIRENT64, 'struct dirent' and + 'struct dirent64' have slight different internal layout with d_ino + being a __ino_t on non-LFS version with an extra __pad field which should + be zeroed. */ + +#include +#undef _DIRENT_MATCHES_DIRENT64 +#define _DIRENT_MATCHES_DIRENT64 0 #define DIRENT_SET_DP_INO(dp, value) \ do { (dp)->d_ino = (value); (dp)->__pad = 0; } while (0) #include diff --git a/sysdeps/unix/sysv/linux/alpha/getdents64.c b/sysdeps/unix/sysv/linux/alpha/getdents64.c index 50f1368..53cf93c 100644 --- a/sysdeps/unix/sysv/linux/alpha/getdents64.c +++ b/sysdeps/unix/sysv/linux/alpha/getdents64.c @@ -1 +1,10 @@ +/* Although Alpha defines _DIRENT_MATCHES_DIRENT64, 'struct dirent' and + 'struct dirent64' have slight different internal layout with d_ino + being a __ino_t on non-LFS version with an extra __pad field which should + be zeroed. */ + +#include +/* It suppress the __getdents64 to __getdents alias. */ +#undef _DIRENT_MATCHES_DIRENT64 +#define _DIRENT_MATCHES_DIRENT64 0 #include diff --git a/sysdeps/unix/sysv/linux/arm/getdents64.c b/sysdeps/unix/sysv/linux/arm/getdents64.c deleted file mode 100644 index 0c75fb5..0000000 --- a/sysdeps/unix/sysv/linux/arm/getdents64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/generic/getdents.c b/sysdeps/unix/sysv/linux/generic/getdents.c deleted file mode 100644 index 14dbbc7..0000000 --- a/sysdeps/unix/sysv/linux/generic/getdents.c +++ /dev/null @@ -1 +0,0 @@ -/* Defined in getdents64.c */ diff --git a/sysdeps/unix/sysv/linux/generic/getdents64.c b/sysdeps/unix/sysv/linux/generic/getdents64.c deleted file mode 100644 index 0f876b8..0000000 --- a/sysdeps/unix/sysv/linux/generic/getdents64.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright (C) 2011-2018 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Chris Metcalf , 2011. - - 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 -#include -#include - -#include -#include - -/* The kernel struct linux_dirent64 matches the 'struct getdents64' type. */ -ssize_t -__getdents64 (int fd, char *buf, size_t nbytes) -{ - return INLINE_SYSCALL (getdents64, 3, fd, buf, nbytes); -} - -#if __WORDSIZE == 64 -strong_alias (__getdents64, __getdents) -#endif diff --git a/sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c b/sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c deleted file mode 100644 index 7158fd1..0000000 --- a/sysdeps/unix/sysv/linux/generic/wordsize-32/getdents.c +++ /dev/null @@ -1,115 +0,0 @@ -/* Copyright (C) 1993-2018 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Simplified from sysdeps/unix/sysv/linux/getdents.c. - - 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 -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -/* Pack the dirent64 struct down into 32-bit offset/inode fields, and - ensure that no overflow occurs. */ -ssize_t -__getdents (int fd, char *buf, size_t nbytes) -{ - union - { - struct dirent64 k; /* Kernel structure. */ - struct dirent u; - char b[1]; - } *kbuf = (void *) buf, *outp, *inp; - size_t kbytes = nbytes; - off64_t last_offset = -1; - ssize_t retval; - - const size_t size_diff = (offsetof (struct dirent64, d_name) - - offsetof (struct dirent, d_name)); - if (nbytes <= sizeof (struct dirent)) - { - kbytes = nbytes + offsetof (struct dirent64, d_name) - - offsetof (struct dirent, d_name); - kbuf = __alloca(kbytes); - } - - retval = INLINE_SYSCALL (getdents64, 3, fd, kbuf, kbytes); - if (retval == -1) - return -1; - - /* These two pointers might alias the same memory buffer. - Standard C requires that we always use the same type for them, - so we must use the union type. */ - inp = kbuf; - outp = (void *) buf; - - while (&inp->b < &kbuf->b + retval) - { - const size_t alignment = __alignof__ (struct dirent); - /* Since inp->k.d_reclen is already aligned for the kernel - structure this may compute a value that is bigger - than necessary. */ - size_t old_reclen = inp->k.d_reclen; - size_t new_reclen = ((old_reclen - size_diff + alignment - 1) - & ~(alignment - 1)); - - /* Copy the data out of the old structure into temporary space. - Then copy the name, which may overlap if BUF == KBUF. */ - const uint64_t d_ino = inp->k.d_ino; - const int64_t d_off = inp->k.d_off; - const uint8_t d_type = inp->k.d_type; - - memmove (outp->u.d_name, inp->k.d_name, - old_reclen - offsetof (struct dirent64, d_name)); - - /* Now we have copied the data from INP and access only OUTP. */ - - outp->u.d_ino = d_ino; - outp->u.d_off = d_off; - if ((sizeof (outp->u.d_ino) != sizeof (inp->k.d_ino) - && outp->u.d_ino != d_ino) - || (sizeof (outp->u.d_off) != sizeof (inp->k.d_off) - && outp->u.d_off != d_off)) - { - /* Overflow. If there was at least one entry before this one, - return them without error, otherwise signal overflow. */ - if (last_offset != -1) - { - __lseek64 (fd, last_offset, SEEK_SET); - return outp->b - buf; - } - __set_errno (EOVERFLOW); - return -1; - } - - last_offset = d_off; - outp->u.d_reclen = new_reclen; - outp->u.d_type = d_type; - - inp = (void *) inp + old_reclen; - outp = (void *) outp + new_reclen; - } - - return outp->b - buf; -} diff --git a/sysdeps/unix/sysv/linux/getdents.c b/sysdeps/unix/sysv/linux/getdents.c index 591ce67..4e52729 100644 --- a/sysdeps/unix/sysv/linux/getdents.c +++ b/sysdeps/unix/sysv/linux/getdents.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1993-2018 Free Software Foundation, Inc. +/* Get directory entries. Linux no-LFS version. + Copyright (C) 1993-2018 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 @@ -12,260 +13,102 @@ 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 + License along with the GNU C Library. If not, see . */ -#include -#include -#include #include -#include -#include -#include -#include -#include -#include -#include -#include +#if !_DIRENT_MATCHES_DIRENT64 -#include +# include +# include +# include -#include +# ifndef DIRENT_SET_DP_INO +# define DIRENT_SET_DP_INO(dp, value) (dp)->d_ino = (value) +# endif -/* For Linux we need a special version of this file since the - definition of `struct dirent' is not the same for the kernel and - the libc. There is one additional field which might be introduced - in the kernel structure in the future. - - Here is the kernel definition of `struct dirent' as of 2.1.20: */ - -struct kernel_dirent - { - long int d_ino; - __kernel_off_t d_off; - unsigned short int d_reclen; - char d_name[256]; - }; - -struct kernel_dirent64 - { - uint64_t d_ino; - int64_t d_off; - unsigned short int d_reclen; - unsigned char d_type; - char d_name[256]; - }; - -#ifndef __GETDENTS -# define __GETDENTS __getdents -#endif -#ifndef DIRENT_TYPE -# define DIRENT_TYPE struct dirent -#endif -#ifndef DIRENT_SET_DP_INO -# define DIRENT_SET_DP_INO(dp, value) (dp)->d_ino = (value) -#endif - -/* The problem here is that we cannot simply read the next NBYTES - bytes. We need to take the additional field into account. We use - some heuristic. Assuming the directory contains names with 14 - characters on average we can compute an estimated number of entries - which fit in the buffer. Taking this number allows us to specify a - reasonable number of bytes to read. If we should be wrong, we can - reset the file descriptor. In practice the kernel is limiting the - amount of data returned much more then the reduced buffer size. */ +/* Pack the dirent64 struct down into 32-bit offset/inode fields, and + ensure that no overflow occurs. */ ssize_t -__GETDENTS (int fd, char *buf, size_t nbytes) +__getdents (int fd, char *buf, size_t nbytes) { + union + { + struct dirent64 k; /* Kernel structure. */ + struct dirent u; + char b[1]; + } *kbuf = (void *) buf, *outp, *inp; + size_t kbytes = nbytes; + off64_t last_offset = -1; ssize_t retval; - /* The d_ino and d_off fields in kernel_dirent and dirent must have - the same sizes and alignments. */ - if (sizeof (DIRENT_TYPE) == sizeof (struct dirent) - && (sizeof (((struct kernel_dirent *) 0)->d_ino) - == sizeof (((struct dirent *) 0)->d_ino)) - && (sizeof (((struct kernel_dirent *) 0)->d_off) - == sizeof (((struct dirent *) 0)->d_off)) - && (offsetof (struct kernel_dirent, d_off) - == offsetof (struct dirent, d_off)) - && (offsetof (struct kernel_dirent, d_reclen) - == offsetof (struct dirent, d_reclen))) - { - retval = INLINE_SYSCALL (getdents, 3, fd, buf, nbytes); +# define size_diff (offsetof (struct dirent64, d_name) \ + - offsetof (struct dirent, d_name)) + char kbuftmp[sizeof (struct dirent) + size_diff]; + if (nbytes <= sizeof (struct dirent)) + kbuf = (void*) kbuftmp; - /* The kernel added the d_type value after the name. Change - this now. */ - if (retval != -1) - { - union - { - struct kernel_dirent k; - struct dirent u; - } *kbuf = (void *) buf; + retval = INLINE_SYSCALL_CALL (getdents64, fd, kbuf, kbytes); + if (retval == -1) + return -1; - while ((char *) kbuf < buf + retval) - { - char d_type = *((char *) kbuf + kbuf->k.d_reclen - 1); - memmove (kbuf->u.d_name, kbuf->k.d_name, - strlen (kbuf->k.d_name) + 1); - kbuf->u.d_type = d_type; + /* These two pointers might alias the same memory buffer. + Standard C requires that we always use the same type for them, + so we must use the union type. */ + inp = kbuf; + outp = (void *) buf; - kbuf = (void *) ((char *) kbuf + kbuf->k.d_reclen); - } - } - - return retval; - } - - off64_t last_offset = -1; - -#ifdef __NR_getdents64 - { - union + while (&inp->b < &kbuf->b + retval) { - struct kernel_dirent64 k; - DIRENT_TYPE u; - char b[1]; - } *kbuf = (void *) buf, *outp, *inp; - size_t kbytes = nbytes; - if (offsetof (DIRENT_TYPE, d_name) - < offsetof (struct kernel_dirent64, d_name) - && nbytes <= sizeof (DIRENT_TYPE)) - { - kbytes = (nbytes + offsetof (struct kernel_dirent64, d_name) - - offsetof (DIRENT_TYPE, d_name)); - kbuf = __alloca(kbytes); - } - retval = INLINE_SYSCALL (getdents64, 3, fd, kbuf, kbytes); - const size_t size_diff = (offsetof (struct kernel_dirent64, d_name) - - offsetof (DIRENT_TYPE, d_name)); - - /* Return the error if encountered. */ - if (retval == -1) - return -1; - - /* If the structure returned by the kernel is identical to what we - need, don't do any conversions. */ - if (offsetof (DIRENT_TYPE, d_name) - == offsetof (struct kernel_dirent64, d_name) - && sizeof (outp->u.d_ino) == sizeof (inp->k.d_ino) - && sizeof (outp->u.d_off) == sizeof (inp->k.d_off)) - return retval; - - /* These two pointers might alias the same memory buffer. - Standard C requires that we always use the same type for them, - so we must use the union type. */ - inp = kbuf; - outp = (void *) buf; - - while (&inp->b < &kbuf->b + retval) - { - const size_t alignment = __alignof__ (DIRENT_TYPE); - /* Since inp->k.d_reclen is already aligned for the kernel - structure this may compute a value that is bigger - than necessary. */ - size_t old_reclen = inp->k.d_reclen; - size_t new_reclen = ((old_reclen - size_diff + alignment - 1) - & ~(alignment - 1)); - - /* Copy the data out of the old structure into temporary space. - Then copy the name, which may overlap if BUF == KBUF. */ - const uint64_t d_ino = inp->k.d_ino; - const int64_t d_off = inp->k.d_off; - const uint8_t d_type = inp->k.d_type; - - memmove (outp->u.d_name, inp->k.d_name, - old_reclen - offsetof (struct kernel_dirent64, d_name)); - - /* Now we have copied the data from INP and access only OUTP. */ - - DIRENT_SET_DP_INO (&outp->u, d_ino); - outp->u.d_off = d_off; - if ((sizeof (outp->u.d_ino) != sizeof (inp->k.d_ino) - && outp->u.d_ino != d_ino) - || (sizeof (outp->u.d_off) != sizeof (inp->k.d_off) - && outp->u.d_off != d_off)) - { - /* Overflow. If there was at least one entry - before this one, return them without error, - otherwise signal overflow. */ - if (last_offset != -1) - { - __lseek64 (fd, last_offset, SEEK_SET); - return outp->b - buf; - } - __set_errno (EOVERFLOW); - return -1; - } - - last_offset = d_off; - outp->u.d_reclen = new_reclen; - outp->u.d_type = d_type; - - inp = (void *) inp + old_reclen; - outp = (void *) outp + new_reclen; - } - - return outp->b - buf; - } -#endif - { - size_t red_nbytes; - struct kernel_dirent *skdp, *kdp; - const size_t size_diff = (offsetof (DIRENT_TYPE, d_name) - - offsetof (struct kernel_dirent, d_name)); - - red_nbytes = MIN (nbytes - - ((nbytes / (offsetof (DIRENT_TYPE, d_name) + 14)) - * size_diff), - nbytes - size_diff); - - skdp = kdp = __alloca (red_nbytes); - - retval = INLINE_SYSCALL (getdents, 3, fd, (char *) kdp, red_nbytes); - - if (retval == -1) - return -1; - - DIRENT_TYPE *dp = (DIRENT_TYPE *) buf; - while ((char *) kdp < (char *) skdp + retval) - { - const size_t alignment = __alignof__ (DIRENT_TYPE); - /* Since kdp->d_reclen is already aligned for the kernel structure - this may compute a value that is bigger than necessary. */ - size_t new_reclen = ((kdp->d_reclen + size_diff + alignment - 1) - & ~(alignment - 1)); - if ((char *) dp + new_reclen > buf + nbytes) - { - /* Our heuristic failed. We read too many entries. Reset - the stream. */ - assert (last_offset != -1); - __lseek64 (fd, last_offset, SEEK_SET); - - if ((char *) dp == buf) - { - /* The buffer the user passed in is too small to hold even - one entry. */ - __set_errno (EINVAL); - return -1; - } - - break; - } + const size_t alignment = __alignof__ (struct dirent); + /* Since inp->k.d_reclen is already aligned for the kernel + structure this may compute a value that is bigger + than necessary. */ + size_t old_reclen = inp->k.d_reclen; + size_t new_reclen = ((old_reclen - size_diff + alignment - 1) + & ~(alignment - 1)); + + /* Copy the data out of the old structure into temporary space. + Then copy the name, which may overlap if BUF == KBUF. */ + const uint64_t d_ino = inp->k.d_ino; + const int64_t d_off = inp->k.d_off; + const uint8_t d_type = inp->k.d_type; + + memmove (outp->u.d_name, inp->k.d_name, + old_reclen - offsetof (struct dirent64, d_name)); + + /* Now we have copied the data from INP and access only OUTP. */ + + DIRENT_SET_DP_INO (&outp->u, d_ino); + outp->u.d_off = d_off; + if ((sizeof (outp->u.d_ino) != sizeof (inp->k.d_ino) + && outp->u.d_ino != d_ino) + || (sizeof (outp->u.d_off) != sizeof (inp->k.d_off) + && outp->u.d_off != d_off)) + { + /* Overflow. If there was at least one entry before this one, + return them without error, otherwise signal overflow. */ + if (last_offset != -1) + { + __lseek64 (fd, last_offset, SEEK_SET); + return outp->b - buf; + } + __set_errno (EOVERFLOW); + return -1; + } + + last_offset = d_off; + outp->u.d_reclen = new_reclen; + outp->u.d_type = d_type; + + inp = (void *) inp + old_reclen; + outp = (void *) outp + new_reclen; + } - last_offset = kdp->d_off; - DIRENT_SET_DP_INO(dp, kdp->d_ino); - dp->d_off = kdp->d_off; - dp->d_reclen = new_reclen; - dp->d_type = *((char *) kdp + kdp->d_reclen - 1); - memcpy (dp->d_name, kdp->d_name, - kdp->d_reclen - offsetof (struct kernel_dirent, d_name)); + return outp->b - buf; +} - dp = (DIRENT_TYPE *) ((char *) dp + new_reclen); - kdp = (struct kernel_dirent *) (((char *) kdp) + kdp->d_reclen); - } +# undef DIRENT_SET_DP_INO - return (char *) dp - buf; - } -} +#endif /* _DIRENT_MATCHES_DIRENT64 */ diff --git a/sysdeps/unix/sysv/linux/getdents64.c b/sysdeps/unix/sysv/linux/getdents64.c index 805917e..f37fe15 100644 --- a/sysdeps/unix/sysv/linux/getdents64.c +++ b/sysdeps/unix/sysv/linux/getdents64.c @@ -1,3 +1,77 @@ -#define __GETDENTS __getdents64 -#define DIRENT_TYPE struct dirent64 -#include +/* Get directory entries. Linux LFS version. + Copyright (C) 1997-2018 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 + +/* The kernel struct linux_dirent64 matches the 'struct getdents64' type. */ +ssize_t +__getdents64 (int fd, char *buf, size_t nbytes) +{ + return INLINE_SYSCALL_CALL (getdents64, fd, buf, nbytes); +} + +#if _DIRENT_MATCHES_DIRENT64 +strong_alias (__getdents64, __getdents) +#else +# include + +# if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) + +# include + +/* kernel definition of as of 3.2. */ +struct compat_linux_dirent +{ + /* Both d_ino and d_off are compat_ulong_t which are defined in all + architectures as 'u32'. */ + uint32_t d_ino; + uint32_t d_off; + unsigned short d_reclen; + char d_name[1]; +}; + +ssize_t +__old_getdents64 (int fd, char *buf, size_t nbytes) +{ + ssize_t retval = INLINE_SYSCALL_CALL (getdents, fd, buf, nbytes); + + /* The kernel added the d_type value after the name. Change this now. */ + if (retval != -1) + { + union + { + struct compat_linux_dirent k; + struct dirent u; + } *kbuf = (void *) buf; + + while ((char *) kbuf < buf + retval) + { + char d_type = *((char *) kbuf + kbuf->k.d_reclen - 1); + memmove (kbuf->u.d_name, kbuf->k.d_name, + strlen (kbuf->k.d_name) + 1); + kbuf->u.d_type = d_type; + + kbuf = (void *) ((char *) kbuf + kbuf->k.d_reclen); + } + } + return retval; +} +# endif /* SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) */ +#endif /* _DIRENT_MATCHES_DIRENT64 */ diff --git a/sysdeps/unix/sysv/linux/hppa/getdents64.c b/sysdeps/unix/sysv/linux/hppa/getdents64.c deleted file mode 100644 index 0c75fb5..0000000 --- a/sysdeps/unix/sysv/linux/hppa/getdents64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/i386/getdents64.c b/sysdeps/unix/sysv/linux/i386/getdents64.c deleted file mode 100644 index 0a2c194..0000000 --- a/sysdeps/unix/sysv/linux/i386/getdents64.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 2000-2018 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 - . */ - -#define __GETDENTS __getdents64 -#define DIRENT_TYPE struct dirent64 - -#include - -#include - -#undef __READDIR -#undef __GETDENTS -#undef DIRENT_TYPE - -#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) - -#include - -#define __GETDENTS __old_getdents64 -#define DIRENT_TYPE struct __old_dirent64 -#define kernel_dirent old_kernel_dirent -#define kernel_dirent64 old_kernel_dirent64 - -#include -#endif diff --git a/sysdeps/unix/sysv/linux/m68k/getdents64.c b/sysdeps/unix/sysv/linux/m68k/getdents64.c deleted file mode 100644 index 0c75fb5..0000000 --- a/sysdeps/unix/sysv/linux/m68k/getdents64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/powerpc/getdents64.c b/sysdeps/unix/sysv/linux/powerpc/getdents64.c deleted file mode 100644 index 0c75fb5..0000000 --- a/sysdeps/unix/sysv/linux/powerpc/getdents64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/getdents64.c b/sysdeps/unix/sysv/linux/s390/s390-32/getdents64.c deleted file mode 100644 index 0c75fb5..0000000 --- a/sysdeps/unix/sysv/linux/s390/s390-32/getdents64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/getdents64.c b/sysdeps/unix/sysv/linux/sparc/sparc32/getdents64.c deleted file mode 100644 index 0c75fb5..0000000 --- a/sysdeps/unix/sysv/linux/sparc/sparc32/getdents64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/get_clockfreq.c b/sysdeps/unix/sysv/linux/sparc/sparc64/get_clockfreq.c index c54d301..6838a77 100644 --- a/sysdeps/unix/sysv/linux/sparc/sparc64/get_clockfreq.c +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/get_clockfreq.c @@ -90,12 +90,12 @@ __get_clockfreq_via_proc_openprom (void) if (obp_fd != -1) { unsigned long int buf[4096 / sizeof (unsigned long int)]; - struct dirent *dirp = (struct dirent *) buf; + struct dirent64 *dirp = (struct dirent64 *) buf; ssize_t len; - while ((len = __getdents (obp_fd, (char *) dirp, sizeof (buf))) > 0) + while ((len = __getdents64 (obp_fd, (char *) dirp, sizeof (buf))) > 0) { - struct dirent *this_dirp = dirp; + struct dirent64 *this_dirp = dirp; while (len > 0) { @@ -140,7 +140,7 @@ __get_clockfreq_via_proc_openprom (void) break; len -= this_dirp->d_reclen; - this_dirp = (struct dirent *) + this_dirp = (struct dirent64 *) ((char *) this_dirp + this_dirp->d_reclen); } if (result != 0) diff --git a/sysdeps/unix/sysv/linux/wordsize-64/getdents.c b/sysdeps/unix/sysv/linux/wordsize-64/getdents.c deleted file mode 100644 index 5ea4c57..0000000 --- a/sysdeps/unix/sysv/linux/wordsize-64/getdents.c +++ /dev/null @@ -1,4 +0,0 @@ -#define __getdents64 __no___getdents64_decl -#include -#undef __getdents64 -weak_alias (__getdents, __getdents64); diff --git a/sysdeps/unix/sysv/linux/wordsize-64/getdents64.c b/sysdeps/unix/sysv/linux/wordsize-64/getdents64.c deleted file mode 100644 index 0df2c8f..0000000 --- a/sysdeps/unix/sysv/linux/wordsize-64/getdents64.c +++ /dev/null @@ -1 +0,0 @@ -/* getdents64 is in getdents.c */ From patchwork Fri Mar 2 18:59:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 130573 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp1601551lja; Fri, 2 Mar 2018 11:00:26 -0800 (PST) X-Google-Smtp-Source: AG47ELt3tK7snWQaCa+FPGZbqKh1vBcXjCAQhYssRDY6S8jPuyxBw5uehR0IaVebPAypvD7r+EFR X-Received: by 10.99.158.17 with SMTP id s17mr5350238pgd.64.1520017226760; Fri, 02 Mar 2018 11:00:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520017226; cv=none; d=google.com; s=arc-20160816; b=W12MAKOtza2KmoHyQf8TCapm5xFggd7tkWBPI2m/es2yMQVdXqjII+p21NKS4EiyFG mA5tvIqQUVysnVUC+BXLQoEeAl/umDE7rsxsJu0imbSq0NZekA239uuV57OBT5z/fNjd ob6DOFbkEE46O34hbBlmQjbS2bbV7aLAWz2823ucwun4xlECw1GJvV1d3K6vM/30AU0Q akopZp2NaCl0+VvPPVqlRl3zzri/9K+cf9oMOP8hop1N68Wh8CiRkR+M8+eCZ4j8jzSd eB91LbRPnqRYWBCvFaWfgR7C6xkLX/p3ykhHDFKtUnza3zeeyU3dMtj5DDi9f63e/xaR gXDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from:delivered-to :sender:list-help:list-post:list-archive:list-subscribe :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=X/cJ7PtNgbmAorrP8HV9N2SU6uTE2ppFDbR9/wBTGPs=; b=X9ySmA9cq79IP406rQp8DIZB8jn1kEHDyqPOcOduSjYNJDr6OP6o5j/ZHvxCMfjfX9 mPB8h4W/AFFHBDSLbvL/FwOXgzISjtqgqac3jr9dTTFynGBxvtH0wMKRTXj4mfaae7lj BVohaSXJ9X5DP0Ww/TxP3+sCvhDKokM+jhK/NpaAOBi9tqd1WJGK2NaOoA9U7pagDFsh cCKNAHzRd10uTwxyKyDApruyH3/JCYsux9fLcaUqvkxMrmW1WoR55kZrULGYGn+PTusR 0o0H9nLhs/QL7Sop9jHvM4l5abbSVn7A3TzvcV+oele7ExW8CebMq21fduPi5apL21SW 2LyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=W+2xYPBf; spf=pass (google.com: domain of libc-alpha-return-90739-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90739-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id i30si4372938pgn.252.2018.03.02.11.00.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 11:00:25 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90739-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=W+2xYPBf; spf=pass (google.com: domain of libc-alpha-return-90739-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90739-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=B3D1Sm0RPpY+UAx0xGmFbVpGi4zrq0D gSyVw85iRTx9CTfeVSMyhxCkdDlx2yu6egH7azN4TmZzWjRR0A6eV3suP5aOFDMZ HtOpCkSBDQH2u7YCS/Uq0y6DXaRoS1aIXnyRydEYuhhFy2MMUY5N30ZumDFgrv/C cluHahTTA1JI= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=zdlBuCIej9mnQGrq5U65lnHToZU=; b=W+2xY PBfKYDcmCwKWbF253SsK0tP7XkGelQIalcZiY0NZdc/uobDFpx02qup4sdvsMUwf yjzptvbOR7LIqWk4TjfADcwRygO1MVi8vmJ8BX2Em+RgjNDDmSrf2QPddQduopin rdD3bYGHC4IpwtV36qRB7ZNpUUxIOZqwHg60ik= Received: (qmail 98645 invoked by alias); 2 Mar 2018 18:59:54 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 97645 invoked by uid 89); 2 Mar 2018 18:59:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=cv, UD:v, c.v, Consolidate X-HELO: mail-qt0-f194.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=X/cJ7PtNgbmAorrP8HV9N2SU6uTE2ppFDbR9/wBTGPs=; b=ppWe8b8Rja7Wkje6t7ScPLUR3UZpw/4Q1iL54gCA3zzyIMvxMPZDqdfoHvb8UqDjvS I0h4pnivdCvme/qDMpd9I/BATpk/BE6eVnK/KENSy+6RiaU4tE0LsrmBCZ9D6PHHtcrT lHwJArq/vzcpV6nq3Ua12qlF1ztba2DvLRKK18YFdpZl3SOT+BmQ1XfJMdMo7IlBaryg rubSTPwagjv6kmh7v7VvzzfergeQma5cO7K2Dp1D/u5kcTMWUQJIkm4ZvOswjII0rtNk +zxnyIS6apVCf8OPDEJdpuw+nVn5I+PAJ+SMmqauoRtTvOO1GD8O1j6xeq7NPoGQYxAD sYDw== X-Gm-Message-State: AElRT7HoT1KZ1z2yKp8uTDOjl2kJw4mk0RyhaSyJGOscvsznC4S5w8Fo SJB2YFvxduZ7z7siA9J8RjxNIQ+1PUc= X-Received: by 10.200.23.176 with SMTP id o45mr10340372qtj.255.1520017177879; Fri, 02 Mar 2018 10:59:37 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 5/7] Consolidate scandir{at}{64} implementation Date: Fri, 2 Mar 2018 15:59:23 -0300 Message-Id: <1520017165-15830-5-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1520017165-15830-1-git-send-email-adhemerval.zanella@linaro.org> References: <1520017165-15830-1-git-send-email-adhemerval.zanella@linaro.org> This patch consolidates scandir{at}{64} implementation on just the default dirent/scandir{at}{64}{_r}.c ones. It changes the logic to follow the conventions used on other code consolidation: * scandir{at} is only built for _DIRENT_MATCHES_DIRENT64 being 0. * scandir{at}{64} is always built and aliased to getdents for ABIs that define _DIRENT_MATCHES_DIRENT64 to 1. Also on Linux the compat symbol for old non-LFS dirent64 definition requires a platform-specific scandir64.c. Checked on aarch64-linux-gnu, x86_64-linux-gnu, i686-linux-gnu, sparcv9-linux-gnu, sparc64-linux-gnu, powerpc-linux-gnu, and powerpc64le-linux-gnu. * dirent/scandir-tail-common.c: New file. * dirent/scandir-tail.c: Use scandir-tail-common.c. (__scandir_tail): Build iff _DIRENT_MATCHES_DIRENT64 is not defined. * dirent/scandir.c: Use scandir-tail-common.c. * dirent/scandirat.c: Likewise. * dirent/scandir64-tail.c: Use scandir-tail-common.c. * dirent/scandir64.c (scandir64): Always build and alias to scandir if _DIRENT_MATCHES_DIRENT64 is defined. * dirent/scandirat64.c (scandirat64): Likewise. * include/dirent.h (__scandir_tail): Only define iff _DIRENT_MATCHES_DIRENT64 is not defined. (__scandir64_tail): Define regardless. (__scandirat, scandirat64): Remove libc_hidden_proto. * sysdeps/unix/sysv/linux/arm/scandir64.c: Remove file. * sysdeps/unix/sysv/linux/m68k/scandir64.c: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/scandir64.c: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/scandir64.c: Likewise. * sysdeps/unix/sysv/linux/i386/scandir64.c: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/scandir64.c: Likewise. * sysdeps/unix/sysv/linux/scandir64.c: New file. --- ChangeLog | 21 +++++ dirent/scandir-tail-common.c | 103 +++++++++++++++++++++ dirent/scandir-tail.c | 95 ++----------------- dirent/scandir.c | 27 +----- dirent/scandir64-tail.c | 10 +- dirent/scandir64.c | 23 +++-- dirent/scandirat.c | 30 +----- dirent/scandirat64.c | 23 +++-- include/dirent.h | 18 ++-- sysdeps/unix/sysv/linux/arm/scandir64.c | 1 - sysdeps/unix/sysv/linux/m68k/scandir64.c | 1 - .../unix/sysv/linux/powerpc/powerpc32/scandir64.c | 1 - sysdeps/unix/sysv/linux/s390/s390-32/scandir64.c | 1 - sysdeps/unix/sysv/linux/{i386 => }/scandir64.c | 37 ++++---- sysdeps/unix/sysv/linux/sparc/sparc32/scandir64.c | 1 - 15 files changed, 198 insertions(+), 194 deletions(-) create mode 100644 dirent/scandir-tail-common.c delete mode 100644 sysdeps/unix/sysv/linux/arm/scandir64.c delete mode 100644 sysdeps/unix/sysv/linux/m68k/scandir64.c delete mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc32/scandir64.c delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/scandir64.c rename sysdeps/unix/sysv/linux/{i386 => }/scandir64.c (81%) delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/scandir64.c -- 2.7.4 diff --git a/dirent/scandir-tail-common.c b/dirent/scandir-tail-common.c new file mode 100644 index 0000000..f89cf77 --- /dev/null +++ b/dirent/scandir-tail-common.c @@ -0,0 +1,103 @@ +/* Common implementation for scandir{at}. + Copyright (C) 2018 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 + +int +SCANDIR_TAIL (DIR *dp, + DIRENT_TYPE ***namelist, + int (*select) (const DIRENT_TYPE *), + int (*cmp) (const DIRENT_TYPE **, const DIRENT_TYPE **)) +{ + if (dp == NULL) + return -1; + + int save = errno; + __set_errno (0); + + int result; + struct scandir_cancel_struct c = { .dp = dp }; + __libc_cleanup_push (&__scandir_cancel_handler, &c); + + DIRENT_TYPE **v = NULL; + size_t vsize = 0; + DIRENT_TYPE *d; + while ((d = READDIR (dp)) != NULL) + { + if (select != NULL) + { + int selected = (*select) (d); + + /* The SELECT function might have set errno to non-zero on + success. It was zero before and it needs to be again to + make the later tests work. */ + __set_errno (0); + + if (!selected) + continue; + } + + if (__glibc_unlikely (c.cnt == vsize)) + { + if (vsize == 0) + vsize = 10; + else + vsize *= 2; + DIRENT_TYPE **new = realloc (v, vsize * sizeof *v); + if (new == NULL) + break; + c.v = v = new; + } + + size_t dsize = &d->d_name[_D_ALLOC_NAMLEN (d)] - (char *) d; + DIRENT_TYPE *vnew = malloc (dsize); + if (vnew == NULL) + break; + v[c.cnt++] = (DIRENT_TYPE *) memcpy (vnew, d, dsize); + + /* Ignore errors from readdir, malloc or realloc. These functions + might have set errno to non-zero on success. It was zero before + and it needs to be again to make the latter tests work. */ + __set_errno (0); + } + + if (__glibc_likely (errno == 0)) + { + __closedir (dp); + + /* Sort the list if we have a comparison function to sort with. */ + if (cmp != NULL) + qsort (v, c.cnt, sizeof *v, (__compar_fn_t) cmp); + + *namelist = v; + result = c.cnt; + } + else + { + /* This frees everything and calls closedir. */ + __scandir_cancel_handler (&c); + result = -1; + } + + __libc_cleanup_pop (0); + + if (result >= 0) + __set_errno (save); + return result; +} diff --git a/dirent/scandir-tail.c b/dirent/scandir-tail.c index 67c9c92..7395dc4 100644 --- a/dirent/scandir-tail.c +++ b/dirent/scandir-tail.c @@ -17,96 +17,13 @@ . */ #include -#include -#include -#include -#include -#ifndef SCANDIR_TAIL -# define SCANDIR_TAIL __scandir_tail -# define READDIR __readdir -# define DIRENT_TYPE struct dirent -#endif - -int -SCANDIR_TAIL (DIR *dp, - DIRENT_TYPE ***namelist, - int (*select) (const DIRENT_TYPE *), - int (*cmp) (const DIRENT_TYPE **, const DIRENT_TYPE **)) -{ - if (dp == NULL) - return -1; - - int save = errno; - __set_errno (0); - - int result; - struct scandir_cancel_struct c = { .dp = dp }; - __libc_cleanup_push (&__scandir_cancel_handler, &c); - - DIRENT_TYPE **v = NULL; - size_t vsize = 0; - DIRENT_TYPE *d; - while ((d = READDIR (dp)) != NULL) - { - if (select != NULL) - { - int selected = (*select) (d); - - /* The SELECT function might have set errno to non-zero on - success. It was zero before and it needs to be again to - make the later tests work. */ - __set_errno (0); - - if (!selected) - continue; - } +#if !_DIRENT_MATCHES_DIRENT64 - if (__glibc_unlikely (c.cnt == vsize)) - { - if (vsize == 0) - vsize = 10; - else - vsize *= 2; - DIRENT_TYPE **new = realloc (v, vsize * sizeof *v); - if (new == NULL) - break; - c.v = v = new; - } +# define SCANDIR_TAIL __scandir_tail +# define READDIR __readdir +# define DIRENT_TYPE struct dirent - size_t dsize = &d->d_name[_D_ALLOC_NAMLEN (d)] - (char *) d; - DIRENT_TYPE *vnew = malloc (dsize); - if (vnew == NULL) - break; - v[c.cnt++] = (DIRENT_TYPE *) memcpy (vnew, d, dsize); +# include - /* Ignore errors from readdir, malloc or realloc. These functions - might have set errno to non-zero on success. It was zero before - and it needs to be again to make the latter tests work. */ - __set_errno (0); - } - - if (__glibc_likely (errno == 0)) - { - __closedir (dp); - - /* Sort the list if we have a comparison function to sort with. */ - if (cmp != NULL) - qsort (v, c.cnt, sizeof *v, (__compar_fn_t) cmp); - - *namelist = v; - result = c.cnt; - } - else - { - /* This frees everything and calls closedir. */ - __scandir_cancel_handler (&c); - result = -1; - } - - __libc_cleanup_pop (0); - - if (result >= 0) - __set_errno (save); - return result; -} +#endif diff --git a/dirent/scandir.c b/dirent/scandir.c index b24e157..6d8352d 100644 --- a/dirent/scandir.c +++ b/dirent/scandir.c @@ -15,31 +15,14 @@ License along with the GNU C Library; if not, see . */ -/* We need to avoid the header declaration of scandir64, because - the types don't match scandir and then the compiler will - complain about the mismatch when we do the alias below. */ -#define scandir64 __renamed_scandir64 - #include -#undef scandir64 - -#ifndef SCANDIR -# define SCANDIR scandir -# define SCANDIR_TAIL __scandir_tail -# define DIRENT_TYPE struct dirent -#endif - - +#if !_DIRENT_MATCHES_DIRENT64 int -SCANDIR (const char *dir, - DIRENT_TYPE ***namelist, - int (*select) (const DIRENT_TYPE *), - int (*cmp) (const DIRENT_TYPE **, const DIRENT_TYPE **)) +scandir (const char *dir, struct dirent ***namelist, + int (*select) (const struct dirent *), + int (*cmp) (const struct dirent **, const struct dirent **)) { - return SCANDIR_TAIL (__opendir (dir), namelist, select, cmp); + return __scandir_tail (__opendir (dir), namelist, select, cmp); } - -#if _DIRENT_MATCHES_DIRENT64 -weak_alias (scandir, scandir64) #endif diff --git a/dirent/scandir64-tail.c b/dirent/scandir64-tail.c index 8d5cc07..4e873d4 100644 --- a/dirent/scandir64-tail.c +++ b/dirent/scandir64-tail.c @@ -18,9 +18,7 @@ #include -#if !_DIRENT_MATCHES_DIRENT64 -# define SCANDIR_TAIL __scandir64_tail -# define READDIR __readdir64 -# define DIRENT_TYPE struct dirent64 -# include -#endif +#define SCANDIR_TAIL __scandir64_tail +#define READDIR __readdir64 +#define DIRENT_TYPE struct dirent64 +#include diff --git a/dirent/scandir64.c b/dirent/scandir64.c index 0c63fa9..6bdd462 100644 --- a/dirent/scandir64.c +++ b/dirent/scandir64.c @@ -15,15 +15,18 @@ License along with the GNU C Library; if not, see . */ +#define scandir __no_scandir_decl #include - -/* scandir.c defines scandir64 as an alias if _DIRENT_MATCHES_DIRENT64. */ -#if !_DIRENT_MATCHES_DIRENT64 - -# define SCANDIR scandir64 -# define SCANDIR_TAIL __scandir64_tail -# define DIRENT_TYPE struct dirent64 - -# include - +#undef scandir + +int +scandir64 (const char *dir, struct dirent64 ***namelist, + int (*select) (const struct dirent64 *), + int (*cmp) (const struct dirent64 **, const struct dirent64 **)) +{ + return __scandir64_tail (__opendir (dir), namelist, select, cmp); +} + +#if _DIRENT_MATCHES_DIRENT64 +weak_alias (scandir64, scandir) #endif diff --git a/dirent/scandirat.c b/dirent/scandirat.c index 96a1b0e..8dad1e8 100644 --- a/dirent/scandirat.c +++ b/dirent/scandirat.c @@ -15,35 +15,15 @@ License along with the GNU C Library; if not, see . */ -/* We need to avoid the header declaration of scandir64, because - the types don't match scandir and then the compiler will - complain about the mismatch when we do the alias below. */ -#define scandirat64 __renamed_scandirat64 - #include -#undef scandirat64 - -#ifndef SCANDIRAT -# define SCANDIRAT __scandirat -# define SCANDIR_TAIL __scandir_tail -# define DIRENT_TYPE struct dirent -# define SCANDIRAT_WEAK_ALIAS -#endif - +#if !_DIRENT_MATCHES_DIRENT64 int -SCANDIRAT (int dfd, const char *dir, - DIRENT_TYPE ***namelist, - int (*select) (const DIRENT_TYPE *), - int (*cmp) (const DIRENT_TYPE **, const DIRENT_TYPE **)) +__scandirat (int dfd, const char *dir, struct dirent ***namelist, + int (*select) (const struct dirent *), + int (*cmp) (const struct dirent **, const struct dirent **)) { - return SCANDIR_TAIL (__opendirat (dfd, dir), namelist, select, cmp); + return __scandir_tail (__opendirat (dfd, dir), namelist, select, cmp); } -libc_hidden_def (SCANDIRAT) -#ifdef SCANDIRAT_WEAK_ALIAS weak_alias (__scandirat, scandirat) #endif - -#if _DIRENT_MATCHES_DIRENT64 -weak_alias (scandirat, scandirat64) -#endif diff --git a/dirent/scandirat64.c b/dirent/scandirat64.c index 520ae7c..7e5e209 100644 --- a/dirent/scandirat64.c +++ b/dirent/scandirat64.c @@ -15,15 +15,18 @@ License along with the GNU C Library; if not, see . */ +#define scandirat __no_scandirat_decl #include - -/* scandirat.c defines scandirat64 as an alias if _DIRENT_MATCHES_DIRENT64. */ -#if !_DIRENT_MATCHES_DIRENT64 - -# define SCANDIRAT scandirat64 -# define SCANDIR_TAIL __scandir64_tail -# define DIRENT_TYPE struct dirent64 - -# include - +#undef scandirat + +int +scandirat64 (int dfd, const char *dir, struct dirent64 ***namelist, + int (*select) (const struct dirent64 *), + int (*cmp) (const struct dirent64 **, const struct dirent64 **)) +{ + return __scandir64_tail (__opendirat (dfd, dir), namelist, select, cmp); +} + +#if _DIRENT_MATCHES_DIRENT64 +weak_alias (scandirat64, scandirat) #endif diff --git a/include/dirent.h b/include/dirent.h index cc8f189..f8f1942 100644 --- a/include/dirent.h +++ b/include/dirent.h @@ -57,25 +57,23 @@ extern int __scandir_tail (DIR *dp, int (*cmp) (const struct dirent **, const struct dirent **)) attribute_hidden; -# if _DIRENT_MATCHES_DIRENT64 -# define __scandir64_tail (dp, namelist, select, cmp) \ - __scandir_tail (dp, (struct dirent ***) (namelist), \ - (int (*) (const struct dirent *)) (select), \ - (int (*) (const struct dirent **, \ - const struct dirent **)) (cmp)) -# else +# if !_DIRENT_MATCHES_DIRENT64 +extern int __scandir_tail (DIR *dp, + struct dirent ***namelist, + int (*select) (const struct dirent *), + int (*cmp) (const struct dirent **, + const struct dirent **)) + attribute_hidden; +# endif extern int __scandir64_tail (DIR *dp, struct dirent64 ***namelist, int (*select) (const struct dirent64 *), int (*cmp) (const struct dirent64 **, const struct dirent64 **)) attribute_hidden; -# endif libc_hidden_proto (__rewinddir) extern __typeof (scandirat) __scandirat; -libc_hidden_proto (__scandirat) -libc_hidden_proto (scandirat64) # if IS_IN (rtld) && !defined NO_RTLD_HIDDEN extern __typeof (__rewinddir) __rewinddir attribute_hidden; diff --git a/sysdeps/unix/sysv/linux/arm/scandir64.c b/sysdeps/unix/sysv/linux/arm/scandir64.c deleted file mode 100644 index 506fd88..0000000 --- a/sysdeps/unix/sysv/linux/arm/scandir64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/m68k/scandir64.c b/sysdeps/unix/sysv/linux/m68k/scandir64.c deleted file mode 100644 index 506fd88..0000000 --- a/sysdeps/unix/sysv/linux/m68k/scandir64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/scandir64.c b/sysdeps/unix/sysv/linux/powerpc/powerpc32/scandir64.c deleted file mode 100644 index 506fd88..0000000 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/scandir64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/scandir64.c b/sysdeps/unix/sysv/linux/s390/s390-32/scandir64.c deleted file mode 100644 index 506fd88..0000000 --- a/sysdeps/unix/sysv/linux/s390/s390-32/scandir64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/i386/scandir64.c b/sysdeps/unix/sysv/linux/scandir64.c similarity index 81% rename from sysdeps/unix/sysv/linux/i386/scandir64.c rename to sysdeps/unix/sysv/linux/scandir64.c index 50590c3..efb502f 100644 --- a/sysdeps/unix/sysv/linux/i386/scandir64.c +++ b/sysdeps/unix/sysv/linux/scandir64.c @@ -15,26 +15,28 @@ License along with the GNU C Library; if not, see . */ +#define scandir __no_scandir_decl #include +#undef scandir -#define SCANDIR __scandir64 -#define SCANDIR_TAIL __scandir64_tail -#define DIRENT_TYPE struct dirent64 - -#include - -#undef SCANDIR -#undef SCANDIR_TAIL -#undef DIRENT_TYPE - -#include +int +__scandir64 (const char *dir, struct dirent64 ***namelist, + int (*select) (const struct dirent64 *), + int (*cmp) (const struct dirent64 **, const struct dirent64 **)) +{ + return __scandir64_tail (__opendir (dir), namelist, select, cmp); +} +#if _DIRENT_MATCHES_DIRENT64 +weak_alias (__scandir64, scandir64) +weak_alias (__scandir64, scandir) +#else +# include versioned_symbol (libc, __scandir64, scandir64, GLIBC_2_2); - -#if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2) -# include -# include -# include "olddirent.h" +# if SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2) +# include +# include +# include "olddirent.h" int __old_scandir64 (const char *dir, struct __old_dirent64 ***namelist, @@ -133,4 +135,5 @@ __old_scandir64 (const char *dir, struct __old_dirent64 ***namelist, } compat_symbol (libc, __old_scandir64, scandir64, GLIBC_2_1); -#endif +# endif /* SHLIB_COMPAT (libc, GLIBC_2_1, GLIBC_2_2) */ +#endif /* _DIRENT_MATCHES_DIRENT64 */ diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/scandir64.c b/sysdeps/unix/sysv/linux/sparc/sparc32/scandir64.c deleted file mode 100644 index 506fd88..0000000 --- a/sysdeps/unix/sysv/linux/sparc/sparc32/scandir64.c +++ /dev/null @@ -1 +0,0 @@ -#include From patchwork Fri Mar 2 18:59:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 130576 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp1602667lja; Fri, 2 Mar 2018 11:01:11 -0800 (PST) X-Google-Smtp-Source: AG47ELvd8I9W5lrSTmVbOPCi7k7s7napcTSFJwF0pm9TNUrxgbFunjc/r4FRYNj+f0HMHErh0piG X-Received: by 2002:a17:902:6b48:: with SMTP id g8-v6mr6087731plt.151.1520017271798; Fri, 02 Mar 2018 11:01:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520017271; cv=none; d=google.com; s=arc-20160816; b=GRwaNWokVl+Hq1c/2hXSFgpndyXfe05UfY9RM9gBN/e7d5Y5OdMaUjkJnossey0Oox smr3g1TEFhM/qsdMv7OBb1HiY6R8abZRGks+ZpsXPsoxSeT5Zsd12x5P/drOG9B7h2fy 9h9KgTxGbtl6U0+88ggTyB/TR/KRU3gu0jC6Ox4x+eKtNb+hwmw4rCDlmWVs08wORpA7 Hj9oEcj8zobSVf1uFeK01EEvKb2fWX7Z+l+PW1+R2gdWzuhefEXi1Mjlp9qUqFvrHz/3 sESqfCz/qan6vpBKSSTGkXXu47r1eUWo1lTCKXTunX6v1H3VyLlfAoKfzfXBC6Os9pGz ukZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from:delivered-to :sender:list-help:list-post:list-archive:list-subscribe :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=jxEHhsSw28S7tJJuN0kt3HrlKOQzFYvoFdRyVEkLopU=; b=MH+88qcDZYU3itO77uAsjYuk99gm4vORcVWTaZSrFIWMoaz9kKZFx6lAMyNfXW7a/s 4DUth+Y2WreMXBPgmqxUNRywffWfm/ugIspjXKJv5jhcHDJ1G+pSHVhktOdh/lYDw70I NyKqZI+ajko9YD2tobMjhVJYmou310tFWYRX79FqC9za2WRuIJ/eAFtMdgdLWcGKfjga NmBF+8NPmMLgYb+7O541+d4RNT3d9xNmB4BDbMQHqlNRHq6U9COra4ChB1OD0CB66F6D oApVJPhs+yxlQKyU1WrUqTLjcCke10R6uMuE5Nb0HY2nmXZSvu/crp1Lptu97hYdn9vg HlHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=DNRVo2C8; spf=pass (google.com: domain of libc-alpha-return-90742-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90742-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id h8-v6si5272895pli.210.2018.03.02.11.01.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 11:01:11 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90742-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=DNRVo2C8; spf=pass (google.com: domain of libc-alpha-return-90742-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90742-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=bICJeYwJpgjLWyDTs5FeW0WgAcna/G3 yElCJfI1OvZL6AfHTUdTMKYoKIezBi8wE6PekM12E6XWCX4T36z0kv6ojut1P5hs hT+vg0utjt6Q+Su9mLIrgnqS86UU5n4gawtExv1iFMpWGhmiutFMKOaywWyFWa/L 7i4ClCycLObg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=7UcRI6FmznfmpcirIa5WDP/iXd0=; b=DNRVo 2C8Qkdu/VrwsWqdXTFemaR824A1fSNy7mgWlv20uiISX6qswdNgTSIz0HLrUcP48 lGoFjCDRHA48Sp/s5ii7vO/zSvtBHxNB0QshXT85lIfZ+mbX2nHg//g00Do/P2Hh BkOyGz09MFLBC6RxhywqpIpDdpEHNUU0IDVMtU= Received: (qmail 98834 invoked by alias); 2 Mar 2018 18:59:55 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 98095 invoked by uid 89); 2 Mar 2018 18:59:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=Consolidate, 1517 X-HELO: mail-qt0-f196.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=jxEHhsSw28S7tJJuN0kt3HrlKOQzFYvoFdRyVEkLopU=; b=oe1iprSu/TywKvx9Qb+YS5+WIf6Xs0Oy5si/59CaAS/qqqJtFEjEs9rPnB+p+l8Jf8 QHeCwXYxD++IAaRRT3K4ijZ+zjBRKg5d6jhed+1zVq+Y7rgjH1z3i6qjtT3A/1NmBAjq dFcTUMcy8kONxcj03uW+EuH/Qxk+bK4kDUR22eNaIFk70qSjlcB7Y8z4mLziekDDVXJ5 H7YiSbJMOAZJLCvQFzfhrDMc/k+07WOudX7JjXo5dA1JOauQod5FX3nrS98lBftqyM2b 9PgFCAxD8dKaupzclxm0rcjWzchW9/07WbjCPGpF9HIVpU+zDABRudv9pCTcw1WNuaIK qdlg== X-Gm-Message-State: AElRT7HSp/szq2hWyDXzND//rK7zRSErSM8/6+ItO0H42WqZNsAJ58aq O7TIsTFZ7YgTg6i/pT+f7Vs4LNmrYL8= X-Received: by 10.237.38.2 with SMTP id z2mr9907267qtc.319.1520017179283; Fri, 02 Mar 2018 10:59:39 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 6/7] Consolidate alphasort{64} and versionsort{64} implementation Date: Fri, 2 Mar 2018 15:59:24 -0300 Message-Id: <1520017165-15830-6-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1520017165-15830-1-git-send-email-adhemerval.zanella@linaro.org> References: <1520017165-15830-1-git-send-email-adhemerval.zanella@linaro.org> This patch consolidates both alphasort{64} and versionsort{64} implementation on just the default dirent/alphasort{64}c and dirent/versionsort{64} respectively. It changes the logic to follow the conventions used on other code consolidation: * the non-LFS variant is only built for _DIRENT_MATCHES_DIRENT64 being 0. * the LFS variant is always built and aliased to getdents for ABIs that define _DIRENT_MATCHES_DIRENT64 to 1. Also on Linux the compat symbol for old non-LFS dirent64 definition requires a platform-specific scandir64.c. For powerpc32 and sparcv9 it requires to add specific arch-implementation to override the generic Linux one because neither ABI exports an compat symbol for non-LFS alphasort64 and versionsort64 variant. Considering both architectures do export other compat symbols for other dirent.h functions I think this is a bug (I need confirmation). Checked on aarch64-linux-gnu, x86_64-linux-gnu, i686-linux-gnu, sparcv9-linux-gnu, sparc64-linux-gnu, powerpc-linux-gnu, and powerpc64le-linux-gnu. * dirent/alphasort.c (alphasort): Build iff _DIRENT_MATCHES_DIRENT64 is defined. * dirent/versionsort.c (versionsort): Likewise. * dirent/alphasort64.c (alphasort64): Build regardless and alias to alphasort if _DIRENT_MATCHES_DIRENT64 is defined. * dirent/versionsort64.c (versionsort64): Likewise. * sysdeps/unix/sysv/linux/i386/alphasort64.c: Remove file. * sysdeps/unix/sysv/linux/arm/alphasort64.c: Likewise. * sysdeps/unix/sysv/linux/arm/versionsort64.c: Likewise. * sysdeps/unix/sysv/linux/m68k/alphasort64.c: Likewise. * sysdeps/unix/sysv/linux/m68k/versionsort64.c: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/alphasort64.c: Likewise. * sysdeps/unix/sysv/linux/s390/s390-32/versionsort64.c: Likewise. * sysdeps/unix/sysv/linux/i386/versionsort64.c: Likewise. * sysdeps/unix/sysv/linux/alphasort64.c: New file. * sysdeps/unix/sysv/linux/versionsort64.c: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/alphasort64.c: Likewise. * sysdeps/unix/sysv/linux/powerpc/powerpc32/versionsort64.c: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/alphasort64.c: Likewise. * sysdeps/unix/sysv/linux/sparc/sparc32/versionsort64.c: Likewise. --- ChangeLog | 21 +++++++++++++++++++++ dirent/alphasort.c | 13 ++----------- dirent/alphasort64.c | 7 ++++--- dirent/versionsort.c | 12 ++---------- dirent/versionsort64.c | 7 ++++--- sysdeps/unix/sysv/linux/{i386 => }/alphasort64.c | 22 +++++++++++----------- sysdeps/unix/sysv/linux/arm/alphasort64.c | 1 - sysdeps/unix/sysv/linux/arm/versionsort64.c | 1 - sysdeps/unix/sysv/linux/m68k/alphasort64.c | 1 - sysdeps/unix/sysv/linux/m68k/versionsort64.c | 1 - .../sysv/linux/powerpc/powerpc32/alphasort64.c | 3 +++ .../sysv/linux/powerpc/powerpc32/versionsort64.c | 3 +++ sysdeps/unix/sysv/linux/s390/s390-32/alphasort64.c | 1 - .../unix/sysv/linux/s390/s390-32/versionsort64.c | 1 - .../unix/sysv/linux/sparc/sparc32/alphasort64.c | 3 +++ .../unix/sysv/linux/sparc/sparc32/versionsort64.c | 3 +++ sysdeps/unix/sysv/linux/{i386 => }/versionsort64.c | 22 +++++++++++----------- 17 files changed, 67 insertions(+), 55 deletions(-) rename sysdeps/unix/sysv/linux/{i386 => }/alphasort64.c (77%) delete mode 100644 sysdeps/unix/sysv/linux/arm/alphasort64.c delete mode 100644 sysdeps/unix/sysv/linux/arm/versionsort64.c delete mode 100644 sysdeps/unix/sysv/linux/m68k/alphasort64.c delete mode 100644 sysdeps/unix/sysv/linux/m68k/versionsort64.c create mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc32/alphasort64.c create mode 100644 sysdeps/unix/sysv/linux/powerpc/powerpc32/versionsort64.c delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/alphasort64.c delete mode 100644 sysdeps/unix/sysv/linux/s390/s390-32/versionsort64.c create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/alphasort64.c create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/versionsort64.c rename sysdeps/unix/sysv/linux/{i386 => }/versionsort64.c (77%) -- 2.7.4 diff --git a/dirent/alphasort.c b/dirent/alphasort.c index a6cd151..6b2a707 100644 --- a/dirent/alphasort.c +++ b/dirent/alphasort.c @@ -15,23 +15,14 @@ License along with the GNU C Library; if not, see . */ -/* We need to avoid the header declaration of alphasort64, because - the types don't match alphasort and then the compiler will - complain about the mismatch when we do the alias below. */ -#define alphasort64 __renamed_alphasort64 - #include -#undef alphasort64 - -#include +#if !_DIRENT_MATCHES_DIRENT64 +# include int alphasort (const struct dirent **a, const struct dirent **b) { return strcoll ((*a)->d_name, (*b)->d_name); } - -#if _DIRENT_MATCHES_DIRENT64 -weak_alias (alphasort, alphasort64) #endif diff --git a/dirent/alphasort64.c b/dirent/alphasort64.c index 3a47a97..b822333 100644 --- a/dirent/alphasort64.c +++ b/dirent/alphasort64.c @@ -15,16 +15,17 @@ License along with the GNU C Library; if not, see . */ +#define alphasort __no_alphasort_decl #include +#undef alphasort #include -/* alphasort.c defines alphasort64 as an alias if _DIRENT_MATCHES_DIRENT64. */ -#if !_DIRENT_MATCHES_DIRENT64 - int alphasort64 (const struct dirent64 **a, const struct dirent64 **b) { return strcoll ((*a)->d_name, (*b)->d_name); } +#if _DIRENT_MATCHES_DIRENT64 +weak_alias (alphasort64, alphasort) #endif diff --git a/dirent/versionsort.c b/dirent/versionsort.c index 5ec15e8..ca38c2d 100644 --- a/dirent/versionsort.c +++ b/dirent/versionsort.c @@ -15,16 +15,10 @@ License along with the GNU C Library; if not, see . */ -/* We need to avoid the header declaration of versionsort64, because - the types don't match versionsort and then the compiler will - complain about the mismatch when we do the alias below. */ -#define versionsort64 __renamed_versionsort64 - #include -#undef versionsort64 - -#include +#if !_DIRENT_MATCHES_DIRENT64 +# include int versionsort (const struct dirent **a, const struct dirent **b) @@ -32,6 +26,4 @@ versionsort (const struct dirent **a, const struct dirent **b) return __strverscmp ((*a)->d_name, (*b)->d_name); } -#if _DIRENT_MATCHES_DIRENT64 -weak_alias (versionsort, versionsort64) #endif diff --git a/dirent/versionsort64.c b/dirent/versionsort64.c index 7689c26..8f47e60 100644 --- a/dirent/versionsort64.c +++ b/dirent/versionsort64.c @@ -15,16 +15,17 @@ License along with the GNU C Library; if not, see . */ +#define versionsort __no_versionsort_decl #include +#undef versionsort #include -/* versionsort.c defines a versionsort64 alias if _DIRENT_MATCHES_DIRENT64. */ -#if !_DIRENT_MATCHES_DIRENT64 - int versionsort64 (const struct dirent64 **a, const struct dirent64 **b) { return __strverscmp ((*a)->d_name, (*b)->d_name); } +#if !_DIRENT_MATCHES_DIRENT64 +weak_alias (versionsort64, versionsort) #endif diff --git a/sysdeps/unix/sysv/linux/i386/alphasort64.c b/sysdeps/unix/sysv/linux/alphasort64.c similarity index 77% rename from sysdeps/unix/sysv/linux/i386/alphasort64.c rename to sysdeps/unix/sysv/linux/alphasort64.c index ee3b00b..7eee9d0 100644 --- a/sysdeps/unix/sysv/linux/i386/alphasort64.c +++ b/sysdeps/unix/sysv/linux/alphasort64.c @@ -15,7 +15,9 @@ License along with the GNU C Library; if not, see . */ +#define alphasort __no_alphasort_decl #include +#undef alphasort #include int @@ -24,17 +26,14 @@ __alphasort64 (const struct dirent64 **a, const struct dirent64 **b) return strcoll ((*a)->d_name, (*b)->d_name); } -#include - +#ifdef _DIRENT_MATCHES_DIRENT64 +weak_alias (__alphasort64, alphasort64) +weak_alias (__alphasort64, alphasort) +#else +# include versioned_symbol (libc, __alphasort64, alphasort64, GLIBC_2_2); - -#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) - -#include - -int -__old_alphasort64 (const struct __old_dirent64 **a, - const struct __old_dirent64 **b); +# if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) +# include int attribute_compat_text_section @@ -45,4 +44,5 @@ __old_alphasort64 (const struct __old_dirent64 **a, } compat_symbol (libc, __old_alphasort64, alphasort64, GLIBC_2_1); -#endif +# endif /* SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) */ +#endif /* _DIRENT_MATCHES_DIRENT64 */ diff --git a/sysdeps/unix/sysv/linux/arm/alphasort64.c b/sysdeps/unix/sysv/linux/arm/alphasort64.c deleted file mode 100644 index 0b5ae47..0000000 --- a/sysdeps/unix/sysv/linux/arm/alphasort64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/arm/versionsort64.c b/sysdeps/unix/sysv/linux/arm/versionsort64.c deleted file mode 100644 index 144b691..0000000 --- a/sysdeps/unix/sysv/linux/arm/versionsort64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/m68k/alphasort64.c b/sysdeps/unix/sysv/linux/m68k/alphasort64.c deleted file mode 100644 index 0b5ae47..0000000 --- a/sysdeps/unix/sysv/linux/m68k/alphasort64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/m68k/versionsort64.c b/sysdeps/unix/sysv/linux/m68k/versionsort64.c deleted file mode 100644 index 144b691..0000000 --- a/sysdeps/unix/sysv/linux/m68k/versionsort64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/alphasort64.c b/sysdeps/unix/sysv/linux/powerpc/powerpc32/alphasort64.c new file mode 100644 index 0000000..c7de3a7 --- /dev/null +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/alphasort64.c @@ -0,0 +1,3 @@ +/* Although powerpc32 define _DIRENT_MATCHES_DIRENT64=0 and have compat + mode for 2.1, it does have a compat symbol for alphasort64. */ +#include diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/versionsort64.c b/sysdeps/unix/sysv/linux/powerpc/powerpc32/versionsort64.c new file mode 100644 index 0000000..ee0e866 --- /dev/null +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/versionsort64.c @@ -0,0 +1,3 @@ +/* Although powerpc32 define _DIRENT_MATCHES_DIRENT64=0 and have compat + mode for 2.1, it does have a compat symbol for alphasort64. */ +#include diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/alphasort64.c b/sysdeps/unix/sysv/linux/s390/s390-32/alphasort64.c deleted file mode 100644 index 0b5ae47..0000000 --- a/sysdeps/unix/sysv/linux/s390/s390-32/alphasort64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/versionsort64.c b/sysdeps/unix/sysv/linux/s390/s390-32/versionsort64.c deleted file mode 100644 index 144b691..0000000 --- a/sysdeps/unix/sysv/linux/s390/s390-32/versionsort64.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/alphasort64.c b/sysdeps/unix/sysv/linux/sparc/sparc32/alphasort64.c new file mode 100644 index 0000000..3970086 --- /dev/null +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/alphasort64.c @@ -0,0 +1,3 @@ +/* Although sparc32 define _DIRENT_MATCHES_DIRENT64=0 and have compat + mode for 2.1, it does have a compat symbol for alphasort64. */ +#include diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/versionsort64.c b/sysdeps/unix/sysv/linux/sparc/sparc32/versionsort64.c new file mode 100644 index 0000000..b195442 --- /dev/null +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/versionsort64.c @@ -0,0 +1,3 @@ +/* Although sparc32 define _DIRENT_MATCHES_DIRENT64=0 and have compat + mode for 2.1, it does have a compat symbol for alphasort64. */ +#include diff --git a/sysdeps/unix/sysv/linux/i386/versionsort64.c b/sysdeps/unix/sysv/linux/versionsort64.c similarity index 77% rename from sysdeps/unix/sysv/linux/i386/versionsort64.c rename to sysdeps/unix/sysv/linux/versionsort64.c index 1777eb2..a3a3a66 100644 --- a/sysdeps/unix/sysv/linux/i386/versionsort64.c +++ b/sysdeps/unix/sysv/linux/versionsort64.c @@ -15,7 +15,9 @@ License along with the GNU C Library; if not, see . */ +#define versionsort __no_versionsort_decl #include +#undef versionsort #include int @@ -24,17 +26,14 @@ __versionsort64 (const struct dirent64 **a, const struct dirent64 **b) return __strverscmp ((*a)->d_name, (*b)->d_name); } -#include - +#if _DIRENT_MATCHES_DIRENT64 +weak_alias (__versionsort64, versionsort64) +weak_alias (__versionsort64, versionsort) +#else +# include versioned_symbol (libc, __versionsort64, versionsort64, GLIBC_2_2); - -#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) - -#include - -int -__old_versionsort64 (const struct __old_dirent64 **a, - const struct __old_dirent64 **b); +# if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) +# include int attribute_compat_text_section @@ -45,4 +44,5 @@ __old_versionsort64 (const struct __old_dirent64 **a, } compat_symbol (libc, __old_versionsort64, versionsort64, GLIBC_2_1); -#endif +# endif /* SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) */ +#endif /* _DIRENT_MATCHES_DIRENT64 */ From patchwork Fri Mar 2 18:59:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 130575 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp1602430lja; Fri, 2 Mar 2018 11:01:02 -0800 (PST) X-Google-Smtp-Source: AG47ELtBpgv1UqDxeCdWs+PuCE6osFEGiVta9LD8Poo1qp3kRrgkBYJQMfGnnI4tyGxCM8UYXLvP X-Received: by 2002:a17:902:8c93:: with SMTP id t19-v6mr6082745plo.304.1520017262458; Fri, 02 Mar 2018 11:01:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520017262; cv=none; d=google.com; s=arc-20160816; b=ImpY0iM7bM77jKzSIBc2rxs/iPAokz9el0PUIO/KvZPUemHnZ7ml/i5z6mPgZ/y3to NWk1uiWQGls6gep9i+E4FoU+YWlkNQRJGvOdEJXfrT8WhSxRnVlPkSVZ7Rl4spgiShJK RuazT1SME8/sry5iC2gzF44mH9/xhavY9FstXPpQuNyYWJ5KcWX7hmRap1stLbr9hjkM dRLGAOmB2UA728M/YYKiew0X789CtM990PQuVzfGm4GT1sYPii1ZeQnqPAW/icw6y0eL 5Vh5FVePEr3r1YBcG1RjGCEM+op9hLsPE8QCakpDqI513mHla1F//NyYjHW56k8O3Cqm Vtfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:to:from:delivered-to :sender:list-help:list-post:list-archive:list-subscribe :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=Ttne6RfRWZNqK+bAAGmZbf6rQnt3WMRo6KZ5qk8Um3o=; b=xa4Z+s2Tn/nS2dkdsi1NpQpitDhTScB/3xIAIlPrQvwJySXcKsTb4DlZUnMcAn2tGV aUX+y/sJoN7clc64LPy2wREpsNAdTxBRRoZdRCju21Hd4QGgRA/gS7Cm4QKTowPMJjQJ fmL9c+fXdXCGVObtHHO95unLDOJ6GKqgw4S+zTknCpAW5eJ3wt2pnHpZ9oaT83+MEaRW HEBOXBKMFNjL/BCnd7sTL5qb2P8t1cab1Y//OP0gol8ZgYaxHSkZfO3Kq+lugERB9997 PMf10ODWD/w+XxK2YM/4+6wNa7IMPdGBYVZYve6pVaCiBbI3u+2MJ5jff2r5k9cXvNO0 1Vkg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=vr/7Qt8Z; spf=pass (google.com: domain of libc-alpha-return-90741-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90741-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id p8-v6si2793139plk.642.2018.03.02.11.01.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Mar 2018 11:01:02 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-90741-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=vr/7Qt8Z; spf=pass (google.com: domain of libc-alpha-return-90741-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-90741-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=OpihLZFUU1RzYe1RJ8AzG0QBvZyVJfQ 4Pdk0qLXFY9I74U6V/Yt8eWPHjic1eMhmJxii0sWxeEwUb6aUBNpI4fFU6+di6+x oTYvmmX2z1bbrRZglo5SWNLFd0FqcIXUeTPBCyuOay2+AGBn6r+tX6LHlzUzKCAV yJL4/hEq8Bxw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=S0rHK298Td/uKPYRUQptf/RCblQ=; b=vr/7Q t8ZP2IeG7OX1lKiOSlLw0VQIZmp+0qz+g1I6z5biZ8W/8aYP6DNex7ZOphRHa+yo ZiIHVJmqWZxk8ClCJRFUTH4pqn55P+G4JzEVBaWt24GA5u1EDMUkP4m4t8A2+iDM 4GnXkoREDLBcrHFuVnDTZT+bGA6td//n9d+2Ek= Received: (qmail 98799 invoked by alias); 2 Mar 2018 18:59:54 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 98062 invoked by uid 89); 2 Mar 2018 18:59:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qt0-f193.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Ttne6RfRWZNqK+bAAGmZbf6rQnt3WMRo6KZ5qk8Um3o=; b=oMbYiJ74/RSVPfAidMspJH/ja0oioBDiWPYOZCpq2X/OErS2JZ6GInVxUxtTTvOvLh 38rEKoYMDcUBYGiUCS7E3hJFye9641GR3mSgHkqPK5Ka/yXeRXJVTpmEdTmOmLHElDfX eigmsrsmGU6kTLhHlBjmufh5hO2inIy/njsx77vMg+Dp3RZiDPSRA/Lm5wMo+tataLGj 5jP8oMZqIn+/WyjCLquXIbunzcOfwpbZtiLCfMcEMZ3b2fk67Xr8gSOWSKXN6IPvLSb5 Sbm+zlhiQSzVMoQbKiQXr61kT1o01hfsjYH+yhfoEB6UIgYaSCdEFavOaTTS7Z9vZ1Yf uPcQ== X-Gm-Message-State: AElRT7G9v/6j3yaR32KeyOtcVBV3RFaXnp2T+w8ilAMC4y08a7lhLthq f1fw8d5kcaDjeJvPnb5RC/yD4Qy5AUg= X-Received: by 10.200.83.12 with SMTP id t12mr10445659qtn.333.1520017180603; Fri, 02 Mar 2018 10:59:40 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 7/7] Consolidate getdirentries{64} implementation Date: Fri, 2 Mar 2018 15:59:25 -0300 Message-Id: <1520017165-15830-7-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1520017165-15830-1-git-send-email-adhemerval.zanella@linaro.org> References: <1520017165-15830-1-git-send-email-adhemerval.zanella@linaro.org> This patch consolidates Linux getdirentries{64} implementation on just the default sysdeps/unix/sysv/linux/getdirentries{64} ones. The default implementation handles the Linux requirements: * getdirentries is only built for _DIRENT_MATCHES_DIRENT64 being 0. * getdirentries64 is always built and aliased to getdents for ABIs that define _DIRENT_MATCHES_DIRENT64 to 1. Checked on aarch64-linux-gnu, x86_64-linux-gnu, i686-linux-gnu, sparcv9-linux-gnu, sparc64-linux-gnu, powerpc-linux-gnu, and powerpc64le-linux-gnu. * sysdeps/unix/sysv/linux/getdirentries.c (getdirentries): Build iff _DIRENT_MATCHES_DIRENT64 is not defined. * sysdeps/unix/sysv/linux/getdirentries64.c (getdirentries64): Open implementation and alias to getdirentries if _DIRENT_MATCHES_DIRENT64 is defined. * sysdeps/unix/sysv/linux/wordsize-64/getdirentries.c: Remove file. * sysdeps/unix/sysv/linux/wordsize-64/getdirentries64.c: Remove file. --- ChangeLog | 8 +++++ sysdeps/unix/sysv/linux/getdirentries.c | 21 +++++------ sysdeps/unix/sysv/linux/getdirentries64.c | 41 ++++++++++++++++++++-- .../unix/sysv/linux/wordsize-64/getdirentries.c | 3 -- .../unix/sysv/linux/wordsize-64/getdirentries64.c | 1 - 5 files changed, 54 insertions(+), 20 deletions(-) delete mode 100644 sysdeps/unix/sysv/linux/wordsize-64/getdirentries.c delete mode 100644 sysdeps/unix/sysv/linux/wordsize-64/getdirentries64.c -- 2.7.4 diff --git a/sysdeps/unix/sysv/linux/getdirentries.c b/sysdeps/unix/sysv/linux/getdirentries.c index bc40292..23f626b 100644 --- a/sysdeps/unix/sysv/linux/getdirentries.c +++ b/sysdeps/unix/sysv/linux/getdirentries.c @@ -16,26 +16,21 @@ . */ #include -#include - -#ifndef GETDIRENTRIES -# define GETDIRENTRIES getdirentries -# define __GETDENTS __getdents -#else -# define off_t off64_t -# define __lseek __lseek64 -#endif + +#if !_DIRENT_MATCHES_DIRENT64 +# include ssize_t -GETDIRENTRIES (int fd, char *buf, size_t nbytes, off_t *basep) +getdirentries (int fd, char *buf, size_t nbytes, off_t *basep) { - off_t base = __lseek (fd, (off_t) 0, SEEK_CUR); - ssize_t result; + off_t base = __lseek (fd, 0, SEEK_CUR); - result = __GETDENTS (fd, buf, nbytes); + ssize_t result = __getdents (fd, buf, nbytes); if (result != -1) *basep = base; return result; } + +#endif diff --git a/sysdeps/unix/sysv/linux/getdirentries64.c b/sysdeps/unix/sysv/linux/getdirentries64.c index e486a36..c1a23a7 100644 --- a/sysdeps/unix/sysv/linux/getdirentries64.c +++ b/sysdeps/unix/sysv/linux/getdirentries64.c @@ -1,3 +1,38 @@ -#define GETDIRENTRIES getdirentries64 -#define __GETDENTS __getdents64 -#include "getdirentries.c" +/* Copyright (C) 1993-2018 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 + . */ + +#define getdirentries __no_getdirentries_decl +#include +#undef getdirentries +#include + +ssize_t +getdirentries64 (int fd, char *buf, size_t nbytes, off64_t *basep) +{ + off64_t base = __lseek64 (fd, (off_t) 0, SEEK_CUR); + + ssize_t result = __getdents64 (fd, buf, nbytes); + + if (result != -1) + *basep = base; + + return result; +} + +#if _DIRENT_MATCHES_DIRENT64 +weak_alias (getdirentries64, getdirentries) +#endif diff --git a/sysdeps/unix/sysv/linux/wordsize-64/getdirentries.c b/sysdeps/unix/sysv/linux/wordsize-64/getdirentries.c deleted file mode 100644 index 298d1e9..0000000 --- a/sysdeps/unix/sysv/linux/wordsize-64/getdirentries.c +++ /dev/null @@ -1,3 +0,0 @@ -#include "../getdirentries.c" - -weak_alias (getdirentries, getdirentries64) diff --git a/sysdeps/unix/sysv/linux/wordsize-64/getdirentries64.c b/sysdeps/unix/sysv/linux/wordsize-64/getdirentries64.c deleted file mode 100644 index 622baf0..0000000 --- a/sysdeps/unix/sysv/linux/wordsize-64/getdirentries64.c +++ /dev/null @@ -1 +0,0 @@ -/* Defined in getdirentries.c. */