pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/pkgfind Make this a bit more portable:



details:   https://anonhg.NetBSD.org/pkgsrc/rev/de6d19293cbc
branches:  trunk
changeset: 488314:de6d19293cbc
user:      jschauma <jschauma%pkgsrc.org@localhost>
date:      Thu Jan 27 20:42:23 2005 +0000

description:
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.

diffstat:

 pkgtools/pkgfind/Makefile        |  10 ++++++----
 pkgtools/pkgfind/files/pkgfind.c |  33 ++++++++++++++++++++-------------
 2 files changed, 26 insertions(+), 17 deletions(-)

diffs (104 lines):

diff -r 34d032273ebd -r de6d19293cbc pkgtools/pkgfind/Makefile
--- a/pkgtools/pkgfind/Makefile Thu Jan 27 20:40:20 2005 +0000
+++ b/pkgtools/pkgfind/Makefile Thu Jan 27 20:42:23 2005 +0000
@@ -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 @@
 
 .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 -r 34d032273ebd -r de6d19293cbc pkgtools/pkgfind/files/pkgfind.c
--- a/pkgtools/pkgfind/files/pkgfind.c  Thu Jan 27 20:40:20 2005 +0000
+++ b/pkgtools/pkgfind/files/pkgfind.c  Thu Jan 27 20:42:23 2005 +0000
@@ -38,8 +38,13 @@
 #include <sys/param.h>
 #include <sys/stat.h>
 
+#ifdef NEED_LIBNBCOMPAT
+#include <nbcompat.h>
+#else
+#include <err.h>
+#endif
+
 #include <ctype.h>
-#include <err.h>
 #include <dirent.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -63,7 +68,7 @@
 
 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 @@
        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 @@
 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 @@
 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);
 }



Home | Main Index | Thread Index | Old Index