diff options
author | Guillem Jover <guillem@debian.org> | 2010-11-03 09:41:29 +0100 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2010-11-19 05:21:15 +0100 |
commit | b070e0ec0d33b585809dd420e0433a4f67ca12c0 (patch) | |
tree | dbc11294af217523dba2ff97639631db943c9893 /lib | |
parent | 04eaf265a0b219ed8689607196405fdff9a4a432 (diff) | |
download | dpkg-b070e0ec0d33b585809dd420e0433a4f67ca12c0.tar.gz |
libdpkg: Rewrite get_prefix_name() to be more efficient
Avoid temporary allocations from the heap and use sprintf to write the
string with delimited parts.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dpkg/tarfn.c | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/lib/dpkg/tarfn.c b/lib/dpkg/tarfn.c index 564b4ee24..fff39a534 100644 --- a/lib/dpkg/tarfn.c +++ b/lib/dpkg/tarfn.c @@ -95,26 +95,17 @@ StoC(const char *s, int size) return str; } -/* FIXME: Rewrite using varbuf, once it supports the needed functionality. */ static char * get_prefix_name(struct tar_header *h) { - char *prefix, *name, *s; + char *path; - /* The size is not going to be bigger than that. */ - s = m_malloc(257); + path = m_malloc(sizeof(h->prefix) + 1 + sizeof(h->name) + 1); - prefix = StoC(h->prefix, sizeof(h->prefix)); - name = StoC(h->name, sizeof(h->name)); + sprintf(path, "%.*s/%.*s", (int)sizeof(h->prefix), h->prefix, + (int)sizeof(h->name), h->name); - strcpy(s, prefix); - strcat(s, "/"); - strcat(s, name); - - free(prefix); - free(name); - - return s; + return path; } static mode_t |