diff options
author | Mike Frysinger <vapier@gentoo.org> | 2014-03-10 03:12:02 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2014-03-10 03:12:02 -0400 |
commit | 054269125460aadf20059019a7a106800160c69a (patch) | |
tree | 70a960da7c38d2ca2df705b06094a703e31e160a /qdepends.c | |
parent | qmerge: fix color used in displaying downgrades (diff) | |
download | portage-utils-054269125460aadf20059019a7a106800160c69a.tar.gz portage-utils-054269125460aadf20059019a7a106800160c69a.tar.bz2 portage-utils-054269125460aadf20059019a7a106800160c69a.zip |
eat_file: convert API to work on dynamic buffers
Rather than use static allocated buffers everywhere where we assume we
picked a size big enough for real world uses (and just silently truncate
or die in large edge cases), convert the API to use malloc instead. We
will grow the buffers (never shrink) so that repeat calls should ramp up
to the max quickly and thus avoid having to call malloc() repeatedly.
This might report memory leaks with some funcs as we hold on to some
buffers indefinitely since we know the buffer isn't used outside the
context of the func. Helps out when the func is called repeatedly.
This should make future enhancements (like eating more than one element
in a vdb pkg dir) a lot easier.
Diffstat (limited to 'qdepends.c')
-rw-r--r-- | qdepends.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -396,7 +396,8 @@ _q_static int qdepends_main_vdb_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv) int i; char *ptr; char buf[_Q_PATH_MAX]; - char depend[65536], use[8192]; + static char *depend, *use; + static size_t depend_len, use_len; dep_node *dep_tree; /* see if this cat/pkg is requested */ @@ -412,7 +413,7 @@ _q_static int qdepends_main_vdb_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv) IF_DEBUG(warn("matched %s/%s", catname, pkgname)); - if (!eat_file_at(pkg_ctx->fd, state->depend_file, depend, sizeof(depend))) + if (!eat_file_at(pkg_ctx->fd, state->depend_file, &depend, &depend_len)) return 0; IF_DEBUG(warn("growing tree...")); @@ -433,7 +434,7 @@ _q_static int qdepends_main_vdb_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv) printf("%s%s/%s%s%s: ", BOLD, catname, BLUE, pkgname, NORM); } - if (!eat_file_at(pkg_ctx->fd, "USE", use, sizeof(use))) { + if (!eat_file_at(pkg_ctx->fd, "USE", &use, &use_len)) { warn("Could not eat_file(%s), you'll prob have incorrect output", buf); } else { for (ptr = use; *ptr; ++ptr) @@ -466,12 +467,13 @@ _q_static int qdepends_vdb_deep_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv) size_t len; char *ptr; char buf[_Q_PATH_MAX]; - char depend[16384], use[8192]; + static char *depend, *use; + static size_t depend_len, use_len; dep_node *dep_tree; IF_DEBUG(warn("matched %s/%s for %s", catname, pkgname, state->depend_file)); - if (!eat_file_at(pkg_ctx->fd, state->depend_file, depend, sizeof(depend))) + if (!eat_file_at(pkg_ctx->fd, state->depend_file, &depend, &depend_len)) return 0; IF_DEBUG(warn("growing tree...")); @@ -481,7 +483,7 @@ _q_static int qdepends_vdb_deep_cb(q_vdb_pkg_ctx *pkg_ctx, void *priv) IF_DEBUG(puts(depend)); IF_DEBUG(dep_dump_tree(dep_tree)); - if (eat_file_at(pkg_ctx->fd, "USE", use, sizeof(use)) == 1) + if (eat_file_at(pkg_ctx->fd, "USE", &use, &use_len)) use[0] = ' '; for (ptr = use; *ptr; ++ptr) |