aboutsummaryrefslogtreecommitdiff
path: root/library.c
diff options
context:
space:
mode:
authorPetr Machata <pmachata@redhat.com>2013-01-07 18:09:32 +0100
committerPetr Machata <pmachata@redhat.com>2013-03-08 22:55:31 +0100
commitb1ab2aefa199ea8e14e29bac78ae71030c2d4863 (patch)
treedaf37ac44f5b412fc2788708abf1effcf721b7df /library.c
parent395a4e3ad6b03949fbe0a2818bfdec738da1c281 (diff)
downloadltrace-b1ab2aefa199ea8e14e29bac78ae71030c2d4863.tar.gz
Consolidate two duplicate conditional strdup wrappers to strdup_if
- Convert callers in prototype.c and library.c - Current placement in library.c is somewhat arbitrary. There currently doesn't seem to be a more suitable place. - The behavior subtly changed: in case of failure, RET is now unaffected.
Diffstat (limited to 'library.c')
-rw-r--r--library.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/library.c b/library.c
index d894663..a2f3fa5 100644
--- a/library.c
+++ b/library.c
@@ -1,6 +1,6 @@
/*
* This file is part of ltrace.
- * Copyright (C) 2011,2012 Petr Machata, Red Hat Inc.
+ * Copyright (C) 2011,2012,2013 Petr Machata, Red Hat Inc.
* Copyright (C) 2001,2009 Juan Cespedes
* Copyright (C) 2006 Ian Wienand
*
@@ -90,19 +90,17 @@ arch_addr_eq(const arch_addr_t *addr1, const arch_addr_t *addr2)
return *addr1 == *addr2;
}
-/* If the other symbol owns the name, we need to make the copy, so
- * that the life-times of the two symbols are not dependent on each
- * other. */
-static int
-strdup_if_owned(const char **retp, const char *str, int owned)
+int
+strdup_if(const char **retp, const char *str, int whether)
{
- if (!owned || str == NULL) {
- *retp = str;
- return 0;
- } else {
- *retp = strdup(str);
- return *retp != NULL ? 0 : -1;
+ if (whether && str != NULL) {
+ str = strdup(str);
+ if (str == NULL)
+ return -1;
}
+
+ *retp = str;
+ return 0;
}
static void
@@ -154,8 +152,10 @@ library_symbol_destroy(struct library_symbol *libsym)
int
library_symbol_clone(struct library_symbol *retp, struct library_symbol *libsym)
{
+ /* Make lifetimes of name stored at original independent of
+ * the one at the clone. */
const char *name;
- if (strdup_if_owned(&name, libsym->name, libsym->own_name) < 0)
+ if (strdup_if(&name, libsym->name, libsym->own_name) < 0)
return -1;
private_library_symbol_init(retp, libsym->enter_addr,
@@ -262,9 +262,11 @@ library_clone(struct library *retp, struct library *lib)
{
const char *soname = NULL;
const char *pathname;
- if (strdup_if_owned(&soname, lib->soname, lib->own_soname) < 0
- || strdup_if_owned(&pathname,
- lib->pathname, lib->own_pathname) < 0) {
+
+ /* Make lifetimes of strings stored at original independent of
+ * those at the clone. */
+ if (strdup_if(&soname, lib->soname, lib->own_soname) < 0
+ || strdup_if(&pathname, lib->pathname, lib->own_pathname) < 0) {
if (lib->own_soname)
free((char *)soname);
return -1;