NetBSD/external/bsd/pkg_install/dist/lib/str.c
joerg d66ee6c3fd Import pkg_install-20090201. From the branch merge in pkgsrc:
- DB support is always included from libnbcompat if needed
- pkg_view and linkfarm are not installed any more; they are not moved
into the attic yet, so they can easily be installed as separte package
- common configuration file to customise the behavior of various
components; this supersedes the old audit-packages.conf
- support for PKSC7 signatures (using X509 certs) and GPG signatures for
packages in a secure way. See pkg_admin(8) for how to create them and
pkg_install.conf(5) for the options to use them
- audit-packages and download-vulnerability-list are wrapper scripts
  around pkg_admin. They try to mimic the classic options if used
  sanely.
  "pkg_admin audit" is now an order of magnitude faster than before
- pkg_add uses libarchive and libfetch instead of external ftp and tar:
  - progress bar is currently missing for downloads
  - "pkg_add -" is no longer supported
  - no adhoc check for conficts between dependencies and already
    installed packages
  - "pkg_add -s" has been replaced with an option in pkg_install.conf,
    verification of plain detached GPG signatures is no longer supported
  - optional check for vulnerabilities before adding a package
  - if /var and /usr/pkg are on different fileystems it is twice as fast
    now
  - conflicts due to overlapping plists are checked before installation
  - pkg_add no longer plays with the process limits
  - pkg_add and pkg_delete have a new destdir option; scripts have to
    either be modified to use PKG_DESTDIR or should be disabled
- pkg_add -u for now can't be used to update to the exact same version
- internal "rm -rf" and "mkdir_p" code
- all memory allocation failures are not explicitly fatal
- if a file is not removed due to a failed checksum, still remove the
  entry from pkgdb
2009-02-02 20:44:00 +00:00

103 lines
2.1 KiB
C

/* $NetBSD: str.c,v 1.1.1.2 2009/02/02 20:44:08 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <nbcompat.h>
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
__RCSID("$NetBSD: str.c,v 1.1.1.2 2009/02/02 20:44:08 joerg Exp $");
/*
* FreeBSD install - a package for the installation and maintainance
* of non-core utilities.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Jordan K. Hubbard
* 18 July 1993
*
* Miscellaneous string utilities.
*
*/
#if HAVE_ASSERT_H
#include <assert.h>
#endif
#if HAVE_ERR_H
#include <err.h>
#endif
#if HAVE_FNMATCH_H
#include <fnmatch.h>
#endif
#include "lib.h"
#include "dewey.h"
/* pull in definitions and macros for resizing arrays as we go */
#include "defs.h"
/*
* Return the suffix portion of a path
*/
const char *
suffix_of(const char *str)
{
const char *dot;
return ((dot = strrchr(basename_of(str), '.')) == NULL) ? "" : dot + 1;
}
/*
* Return the filename portion of a path
*/
const char *
basename_of(const char *str)
{
const char *slash;
return ((slash = strrchr(str, '/')) == NULL) ? str : slash + 1;
}
/*
* Return the dirname portion of a path
*/
const char *
dirname_of(const char *path)
{
size_t cc;
char *s;
static char buf[MaxPathSize];
if ((s = strrchr(path, '/')) == NULL) {
return ".";
}
if (s == path) {
/* "/foo" -> return "/" */
return "/";
}
cc = (size_t) (s - path);
if (cc >= sizeof(buf))
errx(EXIT_FAILURE, "dirname_of: too long dirname: '%s'", path);
(void) memcpy(buf, path, cc);
buf[cc] = 0;
return buf;
}
/*
* Does the pkgname contain any of the special chars ("{[]?*<>")?
* If so, return 1, else 0
*/
int
ispkgpattern(const char *pkg)
{
return strpbrk(pkg, "<>[]?*{") != NULL;
}