Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/package.c
diff options
context:
space:
mode:
authorAurelien Foret <aurelien@archlinux.org>2005-04-08 20:43:13 +0000
committerAurelien Foret <aurelien@archlinux.org>2005-04-08 20:43:13 +0000
commit7775afa59b62ff47fb2bac9f9f10ae8c53cb6eb4 (patch)
treef3fd8ae2406fc7d5da5dccd175f8efbee6d96dd2 /lib/libalpm/package.c
parent70481b0ee1e308de56b353b5932556326fa6474e (diff)
added function pkg_splitname (not used for now)
Diffstat (limited to 'lib/libalpm/package.c')
-rw-r--r--lib/libalpm/package.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 622fd99b..7e0854de 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -338,4 +338,47 @@ int pkg_isin(pmpkg_t *needle, PMList *haystack)
return(0);
}
+int pkg_splitname(char *target, char *name, char *version)
+{
+ char tmp[(PKG_NAME_LEN-1)+1+(PKG_VERSION_LEN-1)+7+1];
+ char *p, *q;
+
+ if(target == NULL) {
+ return(-1);
+ }
+
+ /* trim path name (if any) */
+ if((p = strrchr(target, '/')) == NULL) {
+ p = target;
+ } else {
+ p++;
+ }
+ STRNCPY(tmp, p, (PKG_NAME_LEN-1)+1+(PKG_VERSION_LEN-1)+7+1);
+ /* trim file extension (if any) */
+ if((p = strstr(tmp, PM_EXT_PKG))) {
+ *p = 0;
+ }
+
+ p = tmp + strlen(tmp);
+
+ for(q = --p; *q && *q != '-'; q--);
+ if(*q != '-' || q == tmp) {
+ return(-1);
+ }
+ for(p = --q; *p && *p != '-'; p--);
+ if(*p != '-' || p == tmp) {
+ return(-1);
+ }
+ if(version) {
+ STRNCPY(version, p+1, PKG_VERSION_LEN);
+ }
+ *p = 0;
+
+ if(name) {
+ STRNCPY(name, tmp, PKG_NAME_LEN);
+ }
+
+ return(0);
+}
+
/* vim: set ts=2 sw=2 noet: */