1 /* $NetBSD: str.c,v 1.26 2009/02/02 12:35:01 joerg Exp $ */
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
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.
28 * Miscellaneous string utilities.
44 /* pull in definitions and macros for resizing arrays as we go */
48 * Return the suffix portion of a path
51 suffix_of(const char *str
)
55 return ((dot
= strrchr(basename_of(str
), '.')) == NULL
) ? "" : dot
+ 1;
59 * Return the filename portion of a path
62 basename_of(const char *str
)
66 return ((slash
= strrchr(str
, '/')) == NULL
) ? str
: slash
+ 1;
70 * Return the dirname portion of a path
73 dirname_of(const char *path
)
77 static char buf
[MaxPathSize
];
79 if ((s
= strrchr(path
, '/')) == NULL
) {
83 /* "/foo" -> 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
);
95 * Does the pkgname contain any of the special chars ("{[]?*<>")?
96 * If so, return 1, else 0
99 ispkgpattern(const char *pkg
)
101 return strpbrk(pkg
, "<>[]?*{") != NULL
;