From 94265c64d4111f45786d6d876e27bb3f8fa96d99 Mon Sep 17 00:00:00 2001 From: enami Date: Tue, 7 Sep 2004 02:54:40 +0000 Subject: [PATCH] Fix default format so that not to print NULL (e.g., ldd mozilla-bin). --- usr.bin/ldd/ldd_elf/ldd.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/usr.bin/ldd/ldd_elf/ldd.c b/usr.bin/ldd/ldd_elf/ldd.c index 391793fce7bc..58d8aa6d1293 100644 --- a/usr.bin/ldd/ldd_elf/ldd.c +++ b/usr.bin/ldd/ldd_elf/ldd.c @@ -1,4 +1,4 @@ -/* $NetBSD: ldd.c,v 1.24 2004/05/23 06:51:05 skrll Exp $ */ +/* $NetBSD: ldd.c,v 1.25 2004/09/07 02:54:40 enami Exp $ */ /*- * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc. @@ -255,22 +255,26 @@ fmtprint(const char *libname, Obj_Entry *obj, const char *fmt1, char *cp; int c; - if (fmt1 == NULL) - fmt1 = "\t-l%o.%m => %p\n"; - if (fmt2 == NULL) - fmt2 = "\t%o => %p\n"; - - if (strncmp(libname, "lib", 3) == 0 - && (cp = strstr(libname, ".so")) != NULL) { + if (strncmp(libname, "lib", 3) == 0 && + (cp = strstr(libname, ".so")) != NULL) { int i = cp - (libname + 3); + if (i >= sizeof(libnamebuf)) i = sizeof(libnamebuf) - 1; (void)memcpy(libnamebuf, libname + 3, i); - libnamebuf[i] = '\0'; - if (cp[3] && isdigit((unsigned char)cp[4])) - libmajor = &cp[4]; - libname = libnamebuf; + libnamebuf[i] = '\0'; + if (cp[3] && isdigit((unsigned char)cp[4])) + libmajor = &cp[4]; + libname = libnamebuf; } + + if (fmt1 == NULL) + fmt1 = libmajor != NULL ? + "\t-l%o.%m => %p\n" : + "\t-l%o => %p\n"; + if (fmt2 == NULL) + fmt2 = "\t%o => %p\n"; + fmt = libname == libnamebuf ? fmt1 : fmt2; while ((c = *fmt++) != '\0') { switch (c) {