From f683d8cb1e31c83d1b48e00adccabeaa368cb06a Mon Sep 17 00:00:00 2001 From: jschauma Date: Thu, 27 Jan 2005 20:42:23 +0000 Subject: Make this a bit more portable: - get rid of asprintf - use libnbcompat if necessary - while here, get rid of unused variable Bump date. ok peter@, tv@ Non-NetBSD platforms may need to test this and adjust following the IRIX example. --- pkgtools/pkgfind/Makefile | 10 ++++++---- pkgtools/pkgfind/files/pkgfind.c | 33 ++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/pkgtools/pkgfind/Makefile b/pkgtools/pkgfind/Makefile index a9ce70eeb9f..c2d9b93d00d 100644 --- a/pkgtools/pkgfind/Makefile +++ b/pkgtools/pkgfind/Makefile @@ -1,6 +1,6 @@ -# $NetBSD: Makefile,v 1.7 2005/01/25 23:39:30 cube Exp $ +# $NetBSD: Makefile,v 1.8 2005/01/27 20:42:23 jschauma Exp $ -DISTNAME= pkgfind-20050125 +DISTNAME= pkgfind-20050127 CATEGORIES= pkgtools MASTER_SITES= # empty DISTFILES= # empty @@ -34,8 +34,10 @@ SUBST_MESSAGE.path= "Adjusting pkgsrc directory." .include "../../mk/bsd.prefs.mk" -.if ${OPSYS} == "Interix" -. include "../../devel/libiberty/application.mk" # need asprintf(3) +.if ${OPSYS} == "IRIX" +CFLAGS+= -DNEED_LIBNBCOMPAT +LDFLAGS+= -lnbcompat +. include "../../pkgtools/libnbcompat/buildlink3.mk" # need err(1), warn(1) .endif .include "../../mk/bsd.pkg.mk" diff --git a/pkgtools/pkgfind/files/pkgfind.c b/pkgtools/pkgfind/files/pkgfind.c index 06013d4b4be..b4b12327647 100644 --- a/pkgtools/pkgfind/files/pkgfind.c +++ b/pkgtools/pkgfind/files/pkgfind.c @@ -38,8 +38,13 @@ #include #include -#include +#ifdef NEED_LIBNBCOMPAT +#include +#else #include +#endif + +#include #include #include #include @@ -63,7 +68,7 @@ static void usage(void); static int (*search)(const char *, const char *); -static int Cflag, cflag, qflag, xflag; +static int Cflag, cflag, qflag; int main(int argc, char *argv[]) @@ -71,10 +76,12 @@ main(int argc, char *argv[]) const char *path; int ch; + setprogname("pkgfind"); + /* default searches have partial matches */ search = partialmatch; - Cflag = cflag = qflag = xflag = 0; + Cflag = cflag = qflag = 0; while ((ch = getopt(argc, argv, "Ccqx")) != -1) { switch (ch) { @@ -165,18 +172,20 @@ static void showpkg(const char *path, const char *cat, const char *pkg) { char *mk, *comment = NULL; + size_t len; + + len = strlen(path) + strlen(cat) + strlen(pkg) + strlen("Makefile") + 3 + 1; if (!qflag) { - (void)asprintf(&mk, "%s/%s/%s/Makefile", path, cat, pkg); - if (mk == NULL) - err(EXIT_FAILURE, "asprintf"); + if ((mk = malloc(len)) == NULL) + err(EXIT_FAILURE, "malloc"); + (void)snprintf(mk, len, "%s/%s/%s/Makefile", path, cat, pkg); if (getcomment(mk, &comment) == 0) { - free(mk); - (void)asprintf(&mk, "%s/%s/%s/Makefile.common", + if ((mk = realloc(mk, len + 7)) == NULL) + err(EXIT_FAILURE, "malloc"); + (void)snprintf(mk, len+7, "%s/%s/%s/Makefile.common", path, cat, pkg); - if (mk == NULL) - err(EXIT_FAILURE, "asprintf"); (void)getcomment(mk, &comment); } free(mk); @@ -259,8 +268,6 @@ exactmatch(const char *s, const char *find) static void usage(void) { - extern char *__progname; - - (void)fprintf(stderr, "Usage: %s [-Ccqx] keyword [...]\n", __progname); + (void)fprintf(stderr, "Usage: %s [-Ccqx] keyword [...]\n", getprogname()); exit(EXIT_FAILURE); } -- cgit v1.2.3