From nobody Wed Aug 24 19:44:06 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MCc3q1dh3z4Zhch; Wed, 24 Aug 2022 19:44:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MCc3p46Pgz3TW4; Wed, 24 Aug 2022 19:44:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661370246; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ckCj5OTEGvjCmLuEskrwIfdIi4p4o73fgj27jAMqNUU=; b=HnZt2Bowk1eQNPzl0UsJWFSyDmZTTvsuNdaUXeX4EvaOfRZoex+nwssJz7kX3jmVvl1OdP oS2yXOUnSK2pAVAfh4ghpNAKAaXoHGQppDmJ/xyTc1XE3qCYOwOHZZGnqUHLpt9lwmdR1J Mh1/ZY4K4M/vOy2FiZ5i3O8j57bD2TN5bP1uaKGoUQJ2PLQc0OX20SRvkJsqshxSSiyiSh PyKw6hEmNjPfeGn2ZI4lwY/WJUpLzwOIGZsp1fT06HdhHv8L2gJt5ISLmFzJOe0g7+Odx7 TRXa3UMoDNVCC17pXT5xLWa/4xDrWSQqQR/uuCwrZCwRFWFSEGbSxzGrpalaUg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MCc3p306nzLKF; Wed, 24 Aug 2022 19:44:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 27OJi6Wx096933; Wed, 24 Aug 2022 19:44:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27OJi6ML096932; Wed, 24 Aug 2022 19:44:06 GMT (envelope-from git) Date: Wed, 24 Aug 2022 19:44:06 GMT Message-Id: <202208241944.27OJi6ML096932@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: cb6e97f4dae6 - main - libc: split scandir() into scandir_dirp() and proper scandir() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: cb6e97f4dae6d0b631b65f23baf2d4c67120f672 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661370246; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ckCj5OTEGvjCmLuEskrwIfdIi4p4o73fgj27jAMqNUU=; b=TC8Y/fOH38/7EASGQobhjZ4z5EEOFcXtyvWi8JpYPZMBrfQyYIEBueOb4seG403kqf6u7y UhPKaoA4SFQ1PGlcjZUdTL0Fdl44fg0yURLu8OaXHtNObj7PDZMwcXQ0r4J50TYc68z/vy +33MiJQEltAoUcGFOHVLmjLwpAfkoF2OpkDGnH09hr4AqMQZc6EkrecaEdO08w8NS3tIpz zOxGDqtSZb5iyn6zaEKecdNZ55au0AcVtY874rQS7jWzYG/kWzz8zoPd6TiLUT5G7pdDXE f71+FcKBcPxZAMSTHlANGsOcUdhEc4NSKtFxkib+acEnwpC/ey84LKW9BxTIdg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1661370246; a=rsa-sha256; cv=none; b=neGM5M40n31RWECqLmWq4KWK1e/qZ+VFbw99bjv1Mf/jo8ch24rI6Z7jXYbOFCUIe8tYrQ wAgAQktxPeq+5dcKDDn0I9DpaGfmJm1O9+VbVdQU8SQjmWjpJo/1STAQXGRGcTmOPdokhG C75032RWmjMdqCdR6DJmiBBdaOVZjwpXpRJJ2piBo6y8ipCpaq6GNhoGXUwPKv5s/OwnC8 dbrsl1OVvxyNTv6/V5msjtbcC7jQKTwQ9U9P6Y4GOdF6GO3R/6NRvVVgbVqFa/xXqU447O X/gXlIpgANY8ivivb/1GGjRGtEmiCvA4Pksev/Ihq/0yA7F8AJIybvq47VzIcQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=cb6e97f4dae6d0b631b65f23baf2d4c67120f672 commit cb6e97f4dae6d0b631b65f23baf2d4c67120f672 Author: Konstantin Belousov AuthorDate: 2022-08-23 04:30:40 +0000 Commit: Konstantin Belousov CommitDate: 2022-08-24 19:26:00 +0000 libc: split scandir() into scandir_dirp() and proper scandir() The new helper scandir_dirp() takes DIR *, i.e. a pre-opened directory, instead of the directory name. Reviewed by: emaste, imp, kevans, markj, Aymeric Wibo Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D36301 --- lib/libc/gen/scandir.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/lib/libc/gen/scandir.c b/lib/libc/gen/scandir.c index 10cd7633dac1..4cfc823e4f94 100644 --- a/lib/libc/gen/scandir.c +++ b/lib/libc/gen/scandir.c @@ -64,22 +64,18 @@ typedef DECLARE_BLOCK(int, dcomp_block, const struct dirent **, static int alphasort_thunk(void *thunk, const void *p1, const void *p2); #endif -int +static int #ifdef I_AM_SCANDIR_B -scandir_b(const char *dirname, struct dirent ***namelist, select_block select, +scandir_b_dirp(DIR *dirp, struct dirent ***namelist, select_block select, dcomp_block dcomp) #else -scandir(const char *dirname, struct dirent ***namelist, +scandir_dirp(DIR *dirp, struct dirent ***namelist, int (*select)(const struct dirent *), int (*dcomp)(const struct dirent **, - const struct dirent **)) + const struct dirent **)) #endif { struct dirent *d, *p, **names = NULL; size_t arraysz, numitems; - DIR *dirp; - - if ((dirp = opendir(dirname)) == NULL) - return(-1); numitems = 0; arraysz = 32; /* initial estimate of the array size */ @@ -138,6 +134,30 @@ fail: return (-1); } +int +#ifdef I_AM_SCANDIR_B +scandir_b(const char *dirname, struct dirent ***namelist, select_block select, + dcomp_block dcomp) +#else +scandir(const char *dirname, struct dirent ***namelist, + int (*select)(const struct dirent *), int (*dcomp)(const struct dirent **, + const struct dirent **)) +#endif +{ + DIR *dirp; + + dirp = opendir(dirname); + if (dirp == NULL) + return (-1); + return ( +#ifdef I_AM_SCANDIR_B + scandir_b_dirp +#else + scandir_dirp +#endif + (dirp, namelist, select, dcomp)); +} + #ifndef I_AM_SCANDIR_B /* * Alphabetic order comparison routine for those who want it.