commit:     1cffb01452f2553747be26778ef4f84425e45554
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Mon May 25 10:30:52 2020 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Mon May 25 10:30:52 2020 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=1cffb014

libq/tree: slightly optimise tree_open_pkg

don't construct a new path, but open at the existing filedescriptor
instead.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 libq/tree.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/libq/tree.c b/libq/tree.c
index ebcc133..7fbb739 100644
--- a/libq/tree.c
+++ b/libq/tree.c
@@ -27,7 +27,7 @@
 #include <xalloc.h>
 
 static int tree_pkg_compar(const void *l, const void *r);
-static tree_pkg_ctx * tree_next_pkg_int(tree_cat_ctx *cat_ctx);
+static tree_pkg_ctx *tree_next_pkg_int(tree_cat_ctx *cat_ctx);
 static void tree_close_meta(tree_pkg_meta *cache);
 
 static tree_ctx *
@@ -132,18 +132,19 @@ tree_ctx *
 tree_open_binpkg(const char *sroot, const char *spkg)
 {
        tree_ctx *ret = tree_open_int(sroot, spkg, true);
-       char buf[_Q_PATH_MAX];
+       int fd;
 
        if (ret != NULL) {
                ret->cachetype = CACHE_BINPKGS;
 
-               snprintf(buf, sizeof(buf), "%s%s/%s", sroot, spkg, 
binpkg_packages);
-               if (eat_file(buf, &ret->pkgs, &ret->pkgslen)) {
+               fd = openat(ret->tree_fd, binpkg_packages, O_RDONLY | 
O_CLOEXEC);
+               if (eat_file_fd(fd, &ret->pkgs, &ret->pkgslen)) {
                        ret->cachetype = CACHE_PACKAGES;
                } else if (ret->pkgs != NULL) {
                        free(ret->pkgs);
                        ret->pkgs = NULL;
                }
+               close(fd);
        }
 
        return ret;

Reply via email to