Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / bsd / pkg_install / dist / lib / str.c
blobb190a1e8a77e983d01a521e0cdf4bad7ca8469d9
1 /* $NetBSD: str.c,v 1.26 2009/02/02 12:35:01 joerg Exp $ */
3 #if HAVE_CONFIG_H
4 #include "config.h"
5 #endif
6 #include <nbcompat.h>
7 #if HAVE_SYS_CDEFS_H
8 #include <sys/cdefs.h>
9 #endif
10 __RCSID("$NetBSD: str.c,v 1.26 2009/02/02 12:35:01 joerg Exp $");
13 * FreeBSD install - a package for the installation and maintainance
14 * of non-core utilities.
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
25 * Jordan K. Hubbard
26 * 18 July 1993
28 * Miscellaneous string utilities.
32 #if HAVE_ASSERT_H
33 #include <assert.h>
34 #endif
35 #if HAVE_ERR_H
36 #include <err.h>
37 #endif
38 #if HAVE_FNMATCH_H
39 #include <fnmatch.h>
40 #endif
41 #include "lib.h"
42 #include "dewey.h"
44 /* pull in definitions and macros for resizing arrays as we go */
45 #include "defs.h"
48 * Return the suffix portion of a path
50 const char *
51 suffix_of(const char *str)
53 const char *dot;
55 return ((dot = strrchr(basename_of(str), '.')) == NULL) ? "" : dot + 1;
59 * Return the filename portion of a path
61 const char *
62 basename_of(const char *str)
64 const char *slash;
66 return ((slash = strrchr(str, '/')) == NULL) ? str : slash + 1;
70 * Return the dirname portion of a path
72 const char *
73 dirname_of(const char *path)
75 size_t cc;
76 char *s;
77 static char buf[MaxPathSize];
79 if ((s = strrchr(path, '/')) == NULL) {
80 return ".";
82 if (s == path) {
83 /* "/foo" -> return "/" */
84 return "/";
86 cc = (size_t) (s - path);
87 if (cc >= sizeof(buf))
88 errx(EXIT_FAILURE, "dirname_of: too long dirname: '%s'", path);
89 (void) memcpy(buf, path, cc);
90 buf[cc] = 0;
91 return buf;
95 * Does the pkgname contain any of the special chars ("{[]?*<>")?
96 * If so, return 1, else 0
98 int
99 ispkgpattern(const char *pkg)
101 return strpbrk(pkg, "<>[]?*{") != NULL;