diff options
author | jschauma <jschauma@pkgsrc.org> | 2005-01-27 20:42:23 +0000 |
---|---|---|
committer | jschauma <jschauma@pkgsrc.org> | 2005-01-27 20:42:23 +0000 |
commit | f683d8cb1e31c83d1b48e00adccabeaa368cb06a (patch) | |
tree | 57ed0b92d3821ba9c0eeef6891740a0bd12abd8d /pkgtools/pkgfind/files/pkgfind.c | |
parent | a04dce0954a4a0bdb8e82f1fda473e8700f0f660 (diff) | |
download | pkgsrc-f683d8cb1e31c83d1b48e00adccabeaa368cb06a.tar.gz |
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 (limited to 'pkgtools/pkgfind/files/pkgfind.c')
-rw-r--r-- | pkgtools/pkgfind/files/pkgfind.c | 33 |
1 files changed, 20 insertions, 13 deletions
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 <sys/param.h> #include <sys/stat.h> -#include <ctype.h> +#ifdef NEED_LIBNBCOMPAT +#include <nbcompat.h> +#else #include <err.h> +#endif + +#include <ctype.h> #include <dirent.h> #include <stdio.h> #include <stdlib.h> @@ -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); } |